|
通过按键计数自加1
- #include <reg52.h>
- sbit key=P1^0;
- unsigned char code s[]={0x3f,0x06,0x5b,0x4f,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char i=0,j=0;
- void delay(unsigned char i)
- {
- while(i--);
- }
- void keyscan()
- {
- if(key==0)
- {
- delay(5000);
- if(key==0)
- {
- P0=s[i];
- i++;
- if(i==10)
- {
- P0=s[0];
- i=0;
- j++;
- if(j==2)j=0;
- P2=s[j];
-
- }
- }
- while(!key);
- }
- }
- void main()
- {
- P0=s[0];
- P2=s[0];
- while(1)keyscan();
- }
复制代码
|
|