《《单片机原理与应用》课件(18)》由会员分享,可在线阅读,更多相关《《单片机原理与应用》课件(18)(8页珍藏版)》请在金锄头文库上搜索。
1、任务二 行列式键盘输入实验,任务要求:P1口接44键盘作为输入,P2口输出。按下0号键数码管显示0,按下1号键数码管按下时显示1,以此类推。,项目五 单片机键盘接口技术,#includereg51.h#includeabsacc.h#define uchar unsigned char#define uint unsigned intunsigned char code num =0x3f, 0x06,0x5b,0x46,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00;void delays(void);ucha
2、r kbscan(void);,void main( ) uchar key,temp; while(1) key=kbscan(); switch(key) case 0x11: temp=0;break; case 0x21: temp=1;break; case 0x41: temp=2;break; case 0x81: temp=3;break; case 0x12: temp=4;break; case 0x22: temp=5;break; case 0x42: temp=6;break;,case 0x82: temp=7;break;case 0x14: temp=8;bre
3、akcase 0x24: temp=9;break;case 0x44: temp=10;break;case 0x84: temp=11;break;case 0x18: temp=12;break;case 0x28: temp=13;break;case 0x48: temp=14;break;case 0x88: temp=15;break;,default: temp=16; P2=numtemp;delays( ); ,void delays(void) uchar i; for(i=300;i0;i-); ,uchar kbscan(void) uchar scancode,recode; P1=0xf0; if(P1,return(scancode)+(recode);else scancode=(scancode1)|0x01; return(0);,