具有左转功能的交通灯

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

交通灯系统框图:根据设计要求和系统所具有的功能,并参考相关的文献资料,经行方案设计,可以画出如下图所示的交通信号灯控制器的系统框图。50MHZ50MHZ1HZ50MHZ数码管及LED信号时钟分频模块CLK交通灯控制及计时模块扫描显示译码模块LED显示数码管位码数码管段码系统的状态转换图如下所示:交通灯设计过程中总共只需要八个状态即可完,设置A为主干道,B为支干道,则B路的红灯时间要长于A路10秒,而绿灯时间则要缩短10s,详细情况见下状态图。系统模块图如下所示:在用QUARTUS综合后可得到详细的原理图,详细情况见下:简单仿真图:用Modelsim进行仿真,由于50MHZ分频后,仿真图上状态转换很难观测,于是降低分频系数,便于观察从而得到近似的仿真结果,在下板子的过程中只需要将分频系数改回原来的50MHZ分频即可。引脚分配:使用ALTERA的DE2-70来模拟交通灯过程,将引脚绑定,具体引脚分配详见下图:交通灯实物模拟图:将编译好的程序下载如DE2-70,模拟后得到如下图:交通灯代码:初始化模块:moduleinit_mod(reset,ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft);inputreset;output[7:0]ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft;reg[7:0]ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft;always@(reset)//??????????if(!reset)beginared=8'b01010101;//55sayellow=8'b00000101;//5sagreen=8'b01000000;//40saleft=8'b00010101;//15sbred=8'b01100101;//65sbyellow=8'b00000101;//5sbgreen=8'b00110000;//30sbleft=8'b00010101;//15sendendmodule分频模块:modulediv_clk(CLK,reset,CLK_1HZ);inputCLK,reset;outputCLK_1HZ;regCLK_1HZ;reg[25:0]count;always@(posedgeCLKornegedgereset)beginif(!reset)beginCLK_1HZ=0;count=0;endelseif(count26'd26214400)//??0.5s??begincount=count+1;//???????endelsebegincount=0;//?????CLK_1HZ=~CLK_1HZ;//?????????????1sendendendmoduleA方向控制计数模块:moduletraffic_A(CLK_1HZ,reset,ared,ayellow,agreen,aleft,lampa,numa);output[3:0]lampa;output[7:0]numa;inputCLK_1HZ;inputreset;input[7:0]ared,ayellow,agreen,aleft;reg[7:0]numa;//?????regtempa;//?????????????reg[2:0]counta;//??????????reg[3:0]lampa;always@(posedgeCLK_1HZornegedgereset)/beginif(!reset)//??????????beginlampa=4'b1000;counta=0;tempa=0;numa=0;endelseif(!tempa)//??????????????????begintempa=1'b1;//?????????case(counta)//??????????0:beginnuma=agreen;lampa=4'b0100;counta=1;end//??1:beginnuma=ayellow;lampa=4'b0010;counta=2;end//??2:beginnuma=aleft;lampa=4'b0001;counta=3;end//???3:beginnuma=ayellow;lampa=4'b0010;counta=4;end//??4:beginnuma=ared;lampa=4'b1000;counta=0;end//??default:lampa=4'b1000;//??endcaseendelse//???beginif(numa1)if(numa[3:0]==0)//????0?beginnuma[3:0]=4'b1001;//????9numa[7:4]=numa[7:4]-1;//?????1endelsenuma[3:0]=numa[3:0]-1;//?????1if(numa==2)tempa=0;endendendmoduleB方向控制计数模块:moduletraffic_B(CLK_1HZ,reset,bred,byellow,bgreen,bleft,lampb,numb);output[3:0]lampb;output[7:0]numb;inputCLK_1HZ;inputreset;input[7:0]bred,byellow,bgreen,bleft;reg[7:0]numb;//?????regtempb;//?????????????reg[2:0]countb;//??????????reg[3:0]lampb;always@(posedgeCLK_1HZornegedgereset)beginif(!reset)//??????????beginlampb=4'b1000;countb=0;tempb=0;numb=0;endelseif(!tempb)//??????????????????begintempb=1;//?????????case(countb)//??????????0:beginnumb=bred;lampb=4'b1000;countb=1;end//??1:beginnumb=bgreen;lampb=4'b0100;countb=2;end//??2:beginnumb=byellow;lampb=4'b0010;countb=3;end3:beginnumb=bleft;lampb=4'b0001;countb=4;end//???4:beginnumb=byellow;lampb=4'b0010;countb=0;enddefaultlampb=4'b1000;endcaseendelse//???beginif(numb1)if(numb[3:0]==0)//????0?beginnumb[3:0]=4'b1001;//????9numb[7:4]=numb[7:4]-1;//?????1endelsenumb[3:0]=numb[3:0]-1;//?????1if(numb==2)tempb=0;endendendmodule显示模块:moduledisplay(in4,out8);output[7:0]out8;input[3:0]in4;reg[7:0]out8;always@(in4)//?????begincase(in4)4'h0:out8=8'hc0;4'h1:out8=8'hf9;4'h2:out8=8'ha4;4'h3:out8=8'hb0;4'h4:out8=8'h99;4'h5:out8=8'h92;4'h6:out8=8'h82;4'h7:out8=8'hf8;4'h8:out8=8'h80;4'h9:out8=8'h90;4'ha:out8=8'h88;4'hb:out8=8'h83;4'hc:out8=8'hc6;4'hd:out8=8'ha1;4'he:out8=8'h86;4'hf:out8=8'h8e;endcaseendendmodule顶层模块:moduletraffic(CLK,reset,lampa,lampb,out8_a_h,out8_a_l,out8_b_h,out8_b_l);inputCLK;inputreset;output[3:0]lampa,lampb;output[7:0]out8_a_h,out8_a_l,out8_b_h,out8_b_l;wire[7:0]ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft;wireCLK_1HZ;wire[7:0]numa_m,numb_m;/*????*/init_modQ1(.reset(reset),.ared(ared),.ayellow(ayellow),.agreen(agreen),.aleft(aleft),.bred(bred),.byellow(byellow),.bgreen(bgreen),.bleft(bleft));div_clkQ2(.CLK(CLK),.CLK_1HZ(CLK_1HZ),.reset(reset));traffic_AQ3(.CLK_1HZ(CLK_1HZ),.reset(reset),.ared(ared),.ayellow(ayellow),.agreen(agreen),.aleft(aleft),.lampa(lampa),.numa(numa_m));traffic_BQ4(.CLK_1HZ(CLK_1HZ),.reset(reset),.bred(bred),.byellow(byellow),.bgreen(bgreen),.bleft(bleft),.lampb(lampb),.numb(numb_m));//B?????displayQ5(.in4(numa_m[7:4]),.out8(out8_a_h));//4???????A?B??????displayQ6(.in4(numa_m[3:0]),.out8(out8_a_l));displayQ7(.in4(numb_m[7:4]),.out8(out8_b_h));displayQ8(.in4(numb_m[3:0]),.out8(out8_b_l));endmodule

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功