您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 制造加工工艺 > 基于51单片机行列式按键扫描显示程序线反转法
基于51单片机行列式按键扫描显示程序#includereg51.h#includeintrins.h#defineucharunsignedchar#defineuintunsignedintsbitbeep=P3^0;ucharcodeled[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//0-f//------------------------------------------delay1ms------------voiddelay(uinta){uinti;while(--a!=0){for(i=0;i100;i++);}}//-----------------------------------------keyscan--------------ucharkeyscan(){ucharh,l;//h:行l:列P1=0x0f;//列全置低电平,行全置高电平h=P1&0x0f;if(h!=0x0f)//若有键按下则行会出现低电平{delay(10);//按键去抖if(h!=0x0f){h=P1&0x0f;//读入行值P1=0xf0;//电平反转l=P1&0xf0;//读入列值}}return(h+l);//行值+列值,即按键值}voiddisplay(){uchark;k=keyscan();switch(k){case0x7e:{P0=led[0];beep=0;delay(2);beep=1;}break;//0case0x7d:{P0=led[1];beep=0;delay(2);beep=1;}break;//1case0x7b:{P0=led[2];beep=0;delay(2);beep=1;}break;//2case0x77:{P0=led[3];beep=0;delay(2);beep=1;}break;//3case0xbe:{P0=led[4];beep=0;delay(2);beep=1;}break;//4case0xbd:{P0=led[5];beep=0;delay(2);beep=1;}break;//5case0xbb:{P0=led[6];beep=0;delay(2);beep=1;}break;//6case0xb7:{P0=led[7];beep=0;delay(2);beep=1;}break;//7case0xde:{P0=led[8];beep=0;delay(2);beep=1;}break;//8case0xdd:{P0=led[9];beep=0;delay(2);beep=1;}break;//9case0xdb:{P0=led[10];beep=0;delay(2);beep=1;}break;//acase0xd7:{P0=led[11];beep=0;delay(2);beep=1;}break;//bcase0xee:{P0=led[12];beep=0;delay(2);beep=1;}break;//ccase0xed:{P0=led[13];beep=0;delay(2);beep=1;}break;//dcase0xeb:{P0=led[14];beep=0;delay(2);beep=1;}break;//ecase0xe7:{P0=led[15];beep=0;delay(2);beep=1;}break;//f}}voidmain(){P2=0x00;beep=1;while(1){display();}}
本文标题:基于51单片机行列式按键扫描显示程序线反转法
链接地址:https://www.777doc.com/doc-2732468 .html