资源描述:
《实验八 交通灯控制器设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验八交通灯控制器设计实验报告一、实验要求1、GW48实验箱;2、设计十字路口交通灯控制器,并进行编译、仿真、下载;3、总结实验步骤和实验结果。二、实验内容设计一个十字路口交通控制系统,其东西,南北两个方向除了有红、黄、绿灯指示是否允许通行外,还设有时钟,以倒计时方式显示每一路允许通行的时间。当东西或南北两路中任一道上出现特殊情况,例如有消防车,警车要去执行任务,此时交通控制系统应可由交警手动控制立即进入特殊运行状态,即两条道上的所有车辆皆禁止通行,红灯全亮,时钟停止计时。当特殊运行状态结束后,管理系统恢复原来的状态,继续正常运行。/*信号定义与说明
2、:CLK:为同步时钟;EN:使能信号,为1的话,则控制器开始工作;LAMPA:控制A方向四盏灯的亮灭;其中,LAMPA0~LAMPA3,分别控制A方向的左拐灯、绿灯、黄灯和红灯;LAMPB:控制B方向四盏灯的亮灭;其中,LAMPB0~LAMPB3,分别控制B方向的左拐灯、绿灯、黄灯和红灯;ACOUNT:用于A方向灯的时间显示,8位,可驱动两个数码管;BCOUNT:用于B方向灯的时间显示,8位,可驱动两个数码管。*/modulezdw8(CLK,EN,LAMPA,LAMPB,ACOUNT,BCOUNT);output[7:0]ACOUNT,BCOUNT
3、;output[3:0]LAMPA,LAMPB;inputCLK,EN;reg[7:0]numa,numb;regtempa,tempb;reg[2:0]counta,countb;reg[7:0]ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft;reg[3:0]LAMPA,LAMPB;always@(EN)if(!EN)begin//shezhigezhongdengdeyuzhishuared<=8'h55;//55minus7ayellow<=8'h5;//5minusagreen<=8'h
4、40;//40minusaleft<=8'h15;//15minusbred<=8'h65;//65minusbyellow<=8'h5;//5minusbleft<=8'h15;//15minusbgreen<=8'h30;//30minusendassignACOUNT=numa;assignBCOUNT=numb;always@(posedgeCLK)//kongzhiAfangxiangdesizhongdengbeginif(EN)beginif(!tempa)begintempa<=1;case(counta)//kongzhiliang
5、dengshunxu0:beginnuma<=agreen;LAMPA<=2;counta<=1;end1:beginnuma<=ayellow;LAMPA<=4;counta<=2;end2:beginnuma<=aleft;LAMPA<=1;counta<=3;end3:beginnuma<=ayellow;LAMPA<=4;counta<=4;end4:beginnuma<=ared;LAMPA<=8;counta<=0;enddefault:LAMPA<=8;endcaseendelsebegin//daojishiif(numa>1)if(
6、numa[3:0]==0)beginnuma[3:0]<=4'b1001;numa[7:4]<=numa[7:4]-1;endelsenuma[3:0]<=numa[3:0]-1;if(numa==2)tempa<=0;7endendelsebeginLAMPA<=4'b1000;counta<=0;tempa<=0;endendalways@(posedgeCLK)//kongzhiBfangxiangdesizhongdengbeginif(EN)beginif(!tempb)begintempb<=1;case(countb)//kongzhi
7、liangdengshunxu0:beginnumb<=bred;LAMPB<=8;countb<=1;end1:beginnumb<=bgreen;LAMPB<=2;countb<=2;end2:beginnumb<=byellow;LAMPB<=4;countb<=3;end3:beginnumb<=bleft;LAMPB<=1;countb<=4;end4:beginnumb<=byellow;LAMPB<=4;countb<=0;enddefault:LAMPB<=8;endcaseendelsebegin//daojishiif(numb>
8、1)if(numb[3:0]==0)beginnumb[3:0]<=9;numb[7:4]<=numb[7: