基于fpga的多功能万年历(编辑修改稿)内容摘要:

接口电路原理 校时控制模块在本系统中也就是键盘接口电路部分。 下面先介绍键盘接口电路的工作原理 ,如图 49。 本系统采用的就是这种行列式键盘接口,相对个按键的键盘接口来说节省了 I/O 接口。 其中行线与列线分别与按键的两端相连。 在查询工作方式中判断是否有按键按下的方法是:先有响应的 I/O 接口将列线输出为 0电平,在由相应的 I/O 接口将所有的行线结果读入到控制器中。 若有行线输入为 0,则有键按下,反之,则没有键按下。 如果发现有按键按下界限来就是通过安检扫描来确定是哪个按键被按下,键盘扫描的过程是依次轮流将列线输出为 0 电平,然后再检查各行线的状态。 若某行线输入为 0,组对应的该行线与该列线的按键被按下,即可确定对 应的键号。 第 15 页 共 37 页 图 49 键盘接口电路 键盘接口的 VHDL 描述 (1).按键消抖 本系统采用的是软件消抖的办法去除按键抖动,基本原理是:首先判断有没有按键按下,如发现有按键按下则延时一段时间,在判断是否有按键按下的信号,如果有则确定有按键按下,就产生一个有按键按下的信号。 这样就消除了按键的机械抖动。 该模块的逻辑框图如图 410所示。 图 410 去抖逻辑框图 该电路的 VHDL 程序如下: library ieee。 use。 use。 use。 第 16 页 共 37 页 entity qudou is port(clk1:in std_logic。 row:in std_logic_vector(3 downto 0)。 key_pre:out std_logic)。 end qudou。 architecture behav of qudou is signal sig1,counter:std_logic_vector(3 downto 0)。 signal tmp1,sig2:std_logic。 begin sig1=row。 tmp1=sig1(0)and sig1(1)and sig1(2)and sig1(3)。 key_pre=counter(0)and counter(1)and counter(2)and counter(3)。 process(clk1) begin if(clk139。 event and clk1=39。 139。 )then if(tmp1=39。 039。 )then if(sig2=39。 039。 )then sig2=39。 139。 end if。 end if。 if(sig2=39。 139。 )then if(counter=1111)then sig2=39。 039。 第 17 页 共 37 页 counter=0000。 else counter=counter+39。 139。 end if。 end if。 end if。 end process。 end behav。 (2).键扫描模块 键扫描模块的框图如图 411所示。 图 411 按键扫描模块 CLKY 是由分频器模块分出的 4MHZ 的输入时钟信号,因为键扫描是一个比较快的过程所以这里采用的是频率较高的时钟信号。 Key_pre 是去抖模块输出的有按键按下的信号作为启动按键扫描的使能信号。 ROW[3..0]与键盘的行线相连, COM[3..0]与键盘的列线相连。 SCAN_CODE[7..0]输出被按下键的键码。 键盘扫描程序如下: library ieee。 use。 use。 use。 第 18 页 共 37 页 entity ajsm is port(clky,key_pre:in std_logic。 row:in std_logic_vector(3 downto 0)。 :out std_logic_vector(3 downto 0)。 scan_code:out std_logic_vector(7 downto 0))。 end ajsm。 architecture behav of ajsm is signal sig_:std_logic_vector(3 downto 0)。 signal counter:std_logic_vector(1 downto 0)。 signal tmp,sig1,sig2:std_logic。 begin sig2=key_pre。 tmp=row(0) and row(1) and row(2) and row(3)。 process(clky) begin if(clky39。 event and clky=39。 139。 )then 计数进程 if(sig2=39。 139。 )then if(counter=11)then sig1=39。 039。 counter=00。 else sig1=39。 139。 counter=counter+39。 139。 第 19 页 共 37 页 end if。 end if。 end if。 end process。 process(clky) 列线逐位输出低电平 variable jt :std_logic。 begin if(clky39。 event and clky=39。 139。 )then if(sig1=39。 139。 )then jt:=sig_(3)。 for i in 3 downto 1 loop sig_(i)=sig_(i1)。 end loop。 sig_(0)=jt。 else sig_=1110。 end if。 end if。 end process。 process(clky) begin if(clky39。 event and clky=39。 139。 )then if(sig1=39。 139。 )then 第 20 页 共 37 页 =sig_。 else =0000。 end if。 end if。 end process。 process(clky) 键码信号赋值 begin if(clky39。 event and clky=39。 139。 )then if(sig1=39。 139。 )then if(tmp=39。 039。 )then scan_code=row amp。 sig_。 else scan_code=11111111。 end if。 else scan_code=11111111。 end if。 end if。 end process。 end behav。 (3).键码转换模块 该模块框图如图 412 所示。 模块主要完成从键扫描码到按键编码的转换。 第 21 页 共 37 页 图 412 键码转换模块逻辑框图 键码转换的核心程序如下: library ieee。 use。 use。 use。 entity jmzh is port(clky:in std_logic。 scan_code:in std_logic_vector(7 downto 0)。 key_code:out std_logic_vector(3 downto 0))。 end jmzh。 architecture behav of jmzh is begin process(clky) begin if(clky39。 event and clky=39。 139。 )then case scan_code is when 11101110=key_code=0000。 when 11101101=key_code=0001。 when 11101011=key_code=0010。 第 22 页 共 37 页 when 11100111=key_code=0011。 when 11011110=key_code=0100。 when 11011101=key_code=0101。 when 11011011=key_code=0110。 when 11010111=key_code=0111。 when 10111110=key_code=1000。 when 10111101=key_code=1001。 when 10111011=key_code=1010。 when 10110111=key_code=1011。 when 01111110=key_code=1100。 wh。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。