- #include<reg51.h>
- #define uchar unsigned char
- uchar duanma [10]={0xc0,0xf9,0xa4,0xb0,0x99,
- 0x92,0x82,0xf8,0x80,0x90};
- uchar weima[4]={0x01,0x02,0x04,0x08};
- uchar jishu1,jishu2,miao,haomiao;
- uchar xianshi[4]={0,0,0,0};
- bit kaiting = 0;
- sbit k1=P3^0;
- sbit k2=P3^1;
- void yanshi20ms (void)
- {
- uchar i,j;
- for (i=40;i>0;i--)
- for (j=250;j>0;j--);
- }
- void chushihua(void)
- {
- TMOD=0x01;
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- EA=1;ET0=1;TR0=1;
- }
- void main(void)
- {
- uchar saomiao;
- miao=0;haomiao=0;
- chushihua();
- while(1)
- {
- P3=0xff;
- saomiao=P3;
- if(saomiao!=0xff)
- {
- yanshi20ms();
- saomiao=P3;
- if(saomiao!=0xff)
- {
- if(k1==0)
- {
- kaiting=~kaiting;
- }
- if((k2==0)&&(kaiting==1))
- {
- miao=0;
- haomiao=0;
- }
- while(P3!=0xff);
- }
- }
- }
- }
- void miaobiao(void)interrupt 1
- {
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- xianshi[0]=duanma[miao/10];
- xianshi[1]=duanma[miao%10];
- xianshi[2]=duanma[haomiao/10];
- xianshi[3]=duanma[haomiao%10];
- jishu1++;
- if(jishu1==4)jishu1=0;
- P2=weima[jishu1];
- P1=xianshi[jishu1];
- jishu2++;
- if (jishu2==100)
- {
- jishu2=0;
- if(kaiting==0)
- haomiao++;
- if (haomiao==100)
- {
- haomiao=0;
- miao++;
- if(miao==60)
- miao=0;
- }
- }
- }
复制代码
|