【51蛋骗鸡16路电子开关编程CD4067使用switch】2021-12-27
缘由关于单片机矩阵键盘控制16路led - 24小时必答区
矩阵键值必须配合硬件对应,若矩阵接法不同则键值也不同,取键值可以直接调用矩阵扫描函数,按下按键后看P2输出Q0对应计算器最末位Q7对应第八位,并可发送一个值到P2验证.CD4067为十六路模拟开关,其内部包括一个16选1的译码器和被译码输出所控制的16个双向模拟开关
#include "REG52.h"
unsigned char JianPanShaoMiao(/*使用行列反转扫描法*/)
{
unsigned char H=15,L=240,Ys=0;
P1=H;
if(P1!=15)
{
while(++Ys);//消抖
H=P1;
P1=L;
L=P1;
while(P1!=240);
}
P1 = 255;
return (H+L);
}
unsigned char JianPan_QuZhi16()
{
unsigned char JianZhi=255;
switch(JianPanShaoMiao())
{
case 128:JianZhi = 0; break; /*s06=0 s07=4 s08=8 s09=12*/
case 129:JianZhi = 1; break; /*s10=1 s11=5 s12=9 s13=13*/
case 131:JianZhi = 2; break; /*s14=2 s15=6 s16=10 s17=14*/
case 135:JianZhi = 3; break; /*s18=3 s19=7 s20=11 s21=15*/
case 64:JianZhi = 4; break;
case 65:JianZhi = 5; break;
case 67:JianZhi = 6; break;
case 71:JianZhi = 7; break;
case 32:JianZhi = 8; break;
case 33:JianZhi = 9; break;
case 35:JianZhi = 10; break;
case 39:JianZhi = 11; break;
case 16:JianZhi = 12; break;
case 17:JianZhi = 13; break;
case 19:JianZhi = 14; break;
case 23:JianZhi = 15; break;
default: JianZhi = 255;break;
}
return JianZhi;
}
void main()
{
unsigned char xz=255,cs=0;
unsigned int wei=1;
P2=xz;
while(1)
{
if(++wei==0)
{
cs=JianPan_QuZhi16();
if(cs!=255)P2=cs;else;
}
}
}