键盘显示密码原理图加程序

发布于:2021-10-23 10:03:42

键盘显示密码原理图加程序 #include<reg52.h> //#include"ds1302.h" #define uchar unsigned char #define uint unsigned int

uchar code bitsel[]={0x00,0x01,0x02,0x03,0x04,0x05}; //位选 位选 uchar code segsel[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67}; //段选 段选

static uchar pwdchr[6] ; static uchar pwdchr2[6] ; //密码存储 密码存储

void delayms (uchar a) //延时 延时 { uchar i,j; while(a--!=0)

{ for (i=0;i<6;i++) {for (j=0;j<48;j++) {} } }

}

void clrpwd(uchar a[6]) //清空密码 清空密码 { uchar i; for(i=0;i<6;i++) { a[i]=0x40; } }

uchar scankeys(void) //扫描按键 扫描按键

{ uchar scan_h,scan_v; 值 P3=0xff; P3=0x0f; 出全为 0 scan_h=P3 & 0x0f; 值 if(scan_h !=0x0f) 按键按下 { delayms(8); if(scan_h !=0x0f) { scan_h=P3 & 0x0f; P3=scan_h | 0xf0; scan_v=P3 & 0xf0; return(scan_h+scan_v); } }return(0xff); //读入列线值 读入列线值 //列线值输出为 0 列线值输出为 //读入列线值 读入列线值 //返回键盘编码 返回键盘编码 //按键去抖动 按键去抖动 // 检测有无 //读入列线 读入列线 //初始化 初始化 //行线输 行线输 //行列扫描 行列扫描

}

void disppwd(void) //密码显示 密码显示 { uint i; for(i=0;i<6;i++) { P2=bitsel[i]; P0=pwdchr[i]; delayms(6); } //位选 位选 //段选 段选 //密码输入次数 密码输入次数

} void waitkey(void) { while(scankeys()==0xff) //等待按键 等待按键 { disppwd(); } }

uchar key2seg(uchar n) //键盘译成段选 键盘译成段选 { switch(n) { case 0xee: //0 case 0xde: //1 case 0xbe: //2 case 0x7e: //3 case 0xed: //4 case 0xdd: case 0xbd: //6 case 0xe7: //7 case 0xd7: return (0x7f); break; return (0x07); break; return (0x6d); break; return (0x7c); break; //5 return (0x66); break; return (0x4f); break; return (0x5b); break; return (0x06); break; return (0x3f); break;

//8 case 0xb7: //9 case 0x7d: 除/移位键 移位键 case 0x77: 确认键 default : break; } } return (0x77); break; // return (0x7d); break; //清 清 return (0x67); break;

void inpwd(void) //密码输入 密码输入 { uchar i,k,j; j=1; while(j) { waitkey(); k=scankeys(); if(k==0x7d) { //清除 移位键 清除/移位键 清除

clrpwd(pwdchr); i=0; } else if(k==0x77) { j=0; break; } else if(i<6) { pwdchr[i]=key2seg(k); while(scankeys()!=0xff) !! !! !! 放 ! !! !! ! { disppwd(); } ++i; } //等键释 等键释 //确认键 确认键

}

}

main() { clrpwd(pwdchr); while(1) { inpwd(); disppwd();} }


相关推荐

最新更新

猜你喜欢