【正文】
1 廣西工學院 課程設計 說 明 書 設計題目 系 別 專業(yè)班級 學生姓名 學 號 指導教師 日 期 — — 裝 訂 線 — — 2 基于 VHDL 的鍵 盤掃描及顯示電路 摘要 運 VHDL 硬件描述語言和圖形設計綜合方法,實現(xiàn)了 4 4鍵盤掃描電路的程序設計,通過運用 QuartusⅡ軟件平臺生成電路符號,建立波形文件,設置輸入端口,實現(xiàn)模擬仿真,得到仿真波形圖。 關鍵字: VHDL QuartusⅡ 數碼管 1 題目分析 本次課程設計題目為 4 4 鍵盤掃描電路的設計。要求通過查閱相關書籍資料,熟悉和初步掌握 VHDL 語言的語法及其功能,根據要求首先進行理論上的分析,深入分析 4 4 鍵盤掃描電路的原理,然后根據分析結果設計程序,進行上機的調試,通過 以上軟件進行仿真,并記錄仿真的結果。 2 矩陣鍵盤及 顯示電路設計思路 矩陣鍵盤及顯示電路能夠將機械式 44矩陣鍵盤的按鍵值依次顯示到 8個 7段數碼管上,每次新的按鍵值顯示在最右端的第 O 號數碼管上,原有第 0~ 6號數碼管顯示的數值整體左移到第 1~ 7號數碼管上顯示,見圖 1??傮w而言,矩陣鍵盤及顯示電路的設計可分為 4個部分: (1)矩陣鍵盤的行及列的掃描控制和譯碼。該設計所使用的鍵盤是通過將列掃描信號作為輸入信號,控制行掃描信號輸出,然后根據行及列的掃描結果進行譯碼。 (2)機械式按鍵的防抖設計。由于機械式按鍵在按下和彈起的過程中均有 5~ 10 ms 的信號抖 動時間,在信號抖動時間內無法有效判斷按鍵值,因此按鍵的防抖設計是非常關鍵的,也是該設計的一個重點。 (3)按鍵數值的移位寄存。由于該設計需要在 8個數碼管上依次顯示前后共 8次按鍵的數值,因此對已有數據的存儲和調用也是該設計的重點所在。 (4)數碼管的掃描和譯碼顯示。由于該設計使用了 8個數碼管,因此需要對每個數碼管進行掃描控制,并根據按鍵值對每個數碼管進行 7段數碼管的譯碼顯示。 2 矩陣鍵盤及顯示電路的實現(xiàn) 本文所設計的矩陣鍵盤及顯示電路的電路符號如圖 2所示。其中, clk 為時鐘信號輸入端(頻率可 為 1 024~ 32 768Hz)。start 為清零控制端 。kbrow 為列掃描信號輸入端 。kbeol 為行掃描信號輸出端 。scan 為數碼管地址掃描信號輸出端 。seg7為數碼管顯示信號輸出端。 — — 裝 訂 線 — — 3 4 4鍵盤掃描電路的電路符號如圖 2所示。其中 clk1 為 時鐘信號輸入端, start1 為開始信號輸入端, kbcol1[3..0]為行掃描信號輸出端, kbrow 1[3..0]為列掃描信號輸入端, seg71[7..0]為八段顯示控制信號輸出端,scan1[2..0]為數碼管地址選擇控制信號輸出端。 4 4 鍵盤掃描電路用 VHDL 語言描述, 全部代碼由 五個模塊 組成 , 其代碼分別如下: 鍵盤掃描模塊程序、原理圖及仿真波形: library ieee。 use 。 use 。 entity saomiao is port( en: out std_logic。 state: out std_logic_vector(1 downto 0)。 clk : in std_logic。 — — 裝 訂 線 — — 4 kbrow : in std_logic_vector(3 downto 0)。 kbcol : out std_logic_vector(3 downto 0) )。 End saomiao 。 architecture one of saomiao is signal count:std_logic_vector(1 downto 0)。 begin process (clk , kbrow) begin en = not ( kbrow(0) or kbrow(1) or kbrow(2) or kbrow(3) )。 if( clk39。event and clk=39。139。) then if not ( kbrow(0) or kbrow(1) or kbrow(2) or kbrow(3) )=39。139。 then count =count + 1。 end if。 end if。 end process。 process(clk) begin if clk39。event and clk=39。139。 then case count is when 00 = kbcol= 0001。state = 00。 when 01 = kbcol = 0010。state = 01。 when 10 = kbcol= 0100。state = 10。 when 11 = kbcol= 1000。state = 11。 when others = kbcol =1111。 end case。 end if。 end process。 End。 5 按鍵數值輸出模塊: library ieee。 use 。 use 。 entity shuju is port( at : out std_logic_vector(3 downto 0)。 tate: in std_logic_vector(1 downto 0)。 clk : in std_logic。 brow : in std_logic_vector(3 downto 0) )。 End shuju 。 architecture one of shuju is Begin process(clk) begin if clk39。event and clk=39。139。 then case tate is when 00= case brow is when 0001=at=1111。 when 0010=at=1110。 when 0100=at=1101。 When 1000= at=1100。 6 when others=null。 end case。 when 01= case brow is when 0001=at=1011。 when 0010=at=1010。 when 0100=at=1001。 When 1000 = at=1000。 when others=null。 end case。 when 10= case brow is when 0001=at=0111。 when 0010=at=0110。 when 0100=at=0101。 When 1000= at=0100。 when others=null。 end case。 when 11= Case brow is When 0001= at=0011。 When 0010 = at =0010。 When 0100 = at =0001。 When 1000 = at =0000。 when others=null。 end case。 end case。 end if 。 end process。 End。 7 防抖模塊: library ieee。 use 。 use 。 entity dizfenp is port( n: in std_logic。 da : in std_logic_vector(3 downto 0)。 data : out std_logic_vector(3 downto 0)。 start : in std_logic。 clk : in std_logic。 scan : out std_logic_vector(2 downto 0) )。 End dizfenp 。 architecture one of dizfenp is signal temp:std_logic_vector(31 downto 0)。 Signal fnq : std_logic。 Signal t8: std_logic_vector(2 downto 0)。 Signal key :std_logic_vector(7 downto 0)。 begin process(clk) variable reg8: std_logic_vector(7 downto 0)。 begin if(clk39。event and clk=39。139。) then reg8:=reg8 (6 downto 0) amp。 n。 end if。 key= reg8。 end process。 fnq=key(0) and key(1) and key(2) and key(3) and key(4) and key(5) and key(6) and key(7) 。 process(fnq,start) begin if start=39。039。 then temp=00000000000000000000000000000000。 8 elsif (fnq39。event and fnq=39。139。) then temp=temp(27 downto 0)amp。da。 end if。 end process。 process(clk,temp,t8) begin if clk39。event and clk=39。139。 then t8 = t8 + 1。 end if。 case t8 is when 000= scan =000。data=temp(3 downto 0)。 when 001= scan =001。data=temp(7 downto 4)。 when 010= scan =010。data=temp(11 downto 8)。 when 011= scan =011。data=temp(15 downto 12)。 when 100= scan =100。data=temp(19 downto 16)。 when 101= scan =101。data=temp(23 downto 20)。 when 110= scan =110。data=temp(27 downto 24)。 when 111= scan =111。data=temp(31 downto 28)。 when others =null。 end case。 end process。 End。 譯碼模塊: library ieee。 use 。 use 。 entity yima is 9 port( data : in std_logic_vector(3 downto 0)。 seg7 : out std_logic_vector(7 downto 0) )。 End yima。 architecture one of yima is begin Process(data) Begin Case data is When 0000 = seg7=00111111。 When 0001 = seg7=00000110。 When 0010