匿名
未登录
登录
丢石头百科
搜索
查看“AVR IO输入之矩阵按键扫描程序”的源代码
来自丢石头百科
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
AVR IO输入之矩阵按键扫描程序
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
<table border="0" cellpadding="0" cellspacing="0" style="color: rgb(72, 61, 139); font-family: Arial, 新宋体, 微软雅黑; font-size: 12px;" width="780"><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"><div align="left"><table border="0" cellpadding="0" cellspacing="0" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">系统功能</th></tr></table><br/> 使用AVR扫描4*4矩阵按键,一旦扫描到按键被按,做出被按的按键号指示。<br/><br/><br/></div></th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"><div align="left"><table border="0" cellpadding="0" cellspacing="0" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">硬件设计</th></tr></table><br/> 关于AVR的I/O结构及相关介绍详见Datasheet,这里仅对作部分简单介绍,下面是AVR的I/O引脚配置表:<br/><table bgcolor="#DDDDDD" border="0" cellpadding="1" cellspacing="1" width="660"><tr bgcolor="#999999" class="white_14px" style="font-size: 14px; color: rgb(255, 255, 255); font-family: Arial, Helvetica, sans-serif;" valign="middle"><th colspan="6" height="25">AVR I/O 口引脚配置表</th></tr><tr bgcolor="#FFFFFF" class="type_483D8B_12px_b" style="font-size: 12px; font-weight: bold; color: rgb(72, 61, 139); line-height: 20px; font-family: Arial, Helvetica, sans-serif;" valign="middle"><td height="20" width="70"><p align="center">DDRXn</p></td><td height="20" width="70"><p align="center">PORTXn</p></td><td height="20" width="70"><p align="center">PUD</p></td><td height="20" width="90"><p align="center">I/O 方式</p></td><td height="20" width="90"><p align="center">内部上拉电阻</p></td><td height="20" width="268"><p align="center">引脚状态说明</p></td></tr><tr bgcolor="#F8F8FF" class="type_483D8B" style="font-size: 12px; line-height: 20px; border-top-style: none; color: rgb(72, 61, 139);" valign="middle"><td height="20" width="70"><p align="center">0</p></td><td height="20" width="70"><p align="center">0</p></td><td height="20" width="70"><p align="center">X</p></td><td height="20" width="90"><p align="center">输入</p></td><td height="20" width="90"><p align="center">无效</p></td><td height="20" width="268"><p align="center">三态(高阻)</p></td></tr><tr bgcolor="#FFFFFF" class="type_483D8B" style="font-size: 12px; line-height: 20px; border-top-style: none; color: rgb(72, 61, 139);" valign="middle"><td height="20" width="70"><p align="center">0</p></td><td height="20" width="70"><p align="center">1</p></td><td height="20" width="70"><p align="center">0</p></td><td height="20" width="90"><p align="center">输入</p></td><td height="20" width="90"><p align="center">有效</p></td><td height="20" width="268"><p align="center">外部引脚拉低时输出电流 (uA)</p></td></tr><tr bgcolor="#F8F8FF" class="type_483D8B" style="font-size: 12px; line-height: 20px; border-top-style: none; color: rgb(72, 61, 139);" valign="middle"><td height="20" width="70"><p align="center">0</p></td><td height="20" width="70"><p align="center">1</p></td><td height="20" width="70"><p align="center">1</p></td><td height="20" width="90"><p align="center">输入</p></td><td height="20" width="90"><p align="center">无效</p></td><td height="20" width="268"><p align="center">三态(高阻)</p></td></tr><tr bgcolor="#FFFFFF" class="type_483D8B" style="font-size: 12px; line-height: 20px; border-top-style: none; color: rgb(72, 61, 139);" valign="middle"><td height="20" width="70"><p align="center">1</p></td><td height="20" width="70"><p align="center">0</p></td><td height="20" width="70"><p align="center">X</p></td><td height="20" width="90"><p align="center">输出</p></td><td height="20" width="90"><p align="center">无效</p></td><td height="20" width="268"><p align="center">推挽 0 输出,吸收电流 (20mA)</p></td></tr><tr bgcolor="#F8F8FF" class="type_483D8B" style="font-size: 12px; line-height: 20px; border-top-style: none; color: rgb(72, 61, 139);" valign="middle"><td height="20" width="70"><p align="center">1</p></td><td height="20" width="70"><p align="center">1</p></td><td height="20" width="70"><p align="center">X</p></td><td height="20" width="90"><p align="center">输出</p></td><td height="20" width="90"><p align="center">无效</p></td><td height="20" width="268"><p align="center">推挽 1 输出,输出电流 (20mA)</p></td></tr></table><p align="center">[[File:AVR_IO输入之矩阵按键扫描程序-0.jpg|400px]]<br/>AVR主控电路原理图(点击图片放大,不需要放大镜![[File:AVR_IO输入之矩阵按键扫描程序-1.gif|400px]])<br/>[[File:AVR_IO输入之矩阵按键扫描程序-2.jpg|400px]] <br/>LED控制电路原理图(点击图片放大,不需要放大镜![[File:AVR_IO输入之矩阵按键扫描程序-1.gif|400px]])<br/>[[File:AVR_IO输入之矩阵按键扫描程序-4.jpg|400px]]<br/>4*4矩阵按键扫描电路原理图(点击图片放大,不需要放大镜![[File:AVR_IO输入之矩阵按键扫描程序-1.gif|400px]])<br/><br/><br/><br/></p></div></th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"><div align="left"><table border="0" cellpadding="0" cellspacing="0" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">软件设计</th></tr></table><span class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;"><br/>下面部分从TXT拷出,拷到网页,代码部分缺省了很多空格,比较凌乱,请谅解!<br/><br/>//目标系统: 基于AVR单片机<br/>//应用软件: ICC AVR<br/></span><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">/*01010101010101010101010101010101010101010101010101010101010101010101<br/>----------------------------------------------------------------------<br/>实验内容:<br/>循环扫描PA口接入的按键,并使用PB口的LED指示灯指示按键的码值。<br/>----------------------------------------------------------------------<br/>硬件连接:<br/>将PB口的LED指示灯使能开关切换到"ON"状态,使其指示按键的码值。<br/>MatrixKeyBoard:K0----K7<br/> | |<br/>SMK1632: PA0--PA7<br/>----------------------------------------------------------------------<br/>注意事项: <br/>(1)若有加载库程序,请将光盘根目录下的“库程序”下的“ICC_H”文件夹拷到D盘<br/>(2)请详细阅读:光盘根目录下的“产品资料\开发板实验板\SMK系列\SMK1632\说明资料”<br/>----------------------------------------------------------------------<br/>10101010101010101010101010101010101010101010101010101010101010101010*/</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">#include <iom16v.H><br/>#include "D:\ICC_H\CmmICC.H"</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">#define LED_DDR DDRB<br/>#define LED_PORT PORTB<br/>#define KEY_DDR DDRA<br/>#define KEY_PORT PORTA<br/>#define KEY_PIN PINA</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">/*--------------------------------------------------------------------<br/>程序名称:4*4按键扫描程序<br/>程序功能:键盘扫描<br/>注意事项:<br/>提示说明:<br/>输 入:<br/>返 回:<br/>--------------------------------------------------------------------*/<br/>/*<br/> K4-----K5-----K6-----K7<br/> | | | |<br/> 03H----02H----01H----00H -K0<br/> 07H----06H----05H----04H -K1<br/> 0BH----0AH----09H----08H -K2<br/> 0FH----0EH----0DH----0CH -K3<br/>*/<br/>const uint8 setSta_[4]={0xfe,0xfd,0xfb,0xf7}; <br/>const uint8 getSta_[4]={0x70,0xb0,0xd0,0xe0}; <br/>uint8 GetKeyVal()<br/>{<br/> uint8 i,j,getSta,keyVal;<br/> <br/> for(i=0;i<4;i++) <br/> { <br/> KEY_PORT = setSta_[i];<br/> delay50us(1); <br/> if(KEY_PIN!=setSta_[i])<br/> {<br/> getSta=KEY_PIN&0xf0;<br/> for(j=0;j<4;j++) <br/> if(getSta==getSta_[j]) <br/> {<br/> keyVal=j+i*4;<br/> return keyVal;<br/> }<br/> }<br/> }<br/> return 0xFF;<br/>}<br/>/*--------------------------------------------------------------------<br/>程序名称:<br/>程序功能:<br/>注意事项:<br/>提示说明:<br/>输 入:<br/>返 回:<br/>--------------------------------------------------------------------*/<br/>void main()<br/>{<br/> uint8 keyVal;<br/> LED_DDR = 0XFF;<br/> KEY_DDR = 0X0F; <br/> while(1)<br/> {<br/> keyVal = GetKeyVal();<br/> if( keyVal!=0xFF ) <br/> LED_PORT = keyVal;<br/> }<br/>}</p><p></p></div></th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"><div align="left"><br/><table border="0" cellpadding="0" cellspacing="0" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">系统调试</th></tr></table><p>(1)按键,观察LED的指示。<br/>(2)去除“<span class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">delay50us(1);</span>”观察效果。</p></div></th></tr></table>
返回至
AVR IO输入之矩阵按键扫描程序
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
首页
首页
树莓派
主机
配件包
外壳
键鼠
电源
扩展板
显示屏
墨水屏
摄像模块
通信模块
继电器
电机驱动板
游戏机
产品分类
树莓派
Arduino
micro:bit
STM32
Espressif
WiFi模块
蓝牙模块
无线模块
LoRa模块
4G模块
GSM
GPRS
以太网
导航模块
北斗卫星
GPS
LCD
墨水屏
OLED
摄像头
USB模块
串口模块
RS232
RS485
CAN
传感器
温度模块
湿度模块
气压模块
继电器
电机模块
指纹模块
电平转换
音频模块
编程器
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志