【正文】
output_temp(3 downto 0)=input。 output_temp(11 downto 8)=output_temp(7 downto 4)。039。 then output=null。 begin process(clk) begin if rest=39。 architecture behave of yw is signal output_temp: std_logic_vector(15 downto 0)。 output :out std_logic_vector(15 downto 0))。 entity yw is port(input:in std_logic_vector(3 downto 0)。 原理圖如圖 35 VHDL 語言 移位寄存電路 原理圖所示: 圖 35 移位寄存電路 移位寄存電路程序代碼: library ieee。 移位寄存工作原理就是在下一次數(shù)據(jù)輸入前,對其進行移位寄存以確保不會丟失,如我們定義輸入為 4 位二進制數(shù),輸出為 16 為二進制數(shù),由低位向高位移位,第一次輸入的是 0000,第二次輸入的是 0001,第三次輸入的是 0010,第四次是 0011,這時輸出的就是 0000000100100011。 end f。 end if。 gaimij2=gaimij1。rest2=rest1。139。 process(clk_temp) begin if clk_temp 39。 end if。 else qi=qi+1。 begin process(clk) begin if rising_edge(clk) then if qi=3 then qi=0。 architecture f of d4 is signal qi:integer range 0 to 3。 rest2,querenj2,gaimij2,sanchuj2:out std_logic)。 rest1,querenj1,gaimij1,sanchuj1:in std_logic。 entity d4 is port is( clk:in std_logic。原理圖如圖 34VHDL 語言鍵盤消抖電路原理圖所示: 圖 34 鍵盤消抖電路原理圖 鍵盤消抖電路的程序代碼: library ieee。 如果調(diào)整取樣頻率 , 彈跳現(xiàn)象可得到改善。這樣就避免開按鍵發(fā)生抖動的那一段時間,使 CPU 能可靠地讀按鍵狀態(tài)。也可以利用現(xiàn)成的專用消抖電路,如 MC14490 就是六路消抖電路。 鍵盤消抖電路 因為按鍵大多是機械式開關(guān) , 在開關(guān)切換的瞬間會在接解點出現(xiàn)來回彈跳的現(xiàn)象 , 雖然只是按了一次鍵 , 實際產(chǎn)生的按鍵信號卻不只跳動一次 , 經(jīng)過取樣信號的檢查后 , 將會造成誤碼判斷 , 認為是按了兩次鍵。gnkzj1=gnkzj。 end process p8。rest=null。sanchuj=null。rest=rest1。sanchuj=sanchuj1。039。139。 end if。 then dataout=temp。 and gnkzj=39。 p8:process(szkzj,gnkzj) begin if szkzj=39。 end if。 end if。 else rest1=39。gnkzj=39。szkzj=39。) then rest1=39。 if(sel(3)=39。039。139。039。139。039。 end if。 else sanchuj1=39。gnkzj=39。szkzj=39。) then sanchuj1=39。 if(sel(1)=39。039。139。039。139。039。039。 end if。gnkzj=39。) then szkzj=39。 elsif(sel(3)=39。gnkzj=39。)then szkzj=39。 elsif(sel(2)=39。gnkzj=39。szkzj=39。039。039。139。)then temp=1000。) then if(sel(0)=39。 elsif(R(2)=39。039。139。) then temp=0111。 elsif(sel(3)=39。gnkzj=39。szkzj=39。039。039。139。) then temp=0101。 elsif(sel(1)=39。gnkzj=39。szkzj=39。039。039。 end if。gnkzj=39。szkzj=39。039。039。139。)then temp=0010。 elsif(sel(2)=39。gnkzj=39。szkzj=39。039。 0,數(shù)字標識,功能標識。gnkzj=39。szkzj=39。039。039。 end process p。 p:process(clk) begin if(falling_edge(clk)) then L=sel。 end process p3。139。 end process p2。 end if。 else carry1=39。 第 三 章 硬件原理及軟件設計 8 p2:process(clk) begin if(rising_edge(clk))then if(count=1111) then carry1=39。 end if。 p1:process(clk) begin if(rising_edge(clk)) then count=count+39。 signal querenj1,sanchuj1,gaimij1,rest1:std_logic。 signal sel:std_logic_vector(3 downto 0)。 signal count:std_logic_vector(3 downto 0)。 end jp。 szkzj1,gnkzj1:out std_logic。 L:out std_logic_vector(3 downto 0)。 entity jp is port ( clk :in std_logic 。 use 。 圖 33 矩陣鍵盤 第 三 章 硬件原理及軟件設計 7 鍵盤程序代碼: library ieee。信號為從上到下的順序 。 圖 31 系統(tǒng)頂層框圖 各模塊程序設計 鍵盤輸入部分的源程序 4*4 按鍵分行線和列線去控制,行線連接 16 個按鍵的一端,列線連接 16 個按鍵的另外一端,當給行線(或 者列線)一個信號,有按鍵按下的時候讀回來的時密碼輸入電路 掃描信號 按鍵輸入 鍵盤掃描 鍵盤 彈跳消除 鍵盤譯碼 控制密碼電路 按鍵數(shù)據(jù)存儲 顯示電路 數(shù) 碼 管 顯 示 開 /關(guān)鎖 報警 數(shù)值比較 第 三 章 硬件原理及軟件設計 6 候的數(shù)據(jù)是不一樣的,也就是證明有按鍵按下! 當 行信號( KEY)接到高電平,當沒有鍵按時,行線與列線( KEYSCAN)是斷開的,且行線都是高電平( 1111),行信號作為 CPLD、列信號作為 CPLD。 首先 用 鍵盤輸入密碼, 通過消抖后進入存儲器,輸入密碼與設定的密碼,相同時 開鎖,當輸入密碼錯誤時,開始計數(shù),當?shù)谌屋斎朊艽a錯誤時,揚聲器報警。主要由三部分組成: 4*4 矩陣鍵盤接口電 路、密碼鎖的控制電路、輸出八段顯示電路。 3) 修改