资源描述:
《--控制模块,keepmudoe》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、----------控制模块,keepmudoelibraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitykeepisport(alarm,b,clk,reset,jeep:instd_logic;key:instd_logic_vector(2downto0);ns,ew:outstd_logic_vector(2downto0);--两个方向的红、黄、绿。c:outstd_logic_vector(1downto0)
2、;--状态输出端00,01,10,11nsh,nsl,ewh,ewl:outstd_logic_vector(3downto0);en:outstd_logic);--;endkeep;architecturekeep_arcofkeepistypestate_typeis(s0,s1,s2,s3,s4);typemode_typeis(m1,m2,m3,m4);signalcurrent_state:state_type;signalnew_state:state_type;signalmode:mode_ty
3、pe;signalnsh_c,nsl_c,ewh_c,ewl_c:std_logic_vector(3downto0);beginnewstate_logic:process(current_state,b,alarm,reset,clk,mode)variablem:integerrange0to3;begin------------------------------------------------------------------------------------------------------
4、-----------------------------if(clk'eventandclk='1')thencurrent_state<=new_state;if(key="100")thenen<='0';casemodeiswhenm1=>mode<=m2;ewl<=ewl_c;whenm2=>mode<=m3;ewh<=ewh_c;whenm3=>mode<=m4;nsl<=nsl_c;whenm4=>mode<=m1;nsh<=nsh_c;whenothers=>null;endcase;------
5、-------------------------------------------------elsif(key="010")thenen<='0';casemodeiswhenm1=>--en<='0';if(ewl_c="1001")thenewl_c<="0000";elseewl_c<=ewl_c+'1';endif;whenm2=>--en<='0';if(ewh_c="1001")thenewh_c<="0000";elseewh_c<=ewh_c+'1';endif;whenm3=>--en<=
6、'0';if(nsl_c="1001")thennsl_c<="0000";elsensl_c<=nsl_c+'1';endif;whenm4=>--en<='0';if(nsh_c="1001")thennsh_c<="0000";elsensh_c<=nsh_c+'1';endif;whenothers=>null;endcase;------------------------------------------------------------------------------------------
7、------------------------------------------elsif(key="001")thenen<='1';-------------------------------------------------if(alarm='1')thennew_state<=s0;----紧急报警状态elseif(reset='1')thennew_state<=s1;----------------通电复位后给交通灯状态赋初值elsecasecurrent_stateiswhens1=>m:=
8、0;if(b='1'andjeep='0')then---当计数到20s且无紧急情况时,交通灯跳至下一状态new_state<=s2;--elsif(a='1')thennew_state<=s0;-----有紧急情况时,交通灯变为紧急状态elsenew_state<=s1;------------------计时未到的时候保持原状态不变endif;whens2=>m:=