|
- /*
- *平臺(tái):Keil U4+STC89C52
- *名稱(chēng):/*
- *平臺(tái):Keil U4+STC89C52
- *名稱(chēng):P1.0輸出1HZ方波,送入定時(shí)器T0,計(jì)的數(shù)通過(guò)數(shù)碼管的方式顯示出來(lái),
- 最多顯示到99,超過(guò)以后重新回到0。
- *日期:2017.11.19*/
- #include<reg52.h>
- #define WEI0 P1=0xfd; //定義位選引腳
- #define WEI1 P1=0xfb;
- int m=1;
- unsigned int count;//用來(lái)計(jì)數(shù)
- //unsigned int i,j;
- //定義一個(gè)數(shù)組,將0~9對(duì)應(yīng)的編碼存入數(shù)組
- unsigned char n[] = {0xc0,0xf9,0xa4,0xb0,
- 0x99,0x92,0x82,0xf8,
- 0x80,0x90};
- sbit LED=P1^0;
- void timer0();//函數(shù)聲明
- /*定時(shí)器T0,工作方式2,200微秒發(fā)起一次中斷*/
- void timer0()
- {
- TMOD=0x02;
- TH0=0x48;//初始化TH0和TL0
- TL0=0x48; //每隔200微秒發(fā)起一次中斷
- ET0=1;//開(kāi)啟T0中斷
- EA=1;//開(kāi)啟總中斷
- TR0=1;//打開(kāi)T0定時(shí)器
- count=0;//count初始值為零
- }
- void SMG_display(int a,int b);//聲明顯示函數(shù)
- void SMG_display(int a,int b)
- {
- switch(m)
- {
- case 0x01: P0=0xff;WEI1;P0=n[a];m++; break;
- case 0x02: P0=0xff;WEI0;P0=n[ b];m=1; break;
- default: break;
- }
- }
- void main()
- {
- int a,b;
- LED=1; //關(guān)閉LED
- timer0();//
- while(1)
- {
- for(b=0;b<10;b++)
- {
- for(a=0;a<10;)
- {
- SMG_display(a,b);
- if(count<=2500)
- {
- LED=0;
- }
- if(count>2500&&count<=4999)
- {
- LED=1;
- }
- if(count==5000)
- {
- LED=0;
- count=0;
- a++;
- }
- }
- }
- P0=1; //關(guān)閉數(shù)碼管
- }
- }
- void timer() interrupt 1
- {
- count++;//每次中斷count+1
- }
復(fù)制代碼
|
|