- UID
- 538014
- 阅读权限
- 5
- 推广
-
- 幽默
-
- 注册时间
- 2014-1-4
- 最后登录
- 1970-1-1
|
注册家电维修技术论坛,与同行畅聊维修技术,享更多技术论坛功能。
您需要 登录 才可以下载或查看,没有帐号?快速注册
x
- #include<reg51.h>
- unsigned char dispcode[]={0xc0,0xf9,0xa4,
- 0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- unsigned char time;
- unsigned int cont,time1;
- bit flag,flag1,flag2;
- sbit P2_0=P2^0;
- sbit P2_1=P2^1;
- sbit P2_2=P2^2;
- sbit P2_3=P2^3;
- sbit P2_4=P2^4;
- void reset(void)
- {TMOD=0x02;
- TH0=0x06;
- TL0=0x06;
- EA=1;
- ET0=1;
- TR0=1;}
- void delay(unsigned int x)
- {unsigned i;
- while(--x!=0)
- {for(i=0;i<125;i++) ;}
- }
- void keyboard(void)
- {
- if(!P2_0){delay(200);++cont;flag2=0;
- if(cont==99) cont=0;}
- if(!P2_1){delay(200); flag2=1;}
- }
- void main(void)
- {reset();
- while(1)
- {keyboard();}
- }
- void intt0(void) interrupt 1 using 1
- {++time;
- if(time==4)
- {time=0;
- if(flag1==1){P2_4=1;P2_3=0;P1=dispcode[cont/10];flag1=0;}
- else{P2_3=1;P2_4=0;P1=dispcode[cont%10];
- flag1=1;}
- ++time1;
- }
- if(time1==500)
- {time1=0;
- if(flag2){
- if(cont>0) cont=cont-1;
- else {flag=1;P2_2=~P2_2;}}
- }
- }
复制代码
|
|