基于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();}}

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功