【文章內(nèi)容簡(jiǎn)介】
else y=y+1。 end if。 end if。 end process p1。 p2:process(btn0,clk_dou)btn0 鍵防抖 begin if clk_dou39。event and clk_dou=39。139。 then q3=q2。 q2=q1。 q1=btn0。 q4=q1 and q2 and q3。經(jīng)過三個(gè)防抖信號(hào)周期 ( ), q4 變?yōu)?1,作為按鍵信號(hào)輸出 end if。 end process p2。 p3:process(btn1,clk_dou)btn1 鍵防抖 begin if clk_dou39。event and clk_dou=39。139。 then q7=q6。 q6=q5。 q5=btn1。 q8=q5 and q6 and q7。 end if。 end process p3。 p4:process(q4,reset) begin if reset=39。139。 then如果復(fù)位信號(hào)為 1,局?jǐn)?shù)歸零 ju=0。 elsif q439。event and q4=39。139。 thenq4 為甲按鍵防抖后輸出信號(hào) xx=(x rem 6)+1。 產(chǎn)生第一位隨機(jī)數(shù) yy=(y rem 6)+1。產(chǎn)生第二位隨機(jī)數(shù) if ju=6 then局?jǐn)?shù)統(tǒng)計(jì) ju=1。 else ju=ju+1。 end if。 end if。 case xx is when 6 =qout1=0110。譯碼輸出 when 5 =qout1=0101。 when 4 =qout1=0100。 when 3 =qout1=0011。 when 2 =qout1=0010。 when 1 =qout1=0001。 when others=qout1=0001。 end case。 case yy is when 6 =qout2=0110。 when 5 =qout2=0101。 when 4 =qout2=0100。 when 3 =qout2=0011。 when 2 =qout2=0010。 when 1 =qout2=0001。 when others=qout2=0001。 end case。 case ju is when 6 =qout5=0110。 when 5 =qout5=0101。 when 4 =qout5=0100。 when 3 =qout5=0011。 when 2 =qout5=0010。 when 1 =qout5=0001。 when 0 =qout5=0000。 when others=qout5=0000。 end case。 end process p4。 p5:process(q8)產(chǎn)生乙方的隨機(jī)數(shù) begin if q839。event and q8=39。139。 then xx1=(x rem 6)+1。 yy1=(y rem 6)+1。 end if。 case xx1 is when 6 =qout3=0110。 when 5 =qout3=0101。 when 4 =qout3=0100。 when 3 =qout3=0011。 when 2 =qout3=0010。 when 1 =qout3=0001。 when others=qout3=0001。 end case。 case yy1 is when 6 =qout4=0110。 when 5 =qout4=0101。 when 4 =qout4=0100。 when 3 =qout4=0011。 when 2 =qout4=0010。 when 1 =qout4=0001。 when others=qout4=0001。 end case。 end process p5。 end a。 數(shù)碼管模塊 library ieee。 use 。 ENTITY shumaguan IS PORT( clk_shu:in std_logic。 數(shù)碼管掃描頻率 qin1,qin2,qin3,qin4,qin5:IN STD_LOGIC_VECTOR(3 DOWNTO 0)。隨機(jī)數(shù)輸入信號(hào) g:OUT STD_LOGIC_VECTOR(6 DOWNTO 0)。段選輸出信號(hào) cat:OUT STD_LOGIC_VECTOR(5 DOWNTO 0))。 位選輸出信號(hào) END shumaguan。 ARCHITECTURE a OF shumaguan IS SIGNAL tmpg:STD_LOGIC_VECTOR(6 DOWNTO 0)。 SIGNAL tmpn:STD_LOGIC_VECTOR(3 DOWNTO 0)。 SIGNAL tmpc:INTEGER RANGE 0 TO 4。 BEGIN p1:PROCESS(clk_shu) 0 到 4 計(jì)數(shù)器 BEGIN if(clk_shu39。event and clk_shu=39。139。)then if tmpc = 4 then tmpc=0。 else tmpc=tmp