CT107D蓝桥杯矩阵键盘使用

    xiaoxiao2021-03-25  117

    这里单独讲一下矩阵键盘,这里没有加消抖,可以看看前面的独立键盘加上消抖。

    sfr P4=0xC0; //4行 sbit r1=P3^0; sbit r2=P3^1; sbit r3=P3^2; sbit r4=P3^3; //4列 sbit c1=P4^4; sbit c2=P4^2; sbit c3=P3^5; sbit c4=P3^4; //矩阵键盘检查 unsigned char key_scan() { unsigned char key_value; r1=0; r2=r3=r4=1; c1=c2=c3=c4=1; if(!c1)key_value=0; else if(!c2)key_value=1; else if(!c3)key_value=2; else if(!c4)key_value=3; r2=0; r1=r3=r4=1; c1=c2=c3=c4=1; if(!c1)key_value=4; else if(!c2)key_value=5; else if(!c3)key_value=6; else if(!c4)key_value=7; r3=0; r2=r1=r4=1; c1=c2=c3=c4=1; if(!c1)key_value=8; else if(!c2)key_value=9; else if(!c3)key_value=10; else if(!c4)key_value=11; r4=0; r2=r3=r1=1; c1=c2=c3=c4=1; if(!c1)key_value=12; else if(!c2)key_value=13; else if(!c3)key_value=14; else if(!c4)key_value=15; return key_value; }

    转载请注明原文地址: https://ju.6miu.com/read-23971.html

    最新回复(0)