// 用定時(shí)器1定時(shí),使用方式一,晶振頻率為11.0592MHZ,常數(shù)為4C00; //用外部中斷一計(jì)數(shù),每中斷一次,count加一 //使用P1口接的八個(gè)發(fā)光二極管顯示 //本程序?yàn)橐粋(gè)網(wǎng)友應(yīng)邀而寫,在硬件上測試通過,在低頻率時(shí),效果不錯(cuò). #include<reg51.h> unsigned int t1oc=20;//5000; unsigned int count=0,precount; void display(unsigned int dis) { P1=dis;//顯示語句 } void t1int() interrupt 3 { TR1=0; t1oc--; TH1=0x4c;//72;//56; TL1=0x00;//72;//56; if(t1oc==0) { t1oc=20;//5000; precount=count; count=0; } TR1=1; } void int0int() interrupt 0 { EX0=1; count++; EX0=0; } void main(void) { TMOD=0x10;//0x20; TH1=0x4c;//72;//56; TL1=0x00;//72;//56; EA=1; EX0=1;IT0=1; ET1=1; TR1=1; while(1) { display(precount); } }
|