【文章內(nèi)容簡介】
位信號 rst;警報信號 tmp。 (二)計時模塊 VHDL 源程序 library ieee。 use 。 use 。 entity js is port(clk,rst,s,stop:in std_logic。 warn:out std_logic。 ta,tb:buffer std_logic_vector(3 downto 0))。 end js。 architecture one of js is signal co:std_logic。 begin p1:process(clk,rst,s,stop,ta) begin 8 if rst=39。039。 or stop=39。139。 then ta=0000。 elsif clk39。event and clk=39。139。 then co=39。039。 if s=39。139。 then if ta=0000 then ta=1001。co=39。139。 else ta=ta1。 end if。 end if。 end if。 end process p1。 p2:process(co,rst,s,stop,tb) begin if rst=39。039。 or stop=39。139。 then tb=0010。 elsif co39。event and co=39。139。 then if s=39。139。 then if tb=0000 then tb=0011。 else tb=tb1。 end if。 end if。 end if。 end process p2。 end one。 仿真圖 9 計時模塊圖 在這個模塊中主要實現(xiàn)搶答過程中的計時功能,在有搶答開始后進行 30 秒的倒計時,并且在 30 秒倒計時后無人搶答顯示超時并報警。其中有搶答時鐘信號 clk2;系統(tǒng)復(fù)位信號 rst;搶答使能信號 s;搶答狀態(tài)顯示信號 states;無人搶答警報信號 warn;計時中止信號 stop;計時十位和個位信號 tb, ta。 (三)數(shù)據(jù)選擇模塊 VHDL 源程序 library ieee。 use 。 use 。 use 。 entity sjxz is port (a,b,c: in std_logic_vector(3 downto 0)。 clk2,rst: in std_logic。 s: out std_logic_vector(1 downto 0)。 10 y: out std_logic_vector(3 downto 0) )。 end sjxz。 architecture body_chooser of sjxz is signal count: std_logic_vector (1 downto 0)。 begin s=count。 process(clk2,rst) begin if(rst=39。039。)then count=00。 elsif(clk239。event and clk2=39。139。)then if(count=10)then count=00。 else count=count+1。 end if。 end if。 case count is when 00=y=a。 when 01=y=b。 when 10=y=c。 when others=null。 end case。 end PROCESS。 end body_chooser。 仿真圖 11 數(shù)據(jù)選擇模塊圖 在這個模塊中主要實現(xiàn)搶答過程中的數(shù)據(jù)輸入功能,輸入信號 a[3..0]、 b[3..0]、 c[3..0];計數(shù)輸出信號 s;數(shù)據(jù)輸出信號 y;計數(shù)脈沖 clk2,實現(xiàn) a、 b、 c 按脈沖輪流選通,在數(shù)碼管上顯示。 (四)報警模塊 VHDL 源程序 LIBRARY IEEE。 USE 。 USE 。 ENTITY ALARM IS PORT(CLK,I:IN STD_LOGIC。 Q:OUT STD_LOGIC)。 END ALARM。 12 ARCHITECTURE BEHAVE OF ALARM IS SIGNAL WARN:STD_LOGIC。 SIGNAL N:INTEGER RANGE 0 TO 20。 BEGIN Q= WARN。 PROCESS(CLK) BEGIN IF CLK39。EVENT AND CLK=39