【正文】
nv_std_logic_vector(yellowsn_time,8)。 sign_state=“ 001”時,南北方向黃燈亮 5s。 when 010=load=conv_std_logic_vector(redsn_time,8)。 sign_state=“ 010”時,南北方向紅燈亮 15s。 when 011=load=conv_std_logic_vector(redew_time,8)。 sign_state=“ 011”時,東西方向紅燈亮 15s。 when 100=load=conv_std_logic_vector(yellowew_time,8)。 sign_state=“ 100”時,東西方向黃燈亮 5s。 when 101=load=conv_std_logic_vector(greenew_time,8)。 sign_state=“ 101”時,東西方向綠燈亮 25s。 when others=load=conv_std_logic_vector(yellowsn_time,8)。 end case。 計數(shù)秒數(shù)選擇電路程序代碼 27 library ieee。 use 。 use 。 entity hld2 is port(reset:in std_logic。 clk:in std_logic。 ena_scan:in std_logic。 recount:in std_logic。 sign_state:in std_logic_vector(2 downto 0)。 load:out std_logic_vector(7 downto 0))。 end。 architecture bhv of hld2 is constant redew_time:integer:=15。 constant yellowew_time:integer:=5。 constant greenew_time:integer:=25。 constant redsn_time:integer:=15。 constant yellowsn_time:integer:=5。 constant greensn_time:integer:=25。 begin process(reset,clk) begin if reset=39。139。 then load=00000000。 elsif (clk39。event and clk=39。139。) then if (ena_scan=39。139。 and recount=39。139。) then case sign_state is when 000=load=conv_std_logic_vector(greensn_time,8)。 when 001=load=conv_std_logic_vector(yellowsn_time,8)。 when 010=load=conv_std_logic_vector(redsn_time,8)。 when 011=load=conv_std_logic_vector(redew_time,8)。 28 when 100=load=conv_std_logic_vector(yellowew_time,8)。 when 101=load=conv_std_logic_vector(greenew_time,8)。 when others=load=conv_std_logic_vector(yellowsn_time,8)。 end case。 end if。 end if。 end process。 end。 architecture bhv of hld2 is constant redew_time:integer:=15。東西方向紅燈設(shè)定為 15s。 constant yellowew_time:integer:=5。東西方向黃燈設(shè)定為 5s。 constant greenew_time:integer:=25。東西方向綠燈設(shè)定為 25s。 constant redsn_time:integer:=15。南北方向紅燈設(shè)定為 15s。 constant yellowsn_time:integer:=5。南北方向黃燈設(shè)定為 5s。 constant greensn_time:integer:=25。南北方向綠燈設(shè)定為 25s。 library ieee。 use 。 use 。 entity hld4 is port(reset:in std_logic。 clk:in std_logic。 ena_scan:in std_logic。 ena_1hz:in std_logic。 flash_1hz:in std_logic。 a_m:in std_logic。 st_butt:in std_logic。 next_state:in std_logic。 29 recount:out std_logic。 sign_state:out std_logic_vector(2 downto 0)。 red:out std_logic_vector(1 downto 0)。 green:out std_logic_vector(1 downto 0)。 yellow:out std_logic_vector(1 downto 0))。 end。 architecture bhv of hld4 is type sreg0_type is (rewgsn, rewysn, gewrsn, yewrsn, yewysn, yewgsn, gewysn, rewrsn)。 signal state:sreg0_type。 signal st_transfer:std_logic。 signal light:std_logic_vector(5 downto 0)。 begin process(reset,clk,ena_scan,st_butt) variable rebn_ff:std_logic_vector(5 downto 0)。 begin if (st_butt=39。139。or reset=39。139。) then rebn_ff:=111111。 st_transfer=39。039。 elsif (clk39。event and clk=39。139。) then if (ena_scan=39。139。) then if (rebn_ff=3) then rebn_ff:=rebn_ff1。 st_transfer=39。039。 elsif(rebn_ff=2) then rebn_ff:=rebn_ff1。 st_transfer=39。139。 else rebn_ff:=rebn_ff。 st_transfer=39。039。 30 end if。 end if。 end if。 end process。 process(clk,ena_1hz,reset) begin if (reset=39。139。) then state=rewgsn。 sign_state=011。 recount=39。139。 else if (clk39。event and clk=39。139。) then case state is when rewgsn= if (a_m=39。139。 and ena_1hz=39。139。) then if (next_state=39。139。) then recount=39。139。 state=rewysn。 sign_state=011。 else recount=39。039。 state=rewgsn。 end if。 elsif (a_m=39。039。 and ena_scan=39。139。) then if (st_transfer=39。039。) then recount=39。139。 state=rewgsn。 else recount=39。139。 state=rewysn。 31 sign_state=011。 end if。 end if。 when rewysn= if (a_m=39。139。 and ena_1hz=39。139。) then if (next_state=39。139。) then recount=39。139。 state=gewrsn。 sign_state=101。 else recount=39。039。 state=rewysn。 end if。 elsif (a_m=39。039。 and ena_scan=39。139。) then if (st_transfer=39。039。) then recount=39。139。 state=rewysn。 else recount=39。139。 state=gewrsn。 sign_state=101。 end if。 end if。 when gewrsn= if (a_m=39。139。 and ena_1hz=39。139。) then if (next_state=39。139。) then recount=39。139。 state=yewrsn。 sign_state=110。 else 32 recount=39。039。 state=gewrsn。 end if。 elsif (a_m=39。039。 and ena_scan=39。139。) then if (st_transfer=39。039。) then state=gewrsn。 else recount=39。139。 state=yewrsn。 sign_state=110。 end if。 end if。 when yewrsn= if (a_m=39。139。 and ena_1hz=39。139。) then if (next_state=39。139。) then recount=39。139。 state=rewgsn。 sign_state=001。 else recount=39。039。 state=yewrsn。 end if。 elsif (a_m=39。039。 and ena_scan=39。139。) then if (st_transfer=39。039。) then recount=39。139。 state=yewrsn。 else recount=39。139。