1、EDA课程设计键盘扫描电路设计EDA课程设计-键盘扫描电路设计 作者: 日期: 电子课程设计 键盘扫描电路设计 学院: 班级: 姓名: 学号: 指导老师: 2009年12月1.设计任务与要求 12.功能模块 23.选择器件 34.功能模块 55.设计总体电路图 86.心得体会 10一、 设计任务与要求1、键盘按钮数为4,系统时钟10MHz;2、 能识别出所按按钮;3、 按钮被按下后,视为此按钮输入一次,若按钮长时间不松,(时限1S)后每隔0.5S视为再次输入,直至按钮松开;4、要求能对按钮按下时指令的抖动能正确处理。对持续时间小于50ms的输入不作响应;5、各键设置不同优先级,多键同时按下时,
2、视为优先级较高的按键被按下;二、 功能模块 图3 模块delta其VHDL语言如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_unsigned.all;entity keyboard4_4 is port( rst : in std_logic; clk_in : in std_logic; keyin : in std_logic_vector(3 downto 0); scan : out std_logic_vector(3 downto 0);
3、leds : out std_logic_vector(3 downto 0); state : out std_logic; VGA : out std_logic_vector(3 downto 0) );end keyboard4_4;architecture keyboard4_4_arch of keyboard4_4 is-* component debouncing port( key : IN STD_LOGIC ; clk,clr : IN STD_LOGIC ; dly_out : OUT STD_LOGIC ) ; end component ;-*- signal cl
4、kfrq : std_logic; signal cntscn : std_logic_vector(1 downto 0); signal scnlin : std_logic_vector(3 downto 0); signal cntfrq : std_logic_vector(14 downto 0); -signal cntfrq : std_logic_vector(3 downto 0); signal lednum : std_logic_vector(7 downto 0); signal key_tmp : std_logic_vector(3 downto 0); sig
5、nal clk : std_logic; signal cntfrq1 : std_logic_vector(5 downto 0);begin VGA = 0101; -键盘功能选择 scan = not scnlin; lednum = scnlin & (not key_tmp); - key_tmp keyin(0) , DLY_OUT = key_tmp(0) , clr=rst, clk = CLK ); U2: debouncing PORT MAP ( KEY = keyin(1) , dly_out = key_tmp(1) , clr=rst, clk = CLK ); U
6、3: debouncing PORT MAP ( key = keyin(2) , dly_out = key_tmp(2) , clr=rst, clk = CLK ); U4: debouncing PORT MAP ( key = keyin(3) , dly_out = key_tmp(3) , clr=rst, clk = CLK );END block debounuing ;-*- process(rst,clk_in) - 晶振为40MHz,进行40000分频产生去抖时钟(1000Hz) begin if rst = 0 then cntfrq 0); elsif rising
7、_edge(clk_in) then if (cntfrq = 100111000011111 or not (key_tmp=1110 or key_tmp=1101 or key_tmp=1011 or key_tmp=0111) ) then -if (cntfrq = 100111000011111 or key_tmp=1111 ) then -if cntfrq = 1111 then cntfrq 0); clk = not clk;-去抖时钟 else cntfrq = cntfrq + 1; end if; end if; end process; process(rst,c
8、lk) -去抖时钟,50分频,形成扫描时钟 begin if rst = 0 then clkfrq = 0; cntfrq1 0); elsif rising_edge(clk) then if cntfrq1 = 11000 then cntfrq1 0); clkfrq = not clkfrq; else cntfrq1 = cntfrq1 + 1; end if; end if; end process; process(rst,clkfrq) - 根据扫描时钟产生扫描线 begin if rst = 0 then cntscn = 00; elsif rising_edge(clk
9、frq) then if cntscn = 11 then cntscn = 00; else cntscn scnlin scnlin scnlin scnlin null; end case; end if; end process; process(rst, clkfrq) - 根据按键点亮相应的leds begin if(rst = 0 ) then leds leds leds leds leds leds leds leds leds leds leds leds leds leds leds leds leds null; end case; end if; end proces
10、s; process(rst,key_tmp) begin if(rst = 0 ) then state = 1; elsif (key_tmp=1110 or key_tmp=1101 or key_tmp=1011 or key_tmp=0111) then state = 0; elsif (key_tmp=1111) then state = 1; end if; end process; end keyboard4_4_arch;三、 心得体会经过两周的课程设计,由于是第一次,过程有点曲折,有点累,但最后能得到理想的结果,心里感到特别高兴。因为是课程设计,需要制定一个最合理的方案。这就锻炼了我们理论分析、比较,联系实际情况的能力。由于需要各个方面的材料和数据,我们需要运用各种手段去查找资料,这增长了我们自学的能力。在电路的生成和调试过程中,我们遇到了各种问题,通过对种种问题的解决,我们在工程实际的层次上更进一步理解理论知识。我们不仅更好地理解了所学的理论知识,更重要的是把知识从书中提炼出来运用到生活当中,这是一种质的飞跃。在这次课程设计当中也离不开老师的帮助,他们尽心尽责给了我很大的帮助,非常感谢。
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2