匿名
未登录
登录
丢石头百科
搜索
查看“STM8 IO输入之独立按键检测程序”的源代码
来自丢石头百科
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
STM8 IO输入之独立按键检测程序
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
<table border="0" cellpadding="0" cellspacing="0" style="color: rgb(72, 61, 139); font-family: Arial, 新宋体, 微软雅黑; font-size: 12px;" width="780"><tbody><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" 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></tbody></table> 使用STM8检测三个独立按键,一旦检测到按键被按,立刻做出指示! </th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" 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></tbody></table> 关于STM8的I/O结构及相关介绍详见Datasheet,这里仅对作部分简单介绍,下面是STM8的I/O引脚配置表: <table bgcolor="#DDDDDD" border="0" cellpadding="1" cellspacing="1" width="660"><tbody><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"> STM8 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 align="center" height="20" width="70">Px_DDR</td><td align="center" height="20" width="70">Px_CR1</td><td align="center" height="20" width="70">Px_CR2</td><td align="center" height="20" width="90">I/O 方式</td><td align="center" height="20" width="268">引脚状态说明</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 align="center" height="20" width="70">0</td><td align="center" height="20" width="70">0</td><td align="center" height="20" width="70">0</td><td align="center" height="20" width="90">输入</td><td align="center" height="20" width="268">悬浮输入</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 align="center" height="20" width="70">0</td><td align="center" height="20" width="70">0</td><td align="center" height="20" width="70">1</td><td align="center" height="20" width="90">输入</td><td align="center" height="20" width="268">上拉输入</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 align="center" height="20" width="70">0</td><td align="center" height="20" width="70">1</td><td align="center" height="20" width="70">0</td><td align="center" height="20" width="90">输入</td><td align="center" height="20" width="268">中断悬浮输入</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 align="center" height="20" width="70">0</td><td align="center" height="20" width="70">1</td><td align="center" height="20" width="70">1</td><td align="center" height="20" width="90">输入</td><td align="center" height="20" width="268">中断上拉输入</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 align="center" height="20" width="70">1</td><td align="center" height="20" width="70">0</td><td align="center" height="20" width="70">0</td><td align="center" height="20" width="90">输出</td><td align="center" height="20" width="268">开漏输出</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 align="center" height="20" width="70">1</td><td align="center" height="20" width="70">1</td><td align="center" height="20" width="70">0</td><td align="center" height="20" width="90">输出</td><td align="center" height="20" width="268">推挽输出</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 align="center" height="20" width="70">1</td><td align="center" height="20" width="70">X</td><td align="center" height="20" width="70">1</td><td align="center" height="20" width="90">输出</td><td align="center" height="20" width="268">输出(最快速度为10MHZ)</td></tr></tbody></table> [[File:STM8_LED_PB.jpg]] LED控制电路原理图 [[File:STM8_KEY.jpg]] 独立按键电路原理图 </th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" 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></tbody></table>/********************************************************************* 微 雪 电 子 WaveShare <a class="Blue_2_12px_" href="https://{{SERVERNAME}}/" style="color: rgb(7, 66, 184);">http://www.waveShare.net 目标系统: 基于STM8单片机 应用软件: Cosmic CxSTM8 说 明: 若用于商业用途,请保留此段文字或注明代码来源 深 圳 市 微 雪 电 子 有 限 公 司 保 留 所 有 的 版 权 *********************************************************************/ #include <STM8S207S8.h> #define LED_DDR PB_DDR #define LED_ODR PB_ODR #define LED_CR1 PB_CR1 #define LED_CR2 PB_CR2 #define KEY_DDR PB_DDR #define KEY_IDR PB_ODR #define KEY_CR1 PB_CR1 #define KEY_CR2 PB_CR2 void scanKey() { KEY_PORT=0xFF; //设置按键输出“1”,之后语句检测按键,若端口变为“0”,则表示被按 if(KEY_PIN==0xFE) //1111 1110 --> 说明最低位的按键可能被按 { delay50us(1); //去抖 if(KEY_PIN==0xFE) //1111 1110 --> 确认最低位的按键被按 LED_P0RT=0xFE; //进行LED指示 } if(KEY_PIN==0xFD) //1111 1101 --> 说明最低位的按键可能被按 { delay50us(1); //去抖 if(KEY_PIN==0xFD) //1111 1101 --> 确认最低位的按键被按 LED_P0RT=0xFD; //进行LED指示 } if(KEY_PIN==0xFB) { delay50us(1); if(KEY_PIN==0xFB) LED_P0RT=0xFB; } if(KEY_PIN==0xF7) { delay50us(1); if(KEY_PIN==0xF7) LED_P0RT=0xF7; } if(KEY_PIN==0xEF) { delay50us(1); if(KEY_PIN==0xEF) LED_P0RT=0xEF; } if(KEY_PIN==0xDF) { delay50us(1); if(KEY_PIN==0xDF) LED_P0RT=0xDF; } if(KEY_PIN==0xBF) { delay50us(1); if(KEY_PIN==0xBF) LED_P0RT=0xBF; } if(KEY_PIN==0x7F) { delay50us(1); if(KEY_PIN==0x7F) LED_P0RT=0x7F; } } </th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" 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></tbody></table> 按第一个键,第一个LED亮;按第二个键,第二个LED亮。。。</th></tr></tbody></table>
返回至
STM8 IO输入之独立按键检测程序
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
首页
首页
树莓派
主机
配件包
外壳
键鼠
电源
扩展板
显示屏
墨水屏
摄像模块
通信模块
继电器
电机驱动板
游戏机
产品分类
树莓派
Arduino
micro:bit
STM32
Espressif
WiFi模块
蓝牙模块
无线模块
LoRa模块
4G模块
GSM
GPRS
以太网
导航模块
北斗卫星
GPS
LCD
墨水屏
OLED
摄像头
USB模块
串口模块
RS232
RS485
CAN
传感器
温度模块
湿度模块
气压模块
继电器
电机模块
指纹模块
电平转换
音频模块
编程器
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志