键盘接口

合集下载

键盘接口技术

键盘接口技术
(1)训练目的 ①了解独立式键盘的结构与工作原理。 ②掌握按键的检测与软件消抖方法。 ③学会通过独立式按键操作设置参数的编程方法。
(2)训练任务
本项目要完成的任务是设计一个简易数字调节器。 用两位数码管显示数值,变化范围 00—59。开始时 显示 00,每按下 key1 键一次,数值加 1;每按下 key2 键一次,数值减 1;每按下 key3 键一次,数值 归零;按下 key4 键一次,利用定时器功能使数值开 始自动每秒加 1,再次按下 key4 键,数值停止自动 加 1,保持原来的数。Key1—key4 键均采用独立式 按键。 (3)任务引导
TR0=~TR0;
//启动或停止定时器T0
}
}
}
void main()
{
T0_init();
while(1)
{
keyscan();
display(num);
}
}
void T0_time() interrupt 1 //T0中断服务函数
{
TH0=(65536-50000)/256;
//重装初值
TL0=(65536-50000)%256;
1、矩阵式键盘结构
VCC 10k 10k 10k 10k
P1.0 P1.1 8051 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7
2、键盘扫描方式
(逐行)
置低电平,同时读入行(或列)的状态,如果行(
或列)的状态出现非全1状态,这时0状态的行、列
GND
2、独立式键盘接口
结构简单,每个按键接单片机的一条I/O线,通 过对输入线的查询,可以识别每个按键的状态。
I/O
I/O
8051
INT0 INT1

键盘显示器接口

键盘显示器接口

THANK YOU
感谢聆听
HDMI和DisplayPort
HDMI和DisplayPort也是新型的接口技术,广泛应用于 高清视频传输。然而,这些接口技术的普及也面临一些 挑战,如连接线缆的长度限制、设备兼容性和成本等。
兼容性与标准化的挑战
兼容性
随着新型接口技术的出现,键盘显示器接口的兼容性 面临挑战。不同品牌和型号的设备可能采用不同的接 口技术,导致用户在连接时遇到兼容性问题。
HDMI接口
总结词
HDMI接口是一种高清晰度多媒体接口,主要用于连接高清视频源和显示设备。
详细描述
HDMI接口采用小的方形插头,能够传输高质量的音频和视频信号。它支持高分辨率显示,如1080p和4K,并具 有较好的兼容性和易用性。HDMI接口广泛应用于电视、显示器、投影仪等显示设备以及游戏机、DVD播放器等 音视频源设备。
标准化
标准化是推动键盘显示器接口发展的关键因素之一。 缺乏统一的标准化协议可能导致不同设备之间的互操 作性受限,影响用户体验。因此,推动接口技术的标 准化进程对于促进其发展和应用至关重要。
06
总结与展望
键盘显示器接口的重要性和应用价值
重要性和应用价值
键盘显示器接口是计算机系统中的重要组成部分,它能够实现计算机和外部设备之间的数 据传输和控制。键盘显示器接口的应用价值主要体现在人机交互、数据输入输出、远程控 制等方面,对于提高计算机使用效率和用户体验具有重要意义。
会议记录
在会议中,键盘显示器接口用 于实时记录会议内容,方便后 续整理和查阅。
游戏场景中的应用
实时操作
在游戏中,键盘显示器接口用于控制游戏角色行动, 实现精准操作。
竞技对抗
在竞技游戏中,键盘显示器接口用于快速响应,提高 游戏水平。

键盘接口出现故障怎么办

键盘接口出现故障怎么办

键盘接口出现故障怎么办键盘接口内部的弹性接触片由于长时间的使用或者是经常性的弯曲拉动,有时候就会出现扩张现象,从而也就导致了键盘插头的针跟接口中的弹性接触片接触不良或者是没法接触。

一起来看看键盘接口出现故障怎么办,欢迎查阅!键盘的常见故障及处理方法一、键盘的个别按键不能输入这个时候计算机启动时自检正常,但启动后,大多数按键是可以正常输入,有个别的按键不能输入。

这种情况说明键盘上的电路、主机键盘控制接口是正常工作的。

个别按键不能输入的原因可能是该按键座内的弹片失效或者是键内被灰尘污染。

这个时候只要打开键盘,用干的毛巾擦擦按键与金属接触的地方,如果弹片损坏,就小心的拨正它,实在不行就换一个就可以了。

二、按键输入的不是想要的信息当正常启动机器后,在输入框中输入某个按键的字符时时,显示出来的并不是本位按键上的字符,而显示其它键位的字符。

这种情况大多数按键是正常,有几个键位输入时不显示键位本身的字符,而显示其它按键位的字符,一般是按键的连线松动或脱落,造成按键码串位所致。

解决这种情况只要打开键盘,查看键位连接线,查出故障位置,调整正确后,然后拧紧螺丝就可以了。

三、键盘的灰尘清理使用久了,无论是键盘表面还是键盘的内部,都可能积满了灰尘。

这个时候怎么清理呢。

可以把键盘反过来轻轻拍打,让其内的灰尘落出;也可以用湿布清洗键盘表面,但注意湿布一定要拧干,以防水进入键盘内部。

使用时间较长的键盘需要拆开进行维护。

拆卸键盘比较简单,拔下按键盘与主机连接的电缆插头,然后把键盘正面向下放到桌子上,卸下底板上的螺钉,即可取下按键盘后盖板。

如果是清理键盘的内部,一定记着不要用水来清洗,因为水很容易腐蚀按键盘里面的金属。

可以用酒精清洗。

也可以可以用油漆刷或者油画笔扫除电路板和键盘按按键上的灰尘。

四、键盘接口损坏有些时候,键盘的接口损坏,怎么输入也不管用。

这种情况,就要把按键盘拆开。

把按键帽取下,滴入酒精,装上按键帽,反复敲击几次。

键盘、鼠标接口的各针脚功能

键盘、鼠标接口的各针脚功能

键盘、鼠标接口针脚图
主板背面键盘接口针脚图
主板背面鼠标接口针脚图
键盘、鼠标接口的各针脚功能
时钟脚(CLOCK)同步,并通过数据脚(DA TA)交换数据。

主板中键盘、鼠标的接口电路主要由PS/2接口、电容、电感、排阻、跳线、南桥芯片或I/O芯片等组成,主板键盘、鼠标接口电路的时钟信号和数据信号一般由南桥或I/O芯片控制。

检测键盘/鼠标接口时,可以测量以下关键测试点
1、测量键盘、鼠标接口的供电引脚(第4脚)对地阻值,正常阻
值应为180~380Ω。

2、测量键盘、鼠标接口的数据线(第1脚)和时钟脚(第5脚)
的对地阻值,正常阻值应为600Ω左右。

键盘显示器及功率接口

键盘显示器及功率接口

6.1.4 BCD码拨盘接口
BCD码十进制拨盘是向单片机应用系统输入数据的设 备,是一种硬件设置数据的设备。使用拨盘输入的数据具 有不可变性,却又易于修改。十进制输入,BCD输出的拨 盘是最常使用的一种。图6-7所示是一个4位BCD码拨盘组 结构和连接示意图。每位拨盘有0~9十个拨动位置,每个 位置有相应的数字表示,分别代表拨盘输入的十进制数。 所以,一位拨盘可以代表一位十进制数,可以根据设计的 需要,用多位BCD码拨盘组成多位十进制数。
判断是否有键下的方法是,查询哪一根接按键的I/O线为 低电平时,便知此键按下。独立式非编码键盘的优点是电路结 构简单。缺点是当键数较多时,占用的I/O口线多。例如编写 图6-4所示的键处理程序如下:
图 6-4 独立式非编码键盘
程序清单 START:MOV A,#0FFH ; 输入时先置P1口为全1 MOV P1,A MOV A,P1 ;键状态输入 JNB ACC.0,P0F ;0号键按下转POF标号地址 JNB ACC.1,P1F ;1号键按下转P1F标号地址 JNB ACC.2,P2F ;2号键按下转P2F标号地址 JNB ACC.3,P3F ;3号键按下转P3F标号地址 JNB ACC.4,P4F ;4号键按下转P4F标号地址 JNB ACC.5,P5F ;5号键按下转P5F标号地址 JNB ACC.6,P6F ;6号键按下转P6F标号地址 JNB ACC.7,P7F ;7号键按下转P7F标号地址 SJMP START ;无键按下返回
图 6-7 4位BCD码拨盘结构和连接
BCD码盘有一个输入控制线A,4个BCD码输出信号线。拨盘的各个 不同的位置,使输入控制线A分别与4根BCD码输出线中的某几根接通, 使BCD码输出线的状态与拨盘所显示的值一致,并使该编码信号输入单 片机的CPU。BCD码拨盘的输入输出状态如表6-2所示。

9 接口技术II键盘接口

9 接口技术II键盘接口

P.168
b. 线反转法
采用线反转法的键盘行线、 列线端口各自应当可以在输 入与输出方式间切换! 如图:高四位与低四位均可 独立改变其输入或输出方式
实验板4×4键盘 实验板 × 键盘 连接82C55的端口线 连接 的端口线 PC3 PC2 PC1 PC0 PC4 PC5 PC6 PC7
图10-10线反转法原理图 10-10线反转法原理图 第1步:列线输出为全‘0’ ,随后输入行线电平如有‘0’,则 线输出为全‘ 随后输入行线电平如有‘ , 所在的行就是闭合的按键所在行; 则无键闭合。 ‘0’所在的行就是闭合的按键所在行;无‘0’则无键闭合。 所在的行就是闭合的按键所在行 则无键闭合 随后输入列线电平如有‘ , 第2步:行线输出为全‘0’ ,随后输入列线电平如有‘0’,则 线输出为全‘ 则无键闭合。 所在的列就是闭合的按键所在列; 则无键闭合 ‘0’所在的列就是闭合的按键所在列;无‘0’则无键闭合。 所在的列就是闭合的按键所在列 结合上述两步,可确定按键所在行和列。 结合上述两步,可确定按键所在行和列。
键盘扫描子程序---3 TEST2011.ASM 键盘扫描子程序--3 KN:MOV MOV MUL MOV JMP A,61H B,#05H AB DPTR,#K0 DPTR,#K0 @A+DPTR ;根据查表获得的键号00H~0FH之一转向相应处理程序 根据查表获得的键号00H~0FH之一转向相应处理程序 00H ;转移表中每个键号处理程序占 转移表中每个键号处理程序占5 ;转移表中每个键号处理程序占5个地址单元
键盘扫描子程序---1 TEST2011.ASM 键盘扫描子程序--1 KEY:MOV 键盘扫描子程序(反转法) KEY:MOV A,#81H ;键盘扫描子程序(反转法) MOV DPTR,#0FEFFH ;C口先初始化为高 位输出驱行线、 口先初始化为高4 MOVX @DPTR,A ;C口先初始化为高4位输出驱行线、低4位输入列线 MOV DPTR,#0FEFEH 键盘行线 行线( 输出驱动全 驱动全'0' MOV A,#00H ;键盘行线(高4位)输出驱动全'0' MOVX @DPTR,A A,@DPTR 输入键盘列线电平 列线电平( 60H单元 MOVX A,@DPTR ;输入键盘列线电平(低4位)存60H单元 MOV 60H,A ;C口改初始化为高 位输入行线、 口改初始化为高4 MOV A,#88H ;C口改初始化为高4位输入行线、低4位输出驱列线 MOV DPTR,#0FEFFH MOVX @DPTR,A MOV DPTR,#0FEFEH 键盘列线 列线( 输出驱动全 驱动全'0' MOV A,#00H ;键盘列线(低4位)输出驱动全'0' MOVX @DPTR,A 行线电平( 输入键盘行线电平 MOVX A,@DPTR ;输入键盘行线电平(高4位)在A中 ANL 60H,#0FH ;列线电平值保留所在的低4位 列线电平值保留所在的低4 行线电平值保留所在的高4 ANL A,#0F0H ;行线电平值保留所在的高4位 ;两次输入的列线电平值 行线电平值组合成 两次输入的列线电平值、 合成8 ORL 60H,A ;两次输入的列线电平值、行线电平值组合成8位行列码

电脑键盘接线图

电脑键盘接线图

电脑键盘接线图判断键盘控制电路板上的四根线各起什么作用至关重要。

将电路板翻过来后可以看到其背面已有明确的提示(图四):黄线Vcc为+5V高电平;红线为地线GND低电平;绿线为Keyboard DATA高电平;白线为Keyboard Clock低电平。

不同的键盘连线颜色的定义可能也不同,因此如果不能根据提示正确识别的话可以用万用表测量一下或者参考图五中对于连线的定义(图五)。

USB延长线中也是一组四根线,分别为红、白、绿、黑四根。

它们分别对应的是+5V电源、数据负线(DATA-)、数据正线(DATA+)及地线(GND)电脑键盘的四根线如何接罗技键盘,y-ss60线的颜色:红,绿,白,黑盼请解答,谢谢!四根线分别是:电源,地,数据,时钟你要把键盘拆出来,线的另一端焊在里面的电路板,上面标有v(电源),g(地),c(时钟),d(数据).再到网上找个键盘接口定义的图,对着另一端接上去就可以了这是普通的ps/2的键盘接线图,图中是接口(ps/2插头)截面图。

上面标的字母一般在键盘里的电路板上有印的,对照着焊就行了。

如果没有标注字母,这个我就没办法了哈哈~多数键盘应该是按照dcgv的顺序排线的,没有写明的可优先考虑这个。

针脚定义如下:pinnamedirdescription1n/cnotconnected2data-keydata3vccpower,+5vdc4gndgnd5n/cnotconnected6clk-clock键盘接线黄、红、白、绿对应的针脚如下对应ps/2线对应ps/2针脚黄3红4白6绿2对应的电线和针脚连接为:对应ps/2线对应ps/2针脚蓝3白6绿2橙4PS/2鼠标自己动手改USB接口USB作为电脑外设的一种高速连接标准,目前已广泛应用到了各种外部设备上。

电脑主机则在机箱上提供了前置USB接口,有的厂商甚至是在显示器与键盘都添加了USB接口,其目的就是为了能够让用户方便的进行连接鼠标、数码相机等耗电量小的USB外设而无须费力弯腰去机箱背后接插USB设备。

键盘显示接口剖析课件

键盘显示接口剖析课件
是目前市场上的主流接口。
键盘接口电路
键盘接口电路主要由芯片和电阻 、电容等元件组成,负责将键盘 输入的信号转换为电脑能够识别
的电信号。
显示接口
显示接口定义
显示接口是连接显示器和电脑的硬件接口,负责传输显示数据到显 示器进行显示。
显示接口类型
常见的显示接口类型有VGA接口、DVI接口、HDMI接口等,其中 HDMI接口具有传输速度快、画面质量高等优点,逐渐成为市场主 流。
技术创新与进步
新型显示技术
随着OLED、QLED等新型显示技术的不断发展,键盘显示 接口在色彩表现、对比度和响应速度等方面将得到显著提 升。
触控技术集成
将触控技术集成到键盘显示接口中,实现更加直观、高效 的操作方式,提升用户体验。
AI与机器学习
利用AI和机器学习技术,实现智能识别、智能推荐等功能 ,进一步提高键盘显示接口的智能化水平。
显示驱动程序
显示驱动程序
负责将扫描码转换为字符或命令,并在屏幕上显 示。
转换算法
将扫描码转换为对应的字符或命令需要使用特定 的转换算法。
显示缓冲区
为了提高显示效率,显示驱动程序使用缓冲区来 存储要显示的字符或命令。
用户交互程序设计
用户交互程序设计
为了方便用户使用,需要设计友好的用户界面和交互方式。
多媒体应用
在多媒体应用中,键盘显示接口用 于各种音频、视频设备,实现设备 的控制和信息的输入。
02
键盘显示接口的硬件结构
Chapter
键盘接口
键盘接口定义
键盘接口是连接键盘和电脑的硬 件接口,负责传输键盘输入的信
号到电脑进行处理。
键盘接口类型
常见的键盘接口类型有PS/2接口 和USB接口,其中USB接口具有 即插即用、支持热插拔等优点,

8 键盘接口技术

8 键盘接口技术

按键输入原理
在单片机应用系统中,除了复位按键有专门的复位电路及专一的 复位功能外,其他按键都是以开关状态来设置控制功能或输入数据。 当所设置的功能键或数字键按下时,单片机系统应完成该按键所设定
的功能,按键信息输入是与软件结构密切相关的过程。
对于一个键盘或一组按键,单片机系统中总有一个接口电路与 CPU相连。CPU可以采用查询或中断方式了解有无按键输入并检查是 哪一个键按下,将该键号送入累加器ACC,然后通过跳转指令转入执 行该键的功能程序,执行完后再返回主程序。
• 矩阵键盘的接口实例
• 实践与思考
矩阵式键盘的结构与工作原理
矩阵式键盘中,行、列线分别连接到 按键开关的两端,行线通过上拉电阻接到 +5V上。当无键按下时,行线处于高电平状 态;当有键按下时,行、列线将导通,此 时,行线电平将由与此行线相连的列线电 平决定。这一点是识别矩阵按键是否被按
下的关键。然而,矩阵键盘中的行线、列
这种电路每个按键需要
占用一根I/O线,在按
键数量较多时,输入口 浪费大且电路结构很烦
琐,因此这种键盘接口
电路只适用于按键较少 或要求较高操作速度的
场合。
简单键盘的接口电路与编程
下面以图 (a)为例进行编程。 (1)程序实现的功能 (2)程序采用的方法
(3)程序中用到的变量和常量的定义
(4)程序中调用的子程序 (5)程序清单 (6)程序分析与思考
第2章 键盘接口技术
1. 按键
2. 简单键盘接口
3. 矩阵式键盘接口 4. 可编程键盘接口
按键
键盘由一组规则排列的按键组成,一个按键实际上是一个开关元件, 也就是说键盘是一组规则排列的开关。单片机使用的按键是一种常开型 的开关,平时按键的两个触点处于断开状态,按下键时它们才闭合。

计算机键盘接口

计算机键盘接口

输入:扫描键盘、扫描传感器、选通输入方式 输出:8段LED显示器接口,8个或16个,左(右)入口
19
20
21
22
一、外部引脚

面向CPU的信号(15)
D0~7、CS、RD、WR A0:端口选择,=0,数据口,=1, 命令口或状态口 RESET:复位,高有效,复位后工 作于16字符,左入口; 编码扫 描键盘,双键互锁;时钟分频系 数31 IRQ:中断申请,高有效,通常键 盘有数据输入请求时有效 CLK:时钟,为8279提供内部工 作时钟
读位置码->查表->字符码
非编码键盘的按键识别: (1)行扫描法
由程序对键盘进行逐行扫描,通过检测到的列输出状态来确 定闭合键。
8
行扫描法
一.峨峨
(a) 无键按下; (b) 有键按下; (c) 扫描第 0 行; (d)扫描第1行;(e)扫描第2行;(f)扫描第3行
9
行扫描法
(a) 无键按下; (b) 有键按下; (c) 扫描第 0 行; (d)扫描第1行;(e)扫描第2行;(f)扫描第3行
回复缓冲器:缓冲并锁存回复信号RL0~7的状态 去抖动电路:实现对键盘输入的去抖动 控制逻辑:按命令要求控制去抖动电路,并处理回复信 号RL0~7
键盘输入方式,有键闭合时,去抖动 电路被置位,延时10ms再检测,并将 其位置信息与SHIFT、CNTL的状态一 起形成键盘数据,送入FIFO RAM
传感器输入方式,RL0~7的状态直接 送入传感器RAM(即FIFO RAM) 选通输入方式,在CNTL/STB的上升沿 将RL0~7状态送入FIFO RAM
29
二、内部结构
FIFO/传感器RAM:8×8位
键盘输入方式或选通输入方式作先

4.1.键盘接口

4.1.键盘接口
第一节、键盘接口
一、键盘简介 二、非编码键盘 三、编码键盘 四、触摸屏技术
一、键盘简介
1、键盘控制的优点: (1)以少胜多,只要为数不多的按键就可完成传 统仪器中许多面板控扭的作用。 (2)简单可靠,键盘一般使用单触点、双触点按 键,机械结构简单,可靠性高,造价亦低。 (3)易于修改,可不必更改面板的原有结构,只 需修改软件即可更改按键的定义。 (4)便于远控,按键的通、断对应于“0”、“1” 两种状态,即为数字信号,便于传输实现远控。
(二)、矩阵式非编码键盘 1.行扫描法 以步进扫描方式,每次在键盘的一行 发出扫描信号,同时检查列线输入信号, 若发现某列输入信号与扫描信号一致,。
二、非编码键盘
位置码: 一组输出 输入码
查表法 键读数 位置码
二、非编码键盘
(二)矩阵式非编码键盘
二、非编码键盘
(一)、独立联接式非编码键盘
一旦发现有键入,程序即进入KYIDY (按键识别)程序段,进一步去识别出是 哪一个键,并译出键码来。这种键盘接口 的优点是简单,但当键数较多时,就要占 用多个口。
二、非编码键盘
(二)、矩阵式非编码键盘 识别按键有两种方法: 行扫描法 线反转法
二、非编码键盘
;送行码00H,开放所有行 ;取出列信号 ;有键合上吗? ;置A为全1,返回 ;软件延时,去抖动
通过接口进行行扫描; 键盘接口程序如下:
MOV R2,#0FEH MOV R0,#0FDH MOV R1,#0FBH KEYB2: MOV A,R2 MOVX @R0,A MOVX A,@R1 ANL A,#0F0H MOV R3,A CJNE A,#0F0H,KEYB3 MOV A,R2 RL A ;指向第一行
二、非编码键盘

18-13上键盘接口

18-13上键盘接口

简化段定义格式
MASM 6.x支持
.model small ;定义程序的存储模式
.data .code start: mov ; 定义数据段 ; 定义代码段 ax,@data ;程序起始点,建立DS 键盘接口设计实例--源程序(数据段)
mov .exit
end
ds,ax 0 ;程序结束点,返回DOS
实验步骤 8255并行口实验 1、(关实验箱电源)实验接线:(表示相互连接) CS8255 CS0 PA0 K1 PA1 K2 实验内容 PB0 LED1 PB1 LED2 实验题1 实验书120页 实验三 编写程序,使得逻辑电平开关的变化 2、(打开实验箱电源)PC机运行8086调试软件 TECH86---串口COM1—PREST键 在发光二极管上显示出来。即当开关 编辑程序,单步运行,调试程序 ki置于L时,对应发光二极管LEDi点亮; 置于H时熄灭 调试通过后,全速运行程序,观看实验结 果 实验题2 实验题1的改进
本次课内容
6.5 键盘接口
矩阵键盘结构 键盘接口硬件电路 键盘编程 键盘接口设计实例 8255并行口实验
6.5 键盘接口 简易键盘
线性结构键盘
+5V
矩阵结构键盘
列 +5V
+5V
+5V 行
+5V
键盘概述
键盘是计算机最重要的输入设备之一,它是人与计算机 进行沟通的主要工具。 键盘一组按键开关的集合,由一组排列好了的数字键、 字母键或功能键组成,用户通过键盘向计算机输入控制 命令、程序和数据,指挥计算机按用户的要求工作。
键盘接口设计实例--源程序(代码段主程序)
KEY子程序(1)(2)
start ; 汇编结束

常用键盘接口

常用键盘接口

常用键盘接口
常用按键接口可分为独立式按键接口、行列式按键接口和专用芯片式等。

具体采用哪种方式,可根据所设计系统的实际情况而定。

下面分别介绍这几种接口方式的优缺点及适用场合。

1.独立式按键接口
独立式按键接口设计优点是电路配置灵活,软件实现简单。

但缺点也很明显,每个按键需要占用一根口线,若按键数量较多,资源浪费将比较严重,电路结构也变得复杂。

因此本方法主要用于按键较少或对操作速度要求较高的场合。

软件实现时,可以采用中断方式,也可以采用查询方式,示意图如图所示。

图独立式键盘接口
2.行列式按键接口
行列式按键接口示意图如图(a)所示,其使用原理将在下节详细讲述。

行列式按键接口适应于按键数量较多,又不想使用专用键盘芯片的场合。

这种方式的按键接口由行线和列线组成,按键位于行、列的交叉点上。

这种方式的优点就是相对于独立接口方式可以节省很多I/O 资源,相对于专用芯片键盘可以节省成本,且更为灵活。

缺点就是需要用软件处理消抖、重键等。

行列式按键接口是一种老式的键盘接口,其键扫描方法是几乎所有PC 键盘所采用的方法。

tips:感谢大家的阅读,本文由我司收集整编。

仅供参阅!。

22 键盘接口技术

22 键盘接口技术
பைடு நூலகம்
三、 非编码键盘
非编码键盘分为独立式键盘和矩阵键盘。 在计算机控制系统中,有时候只需要使用 简单的键盘就能完成操作输入,按键的数 量较少可采用独立式键盘。当按键的数目 较多时,将增加输入口线,为了减少输入 口线,可采用矩阵键盘。
1、独立式键盘工作原理及接口
(1)查询法接口电路
现以3个按键为例,下图即为独立式键盘查询 法与 合接时C口P,U电数的路据数。线据按直线键接DS接00、、地DS,11、、因D而S22分相C别连PU通,读过当入上按D拉键i=电S0i阻闭; 当按键 Si 断开时,数据线通过上拉电阻接到正 电源,因而 CPU读入Di=1 。该接口电路实现的 功能为:查询检测是否有键按下,如有键闭合, 则消除抖动,再判断键号,然后转入相应的键 处理。其程序流程如图所示。采用查询法时, 必须保证 CPU每隔一定时间主动地去扫描按键 一次,该扫描时间间隔应小于两次按键的时间 间隔,否则会有按键不响应的情形。显然这种 方式占用 CPU 时间比较多。
图 5-5 独立式键盘查询法程序流程图
(2)中断法接口电路
仍以 3个按键为例,下图是一个炉温控制系统的功 能键分配图, S0、S1、S2分别代表自动 / 手动切换、 炉温参数显示和炉温参数打印功能。这是在上述查 询法接口电路的基础上,再把按键 S0、S1、S2的数 据输出线经过与非门和反相器后与 8255A 的选通输 入信号 PC4 相连, 8255A 的PC3 发出中断请求信号 经中断控制器 8259A 与CPU 的中断请求引脚相连, 这是一种典型的中断法键盘接口电路。
1.硬件方法
硬件方法是设计一个滤波延时电路或单稳态电路等硬 件的间电滤。路波按来延键避 时S未开 消按按 抖下键 电时的 路,抖 ,电动 设容时 置两间在端。按电下键压图S为与是C0由,PUR即2数和与据C非线组门D成输i之

AT键盘接口资料

AT键盘接口资料

IBM Keyboards. Not really an interesting topic, one would expect. So why would you want to interface the Keyboard? The IBM keyboard can be a cheap alternative to a keyboard on aMicroprocessor development system. Or maybe you want a remote terminal, just couple it with a LCD Module.Maybe you have a RS-232 Barcode Scanner or other input devices, which you want to use with existing software which only allows you to key in numbers or letters. You could design yourself a little box to convert RS-232 into a Keyboard Transmission, making it transparent to the software.An interfacing example is given showing the keyboard's protocols in action. This interfacingexample uses a 68HC705J1A MCU to decode an IBM AT keyboard and output the ASCIIequivalent of the key pressed at 9600 BPS.Note that this page only deals with AT Keyboards. If you have any XT keyboards, you wish to interface, consider placing them in a museum. We will not deal with this type of keyboard in this document. XT Keyboards use a different protocol compared to the AT, thus code contained on this page will be incompatible.The IBM keyboard you most probably have sitting in front of you, sends scan codes to yourcomputer. The scan codes tell your Keyboard Bios, what keys you have pressed or released.Take for example the 'A' Key. The 'A' key has a scan code of 1C (hex). When you press the 'A' key, your keyboard will send 1C down it's serial line. If you are still holding it down, for longer than it's typematic delay, another 1C will be sent. This keeps occurring until another key has been pressed, or if the 'A' key has been released.However your keyboard will also send another code when the key has been released. Take the example of the 'A' key again, when released, the keyboard will send F0 (hex) to tell you that the key with the proceeding scan code has been released. It will then send 1C, so you know which key has been released.Your keyboard only has one code for each key. It doesn't care it the shift key has been pressed. It will still send you the same code. It's up to your keyboard BIOS to determine this and take the appropriate action. Your keyboard doesn't even process the Num Lock, Caps Lock and Scroll Lock. When you press the Caps Lock for example, the keyboard will send the scan code for the cap locks. It is then up to your keyboard BIOS to send a code to the keyboard to turn on the Caps lock LED.Now there's 101 keys and 8 bits make 256 different combinations, thus you only need to send one byte per key, right?Nop. Unfortunately a handful of the keys found on your keyboard are extended keys, and thus require two scan code. These keys are preceded by a E0 (hex). But it doesn't stop at two scan codes either. How about E1,14,77,E1,F0,14,F0,77! Now that can't be a valid scan code? Wrong again. It's happens to be sent when you press the Pause/break key. Don't ask me why they have to make it so long! Maybe they were having a bad day or something?When an extended key has been released, it would be expect that F0 would be sent to tell you that a key has been released. Then you would expect E0, telling you it was an extended key followed by the scan code for the key pressed. However this is not the case. E0 is sent first, followed by F0, when an extended key has been released.Besides Scan codes, commands can also be sent to and from the keyboard. The following section details the function of these commands. By no means is this a complete list. These are only some of the more common commands.These commands are sent by the Host to the Keyboard. The most common commandwould be the setting/resetting of the Status Indicators (i.e. the Num lock, Caps Lock &Scroll Lock LEDs). The more common and useful commands are shown below.ED Set Status LED's - This command can be used to turn on and off theNum Lock, Caps Lock & Scroll Lock LED's. After Sending ED, keyboardwill reply with ACK (FA) and wait for another byte which determines theirStatus. Bit 0 controls the Scroll Lock, Bit 1 the Num Lock and Bit 2 theCaps lock. Bits 3 to 7 are ignored.EE Echo - Upon sending a Echo command to the Keyboard, the keyboardshould reply with a Echo (EE)F0Set Scan Code Set. Upon Sending F0, keyboard will reply with ACK(FA) and wait for another byte, 01-03 which determines the Scan CodeUsed. Sending 00 as the second byte will return the Scan Code Setcurrently in UseF3Set Typematic Repeat Rate. Keyboard will Acknowledge command withFA and wait for second byte, which determines the Typematic RepeatRate.F4Keyboard Enable - Clears the keyboards output buffer, enablesKeyboard Scanning and returns an Acknowledgment.F5Keyboard Disable - Resets the keyboard, disables Keyboard Scanningand returns an Acknowledgment.FE Resend - Upon receipt of the resend command the keyboard will re-transmit the last byte sent.FF Reset - Resets the Keyboard.Now if the Host Commands are send from the host to the keyboard, then the keyboardcommands must be sent from the keyboard to host. If you think this way, you must becorrect. Below details some of the commands which the keyboard can send.FA AcknowledgeAA Power On Self Test Passed (BAT Completed)EE See Echo Command (Host Commands)FE Resend - Upon receipt of the resend command the Host should re-transmit the last byte sent.00Error or Buffer OverflowFF Error or Buffer OverflowThe diagram below shows the Scan Code assigned to the individual keys. The Scan code is shown on the bottom of the key. E.g. The Scan Code for ESC is 76. All the scan codes are shown in Hex.As you can see, the scan code assignments are quite random. In many cases the easiest way to convert the scan code to ASCII would be to use a look up table. Below is the scan codes for the extended keyboard & Numeric keypad.The PC's AT Keyboard is connected to external equipment using four wires. These wires are shown below for the Male Plug.The Host to Keyboard Protocol is initiated by taking the KBD data line low. However to prevent the keyboard from sending data at the same time that you attempt to send the keyboard data, it is common to take the KBD Clock line low for more than 60us. This is more than one bit length.Then the KBD data line is taken low, while the KBD clock line is released.The keyboard will start generating a clock signal on it's KBD clock line. This process can take up to 10mS. After the first falling edge has been detected, you can load the first data bit on the KBD Data line. This bit will be read into the keyboard on the next falling edge, after which you can place the next bit of data. This process is repeated for the 8 data bits. After the data bits come an Odd Parity Bit.Once the Parity Bit has been sent and the KBD Data Line is in a idle (High) state for the next clock cycle, the keyboard will acknowledge the reception of the new data. The keyboard does this by taking the KBD Data line low for the next clock transition. If the KBD Data line is not idle after the 10th bit (Start, 8 Data bits + Parity), the keyboard will continue to send a KBD Clock signal until the KBD Data line becomes idle.Normally in this series of web pages, we connect something to the PC, to demonstrate theprotocols at work. However this poses a problem with the keyboard. What could be possibly want to send to the computer via the keyboard interface?Straight away any devious minds would be going, why not a little box, which generatespasswords!. It could keep sending characters to the computer until it finds the right sequence.Well I'm not going to encourage what could possibly be illegal practices.In fact a reasonably useful example will be given using a 68HC705J1A single chip microcontroller.We will get it to read the data from the keyboard, convert the scan codes into ASCII and send it out in RS-232 format at 9600 BPS. However we won't stop here, you will want to see the bi-directional use of the KBD Clock & Data lines, thus we will use the keyboards status LEDS, Num Lock, Caps Lock and Scroll Lock.This can be used for quite a wide range of things. Teamed up with a reasonably sized 4 line x 40 character LCD panel, you could have yourself a little portable terminal. Or you could use it with a microcontroller development system. The 68HC705J1A in a One Time Programmable (OTP) is only a fraction of the cost of a 74C922 keyboard decoder chip, which only decodes a 4 x 4 matrix keypad to binary.The keyboard doesn't need to be expensive either. Most people have many old keyboards floating around the place. If it's an AT Keyboard, then use it (XT keyboards will not work with thisprogram.) If we ever see the introduction of USB keyboards, then there could be many redundant AT keyboards just waiting for you to hook them up.! "Before we start with the technical aspects of the project, the salesman in me wants to tell you about the features packed into the 998 bytes of code.Use of the keyboard's bi-directional protocol allowing the status of the Num Lock, Caps Lock and Scroll Lock to be displayed on the Keyboards LEDs.External Reset Line activated by ALT-CTRL-DEL. If you are using it with a Microcontroler development system, you can reset the MCU with the keyboard. I'vealways wanted to be able to use the three fingered solute on the HC11!Scroll Lock and Num Lock toggles two Parallel Port Pins on the HC705. This can be used to turn things on or off, Select Memory Pages, Operating Systems etc "ALTDEC" or what I call the Direct Decimal Enter Routine. Just like using a PC, when you enter a decimal number when holding down one of the ALT keys the number issent as binary to the target system. E.g. If you press and hold down ALT, then type in255 and release ALT, the value FF (Hex) will be sent to the system. Note. Unlike thePC, you can use both the numeric keypad or the numbers along the top of thekeyboard."CTRLHEX" or you guessed it, Direct Hexadecimal Enter Routine. This function is not found with the PC. If you hold CTRL down, you can enter a Hexadecimal number. Justthe thing for Development Systems or even debugging RS-232 Comms?Output is in ASCII using a RS-232 format at 9600 BPS. If using it with a development System, you can tap it in after the RS-232 Line Transceivers to save you a few dollarson RS-232 Level Converters.# $The schematic below, shows the general connections of the keyboard to the HC705. The O.C.on the inverters denotes Open Collector outputs. I've used 74LS05 for the Open Collector Inverters, but it is up to you how you want to implement it. You can also use transistors with a suitable current limiting resistor, if you see fit.The TXD pin, while it transmits in RS-232 format, is not at RS-232 Voltage Levels. If you want to connect it to RS-232 Devices then you will need to attach a RS-232 Level Converter of some kind. If you are using it with a development system, you can bypass both RS-232 Level Converters and connect it directly to the RXD pin of the MCU. However the keyboard can't be a direct replacement for a terminal on a development system, unless you want to type in your code each time! You may want to place a jumper or switch inline to switch between your RS-232 Port and the keyboard.The circuit is designed to run on a 4Mhz crystal (2Mhz Bus Speed). The timing for the RS-232 transmission is based on the bus speed, thus this crystal has to be 4 Mhz. If you are lucky enough to have a 4 Mhz E Clock on your development system you can use it. I might at a later date try to create a 2 Mhz version which will run happily off a HC11 with a 8 Meg Crystal. This will reduce the cost of the project even further.The power supply can also create a slight problem. A standard keyboard can drain about300mA max, thus it would be recommended to use it's own regulator rather than taking a supply from elsewhere. Filter Capacitors are not shown on the general schematic but are implied for reliable operation. Consult your MC68HC705J1A Technical Data Manual for more information.% & 'Now it is time to look at the code. I cannot include a description of all the code in this web page. The list file is just on 16 pages. Most of it (hopefully) is easy to follow. Just like other code, count the number of spelling errors, while you are at it.Receive ldx #08 ;Number of Bitsclra ;Clear Parity Registerbclr clkout,PORTB ;Clear to Sendbrset clkin,PORTB,* ;wait for idle Clockbrset datain,PORTB,Receive ;False Start Bit, RestartRemember the KBD Clock line? If you take it low, the keyboard will buffer any keys pressed. The Keyboard will only attempt to send when both the Data and Clock lines are idle (high). As it can take considerable time to decode the keys pressed, we must stop the keyboard from sending data. If not, some of the data may be lost or corrupted.The program, will keep the KBD Clock line low, unless it is ready to accept data. We will use a loop to retrieve the data bits from the keyboard, thus we will load index register X with the number of bits be want to receive. The Accumulator will be used to verify the parity bit. We must clear this first.We then place the KBD Clock line in the idle state so that the keyboard will start transmitting data if a key has been pressed. The program then loops while the Clock Line is Idle. One the KBD clock goes low, the loop is broken and the KBD Data Line is read. This should be the start bit which should be low. If not we branch to the start of the receive routine.Recdata ror bytejsr highlow ;Wait for high to low Transitionbrset datain,PORTB,Recsetbclr 7,bytejmp RecnextRecset bset 7,byteincaRecnext decxbne Recdata ;Loop until 8 bits been receivedOnce the Start bit has been detected, the 8 data bits must follow. The data is only valid on the falling edge of the clock. The subroutine highlow shown below will wait for the falling edge of the clock.highlow brclr clkin,PORTB,* ;Loop until Clk Highbrset clkin,PORTB,* ;Loop until Clk LowrtsAfter the falling edge we read the level of the KBD Data line. If it is high we set the MSB of byte or if it is clear, we clear it. You will notice if the bit is set, we also increment the accumulator. This keeps track of the number of 1's in the byte and thus can be used to verify the Parity Bit. Index register X is decremented as we have read a byte. It then repeats the above process, until the entire 8 bits have been read.jsr highloweor PORTB ;Parity Bit Detectionand #$01beq r_errorAfter the 8 data bits, comes the dreaded Parity Bit. We could ignore it if we wanted to, but we may as well do something about it. We have been keeping a tally of the number of 1's in the Accumulator. The keyboard uses Odd parity, thus the parity bit should be the complement of the LSBit in the Accumulator. By exclusive OR-ing the Accumulator with the Parity Bit, we get a 1 if both the bits are different. I.e a '1' if the parity bit checks out.As we are only interested in the LSB we can quite happy XOR the accumulator with PORTB. However this means the KBD datain must be connected to PB0. This can be a slight catch if you alter the equates. Then we single out the LSB using the AND function. If the resultant is zero, then a parity error has occurred and the program branches to r_error.jsr highlowbrclr datain,PORTB,r_error ;Stop Bit Detectionbset clkout,PORTB ;Prevent Keyboard from sending data;(Clear to Send)rtsAfter the Parity Bits comes the Stop Bit. Once again we can ignore it if we desire. However we have chosen to branch to an error routine if this occurs. The Stop bits should be set, thus an error occurs when it is clear.r_error lda #$FE ;Resendsta bytejsr Transmitjmp Receive ;Try againWhat you do as error handling is up to you. In most cases it will never be executed. In fact I don't yet know if the above error handling routine works. I need to program another HC705 to send a false parity bit. I've tried it out in close proximity to the Washing Machine, but I really need a controlled source!When an error occurs in the Parity or Stop Bit we should assume that the rest of the byte could have errors as well. We could ignore the error and process the received byte, but it could have unexpected results. Instead the keyboard has a resend command. If we issue a resend (FE) to the keyboard, the keyboard should send the byte back again. This is what occurs here.You may notice that we branch to the error routine which transmits a resend command straightaway, without waiting for the corrupt transmission to finish. This is not a problem, as the keyboard considers any transmission to be successful, if the 10th bit is sent, i.e. the parity bit. If we interrupt the transmission before the parity bit is sent, the keyboard will place the current byte in it's buffer for later transmission.You may of noticed that reading a byte doesn't really require bi-directional data and clock lines. If you can process the byte fast enough then no handshaking (RTS) is required. This means you no longer need the Open Collector inverters and the 2 Parallel Port lines. I have successfully done this with the HC705, outputting only scan codes on a Parallel Bus. But as you can imagine, you must be quick in order to catch the next transmission.( & 'Writing commands to the keyboard involves the use of the Open Collector inverters. If we require an idle line (+5v), then we must transmit a 0 (zero) to achieve this. Everything which is sent via the dataout and clockout lines must be inverted.transmit ldx #$08 ;8 Data Bitsbset clkout,PORTB ;Set Clock Lowlda #$13 ;Delay 64uSjsr delayclra ;Clear Parity Registerbset dataout,PORTB ;Set Data Lowbclr clkout,PORTB ;Release Clock Linejsr highlowThe routine given here is a generic one which can be used for your own purposes. During normal execution of this program the KBD clock line should be low, to prevent data being sent when the MCU isn't ready for it. However in this example, we take low the KBD clock line and wait for the 64uS which is pointless as the line is already low and has been like this for quite some time, since the end of the last Transmission or Reception.The program then initiates the Host to Keyboard transmission by taking the KBD data line low and releasing the KBD clock line. We must then wait for a high to low transition on the KBD clock, before we load the first bit on the KBD data line. - Something which is not clear in other FAQ's on the net.loop ror bytebcs markspace bset dataout,PORTB ; Clear Bitjmp nextmark bclr dataout,PORTB ; Clear Bitinca ; Parity Calculationnext jsr highlow ; Wait for high to low transitiondecxbne loopThe loading of the individual bits on the KBD data line is done in very similar fashion to the read cycle. However note that the bits are inverted. Also like the read cycle, we increment the accumulator so we can calculate the parity bit later on.and #$01bne clr_parset_par bclr dataout,PORTBjmp tr_acknclr_par bset dataout,PORTBtr_ackn jsr highlowAfter the data bits have been sent, it is now time to send the parity bit. Unlike the read cycle, we can't ignore the parity bit. If we do the keyboard will issue a resend (FE) command if the parity bit is incorrect.bclr dataout,PORTB ;Release Data Linejsr highlowbrset datain,PORTB,error ;Check for Ackbrclr clkin,PORTB,* ;Wait for idle linebset clkout,PORTB ;Prevent Keyboard from sending data;(Clear to Send)rtsOnce the Parity bit has been set and the falling edge of the KBD clock detected, we must release the KBD data line, wait for another falling edge of the KBD clock to see if the Keyboard has acknowledged the byte. The keyboard does this by pulling the KBD data line low. If it is not low, then the program branches to an error handler. If all has been successful, the MCU pulls down the KBD clock, to prevent it from transmitting.error lda #$FF ;Resetsta bytejsr transmitrtsWe have taken a harsher approach to handing any transmit errors. Ideally we should wait for the keyboard to send a resend command and then retransmit the byte. However what we have done is to issue a reset of the keyboard. So far I've never had an error, however if this starts to become a problem, then a better error handler will be written."KEYBRD05.ASM Assembled with CASM 02/15/1998 22:12 PAGE 11 *****************************************************2 * *3 * 101 Key, IBM Keyboard Decoder for 68HC705J1A. *4 * *5 * Copyright 1997 / 1998 - Craig Peacock *6 * 15th February 1998 *7 * *8 * Includes ALTDEC & CTRLHEX Routines *9 * *10 *****************************************************110300 12 datain equ 0 ; Must be LSB - See Parity Calculations 0300 13 clkin equ 10300 14 dataout equ 20300 15 clkout equ 30300 16 nreset equ 4 ; Reset Output0300 17 TXD equ 5 ; Transmit Pin on Port B1819 ; Equates for LED Byte200300 21 pscrlck equ 7 ; If true, Scroll Lock Pressed0300 22 pnumlck equ 6 ; If true, Num Lock Pressed230300 24 caplock equ 2 ; If true, Caps Lock is On (Active)0300 25 numlock equ 1 ; If true, Num Lock is On (Active)0300 26 scrlock equ 0 ; If true, Scroll Lock is On (Active)2728 ; Equates for Status Flag, Byte290300 30 rctrl equ 7 ; If true, Right Ctrl Pressed0300 31 lctrl equ 6 ; If true, Left Ctrl Pressed0300 32 ralt equ 5 ; If true, Right Alt Pressed0300 33 lalt equ 4 ; If true, Left Alt Pressed340300 35 caploc equ 2 ; If true, Caps Lock Pressed0300 36 rshift equ 1 ; If true, Right Shift Key Pressed0300 37 lshift equ 0 ; If true, Left Shift Key Pressed3800C0 39 org ram4000C0 41 byte rmb 1 ; Used to hold byte, during Trans & Rec 00C1 42 status rmb 1 ; Status Flags00C2 43 LED rmb 1 ; LED Flags00C3 44 asc rmb 3 ; Used for altdec & ctrlhex4507F8 46 org $7F84707F8 0300 48 dw start ; Timer Interrupt Vector07FA 0300 49 dw start ; IRQ Vector07FC 0300 50 dw start ; Software Interrupt Vector07FE 0300 51 dw start ; Reset Vector520300 53 org rom540300 A6FF 55 start lda #%11111111 ;PORTA0302 B704 56 sta ddra ;Set Data Direction Register0304 B710 57 sta pdra ;Enable Pull Downs580306 A6FC 59 lda #%11111100 ;PORTB0308 B705 60 sta ddrb ;Set Data Direction Register030A B711 61 sta pdrb ;Enable Pull Downs62030C 1A01 63 bset TXD,PORTB ;Transmit Line Idle030E 1501 64 bclr dataout,PORTB ;KBD Data Idle0310 1701 65 bclr clkout,PORTB ;KBD Clock Idle0312 1901 66 bclr nreset,PORTB ;Reset Line Idle670314 CC031E 68 jmp rstflag ;No Attempt to Reset Keyboard made69 ;as keyboard would still be in POST70 ;or BAT Tests, if power applied at71 ;the same time than the HC705.7273 *****************************************************74 * *75 * reset - Sends a Reset Command to the Keyboard. *76 * Not a very good effort to reset keyboard, *77 * as it doesn't check for ACK or BAT *78 * Completion Code. I.e. Reset may not of *79 * even Worked! *80 * *81 *****************************************************820317 A6FF 83 reset lda #$FF ;Reset Keyboard0319 B7C0 84 sta byte031B CD0497 85 jsr transmit8687 *****************************************************88 * *89 * rstflag - Resets Status and LED Flags. Used when *90 * a successful Bat Completion code is *91 * sent to sync keyboard's LED's to 705's *92 * status register *93 * *94 *****************************************************95031E 3FC1 96 rstflag clr status0320 3FC2 97 clr LED9899 *****************************************************100 * *101 * main - Main Keyboard Decoding Routine. Once key *102 * been decoded, program should return here *103 * *104 *****************************************************1050322 CD04E2 106 main jsr Receive ;Get's a Single Byte from the Keyboard.0325 B6C0 107 lda byte1080327 A1F0 109 cmp #$F0 ;A Key has been Released0329 2603 110 bne main1032B CC0429 111 jmp release112032E A1AA 113 main1 cmp #$AA ;Successful Completion of BAT0330 2603 114 bne main20332 CC031E 115 jmp rstflag1160335 A1E0 117 main2 cmp #$E0 ;Extended Keys0337 2603 118 bne main30339 CC03D6 119 jmp extend120033C A112 121 main3 cmp #$12 ;Left Shift Key Pressed033E 2602 122 bne main40340 10C1 123 bset lshift,status1240342 A159 125 main4 cmp #$59 ;Right Shift Key Pressed0344 2602 126 bne main50346 12C1 127 bset rshift,status1280348 A114 129 main5 cmp #$14 ;Left Ctrl034A 2605 130 bne main6034C 1CC1 131 bset lctrl,status034E CC0588 132 jmp clrasc1330351 A111 134 main6 cmp #$11 ;Left Alt0353 2605 135 bne main70355 18C1 136 bset lalt,status0357 CC0588 137 jmp clrasc138035A A158 139 main7 cmp #$58 ;Caps Lock Pressed035C 2605 140 bne main8035E 05C154 141 brclr caploc,status,caps0361 14C1 142 bset caploc,status1430363 A17E 144 main8 cmp #$7E ;Scroll Lock Pressed0365 2605 145 bne main90367 0FC161 146 brclr pscrlck,status,scrl036A 1EC1 147 bset pscrlck,status148036C A177 149 main9 cmp #$77 ;Num Lock Pressed036E 2605 150 bne main100370 0DC14D 151 brclr pnumlck,status,nums0373 1CC1 152 bset pnumlck,status1530375 A18F 154 main10 cmp #$8F ;Last Value in Look-Up Table0377 2503 155 blo main110379 CC0322 156 jmp main ;Out of Bounds157037C 97 158 main11 tax037D 04C20C 159 brset caplock,LED,caps_on0380 02C10F 160 brset rshift,status,shifton0383 00C10C 161 brset lshift,status,shifton1620386 D605C6 163 cancel lda noshift,x ;Load Lower Case Values0389 CC0395 164 jmp main12165038C 02C1F7 166 caps_on brset rshift,status,cancel ;If ShiftLock & Shift, Cancel038F 00C1F4 167 brset lshift,status,cancel1680392 D60656 169 shifton lda shift,x ;Load Upper Case Values1700395 271B 171 main12 beq return ;Scan Code not in Lookup Table. 1720397 97 173 tax0398 B6C1 174 lda status039A A430 175 and #$30 ;Either Alt Key Pressed039C 2704 176 beq main13039E 9F 177 txa039F CC053D 178 jmp altdec17903A2 B6C1 180 main13 lda status03A4 A4C0 181 and #$C0 ;Either CTRL Key Pressed03A6 2704 182 beq main1403A8 9F 183 txa03A9 CC0523 184 jmp ctrlhex18503AC 9F 186 main14 txa03AD B7C0 187 sta byte03AF CD0591 188 jsr RS232T ;Send to RS23218903B2 CC0322 190 return jmp main191192 *****************************************************193 * *194 * caps - Toggle Status of Caps lock and Echo to *195 * Keyboard *196 * *197 *****************************************************19803B5 14C1 199 caps bset caploc,status ; Set caploc flag to prevent routine being 200 ; called again03B7 B6C2 201 lda LED03B9 A804 202 eor #$04 ; Toggle Shift Lock Flag03BB B7C2 203 sta LED03BD CC047B 204 jmp LEDshow205206 *****************************************************207 * *208 * nums - Toggle Status of Nums lock and Echo to *209 * Keyboard *210 * *211 *****************************************************21203C0 1CC1 213 nums bset pnumlck,status21403C2 B6C2 215 lda LED03C4 A802 216 eor #$0203C6 B7C2 217 sta LED03C8 CC047B 218 jmp LEDshow219220 *****************************************************221 * *222 * scrl - Toggle Status of Scroll lock and Echo to *223 * Keyboard *224 * *225 *****************************************************22603CB 1EC1 227 scrl bset pscrlck,status22803CD B6C2 229 lda LED03CF A801 230 eor #$0103D1 B7C2 231 sta LED03D3 CC047B 232 jmp LEDshow。

键盘输入接口电路

键盘输入接口电路

ORG
KEY: ACALL KS
;调用KS子程序
JNZ KEY1
;有键按下转移
ACALL TIM
;延时6ms
AJMP KEY
;无键按下转移
KEY1:ACALL TIM
;延时12ms
ACALL TIM
ACALL KS
JNZ KEY2
ACALL TIM
AJMP KEY
KEY2:MOV R2,#0FEH
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1


PA7
8255
PA1
PA0
PB0
PB1

PB7

图6.33 8×8键盘连接
……
+5V +5V
2. 中断连接方式
中断连接方式,如图6.34所示。所有行线经 “与”门连接到单片
机的中断输入端。当有按键按下时产生负脉冲,向CPU中断请求。
KEY
有键闭合吗? Y
二次调用延时子程序12ms
N
调用延时
子程序6ms
有键闭合吗?
N
Y 判断闭合键键码
闭合键释放吗?
N
Y 转键码处理
返回 图6.31 软件消除抖动和识别键码流程图
图6.31 (2)
+5V
…… …
WR
RD P0口
P2.0
ALE 地
EA P2.4

键盘接口技术PPT课件

键盘接口技术PPT课件

6
7H
5、互动试验装置键盘接口
• 1、装置中键号未 按照顺序定义;
• 使用时可采用查 表方式。
• 2、扫描时,可按 照列号、行号进 行查表,确定键 的键值。
• 全扫描码为0FFH, 无键按下时读入 列值为00H,有键 按下为“1”。
7
例3:键盘扫描程序:D6L3.ASM
• 程序JIANPAN.ASM为键盘扫描例程, 在LED上显示对应的键值。
消除抖动是按键设计所必
须要考虑的问题。
• (2)消除抖动的方法
• 消抖动通常有软件和硬件两种方法。
• 软件消抖动就是在检测到键按下时,执行一段延时子 程序后,再确认该键电平是否仍保持键按下时的状态 电平。延时时间通常取5~10ms以上。
• 硬件消抖动可采用RS触发器或RC延时等方法。
2
2、独立式按键
• 独立式键盘是指各按键相互独立,每个 按键分别与单片机或外扩I/O芯片的一 根输入线相连。
• 如:
• JB P1.0,L1 ;K0闭合? LCALL DELAY ;延时10ms JB P1.0,L1 ;K0闭合? LJMP KEY0 ;K0处理
L1:JB P1.2,L2 ;K1闭合? ……
3
3、行列式键盘(矩阵键盘)
键盘接口技术系统中通常采用非编码键盘 • 非编码键盘连接结构形式有: • (1)独立式键盘 • (2)行列式(矩阵)键盘
1
1、按键闭合过程
• (1)按键抖动问题
• 一般按键开关为机械弹性
开关,由于触点的弹性作
用,会出现“抖动”现象,
抖动时间一般为5~10ms。
• 矩阵式键盘适用于 按键数量较多的场 合。它通常由行线 和列线组成,按键 位于行、列的交叉 点上。

键盘接口实验实验报告及程序

键盘接口实验实验报告及程序

键盘接口实验实验报告及程序一、实验目的本次实验的主要目的是深入了解计算机键盘接口的工作原理,并通过编程实现对键盘输入的读取和处理。

通过这个实验,我们将掌握如何与计算机硬件进行交互,提高对计算机系统底层运作的认识。

二、实验原理计算机键盘通常通过 PS/2 接口或 USB 接口与主机相连。

在本次实验中,我们以 PS/2 接口为例进行研究。

PS/2 接口使用双向同步串行协议进行通信,数据传输速率约为 10 167Kbps 。

键盘在向主机发送数据时,每个字节包含 11 位,分别是起始位(总是 0 )、 8 位数据位(低位在前)、校验位(奇校验)和停止位(总是 1 )。

主机通过向键盘发送命令来控制键盘的工作模式和获取相关信息。

三、实验设备及环境1、计算机一台2、开发板及相关配件3、编程软件(如 Keil 等)四、实验步骤1、硬件连接将开发板与计算机通过相应的接口连接好,确保连接稳定。

2、软件编程选择合适的编程语言和开发环境。

初始化相关的硬件接口和寄存器。

编写读取键盘输入数据的程序代码。

3、编译与下载对编写好的程序进行编译,检查是否有语法错误。

将编译成功的程序下载到开发板中。

4、实验测试按下键盘上的不同按键,观察开发板的输出结果。

检查读取到的数据是否准确,校验位是否正确。

五、程序代码实现以下是一个简单的基于 C 语言的键盘接口读取程序示例:```cinclude <reg51h>//定义 PS/2 接口相关引脚sbit PS2_CLK = P1^0;sbit PS2_DATA = P1^1;//读取一个字节的数据unsigned char ReadByte(){unsigned char data = 0;unsigned char i;while(PS2_CLK == 1);//等待时钟线拉低for(i = 0; i < 8; i++){while(PS2_CLK == 0);//等待时钟上升沿data =(data << 1) | PS2_DATA; //读取数据位}while(PS2_CLK == 1);//等待时钟线拉低return data;}void main(){unsigned char key;while(1){key = ReadByte();//读取键盘输入的数据//在此处对读取到的数据进行处理和显示}}```六、实验结果与分析在实验过程中,我们按下不同的键盘按键,开发板能够准确地读取到相应的键值。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

P2.7 P2.0 WR RD ALE P0 8031 20µ F +5V 1K
3 4 5 6 7 5.1K×4 11 12 13 14 15 19 20 21 22 23 +5V 27 28 29 30 31
3.1.2 键盘信号的获取方法有三种: . 程序扫描法 中断扫描法 定时中断法 键盘监控程序设计方法有 . 直接分析法 状态矩阵法 3.1.3 编码键盘 . 编码键盘的基本任务是识别按键,提供按键读 数,一个高质量的编码键盘还应具有反弹跳、处理 同时按键等功能. . 静态编码器—普通编码器如74148 可编程键盘/显示接口 如8279
8279
8279的组成及引脚
8279 芯片有 40 条引脚, 由单一+5 V电源供电。 它主要由以下几部分组成:
1、 I/O控制和数据缓冲器:利用/CS、A0、/RD、 /WR等信号,控制读写的数据;
2、 控制和定时寄存器及定时控制部分:这些寄 存器储存键盘模式、显示模式,可由程序设置 其操作方式。定时控制包括定时计数器,第1个 计数器为除以N的分频器,可由程序设置,分频 值为2~31。;
8279按设计直接连到CPU总线,CPU通过可编程 控制8279的所有操作方式。这些方式包括: 输入方式: 扫描键盘—带有编码扫描线或译码扫描线。每按一 下按键,就产生一个表示按键位置的6位编码。存储 在FIFO中。 扫描传感器阵列—带有编码扫描线或译码扫描线。 按键的状态被存储在可由CPU寻址的RAM中。 选通输入—在控制线选通时,回送线上数据被传送 到FIFO中。 输出方式: 8字符或16字符的多路切换式显示器。该显示器可被 组合成两组4位或一组8位形式(B0=D0, A3=D7)。 右端输入或左端输入的显示格式。
RL7 RL6 RL5 RL4 RL3 RL2 RL1 RL0
15 14 13 12 11 10 9 8
3、扫描计数器: (1)编码(ENCODE)扫描模式,为二进 码输出,必须外接译码器(74154,4028,74138 等),译码为单一LO或HI,然后送至键盘及显
示器;
(2)译码扫描模式,已经内部译码为单一
LO,只能接4个显示器。
4、返回缓冲器
( 1)键盘扫描模式:当设定键盘扫描模式时,从 SL0~ SL3 送出的扫描信号,将会去扫描键盘,如有按键被 按时,它会等待10ms,然后再检查该按键,将此键码 (含CTRL、SHIFT)存入FIFO RAM内。 ( 2 )传感器模式:当设定为传感器模式时,存入 FIFO RAM的值,完全按扫描的输出码。如有传感元件被触 发时,在 8279内部的 FIFO RAM中都有一个位与之相 对应。 (3)选通输入模式:当CNTR/STB输入一个上升沿触发 时,返回线上的数据码将被反相后存入FIFO RAM, 并由IRQ发出中断信号。
有按键信号? Y 延时等待10ms
N
仍有按键信号? N Y 键盘处理 N
按键释放? Y
8031
+5V
+5V
I/O
INT0 INT1
(a) 中断方式 图 8-1-1 独立式按键电路
I/O
8031
(b)查询方式
独立式按键电路
+5V P 2.7 ALE 8031 P0 WR RD 8 74LS 373 8 PA 0 CS PA 1 8255 PA 2 A0 PA 3 A1 PA 4 D0 ~D 7 PA 5 PA 6 PA 7 WR RD RESET GND 0
• 静态式编码器接口
0 1 2 3 4 5 6 7 10 11 12 13 1 2 3 4 74148 EI 8 7 9 6 A2 A1 键 1 1 1 A2’ 0 A1’ A0’ 1 2 3 4 5 6 7 A2’ A1’ 0 A0’ 0
0
0 0 0 1 1 1
0
1 1 0 0 1 1
1
0 1 0 1 0 1
1 2 3 4 5 6 7
1K
10μF +5V
使用8255扩展I/O的独立式键盘
2.矩阵式非编码键盘
识别按键的方法
行扫描法 线反转法
+5V 10KΩ*3 行码 列 码
0键:1 1 0
1键:1 1 0 2键:1 1 0
1110
1101 1011
行 线
x2
x1 x0
8 4 0
9 5 1
A 6 2
B 7 3
• CLK是系统来的外时钟,8279靠设置定 时器将外部时钟变为内时钟。其内部基 频=外时钟/定时器值。内部时钟的高低 控制着扫描时间和键盘去抖动时间的长 短,若8279内部时钟为100kHz,则扫描 时间为5.1ms,去抖动时间为10.3ms。
双键互锁
• 在读取一个键己按下时,不管另外有无其它键按下的 方式。如同时有多个键按下,则等待只剩下一个键按 下时,再将其值送入RAM。
串键保护
n键同时按下:等到只有一个键按下去再 处理
n键锁定:只处理一个键
消除抖动电路
“1” “0” +5v 抖动时间 <10ms 开关动作时间 >100ms

<10ms
开关
+5v

I/O 接 口
单 片 机
消除抖动电路
+5V R1
(Di) Vo
Vi R2
S
V1
(Di) V 2
图 5-3
滤波延时消抖电路
显示地址寄存器,决定CPU读写哪一个显示器RAM
的字节,可由程序设置,且读/写方式可以是自动或是单 一方式。显示器RAM(16×8位)在设置好模式及地址后, CPU可直接读取。显示器RAM的数据码送出显示时,分 为两部分高4位由OUTA送出,低4位由OUTB送出,也可
单独送出,可以利用程序设置。
说明:
输出通道 D/A
传感器
A/D 电 量
非 电 量
单片机或 DSP RAM、 EPROM I/O接口
外部通信
RS232 USB
打印机
输入ቤተ መጻሕፍቲ ባይዱ道

键盘、开关、 显示器
内嵌微处理器智能仪器的基本结构
键盘接口技术
键盘输入数据和命令,显示用于仪器的状 态、命令和计算结果。 单片机键盘有两种: 全编码键盘,其键码全由硬件提供,但是 这种方式硬件结构复杂,成本高; 非编码键盘,这种键盘多采用矩阵方式, 利用软件识别键码及完成各种键功能处理。 单片机系统中多采用非编码键盘。
N键轮换
• 多个键可以同时按下,按扫描顺序,分别将其值送入 RAM。
传感器矩阵
• 无去抖动功能,键的状态直接映射到RAM中,可以 用软件检查键何时按下,何时抬起。
选通输入方式
• RL7~0作为选通输入口。!CNTL/STB作为选通信号输 入端。这是只选用显示器没有键盘的工作方式。
CLK
ALE 8051
A0
1
a)接口电路
b)真值表
可编程键盘/显示器接口8279
• 由于数据输入和显示乃是许多微处理机外设的 一个不可分离部分。系统设计者需要一种能够 控制这些功能,而又不致于使CPU负载过重的 接口。8279为8位微处理机提供这种功能。 • 8279有两个部分,键盘部分和显示器部分。键 盘部分能够与通常的打字机型键盘或随机乒乓 开关,或钮子开关相联接。显示部分驱动字母 数字显示或一排指示灯。从而减轻了CPU在扫 描键盘和刷新显示时的负担。
8279的引脚图
DB7~0-双向外部数据总线 RL2 CS-片选信号 RL3 CLK A0-区分信息的特征位 IRQ A0=1,命令状态;A0=0,数据 RL4 RD-读选通信号 RL5 RL6 WR-写选通信号 RL7 IRQ-中断请求输出 RESET RL7~RL0-反馈输入线 RD SL3~SL0-扫描输出线 WR OUTB3~0,OUTA3~0-显示段数据输出DB0 DB1 BD-消隐输出 DB2 DB3 RESET-复位输入。复位后: DB4 1. 16个8位字符显示为左端输入 DB5 2. 编码的扫描键为两键连锁 DB6 SHIFT-换档 DB7 CNTL/STB-控制/选通 GND CLK-外时钟输入端
74LS373
A0
P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P2.7
WR RD INT1 +5V 20µF 2K
D0 D1 D2 SL0 D3 SL1 SL2 D4 8279 D5 D6 D7 CS WR B0 RD B1 B2 B3 IRQ A0 RESET A1 A2 CNTL A3 SHIFT
A0=1)。当FIFO RAM不是空的,IRQ会发出一个HI做 中断请求。当设置为SENSOR模式时,存放在FIFO内的 数据与外部 SENSOR 矩阵相对应,只要 SENSOR 矩阵 ( 64 个)中有任何一个变动, IRQ 都会由 LO 转为 HI , 发出中断请求。
6.显示地址寄存器及显示器RAM
滤波延时消抖电路
键连击的处理
读 键
延时去抖 读 键 延时去抖
执 行 等键释放
执 行 延 时
非编码键盘
1)独立式键盘
图 3-1(a)
特点: 一键一线. 优点: 结构简单,键容易识别. 缺点: 占用较多检测线,不便组成大型键盘. 2)矩阵式键盘 图3-1(b) 特点: 把检测线分成二组,一组为行线,另一组为列 线,按键放在行线和列线的交叉点上. 优点: 键盘规模可扩大. 缺点: 键盘分析程序较复杂. 键盘的工作方式 a) 编程扫描方式(查询方式) b) 中断工作方式 c) 定时扫描方式
3键:1 1 0 4键:1 0 1 5键:1 0 1
0111 1110 1101
y0 y1
列线
y2 y3
A键:0 1 1
1011
线反转法
+5V
相关文档
最新文档