《verilog_简单交通灯实现.docx》由会员分享,可在线阅读,更多相关《verilog_简单交通灯实现.docx(5页珍藏版)》请在优知文库上搜索。
1、简易交通控制器一、设计要求设计一个交通控制器,用LED显示灯来表示交通状态,并以七段数码管显示器显示当前状态剩余秒数,具体要求如下:1、主干道绿灯亮时,支干道红灯亮,反之依然,二者交替允许通过;主干道每次放行35s,支干道25s;每次由绿灯变为红灯过程中,黄灯亮作为过度,黄灯亮5s;2、能实现正常的倒计时显示功能;3、能实现总体清零功能,计数器由初始状态开场计数,对应状态的指示灯亮;4、能实现特殊状态的功能的显示,进入特殊状态时,东一西、南一北均显示红灯状态;二、设计原理图三、程序如下modulejiao-tong(clk,jin,razya,gazrb,yb,gbzseg7zscan);in
2、putclkjin;outputrazya,ga,rb,ybzgb;output7:0scan;output7:0seg7;regra,yazgazrb,yb,gb;reg7:0scan;reg7:0seg7;regl:0state,net-state;parameterstate=2bzstatel=2blzstate2=2,bl,state3=2,bll;regclklkhz,clklhz;reg3:0one,ten;regl:0ent;reg3:0data;reg7:0seg7_temp;regrlzr2,glzg2zylzy2;reg14:0countl;reg8:0count2;re
3、ga;reg3:0qh,ql;initialscan=8,b00000000;always(posedgeelk)beginif(countl=,d25000)beginclklkhz=clklkhz;countl=0;endelsebegincountl=countl+l,bljendendalways(posedgeclklkhz)beginif(count2=,d500)beginclklhz=clklhz;count2=0;endelsebegincount2=count2+l,bljendendalways(posedgeclklhz)beginstate=next_state;ca
4、se(state)StateOrbeginif(jin)beginif(!a)beginqh=b0011;ql=b0101;a=l;rl=O;yl=O;gl=l;r2=l;y2=0;g2=0;endelsebeginif(lqh&!ql)beginnext_state=statel;a=0;qh=bOOOO;ql=bOOOO;endelseif(!ql)beginql=bl001;qh=qh-lbl;endelsebeginql=ql-lbl;endendendendStatelrbeginif(jin)beginif(!a)beginqh=b0000;ql=b0101;a=l;rl=0;yl
5、=l;gl=0;r2=l;y2=0;g2=0;endelsebeginif(!q)beginnext_state=state2;a=0;qh=bOOOO;ql=bOOOO;endelsebeginql=ql-l,bl;endendendendstate2:beginif(jin)beginif(!a)beginqh=b0010;ql=b0101;a=l;rl=l;yl=0;gl=0;r2=0;y2=0;g2=l;endelsebeginif(lqh&!ql)beginnext_state=state3;a=0;qh=bOOOO;ql=bOOOO;endelseif(!ql)beginql=bl
6、OOl;qh=qh-lbl;endelsebeginql=ql-lbl;endendendendstate3:beginif(jin)beginif(!a)beginqh=bOOOO;ql=bOlOl;a=l;rl=l;yl=O;gl=O;r2=O;y2=l;g2=O;endelsebeginif(!q)beginnext_state=stateO;a=O;qh=bOOOO;ql=bOOOO;endelsebeginql=ql-l,bl;endendendendendcaseone=ql;ten=qh;end/always(三)(jinzclklhz,rlzr2zgl,g2,yl,y2,seg
7、7-temp)beginif(!jin)beginra=rl|jin;rb=r2|jin;ga=gl&jin;gb=g2&jin;ya=yl&jin;yb=y2&jin;seg70=seg7-temp0Iclklhz;seg7l=seg7_templIclklhz;seg72=seg7_temp2Iclklhz;seg73=seg7-temp3Iclklhz;seg74=seg7-temp4Iclklhz;seg75=seg7-temp5Iclklhz;seg76=seg7-temp6Iclklhz;sg77=seg7-temp7Iclklhz;endelsebeginseg77:0=seg7
8、_temp7:0;ra=rl;rb=r2;ga=gl;gb=g2;ya=yl;yb=y2;endend/always(posedgeclklkhz)beginif(cnt=,bl)begincnt=bOO;endelsebegincnt=cnt+l,bl;endendalways(cnt,onezten)begincase(cnt)bOO:begindata3=tencan=,bllllllljendbl:begindata3:0=one;scan=bl0111111;enddefault:begindata3=,biscan=,bxjendendcaseendalways(data)begi
9、ncase(data3:0)4b0000:seg7_temp7:0=8bll000000;4,b0001:seg7_temp7:0=8blllll001;4,b0010:seg7_temp7:0=8bl0100100;4,b0011:seg7_temp7:0=8bl0110000;4,b0100:seg7_temp7:0=8bl0011001;4,b0101:seg7_temp7:0=8bl0010010;4,b0110:seg7_temp7:0=8bl0000010;4,b0111:seg7_temp7:0=8blllll000;4,bl000:seg7_temp7:0=8bl0000000;4,bl001:seg7_temp7:0=8bl0010000;default:seg7_temp7:0=8bl0000110;endcaseendendmodule