【正文】
一個(gè)上升沿計(jì)一次數(shù),當(dāng)計(jì)數(shù)到一定值的時(shí)候,計(jì)數(shù)值清零并且讓輸出電平取反,根據(jù)計(jì)數(shù)值的不同可以得到不同的輸出頻率。,1HZ,100Hz,200Hz,500Hz的頻率,以供不同的需要。 圖3 分頻模塊分頻模塊源程序: library ieee。use 。use 。entity fpq isport(clk:in std_logic。 FP500HZout,FP200HZout,FP100HZout,FP1HZout,FP01HZout:out std_logic)。end entity。architecture one of fpq issignal clkjs1:std_logic。signal clkjs2:std_logic。signal clkjs3:std_logic。signal clkjs4:std_logic。signal clkjs5:std_logic。signal q1:integer range 5000000 downto 0。signal q2:integer range 5000000 downto 0。signal q3:integer range 5000000 downto 0。signal q4:integer range 5000000 downto 0。signal q5:integer range 50000000 downto 0。beginmk1: process(clk) beginif clk39。event and clk=39。139。 thenif q5=2500000 thenq5=q5+1。elseq5=0。clkjs5=not(clkjs5)。 end if。end if。FP01HZout=clkjs5。end process。mk2:process(clk)beginif clk39。event and clk=39。139。 thenif q1=500 then q1=q1+1。 else q1=0。clkjs1=not(clkjs1)。end if。end if。FP500HZout=clkjs1。end process。mk3:process(clk)beginif clk39。event and clk=39。139。 thenif q2=12500000 then q2=q2+1。q2=q2+1。elseq2=0。clkjs2=not(clkjs2)。end if。end if。FP200Hzout=clkjs2。end process。mk4:process(clk)beginif clk39。event and clk=39。139。 thenif q32500 thenq3=q3+1。elseq3=0。clkjs3=not(clkjs3)。end if。end if。FP100HZout=clkjs3。end process。mk5:process(clk)beginif clk39。event and clk=39。139。thenif q4250000000 then q4=q4+1。elseq4=0。clkjs4=not(clkjs4)。end if。end if。FP1HZout=clkjs4。end process。end。 作為機(jī)械開(kāi)關(guān)的鍵盤(pán),在按鍵操作時(shí),機(jī)械觸點(diǎn)的彈性及電壓突跳等原因,在觸點(diǎn)閉合和開(kāi)啟瞬間會(huì)出現(xiàn)電壓的抖動(dòng)。為保證按鍵識(shí)別的準(zhǔn)確性,在按鍵電壓信號(hào)抖動(dòng)的情況下不能進(jìn)行狀態(tài)輸入。為此必須進(jìn)行去抖動(dòng)處理,消除抖動(dòng)部分的電壓信號(hào),一般有硬件和軟件兩種方法。硬件就是加去抖動(dòng)電路,這樣可以從根本上解決按鍵抖動(dòng)問(wèn)題。軟件消抖就是利用軟件延時(shí)消抖,具體說(shuō)就是當(dāng)檢測(cè)到高電平(有按鍵按下),1kHz脈沖來(lái)一個(gè)高電平計(jì)數(shù)值加1,一遇到低電平計(jì)數(shù)值清零,當(dāng)計(jì)數(shù)值大于10時(shí),說(shuō)明按鍵是被真的按下,消除了抖動(dòng)。本系統(tǒng)采用軟件消抖。 library ieee。use 。use 。entity xiaodou is port( clk:in std_logic。 din:in std_logic。 dout:out std_logic )。end xiaodou。architecture arc of xiaodou isbegin process(clk,din) variable temp:integer。 begin if clk39。event and clk=39。139。 then if (din=39。039。) then temp:=0。 end if。 if temp15 then dout=39。139。 else dout=39。039。 end if。 temp:=temp+1。 end if。 end process。 end arc。 用8位撥碼開(kāi)關(guān)表示車(chē)號(hào),撥碼開(kāi)關(guān)對(duì)應(yīng)的8位二進(jìn)制通過(guò)BCD轉(zhuǎn)換為12位BCD碼。 LIBRARY ieee。USE 。USE 。USE 。******************實(shí)體定義***********************ENTITY chepai IS PORT(clk : IN STD_LOGIC。時(shí)鐘輸入 key : in std_logic_vector(7 downto 0)。鍵入 l : out STD_LOGIC_VECTOR(7 downto 0)。輸出數(shù)碼管位選 chep : out STD_LOGIC_VECTOR(11 downto 0)數(shù)碼管段碼 )。END chepai 。**************構(gòu)造體定義********************ARCHITECTURE an OF chepai ISsignal clock : std_logic。分頻后時(shí)鐘signal p : integer range 0 to 255。顯示數(shù)據(jù)寄存器signal b0,b1,b2 : integer range 0 to 9。顯示數(shù)位寄存器,b0表示個(gè)位,b1表示十位,b2表示百位signal t : integer range 0 to 3:=0。數(shù)碼