资源描述:
《EDA课程设计图》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、libraryieee;useieee.std_logic_1164.all;entityTrafficisport(clk,en:instd_logic;lamp_a,lamp_b:outstd_logic_vector(3downto0);adis_s,adis_g:bufferstd_logic_vector(6downto0);bdis_s,bdis_g:bufferstd_logic_vector(6downto0));endTraffic;architecturearchtraofTrafficis
2、signalacount_max,acount:integerrange0to54;signalbcount_max,bcount:integerrange0to65;signalanum_s,anum_g,bnum_s,bnum_g:integerrange0to9;typestatesis(st0,st1,st2,st3,st4,st5,st6,st7);signalp_state,n_state:states;componentde7ledisport(din:inintegerrange0to9;dou
3、t:outstd_logic_vector(6downto0));endcomponent;begin-------此进程用来把数码管十位与个位分离process(clk,n_state)beginif(clk'eventandclk='1')thenif(en='0')thenif(acount=0)thenp_state<=n_state;acount<=acount_max;elseacount<=acount-1;endif;if(bcount=0)thenp_state<=n_state;bcount
4、<=bcount_max;elsebcount<=bcount-1;endif;elsep_state<=st0;acount<=40;bcount<=65;endif;if(acount>=50)thenanum_s<=5;anum_g<=acount-50;elsif(acount>=40)thenanum_s<=4;anum_g<=acount-40;elsif(acount>=30)thenanum_s<=3;anum_g<=acount-30;elsif(acount>=20)thenanum_s<=
5、2;anum_g<=acount-20;elsif(acount>=10)thenanum_s<=1;anum_g<=acount-10;elseanum_s<=0;anum_g<=acount;endif;if(bcount>=60)thenbnum_s<=6;bnum_g<=bcount-60;elsif(bcount>=50)thenbnum_s<=5;bnum_g<=bcount-50;elsif(bcount>=40)thenbnum_s<=4;bnum_g<=bcount-40;elsif(bcou
6、nt>=30)thenbnum_s<=3;bnum_g<=bcount-30;elsif(bcount>=20)thenbnum_s<=2;bnum_g<=bcount-20;elsif(bcount>=10)thenbnum_s<=1;bnum_g<=bcount-10;elsebnum_s<=0;bnum_g<=bcount;endif;endif;endprocess;process(p_state)begincase(p_state)iswhenst0=>lamp_a<="0010";--A方绿,B方红
7、lamp_b<="1000";n_state<=st1;acount_max<=4;whenst1=>lamp_a<="0100";--A方黄,B方红lamp_b<="1000";n_state<=st2;acount_max<=14;whenst2=>lamp_a<="0001";--A方左拐,B方红lamp_b<="1000";n_state<=st3;acount_max<=4;whenst3=>lamp_a<="0100";--A方黄,B方红lamp_b<="1000";n_state<=st4;aco
8、unt_max<=54;bcount_max<=29;whenst4=>lamp_a<="1000";--A方红,B方绿lamp_b<="0010";n_state<=st5;bcount_max<=4;whenst5=>lamp_a<="1000";--A方红,B方黄lamp_b<="0100";n_state<=st6;bcount_max<=14;whenst6=>lamp_a<