我写了一个24秒倒计时的程序 想添加按键去控制暂停 继续 等功能 我应该把按键程序添加在什么位置 该怎么去写
这是我的程序:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit dula=P2^6;
- sbit wela=P2^7;
- sbit key1=P3^4;
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x40};
- uchar code tablefen[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f};
- uchar code tablemiao[]={0x3f,0x7d,0x6f,0x4f,0x7d,0x6f,0x4f,0x7d,0x6f};
- uchar num,num1,num2,num3,ge,shi,fen,miao;
- void delayms(uint);
- void display(uchar,uchar);
- void display1(uchar,uchar);
- void main()
- {
- dula=1;
- P0=table[2];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfe;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[4];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfd;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[10];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfb;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[10];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xf7;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[0];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xef;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[0];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xdf;
- wela=0;
- delayms(1);
- num1=24;
- shi=2;
- ge=3;
- fen=0;
- miao=0;
- TMOD=0x11;
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- TH1=(65536-45872)/256;
- TL1=(65536-45872)%256;
- EA=1;
- ET0=1;
- ET1=1;
- TR0=1;
- TR1=1;
- while(1)
- {
- display1(fen,miao);
- display(shi,ge);
- }
- }
- void display(uchar shi, uchar ge)
- {
- dula=1;
- P0=table[shi];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfe;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[ge];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfd;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[10];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xfb;
- wela=0;
- delayms(1);
- dula=1;
- P0=table[10];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xf7;
- wela=0;
- delayms(1);
- }
- void display1(uchar fen,uchar miao)
- {
-
- dula=1;
- P0=tablefen[fen];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xef;
- wela=0;
- delayms(1);
- dula=1;
- P0=tablemiao[miao];
- dula=0;
- P0=0xff;
- wela=1;
- P0=0xdf;
- wela=0;
- delayms(1);
- }
- void delayms(uint xms)
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--);
- }
- void exter1() interrupt 3
- {
- TH1=(65536-45872)/256;
- TL1=(65536-45872)%256;
- num2++;
- if(num2==2)
- {
- num2=0;
- if(fen==0)
- fen=9;
- if(miao==0)
- miao=9;
- fen--;
- miao--;
- }
- }
- void exter0() interrupt 1
- {
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- num++;
- if(num==20)
- {
- num=0;
- num1--;
- if(num1==0)
- {
- P1=0xfe;
- delayms(50);
- P1=0xff;
- }
- if(num1==0)
- num1=23;
- shi=num1/10;
- ge=num1%10;
- }
- }
复制代码
|