欢迎来到天天文库
浏览记录
ID:50139097
大小:1.42 MB
页数:8页
时间:2020-03-05
《掌握矩阵键盘使用.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.单片机原理及应用实验五专业:15自动化姓名:学号:指导老师:李素敏中央民族大学信息工程学院Word文档.一、实验目的掌握矩阵键盘使用二、实验仪器1、PC机2、STC89C52单片机三、实验步骤1、熟悉单片机硬件结构,匹配管脚2、根据实验要求编写程序3、编译成功后烧录至单片机四、实验要求对实验板上4*4矩阵键盘的16个按键S6---S21进行按键次数统计。键号06、07……21用最左边2位数码管显示,按键次数用右侧4位数码管显示。有键按下时,显示相应键号和该键累计按键次数,没键按下时,数码管不亮。(无论键号还是按键次数都用其十进制数显示。)五、实验结果#include2、>sbitdula=P2^6;sbitwela=P2^7;unsignedchari=100;unsignedcharj,k,temp,key;unsignedcharjishu[16];unsignedcharp=-1;voiddelay(unsignedchari){for(j=i;j>0;j--)for(k=125;k>0;k--);}unsignedcharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddisplay(unsig3、nedcharnum,unsignedcharjishu){unsignedcharqian,bai,shi,ge,shi1,ge1;unsignedi;for(i=0;i<20;i++){shi1=num/10;ge1=num%10;qian=jishu/1000;bai=(jishu-1000*qian)/100;Word文档.shi=(jishu-1000*qian-100*bai)/10;ge=jishu%10;P0=table[shi1];dula=1;dula=0;P0=0xfe;wela=1;wela=0;delay(5);P0=table[ge1];dula=1;du4、la=0;P0=0xfd;wela=1;wela=0;delay(5);P0=table[qian];dula=1;dula=0;P0=0xfb;wela=1;wela=0;delay(5);P0=table[bai];dula=1;dula=0;P0=0xf7;wela=1;wela=0;delay(5);P0=table[shi];dula=1;dula=0;P0=0xef;wela=1;wela=0;delay(5);P0=table[ge];dula=1;dula=0;P0=0xdf;wela=1;wela=0;delay(5);Word文档.}}voidmain(){dul5、a=0;wela=0;while(1){P3=0xfe;temp=P3;temp=temp&0xf0;if(temp!=0xf0){delay(10);if(temp!=0xf0){temp=P3;switch(temp){case0xee:key=6;jishu[0]++;p=0;break;case0xde:key=7;jishu[1]++;p=1;break;case0xbe:key=8;jishu[2]++;p=2;break;case0x7e:key=9;jishu[3]++;p=3;break;}while(temp!=0xf0){Word文档.temp=P3;temp=6、temp&0xf0;}}}P3=0xfd;temp=P3;temp=temp&0xf0;if(temp!=0xf0){delay(10);if(temp!=0xf0){temp=P3;switch(temp){case0xed:key=10;jishu[4]++;p=4;break;case0xdd:key=11;jishu[5]++;p=5;break;case0xbd:key=12;jishu[6]++;p=6;break;case0x7d:key=13;jishu[7]++;p=7;break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;7、}}}Word文档.P3=0xfb;temp=P3;temp=temp&0xf0;if(temp!=0xf0){delay(10);if(temp!=0xf0){temp=P3;switch(temp){case0xeb:key=14;jishu[8]++;p=8;break;case0xdb:key=15;jishu[9]++;p=9;break;case0xbb:key=16;jishu[10]++;p=10;break;case0x7b:key=17
2、>sbitdula=P2^6;sbitwela=P2^7;unsignedchari=100;unsignedcharj,k,temp,key;unsignedcharjishu[16];unsignedcharp=-1;voiddelay(unsignedchari){for(j=i;j>0;j--)for(k=125;k>0;k--);}unsignedcharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddisplay(unsig
3、nedcharnum,unsignedcharjishu){unsignedcharqian,bai,shi,ge,shi1,ge1;unsignedi;for(i=0;i<20;i++){shi1=num/10;ge1=num%10;qian=jishu/1000;bai=(jishu-1000*qian)/100;Word文档.shi=(jishu-1000*qian-100*bai)/10;ge=jishu%10;P0=table[shi1];dula=1;dula=0;P0=0xfe;wela=1;wela=0;delay(5);P0=table[ge1];dula=1;du
4、la=0;P0=0xfd;wela=1;wela=0;delay(5);P0=table[qian];dula=1;dula=0;P0=0xfb;wela=1;wela=0;delay(5);P0=table[bai];dula=1;dula=0;P0=0xf7;wela=1;wela=0;delay(5);P0=table[shi];dula=1;dula=0;P0=0xef;wela=1;wela=0;delay(5);P0=table[ge];dula=1;dula=0;P0=0xdf;wela=1;wela=0;delay(5);Word文档.}}voidmain(){dul
5、a=0;wela=0;while(1){P3=0xfe;temp=P3;temp=temp&0xf0;if(temp!=0xf0){delay(10);if(temp!=0xf0){temp=P3;switch(temp){case0xee:key=6;jishu[0]++;p=0;break;case0xde:key=7;jishu[1]++;p=1;break;case0xbe:key=8;jishu[2]++;p=2;break;case0x7e:key=9;jishu[3]++;p=3;break;}while(temp!=0xf0){Word文档.temp=P3;temp=
6、temp&0xf0;}}}P3=0xfd;temp=P3;temp=temp&0xf0;if(temp!=0xf0){delay(10);if(temp!=0xf0){temp=P3;switch(temp){case0xed:key=10;jishu[4]++;p=4;break;case0xdd:key=11;jishu[5]++;p=5;break;case0xbd:key=12;jishu[6]++;p=6;break;case0x7d:key=13;jishu[7]++;p=7;break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;
7、}}}Word文档.P3=0xfb;temp=P3;temp=temp&0xf0;if(temp!=0xf0){delay(10);if(temp!=0xf0){temp=P3;switch(temp){case0xeb:key=14;jishu[8]++;p=8;break;case0xdb:key=15;jishu[9]++;p=9;break;case0xbb:key=16;jishu[10]++;p=10;break;case0x7b:key=17
此文档下载收益归作者所有