本帖最后由 辉Se天空 于 2012-5-6 15:34 编辑
一个键盘控制
ps :上传一个电路图请大家帮忙看看吧,我想实现的功能时按键使数码管显示1234567890abcdef
小Q截图-20120506153013.png (91.13 KB, 下载次数: 0)
下载附件
2012-5-6 15:30 上传
代码:
- #include<reg52.h>
- #define unt unsigned int
- #define unc unsigned char
- unc t=0x3f;
- void delay(unsigned int x)
- {
- unsigned i,j;
- for(i=0;i<x;i++)
- for(j=0;j<1827;j++);
- }
- unc a[16]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- unc b[4]={0x80,0x40,0x20,0x10};
- main()
- { unc i;
- while(1)
- {
- P1=0xf0;
- if(P1^0xf0){
- delay(2);
- if(P1^0xf0){
- delay(2);
- if(P1^0xf0){
- for(i=0;i<4;i++)
- {
- P1 = b[i];
- if(P1^b[i] == 0x08) t = a[i*4+0];
- if(P1^b[i] == 0x04) t = a[i*4+1];
- if(P1^b[i] == 0x02) t = a[i*4+2];
- if(P1^b[i] == 0x01) t = a[i*4+3];
- }
- }
-
- }
- }
- P0=t;
- delay(2);
- }
- }
复制代码
一周热门 更多>