实验8交通灯控制器的设计Word下载.docx
《实验8交通灯控制器的设计Word下载.docx》由会员分享,可在线阅读,更多相关《实验8交通灯控制器的设计Word下载.docx(21页珍藏版)》请在冰豆网上搜索。
B方向左拐、绿灯、黄灯、红灯的显示时间分别是15s、30s、5s、65s。
3、控制器有5种工作方式。
可通过方式开关的控制进行切换。
其中,前4种方式用于特殊情况,第5种方式为正常情况下的工作方式。
3.1A方向左拐长时间亮,B方向红灯亮,允许A方向左转车辆通行。
3.2A方向绿灯长时间亮,B方向红灯亮,允许A方向车辆直行。
3.3B方向左拐长时间亮,A方向红灯亮,允许B方向左转车辆通行。
3.4B方向绿灯长时间亮,A方向红灯亮,允许B方向车辆直行。
3.5自动工作方式,两个方向的灯按显示顺序,交替循环显示。
4、控制器设有工作方式状态显示,以指示系统运行的状态。
5、系统设有总复位开关,可在任意时间内对系统进行复位。
(二)画出系统框架,进行功能分割方便模块化设计
1、根据设计要求和系统所具有的功能,交通灯控制器系统框图如图2所示,该系统主要有控制电路模块、译码驱动电路模块、计时模块、扫描显示电路模块构成。
其中CLR为系统总复位信号,M2~M0为系统工作方式设置输入信号,CLK为秒脉冲信号,A~G显示的段码输出,SEL5~SEL0为数码管的位码输出,al,ay,ag,ar分别表示A方向的显示灯,bl,by,bg,br分别表示B方向的显示灯。
控制电路根据M2~M0信号产生系统控制方式,用于控制其他部分协调工作。
图2交通灯控制器系统框图
(三)模块化设计各功能
1.计时电路,按照交通灯的亮灯时间和亮灯顺序,设定A和B两个方向计时器的初值,以及在秒脉冲CLK的作用下进行减1计数,并为扫描显示电路提供倒计时时间。
2.扫描显示电路:
对计时电路的输出计时信号进行选通、译码,实现倒计时的动态显示。
3.译码驱动电路:
根据控制电路的控制信号驱动交通灯的显示。
(四)系统仿真
分模块进行仿真,分析是否符合设计要求。
(五)下载验证
实验中配合示波器观察输出时钟信号。
观察现象并记录,分析是否符合设计。
代码:
计时模块的设计:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityjtd_timeis
port(clk,clr:
instd_logic;
m,s:
instd_logic_vector(2downto0);
at,bt:
outstd_logic_vector(7downto0));
endjtd_time;
architecturejtd_2ofjtd_timeis
signalati,bti:
std_logic_vector(7downto0);
signalart,agt,alt,abyt:
std_logic_vector(7downto0);
signalbrt,bgt,blt:
begin
art<
=x"
55"
;
agt<
40"
alt<
15"
abyt<
05"
brt<
65"
bgt<
30"
blt<
process(clk,clr,m,s)
ifclr='
1'
thenati<
01"
bti<
elsif(clk'
eventandclk='
)then
ifm="
000"
bti<
51"
endif;
001"
06"
010"
41"
011"
ifm>
="
100"
then
if(ati=x"
)or(bti=x"
)then
casesis
when"
=>
ati<
=alt;
=brt;
=abyt;
=agt;
=art;
=blt;
101"
110"
=bgt;
111"
whenothers=>
=ati;
=bti;
endcase;
ifati/=x"
then
ifati(3downto0)="
0000"
ati(3downto0)<
1001"
ati(7downto4)<
=ati(7downto4)-1;
elseati(3downto0)<
=ati(3downto0)-1;
=ati(7downto4);
endif;
ifbti/=x"
ifbti(3downto0)="
bti(3downto0)<
bti(7downto4)<
=bti(7downto4)-1;
elsebti(3downto0)<
=bti(3downto0)-1;
=bti(7downto4);
endprocess;
at<
bt<
endjtd_2;
译码驱动模块的设计:
entityjtd_lightis
port(clr:
abl:
endjtd_light;
architecturejtd_3ofjtd_lightis
signallt:
process(clr,s,m)
thenlt<
00000000"
elseifm="
10000001"
00100001"
00011000"
00010010"
ifm>
lt<
00010100"
01000001"
when"
=lt;
abl<
endjtd_3;
显示模块的设计:
entityjtd_disis
port(clk,clk1k,clr:
m1,m2,m0:
instd_logic_vector(7downto0);
led:
outstd_logic_vector(6downto0);
sel:
outstd_logic_vector(5downto0));
endjtd_dis;
architecturejtd_4ofjtd_disis
signalou,stl,sth,mm:
std_logic_vector(3downto0);
signaldis,ds:
signalsl:
std_logic_vector(2downto0);
signalsq:
std_logic_vector(5downto0);
beginmm<
0"
&
m2&
m1&
m0;
sth<
a"
process(clk1k,clr)
thensl<
elsif(clk1k'
eventandclk1k='
ifsl="
elsesl<
=sl+1;
process(sl)
begin
caseslis
sq<
000001"
000010"
000100"
001000"
010000"
100000"
null;
ou<
=bt(3downto0);
=bt(7downto4);
=at(3downto0);
=at(7downto4);
=stl;
=sth;
process(ou)
caseouis
whenx"
ds<
3f"
1"
2"
5b"
3"
4f"
4"
66"
5"
6d"
whenx"
6"
7d"
7"
07"
8"
7f"
9"
6f"
00"
process(mm,clk)
begin
ifmm>
thenstl<
elsestl<
=mm+1;
thendis<
elsifmm>
=ds;
elsifsl<
"
ifclk='
0'
elsedis<
elsedis<
led<
=dis(6downto0);
sel<
=sq;
endjtd_4;
分频模块的设计:
entityjtd_fpis
port(clk1k:
clk:
outstd_logic);
end;
architecturestrofjtd_fpis
signalfp:
std_logic_vector(9downto0);
process(clk1k)
if(clk1k'
fp<
=fp+1;
clk<
=fp(9);
end;
交通灯控制器控制模块的设计:
entityjtd_ctrlis
m:
s:
outstd_logic_vector(2downto0));
endjtd_ctrl;
architecturejtd_1ofjtd_ctrlis
signalq:
process(clr,clk,m,at,bt)
thenq<
if(at="
)or(bt="
)thenq<
=q+1;
elseq<
=q;
s<
endjtd_1;
顶层设计程序:
entityjtdis
port(clk1k,clr:
m:
outstd_logic_vector(7downto0);
endjtd;
architecturesturctureofjtdis
componentjtd_time
endcomponent;
componentjtd_light
componentjtd_dis
port(clk,clklk,clr:
componentjtd_fp
port(clklk:
componentjtd_ctrl
signalat,bt:
signals:
signalclk:
std_logic;
begin
U0:
jtd_fp
portmap(clk1k,clk);
u1:
jtd_time
portmap(clk,clr,m,s,at,bt);
u2:
jtd_ctrl
portmap(clk,clr,m,at,bt,s);
u3:
jtd_light
portmap(clr,m,s,abl);
u4:
jtd_dis
portmap(clk,clk1k,clr,m
(1),m
(2),m(0),at,bt,led,sel);
endsturcture;
port(clklk:
endjtd_fp;
signalfp:
std_logic_vector(9downto0);
process(clklk)
if(clklk'
eventandclklk='
)then
clk<
endstr;
entityjtd_timeis
endjtd_time;
architecturejtd_2ofjtd_timeis
thenati<
elsif(clk'
endif;
then
if(ati=x"
)or(bti<
when"