|
- /*6月28日 星期一
- ;張培
- ;本程序用中斷實(shí)現(xiàn)數(shù)碼管0-99顯示 */
- #include <reg51.h>
- #define unit unsigned int
- #define uchar unsigned char
- bit BT0;
- void delay(unit n);
- main()
- {
- unit b[10]={0x0C0,0x0F9,0x0A4,0x0B0,0x99,0x92,0x82,0x0F8,0x80,0x90};
- unit a,d,timecount;
- uchar x;
- TMOD=0X01;//T0工作方式1
- TH0=0X0B1;
- TL0=0X0E0;
- TR0=1;//開啟T0
- EA=1;//開啟總中斷
- ET0=1;//開啟T0中斷
- timecount=25;
-
- d=10;
- a=0;
- while (1)
- {
-
- x=a/d;//把A的十位分離
- P2=b[x];//查數(shù)組表
- P3=0X01;//開十位片選
- delay(1);//動(dòng)態(tài)掃描
- P3=0X00;//關(guān)十位片選
- x=a%d;//把A的個(gè)位分離
- P2=b[x];//查數(shù)組表
- P3=0X02;//開個(gè)位片選
- delay(1);//動(dòng)態(tài)掃描
- P3=0X00;//關(guān)十位片選
-
- if (BT0==1)//等待中斷的到來
- BT0=1;
- if (timecount==0)//如果到了0.5S,A加1
- {a=a+1;
- timecount=25;
- }
- else
- timecount--;
- }
- }
- void delay(unit n)//延時(shí)程序
- { unit y;
- unit j;
- for (y=n;y>0;y--)
- for(j=5000;j>0;j--)
- {;}
- }void T0SER (void) interrupt 1 using 1//T0重新賦初植
- {
- TH0=0X0B1;
- TL0=0X0E0;
- BT0=1;
-
- }
復(fù)制代碼
|
|