版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、cpp view plaincopyprint?1. #include 2. #defineucharunsignedchar 3. #defineuintunsignedint 4. sbitdula=P30;5. sbitwela=P31;6. #definekeyport(P1) 7. #definekeystate00/按键确认状态 8. #definekeystate11/按键无动作状态 9. charkeystate=1;/按键状态初始化为按键无动作状态 10. ucharkeynum=0;11. voiddelayms(uintx)/1ms 12. 13. uinty,z;14.
2、 for(y=x;y0;y-)15. for(z=111;z0;z-);16. 17. ucharcodetable=/共阳数码管 18. 0xc0,0xf9,0xa4,0xb0,19. 0x99,0x92,0x82,0xf8,20. 0x80,0x90,0x88,0x83,21. 0xc6,0xa1,0x86,0x8e;22. voidsmg()23. 24. dula=0;25. wela=0;26. P2=0x01;27. wela=1;28. wela=0;29. P2=tablekeynum;30. dula=1;31. dula=0;32. delayms(1);33. 34. P
3、2=0x02;35. wela=1;36. wela=0;37. P2=tablekeynum;38. dula=1;39. dula=0;40. delayms(1);41. 42. P2=0x04;43. wela=1;44. wela=0;45. P2=tablekeynum;46. dula=1;47. dula=0;48. delayms(1);49. 50. P2=0x08;51. wela=1;52. wela=0;53. P2=tablekeynum;54. dula=1;55. dula=0;56. delayms(1);57. 58. P2=0x10;59. wela=1;
4、60. wela=0;61. P2=tablekeynum;62. dula=1;63. dula=0;64. delayms(1);65. 66. P2=0x20;67. wela=1;68. wela=0;69. P2=tablekeynum;70. dula=1;71. dula=0;72. delayms(1);73. 74. P2=0x40;75. wela=1;76. wela=0;77. P2=tablekeynum;78. dula=1;79. dula=0;80. delayms(1);81. 82. P2=0x80;83. wela=1;84. wela=0;85. P2=
5、tablekeynum;86. dula=1;87. dula=0;88. delayms(1);89. 90. voidkeyscan()91. 92. uchartemp1,temp2,column,row;93. switch(keystate)94. 95. casekeystate0:/keystate0,按键按下确认状态,下一状态为keystate1(按键无动作状态) 96. keyport=0x0f;97. temp1=keyport;98. keyport=0xf0;99. temp2=keyport;100. if(temp1|temp2)!=0xff)101. 102. t
6、emp1|=temp2;103. if(!(temp1&0x80)104. row=3;105. else106. if(!(temp1&0x40)107. row=2;108. else109. if(!(temp1&0x20)110. row=1;111. else112. if(!(temp1&0x10)113. row=0;114. if(!(temp1&0x08)115. column=3;116. else117. if(!(temp1&0x04)118. column=2;119. else120. if(!(temp1&0x02)121. column=1;122. else1
7、23. if(!(temp1&0x01)124. column=0;125. keynum=column*4+row;126. while(!(keyport=0x0f|keyport=0xf0);127. keystate=keystate1;128. break;129. 130. 131. else132. keystate=keystate1;133. break;134. casekeystate1:/keystate1,按键无动作状态,下一状态为keystate0(按键无动作状态) 135. keyport=0x0f;136. temp1=keyport;137. keyport=
8、0xf0;138. temp2=keyport;139. if(temp1|temp2)!=0xff)140. 141. keystate=keystate0;142. 143. else144. keystate=keystate1;145. break;146. 147. 148. voidmain()149. 150. while(1)151. 152. keyscan();153. smg();154. 155. #include#define uchar unsigned char#define uint unsigned intsbit dula=P30;sbit wela=P31
9、;#define keyport (P1)#define keystate0 0/按键确认状态#define keystate1 1/按键无动作状态char keystate=1;/按键状态初始化为按键无动作状态uchar keynum=0;void delayms(uint x)/1msuint y,z;for(y=x;y0;y-)for(z=111;z0;z-);uchar code table=/共阳数码管0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e;void smg()du
10、la=0;wela=0;P2=0x01;wela=1;wela=0;P2=tablekeynum;dula=1;dula=0;delayms(1);P2=0x02;wela=1;wela=0;P2=tablekeynum;dula=1;dula=0;delayms(1);P2=0x04;wela=1;wela=0;P2=tablekeynum;dula=1;dula=0;delayms(1);P2=0x08;wela=1;wela=0;P2=tablekeynum;dula=1;dula=0;delayms(1);P2=0x10;wela=1;wela=0;P2=tablekeynum;dul
11、a=1;dula=0;delayms(1);P2=0x20;wela=1;wela=0;P2=tablekeynum;dula=1;dula=0;delayms(1);P2=0x40;wela=1;wela=0;P2=tablekeynum;dula=1;dula=0;delayms(1);P2=0x80;wela=1;wela=0;P2=tablekeynum;dula=1;dula=0;delayms(1);void keyscan()uchar temp1,temp2,column,row;switch(keystate)case keystate0:/keystate0,按键按下确认状
12、态,下一状态为keystate1(按键无动作状态)keyport=0x0f;temp1=keyport;keyport=0xf0;temp2=keyport;if(temp1|temp2)!=0xff)temp1|=temp2;if(!(temp1&0x80)row=3;else if(!(temp1&0x40)row=2;elseif(!(temp1&0x20)row=1;elseif(!(temp1&0x10)row=0;if(!(temp1&0x08)column=3;else if(!(temp1&0x04)column=2;elseif(!(temp1&0x02)column=1;elseif(!(temp1&0x01)column=0;keynum=column*4+row;while(!(keyport=0x0f|keyport=0xf0);keystate=keystate1;break;elsekeystate=keystate1;break;case keystate1:/keystate1,按键无动作状态,下一状态为keystate0(按键无动作状态)keyport=0x0f;tem
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年区块链Web3开发技术白皮书及源码
- 深度复盘智能平衡板年度发展:融资轮次与渗透率
- 脑机接口初探:智慧储能云平台在特殊场景下的交互可能性
- 2026-2027年深圳市固废资源化利用可行性研究报告
- 如何撰写高质量学术论文开题报告
- 蓝图绘就 文体中心项目 2026年大湾区文体中心建设可行性研究报告
- 企业级SaaS产品从0到1的产品设计与增长路径
- 智能拾便袋盒赋能智慧养老:解决失能老人照护核心痛点
- 2024年重庆城市管理职业学院高职单招职业适应性测试考试模拟试卷及参考答案详解【典型题】
- 2024年江西省上饶市高职单招职业技能考试模拟试卷(夺冠系列)附答案详解
- 2026年国企中层干部竞聘笔考试题与答案
- 2026江苏苏州市相城区人民检察院招聘编外人员3人笔试题库及答案详解(新)
- 2026年生产文员测试题及答案
- 2026中国氢能储运装备安全标准与国际对标报告
- 乡镇(街道功能区)党政领导干部离任经济事项交接表(开发区和园区适用本表-修订)
- 2025贵州六盘水市盘州市教育局机关所属事业单位考调19人备考题库必考题
- TSG D0001-2009:压力管道安全技术监察规程-工业管道
- 钠离子电池热失控机理及其防火阻燃策略研究
- 2025年希望杯夏令营竞赛四年级下学期数学S卷
- 2025年部编版新教材语文小学二年级上册全册单元检测题带答案(共8单元)
- 测绘单位安全生产培训
评论
0/150
提交评论