|
开始4个灯亮,按一次按键按顺序亮一个灯
仿真图
- #include<REGX51.h>
- #define LED P1
- sbit BUT = P2^7;
- unsigned char num[]={0x00,0x6e,0x0d,0x0b,0x07};
- void delay(unsigned int num)
- {
- unsigned int i,j;
- for(i=num;i>0;i--)
- for(j=120;j>0;j--);
- }
- void main()
- {
- unsigned int a=0,b=1;
- while(1){
- while(a){
- LED = num[b];
- // delay(5);
- if(BUT==0)
- delay(10);
- if(BUT==0)
- {
- b++;
- if(b>4){
- a=0;b=1;}
- while(BUT==0);
- }
- }
-
- if(BUT==0)
- delay(10);
- if(BUT==0)
- {
- a=1;
- while(BUT==0);
- }
- LED = num[0];
- }
- }
复制代码
|
|