完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好,
这是改进的4x3键盘代码,带有去抖和自动重复。 使用STM8S 2MHz时钟,它的性能非常接近PC键盘。 为清楚起见,action()功能已从键盘管理状态机中取出。 欢迎提出建议和改进。 希望能帮助到你。 圣诞快乐和节日快乐 史蒂芬 u8 key = 255; u8 oldkey = 255; u8 AutoRptMax = 64; u8 AutoRptCount = 0; 而(1) { key = GetKeyPressed(); //扫描键盘以按下键的代码 //&lt;这是一个有效的按键吗? &GT; if(key&lt; 12)// YES { //&lt;关键仍然是旧的? &GT; if(key == oldkey)// YES { //(开始计算autorepeat以遮挡) DelayMS(50); AutoRptCount ++; //&lt;是时候执行关键操作了吗? &GT; if(AutoRptCount&gt; = AutoRptMax)// YES { 动作(键); //根据密钥代码执行操作 AutoRptCount = 0; //重置autorepeat计数器以准备下一次autorepeat事件 AutoRptMax = 16; //使自动重复限制短,以便在保持按键时加快下一次重复 } } 否则//不,关键是新品牌 { 动作(键); //根据密钥代码执行操作 DelayMS(50); //也做了一点点去抖动 } } // END if(key&lt; 12) 否//否,键不在12个定义的键中 { //&lt;钥匙垫是否被释放? &GT; if(oldkey&lt; 255)// YES { AutoRptCount = 0; //重置autorepeat计数器 AutoRptMax = 128; //并使用第一个输入延迟long重新启动 } } oldkey = key; } void动作(u8键) { 开关(键) { 情况9://退格(模式输入''在写'之后''因此我们需要向左移动光标两次) LCD_DATA(0x10,0); LCD_CHR(32); LCD_DATA(0x10,0); 打破; 案例11: LCD_DATA(0x14,0); //光标向右 打破; 默认: LCD_CHR(键+ 48 + 1); //显示键码 打破; } } void DelayMS(int delay) { int nCount = 0; 而(延迟!= 0) { nCount = 100; while(nCount!= 0) { nCount--; } 延迟 - ; } } #stm8s #debounce #autorepeat#4x3-keypad 以上来自于谷歌翻译 以下为原文 Hi all, Here's an improved code for the 4x3 keypad with debounce and autorepeat. With STM8S 2MHz clock it performs pretty close to the PC keyboard. The action() function is out from the keypad management state machine for clarity. Suggestions and improvements are welcome. Hope it helps. Merry Xmas and happy holidays Steven u8 key = 255; u8 oldkey = 255; u8 AutoRptMax = 64; u8 AutoRptCount = 0; while(1) { key = GetKeyPressed(); //Scan the keypad to getting the code of the key pressed // < Is it a valid key pressed ? > if (key < 12) // YES { // < Is key still the old one ? > if (key == oldkey) // YES { // (Start counting for autorepeat to occour) DelayMS(50); AutoRptCount++; // < Is time to execute the key action? > if (AutoRptCount >= AutoRptMax) // YES { Action(key); // perform the action according to the key code AutoRptCount = 0; // reset the autorepeat counter to get ready for the next autorepeat event AutoRptMax = 16; // make the autorepeat limit short for speeding up the next repetition when keeps keypressing } } else // NO, the key is new brand { Action(key); // perform the action according to the key code DelayMS(50); // and also make a little debouncing } } // END if (key < 12) else // NO, the key is not among the 12 defined keys { // < Was the key pad released ? > if (oldkey < 255 ) // YES { AutoRptCount = 0; // reset the autorepeat counter AutoRptMax = 128; // and restart using the first typing delay long } } oldkey = key; } void Action(u8 key) { switch(key) { case 9: // backspace (mode entry is ''right after writing'' so we need to cursor left twice) LCD_DATA(0x10,0); LCD_CHR(32); LCD_DATA(0x10,0); break; case 11: LCD_DATA(0x14,0); // cursor right break; default: LCD_CHR(key + 48 + 1); // display keycode break; } } void DelayMS(int delay) { int nCount = 0; while (delay != 0) { nCount = 100; while (nCount != 0) { nCount--; } delay--; } } #stm8s #debounce #autorepeat #4x3-keypad |
|
相关推荐
2个回答
|
|
|
好,
原始主题已更新。 如果你愿意,请删除这个。 谢谢 SP 以上来自于谷歌翻译 以下为原文 ok, the original thread was updated. Please remove this one if you would. Thanks SP |
|
|
|
|
|
''这是一个改进的4x3键盘代码''
我想你的“改进”与此有关: [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM8SDiscovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM8SDiscovery/Discovery with LCD and 4x3 keypad example&amp; FolderCTID = 0x01200200770978C69A1141439FE559EB459D758000CCDF802E596CAF44ADED5E61F5CA8B1B] https://my.st的.com /公共/ STe2ecommunities / MCU /列表/ STM8SDiscovery / Flat.aspx RootFolder =%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM8SDiscovery%2fDiscovery%20with%20LCD%20于是%204x3%20keypad%20example&安培; FolderCTID = 0x01200200770978C69A1141439FE559EB459D758000CCDF802E596CAF44ADED5E61F5CA8B1B 您还应该使用指向此“改进”的链接更新该线程... 以上来自于谷歌翻译 以下为原文 ''Here's an improved code for the 4x3 keypad'' I guess your ''improvement'' relates to this: [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM8SDiscovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM8SDiscovery/Discovery with LCD and 4x3 keypad example&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000CCDF802E596CAF44ADED5E61F5CA8B1B]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM8SDiscovery/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM8SDiscovery%2fDiscovery%20with%20LCD%20and%204x3%20keypad%20example&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000CCDF802E596CAF44ADED5E61F5CA8B1B You should also update that thread with a link to this ''improvement''... |
|
|
|
|
只有小组成员才能发言,加入小组>>
stm32mp157的异核通信的rpmsg_sdb的m4固件和a7驱动该如何编写?
1465 浏览 0 评论
stm32f103用freertos对一个采样率为1kHz的传感器,进行采样,数据出差
1518 浏览 0 评论
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
3664 浏览 1 评论
3856 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
2475 浏览 1 评论
STM32H7打开DCache后,出现了串口接收信息为空的现象,是哪里出了问题?
745浏览 5评论
用NANO STM32F103RBT6的开发板烧录不了是哪里出了问题?
678浏览 5评论
723浏览 5评论
外部中断触发类型为双边沿触发,进入中断回调后有什么办法判断该边沿是上升沿还是下降沿?
962浏览 5评论
STM32L071CBT6低温环境下无法正常工作是什么原因引起的?
763浏览 5评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-9 07:16 , Processed in 1.072813 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1766