《具有左转功能的交通灯(共10页).doc》由会员分享,可在线阅读,更多相关《具有左转功能的交通灯(共10页).doc(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上交通灯系统框图:根据设计要求和系统所具有的功能,并参考相关的文献资料,经行方案设计,可以画出如下图所示的交通信号灯控制器的系统框图。 CLK 时钟分频模块 交通灯控制及计时模块 50MHZ 扫描显示译码模块 50MHZ 1HZ 50MHZ 数码管及LED信号 数码管段码 数码管位码 LED显示系统的状态转换图如下所示:交通灯设计过程中总共只需要八个状态即可完,设置A为主干道,B为支干道,则B路的红灯时间要长于A路10秒,而绿灯时间则要缩短10s,详细情况见下状态图。系统模块图如下所示:在用QUARTUS综合后可得到详细的原理图,详细情况见下:简单仿真图:用Models
2、im进行仿真,由于50MHZ分频后,仿真图上状态转换很难观测,于是降低分频系数,便于观察从而得到近似的仿真结果,在下板子的过程中只需要将分频系数改回原来的50MHZ 分频即可。引脚分配:使用ALTERA的DE2-70来模拟交通灯过程,将引脚绑定,具体引脚分配详见下图:交通灯实物模拟图:将编译好的程序下载如DE2-70,模拟后得到如下图:交通灯代码:初始化模块:module init_mod(reset,ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft); input reset; output7:0 ared,ayellow,agreen,
3、aleft,bred,byellow,bgreen,bleft; reg7:0 ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft; always(reset) /? if(!reset) begin ared=8b; /55s ayellow=8b; /5s agreen=8b; /40s aleft=8b; /15s bred=8b; /65s byellow=8b; /5s bgreen=8b; /30s bleft=8b; /15s endendmodule分频模块:module div_clk(CLK,reset,CLK_1HZ);
4、 input CLK,reset; output CLK_1HZ; reg CLK_1HZ; reg25:0count; always(posedge CLK or negedge reset) begin if(!reset) begin CLK_1HZ=0; count=0; end else if(count 26d) /?0.5s? begin count=count+1; /? end else begin count=0; /? CLK_1HZ=CLK_1HZ; /?1s end end endmoduleA方向控制计数模块:module traffic_A(CLK_1HZ,res
5、et,ared,ayellow,agreen,aleft,lampa,numa); output3:0 lampa; output7:0 numa; input CLK_1HZ; input reset; input7:0 ared,ayellow,agreen,aleft; reg7:0 numa; /? reg tempa; /? reg2:0 counta; /? reg3:0 lampa; always(posedge CLK_1HZ or negedge reset) / begin if(!reset) /? begin lampa=4b1000; counta=0; tempa=
6、0; numa=0; endelseif(!tempa) /? begin tempa=1b1; /? case(counta) /? 0:begin numa=agreen;lampa=4b0100;counta=1;end /? 1:begin numa=ayellow;lampa=4b0010;counta=2;end /? 2:begin numa=aleft;lampa=4b0001;counta=3;end /? 3:begin numa=ayellow;lampa=4b0010;counta=4;end /? 4:begin numa=ared;lampa=4b1000;coun
7、ta=0;end /? default: lampa1) if(numa3:0=0) /?0? begin numa3:0=4b1001; /?9 numa7:4=numa7:4-1; /?1 end else numa3:0=numa3:0-1; /?1 if(numa=2) tempa=0; end end endmoduleB方向控制计数模块:module traffic_B(CLK_1HZ,reset,bred,byellow,bgreen,bleft,lampb,numb); output3:0 lampb; output7:0 numb; input CLK_1HZ; input
8、reset; input7:0 bred,byellow,bgreen,bleft; reg7:0 numb; /? reg tempb; /? reg2:0 countb; /? reg3:0 lampb; always(posedge CLK_1HZ or negedge reset) begin if(!reset) /? begin lampb=4b1000; countb=0; tempb=0; numb=0; endelseif(!tempb) /? begin tempb=1; /? case(countb) /? 0:begin numb=bred;lampb=4b1000;c
9、ountb=1;end /? 1:begin numb=bgreen;lampb=4b0100;countb=2;end /? 2:beginnumb=byellow;lampb=4b0010;countb=3;end 3:begin numb=bleft;lampb=4b0001;countb=4;end /? 4:beginnumb=byellow;lampb=4b0010;countb=0;end default lampb1) if(numb3:0=0) /?0? begin numb3:0=4b1001 ; /?9 numb7:4=numb7:4-1; /?1 end else nu
10、mb3:0=numb3:0-1; /?1 if(numb=2) tempb=0; end end endmodule显示模块:module display(in4,out8); output7:0out8; input3:0in4; reg7:0out8; always(in4) /? begincase(in4) 4h0:out8=8hc0; 4h1:out8=8hf9; 4h2:out8=8ha4; 4h3:out8=8hb0; 4h4:out8=8h99; 4h5:out8=8h92; 4h6:out8=8h82; 4h7:out8=8hf8; 4h8:out8=8h80; 4h9:ou
11、t8=8h90; 4ha:out8=8h88; 4hb:out8=8h83; 4hc:out8=8hc6; 4hd:out8=8ha1; 4he:out8=8h86; 4hf:out8=8h8e; endcaseendendmodule顶层模块:module traffic(CLK,reset,lampa,lampb,out8_a_h,out8_a_l,out8_b_h,out8_b_l); input CLK; input reset; output3:0lampa,lampb; output7:0out8_a_h,out8_a_l,out8_b_h,out8_b_l; wire7:0are
12、d,ayellow,agreen,aleft,bred,byellow,bgreen,bleft; wire CLK_1HZ; wire7:0numa_m,numb_m; /* ? */init_modQ1(.reset(reset),.ared(ared),.ayellow(ayellow),.agreen(agreen),.aleft(aleft),.bred(bred),.byellow(byellow),.bgreen(bgreen),.bleft(bleft); div_clk Q2(.CLK(CLK),.CLK_1HZ(CLK_1HZ),.reset(reset); traffic
13、_A Q3(.CLK_1HZ(CLK_1HZ),.reset(reset),.ared(ared),.ayellow(ayellow),.agreen(agreen),.aleft(aleft),.lampa(lampa),.numa(numa_m); traffic_B Q4(.CLK_1HZ(CLK_1HZ),.reset(reset),.bred(bred),.byellow(byellow),.bgreen(bgreen),.bleft(bleft),.lampb(lampb),.numb(numb_m); /B?display Q5(.in4(numa_m7:4),.out8(out8_a_h); /4?A?B?display Q6(.in4(numa_m3:0),.out8(out8_a_l); display Q7(.in4(numb_m7:4),.out8(out8_b_h); display Q8(.in4(numb_m3:0),.out8(out8_b_l); endmodule 专心-专注-专业