C语言矩阵键盘程序.docx
《C语言矩阵键盘程序.docx》由会员分享,可在线阅读,更多相关《C语言矩阵键盘程序.docx(1页珍藏版)》请在冰豆网上搜索。
C语言矩阵键盘程序
C语言矩阵键盘程序
大家在大学学习单机片时,老师都会要求大家自己设计矩阵键盘程序,于是,小编在此为广大学生写了一段最容易理解的矩阵键盘程序哦(C语言),希望能帮到大家。
#defineucharunsignedchar uchartemp; voiddelay(ucharx) { uchary,z; for(y=x;y>0;y--) for(z=125;z>0;z--) ; } ucharkeyscan() { P3=0xfe; temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { temp=P3; switch(temp) { case0xee:
num=1; break; case0xde:
num=2; break; case0xbe:
num=3; break; case0x7e:
num=4; break; } while(temp!
=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xfd; temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { temp=P3; switch(temp) { case0xed:
num=5; break; case0xdd:
num=6; break; case0xbd:
num=7; break; case0x7d:
num=8; break; } while(temp!
=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xfb; temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { temp=P3; switch(temp) { case0xeb:
num=9; break; case0xdb:
num=10; break; case0xbb:
num=11; break; case0x7b:
num=12; break; } while(temp!
=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xf7; temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!
=0xf0) { temp=P3; switch(temp) { case0xe7:
num=13; break; case0xd7:
num=14; break; case0xb7:
num=15; break; case0x77:
num=16; break; } while(temp!
=0xf0) { temp=P3; temp=temp&0xf0; } } } returnnum; }