1、 电子课程设计 —键盘扫描电路设计 学院: 班级: 姓名: 学号: 指导老师:
2、12月 目 录 1.设计任务和要求…………………………………………… 1 2.功效模块…………………………………………………… 2 3.选择器件…………………………………………………… 3 4.功效模块…………………………………………………… 5 5.设计总体电路图…………………………………………… 8 6.心得体会………………………………………………… 10 一、 设计任务和要求 1、键盘按钮数为4,系统时钟10MHz; 2、 能识别出所按按钮; 3、 按钮被按下后,视为此按钮输入
3、一次,若按钮长时间不松,(时限1S)后每隔0.5S视为再次输入,直至按钮松开; 4、要求能对按钮按下时指令抖动能正确处理。对连续时间小于50ms输入不作响应; 5、各键设置不一样优先级,多键同时按下时,视为优先级较高按键被按下; 二、 功效模块 图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
4、 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); leds : out std_logic_vector(3 downto 0); state : out std_logic; VGA
5、 : 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 ) ;
6、end component ; --********************************************* -- signal clkfrq : 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
7、 : std_logic_vector(3 downto 0); signal lednum : std_logic_vector(7 downto 0); signal key_tmp : std_logic_vector(3 downto 0); signal clk : std_logic; signal cntfrq1 : std_logic_vector(5 downto 0); begin VGA <= "0101"; --键盘功效选择 scan <= not scnlin;
8、 lednum <= scnlin & (not key_tmp); -- key_tmp <= keyin; --debounuing ckt debounuing : block begin U1: debouncing PORT MAP ( KEY => keyin(0) , DLY_OUT => key_tmp(0) , clr=>rst, clk => CLK ); U2: debouncing PORT MAP ( KEY => keyin(1) , dly_out
9、 => key_tmp(1) , clr=>rst, clk => CLK ); U3: 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,
10、clk => CLK ); END block debounuing ; -- --****************************************************** -- process(rst,clk_in) -- 晶振为40MHz,进行40000分频产生去抖时钟(1000Hz) begin if rst = '0' then cntfrq <= (others => '0'); elsif rising_edge(clk_in) then
11、 if (cntfrq = "111" or not (key_tmp="1110" or key_tmp="1101" or key_tmp="1011" or key_tmp="0111") ) then --if (cntfrq = "111" or key_tmp="1111" ) then --if cntfrq = "1111" then cntfrq <= (others => '0'); clk <= not clk;--去抖时钟
12、 else cntfrq <= cntfrq + 1; end if; end if; end process; process(rst,clk) --去抖时钟,50分频,形成扫描时钟 begin if rst = '0' then clkfrq <= '0'; cntfrq1 <= (others => '0'); elsif rising_edge(clk) then if cntfrq1 = "11000" then
13、 cntfrq1 <= (others => '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(clkfrq) then
14、 if cntscn = "11" then cntscn <= "00"; else cntscn <= cntscn+1; end if; case cntscn is when "00" => scnlin <= "0001"; when "01" => scnlin <= "0010"; when "10" => scnlin <= "010
15、0"; when "11" => scnlin <= "1000"; when others => null; end case; end if; end process; process(rst, clkfrq) -- 依据按键点亮对应leds begin if(rst = '0' ) then leds <= not"1111"; elsif clk
16、frq'event and clkfrq = '0' then case lednum is when "00010001" => leds <= not"0001"; --1 when "00010010" => leds <= not"0010"; --2 when "00010100" => leds <= not"0011"; --3
17、 when "00011000" => leds <= not"1010"; --A when "00100001" => leds <= not"0100"; --4 when "00100010" => leds <= not"0101"; --5 when "00100100" => leds <= n
18、ot"0110"; --6 when "00101000" => leds <= not"1011"; --B when "01000001" => leds <= not"0111"; --7 when "01000010" => leds <= not"1000"; --8
19、 when "01000100" => leds <= not"1001"; --9 when "01001000" => leds <= not"1100"; --C when "10000001" => leds <= not"1110"; --* when "10000010" =>
20、 leds <= not"0000"; --0 when "10000100" => leds <= not"1111"; --# when "10001000" => leds <= not"1101"; --D when others => null; end case;
21、end if; end process; 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; 三、 心得体会 经过两周课程设计,因为是第一次,过程有点曲折,有点累,但最终能得到理想结果,心里感到尤其快乐。因为是课程设计,需要制订一个最合理方案。这就锻炼了我们理论分析、比较,联络实际情况能力。因为需要各个方面材料和数据,我们需要利用多种手段去查找资料,这增加了我们自学能力。在电路生成和调试过程中,我们碰到了多种问题,经过对种种问题处理,我们在工程实际层次上更深入了解理论知识。我们不仅愈加好地了解了所学理论知识,更关键是把知识从书中提炼出来利用到生活当中,这是一个质飞跃。在这次课程设计当中也离不开老师帮助,她们尽心尽责给了我很大帮助,很感谢。






