自己用4*4矩阵键盘与六位数码管仿真的加法计算器(已经做好啦,按键消抖 ,数码管鬼影现象)
- void LedScan() //六位数码管动态扫描
- {
- static unsigned char i=0;
- P0 = 0xFF; //显示消隐
- switch(i) //每过1ms从低到高位刷新一个数码管
- {
- case 0:P2=0x01;i++; P0= LedBuff[0]; break;
- case 1:P2=0x02;i++; P0= LedBuff[1]; break;
- case 2:P2=0x04;i++; P0= LedBuff[2]; break;
- case 3:P2=0x08;i++; P0= LedBuff[3]; break;
- case 4:P2=0x10;i++; P0= LedBuff[4]; break;
- case 5:P2=0x20;i=0; P0= LedBuff[5]; break;
- default :break;
- }
- }
- void KeyScan() //矩阵按键动态扫描
- {
- unsigned char i;
- static unsigned char keyout = 0;
- static unsigned char keybuf[4][4] = {
- {0xff,0xff,0xff,0xff},
- {0xff,0xff,0xff,0xff},
- {0xff,0xff,0xff,0xff},
- {0xff,0xff,0xff,0xff},
- };
- /******按键消抖***************/
- keybuf[keyout][0] = (keybuf[keyout][0] <<1)|KEY_INT_1;
- keybuf[keyout][1] = (keybuf[keyout][1] <<1)|KEY_INT_2;
- keybuf[keyout][2] = (keybuf[keyout][2] <<1)|KEY_INT_3;
- keybuf[keyout][3] = (keybuf[keyout][3] <<1)|KEY_INT_4;
- for(i=0;i<4;i++)
- {
- if((keybuf[keyout][i] & 0x0F) == 0x00)
- {
- KeySta[keyout][i] = 0;
- }
- else if ((keybuf[keyout][i] & 0x0F) == 0x0f)
- {
- KeySta[keyout][i] = 1;
- }
-
- }
- keyout++;
- keyout=keyout & 0x03;
-
- switch(keyout) //扫描矩阵键盘
- {
- case 0: KEY_OUT_4 = 1;KEY_OUT_1 = 0;break;
- case 1: KEY_OUT_1 = 1;KEY_OUT_2 = 0;break;
- case 2: KEY_OUT_2 = 1;KEY_OUT_3 = 0;break;
- case 3: KEY_OUT_3 = 1;KEY_OUT_4 = 0;break;
- default:break;
- }
复制代码 全部资料51hei下载地址:
简单加法器.rar
(70.2 KB, 下载次数: 108)
|