無標題.jpg (106.36 KB, 下載次數(shù): 39)
下載附件
2020-3-19 08:00 上傳
- #include<reg51.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit key1=P3^0;
- sbit key2=P3^1;
- uchar code table[]={ //共陰數(shù)碼管段碼0~F
- 0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,
- 0x39,0x5e,0x79,0x71};
- uchar code table1[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0};//LED低電平亮
- uchar num=0; //鍵值變量
- uchar count=0; //消抖計數(shù)變量
- bit flag=0; //按鍵狀態(tài)標志
- void main(void)
- {
- P2=table[num];
- P1=table1[num];
- while(1)
- {
- if(!key1||!key2)
- {
- if(++count>=100 && flag==0)
- {
- flag=1;
- if(!key1)
- {
- if(num<5)
- num++;
- }
- if(!key2)
- {
- if(num>0)
- num--;
- }
- P2=table[num];
- P1=table1[num];
- }
- }
- else
- {
- count=0;
- flag=0;
- }
- }
- }
復制代碼
|