【正文】
isport( reset:in std_logic。甲按鍵信號(hào) btn1:in std_logic。第一位隨機(jī)數(shù)頻率 clk_y:in std_logic。防抖頻率 qout1: out std_logic_vector(3 downto 0)。甲第二位隨機(jī)數(shù)輸出 qout3: out std_logic_vector(3 downto 0)。乙第二位隨機(jī)數(shù)輸出 qout5: out std_logic_vector(3 downto 0))。architecture a of suijishu3 is signal q5,q6,q7,q8:std_logic。 signal x:integer range 0 to 100。 signal xx:integer range 0 to 6。 signal xx1:integer range 0 to 6。 signal ju:integer range 0 to 6。event and clk_x=39。 then利用clk_x從0到100計(jì)數(shù) if x=100 then x=0。 end if。 if clk_y39。139。 else y=y+1。 end if。 p2:process(btn0,clk_dou)btn0鍵防抖 begin if clk_dou39。139。 q2=q1。 q4=q1 and q2 and q3。end process p2。event and clk_dou=39。 then q7=q6。 q5=btn1。 end if。 p4:process(q4,reset) begin if reset=39。 then如果復(fù)位信號(hào)為1,局?jǐn)?shù)歸零 ju=0。event and q4=39。 thenq4為甲按鍵防抖后輸出信號(hào) xx=(x rem 6)+1。產(chǎn)生第二位隨機(jī)數(shù) if ju=6 then局?jǐn)?shù)統(tǒng)計(jì) ju=1。 end if。 case xx is when 6 =qout1=0110。 when 4 =qout1=0100。 when 2 =qout1=0010。 when others=qout1=0001。 case yy is when 6 =qout2=0110。 when 4 =qout2=0100。 when 2 =qout2=0010。 when others=qout2=0001。 case ju is when 6 =qout5=0110。 when 4 =qout5=0100。 when 2 =qout5=0010。 when 0 =qout5=0000。 end case。 p5:process(q8)產(chǎn)生乙方的隨機(jī)數(shù) begin if q839。139。 yy1=(y rem 6)+1。 case xx1 is when 6 =qout3=0110。 when 4 =qout3=0100。 when 2 =qout3=0010。 when others=qout3=0001。 case yy1 is when 6 =qout4=0110。 when 4 =qout4=0100。 when 2 =qout4=0010。 when others=qout4=0001。end process p5。library ieee。ENTITY shumaguan IS PORT( clk_shu:in std_logic。隨機(jī)數(shù)輸入信號(hào) g:OUT STD_LOGIC_VECTOR(6 DOWNTO 0)。 位選輸出信號(hào) END shumaguan。 SIGNAL tmpn:STD_LOGIC_VECTOR(3 DOWNTO 0)。 BEGIN p1:PROCESS(clk_shu) 0到4計(jì)數(shù)器 BEGIN if(clk_shu39。139。 else tmpc=tmpc+1。 END IF。 p2:PROCESS(tmpc) 數(shù)碼管選通輪流顯示 BEGIN case tmpc is WHEN 0 = tmpn=qin1。 WHEN 1 = tmpn=qin2。 WHEN 2 = tmpn=qin3。 WHEN 3 = tmpn=qin4。 WHEN 4 = tmpn=qin5。 END CASE。p3:PROCESS(tmpn) 譯碼電路 BEGIN CASE tmpn IS WHEN0000= tmpg=。1 WHEN0010= tmpg=。3 WHEN0100= t