[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
这是读取键盘的子程序
主要内容为:如何定义位,如何得到按键状态,防止键盘干扰的方法
以及如何处理读入的键值
思路:首先在某一引脚输出一个电平,然后读入引脚的电平,如果刚好相反
那么可能有按键发生,但是不排除干扰,为了防止干扰,需要软件延时20ms
消除干扰,然后,等待用户释放,否则,可能重复的到某种结果,发生意外情况
应该说键盘输入是单片机外部指令输入的重要途径,因此如何设计键盘以及键盘的工作原理、读键盘的方法、键盘的抗干扰设计等在单电能机系统设计中占有重要地位。这个例子在系统硬件的基础上设计了软件查询程序、软件延时程序(防止干扰),大致讲述了一种查询式键盘的工作原理与读取方式。
下面是汇编语言写的单片机键盘输入程序
**************************************************
led1 bit p1.0 ;LED 显示位定义
led2 bit p1.1
led3 bit p1.2
led4 bit p1.3
led5 bit p1.4
led6 bit p1.5
led7 bit p1.6
led8 bit p1.7
s1 bit p0.0 ;数码管位定义
s2 bit p0.1
s3 bit p0.2
s4 bit p0.3
s5 bit p0.4
s6 bit p0.5
s7 bit p0.6
s8 bit p0.7
led_data equ p2 ;数码管显示数据定义
key1 bit p3.5 ;按键引脚定义
key2 bit p3.6 ;
key3 bit p3.7 ;
key equ 46h ;按键寄存单元
org 00h
jmp main
org 030h
main:mov sp,#30h ;首先定义
lcall REST ;初始化子程序
lp:lcall pro_key ;调用键盘查询子程序
lcall KEYPR ;用来显示所查询到的键值
jmp lp ;反复调用,不断查询
REST: