|
- #include <reg51.h>
- #define uchar unsigned char; #define uint unsigned int; sbit P3_4 = P3^4;
- uchar digit1[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar digit2[10] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef}; uchar Union[6] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb}; uchar Time[6], i, j, count, num;
- uchar INH = 15536/256, INL = 15536%256; /****初始化时间*****/ void Init(){
- for(i = 0; i < 6; i++){ Time[i] = 0; }
- count = 0, num = 0; }
- /****延时1ms*****/ void Delay(){
- unsigned int i;
- for(i = 0; i < 500; i++); }
- /********更新时间*******/ void Update(){
- if(num == 0) j = 5; else j = 5-(num-1)*2; Time[j] += 1;
- for(i = j; i > 1; i -= 2){ if(Time[i] == 10){ Time[i] = 0;
- if(++Time[i-1] == 6){
- Time[i-1] = 0, Time[i-2]++; }
- else return; }
- else return; }
- if(Time[0] != 2 && Time[1] == 10){ Time[0]++, Time[1] = 0; }
- else if(Time[0] == 2 && Time[1] == 4){ Time[0] = 0, Time[1] = 0; } }
- /******显示时间********/ void Play(){
- for(i = 0; i < 6; i++){ P1 = Union[i];
- if(i%2 == 0 || i == 5){ P0 = digit1[Time[i]]; } else{
- P0 = digit2[Time[i]]; }
- Delay(); } }
- /*******外部中断0******/ void Int0() interrupt 0 using 0{ if(++num == 4){
- TR0 = 1, num = 0; } else{
- TR0 = 0, TH0 = INH, TL0 = INL; } }
- /*****定时器0中断********/ void Int1() interrupt 1 using 1{ if(++count == 20){
- count = 0, Update(); }
- TH0 = INH, TL0 = INL; }
- /******外部中断1******/ void Int2() interrupt 2 using 2{ Update(); }
- void main(){
- PX0 = 1, PT0 = 0, PX1 = 1; P1 = 0, Init();
- EA = 1, ET0 = 1, TMOD = 0X01; TH0 = INH, TL0 = INL, TR0 = 1; EX0 = 1, IT0 = 1; EX1 = 1, IT1 = 1; while(1){ Play(); } }
复制代码
|
|