FPGA实验报告交通灯控制器设计Word文档下载推荐.docx
- 文档编号:19898771
- 上传时间:2023-01-12
- 格式:DOCX
- 页数:20
- 大小:137.51KB
FPGA实验报告交通灯控制器设计Word文档下载推荐.docx
《FPGA实验报告交通灯控制器设计Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《FPGA实验报告交通灯控制器设计Word文档下载推荐.docx(20页珍藏版)》请在冰豆网上搜索。
c)输入输出及信号设计:
Port(LCD_Clk:
inSTD_LOGIC;
----50mhz时钟
reset:
inSTD_LOGIC:
='
0'
;
--复位
sensor:
instd_logic:
---特殊情况时,两边都是红灯
up:
;
---有效时调整时间时增大时间
down:
---有效时调整时间时减少时间
choose:
---选择调整哪一个时间
control:
---有效时可以暂停,调整时间
LCD_RS:
outSTD_LOGIC;
LCD_RW:
LCD_EN:
redax,greenax,greenay:
outstd_logic;
--主干道的红灯和两个绿灯,greenay为左转灯
redbx,greenbx,greenby:
--支干道的红灯和两个绿灯,greenby为左转灯
data:
outSTD_LOGIC_VECTOR(3downto0));
--Lcd显示
typeistateis(
write_instr,
write_dataup4,
write_datadown4,
set_addrup,
set_addrdown,
ret_homeup,
ret_homedown
);
signalstate:
istate;
signalt_clk,clk500:
std_logic;
---分别为1hz,500hz
signalt:
integerrange0to15:
=0;
signaltnumh,cntnuml:
integerrange0to9;
--输入到数码管的数字
signalcountnum:
integer;
---计数器
signalreda,greena,greena1,redb,greenb,greenb1:
--各交通灯对应的信?
signalt:
integerrange0to99;
---要输入lcd中的数字
d)基本模块设计:
1)字符译码函数
functionputc(data:
character)returnstd_logic_vectoris
---字符译码函数,将字符显示在lcd上
variableresult:
std_logic_vector(7downto0);
begin
casedatais
when'
o'
=>
result:
=conv_std_logic_vector(111,8);
u'
result:
=conv_std_logic_vector(117,8);
C'
=conv_std_logic_vector(67,8);
n'
=conv_std_logic_vector(110,8);
t'
=conv_std_logic_vector(116,8);
e'
=conv_std_logic_vector(101,8);
r'
=conv_std_logic_vector(114,8);
:
'
=conv_std_logic_vector(58,8);
whenothers=>
=conv_std_logic_vector(32,8);
endcase;
returnresult;
endputc;
2)数字译码函数
functionputn(num:
inintegerrange0to9)returnstd_logic_vectoris
---数字译码函数,将数字显示在lcd上
variablefig:
casenumis
when0=>
fig:
="
00110000"
when1=>
fig:
00110001"
when2=>
00110010"
when3=>
00110011"
when4=>
00110100"
when5=>
00110101"
when6=>
00110110"
when7=>
00110111"
when8=>
00111000"
when9=>
00111001"
returnfig;
endputn;
3)分频,由50Mhz得到500hz,驱动lcd
process(LCD_Clk)
----分频,得到500hz时钟
variablen3:
integerrange0to49999;
ifrising_edge(LCD_Clk)then
ifn3<
49999then
n3:
=n3+1;
else
clk500<
=notclk500;
endif;
endif;
endprocess;
4)分频,由500hz得到1hz,作为交通灯控制器输入
process(clk500)
----分频,得到1hz时钟
variablen:
integerrange0to249;
ifrising_edge(clk500)then
ifn<
249then
n:
=n+1;
cnt_clk<
=nott_clk;
5)主要功能实现:
process(cnt_clk,reset,choose,up,down,control,t)
---实现各种要求功能,包括倒计时显示,红绿灯(含左转灯)转换,以及转换时间调整
variablem:
integerrange0to4;
---m表示转换的是哪一个时间(t0-t4中哪一个)
variablecount:
naturalrange0to99;
---计数器,将正计数转换为倒计数
variablet0:
integerrange0to99:
=5;
---绿灯闪烁时间
variablet1:
=79;
---主干道绿灯亮的时间
variablet2:
=20;
---主干道左转灯亮的时间
variablet3:
integerrange0to99:
---支干道绿灯亮的时间
variablet4:
=10;
---支干道左转灯亮的时间
ifreset='
1'
then--1
----复位,计数器清零,m,t0-t4赋初值
countnum<
m:
t0:
t1:
t2:
t3:
t4:
elsifcontrol='
then--可调节时间或暂停
ifrising_edge(cnt_clk)then--2
ifchoose='
then–选择t0-t4中的哪一个3
ifm=4then--4
m:
---m在0-4之间循环
else
=m+1;
endif;
--4
t<
=m;
--显示m
else--choose为0时调节所选时间3
ifup='
then--tx增大--4
ifm=0then--调整t0,即闪烁时间,上限为7s,5
ift0=7then--6
t0:
else
=t0+1;
endif;
--6
t<
=t0;
--显示t0
elsifm=1then--调整t1,上限99s
ift1=99then--6
t1:
=t1+1;
=t1;
--显示t1
elsifm=2then--调整t2,上限为30s
ift2=30then--6
t2:
=t2+1;
=t2;
--显示t2
elsifm=3then--调整t3,上限为30s
ift3=30then--6
t3:
=t3+1;
=t3;
--显示t3
elsifm=4then--调整t4,上限为15s
ift4=15then--6
t4:
=t4+1;
=t4;
--显示t4
endif;
--5
elsifdown='
then--tx减小4
ifm=0then----调整t0,即闪烁时间,下限为2s,5
ift0=2then--6
elset0:
=t0-1;
---显示t0
elsifm=1then----调整t1,下限为39秒
ift1=39then--6
elset1:
=t1-1;
elsifm=2then----调整t2,下限为10s
ift2=10then--6
elset2:
=t2-1;
---显示t2
elsifm=3then-----调整t3,下限10s
ift3=10then--6
elset3:
=t3-1;
--6
---显示t3
elsifm=4then----调整t4,下限8s
ift4=8then--6
elset4:
=t4-1;
--显示t4
endif;
--3
--2
elsifrising_edge(cnt_clk)then--此时reset=0
ifcountnum=t1+t2+t3+t4then--2记数到整周期时,记数器清零
countnum<
=countnum+1;
---计数器小于整周期时,正常记数
ifsensor='
then--2sensor信号有效期间,表示紧急情况两组路灯都为红灯
reda<
redb<
greena<
greenb<
greena1<
greenb1<
ifcountnum<
=t1-t0then--3主干道绿灯亮且非闪烁,支干道红灯亮
reda<
greena<
greena1<
='
redb<
greenb<
greenb1<
elsifcountnum<
=t1then--主干道绿灯亮且闪烁,支干道红灯亮
=notgreena;
greena1<
=t1+t2-t0then--主干道左转绿灯亮且非闪烁,支干道红灯亮
elsif(countnum<
=t1+t2)then--主干道左转绿灯亮且闪烁,支干道红亮
=notgreena1;
=t1+t2+t3-t0)then--支干道绿灯亮且非闪烁,主干道红灯亮
=t1+t2+t3)then--支干道绿灯亮且闪烁,主干道红灯亮
=notgreenb;
=t1+t2+t3+t4-t0)then--支干道左转绿灯亮且非闪烁,主干道红灯亮
=t1+t2+t3+t4)then--支干道左转绿灯亮且闪烁,主干道红灯亮
=notgreenb1;
----下面将正计数转换为倒计数-----
ifcountnum<
=t1then--2
count:
=t1-countnum;
---主干道绿灯亮,支干道红灯亮时倒计时
elsifcountnum<
=t1+t2then---主干道左转绿灯亮,支干道红灯亮时倒计时
=t1+t2-countnum;
=t1+t2+t3then----支干道绿灯亮,主干道红灯亮时倒计时
=t1+t2+t3-countnum;
=t1+t2+t3+t4then---支干道左转绿灯亮,主干道红灯亮时倒计时
=t1+t2+t3+t4-countnum;
----上面将正计数转换为倒计数----
t<
=count;
---显示count
--1
-----以下代码为分位译码-----
ift>
=90then--1
cntnumh<
=9;
cntnuml<
=t-90;
elsift>
=80then
=8;
=t-80;
=70then
=7;
=t-70;
=60then
=6;
=t-60;
=50then
=t-50;
=40then
=4;
=t-40;
=30then
=3;
=t-30;
=20then
=2;
=t-20;
=10then
=1;
=t-10;
else
=t;
--1
-----以上代码为分位译码-----
---各信号赋给各输出的交通灯
greenax<
=greena;
----主干绿灯
greenay<
=greena1;
---主干左转绿灯
greenbx<
=greenb;
---支干道绿灯
greenby<
=greenb1;
---支干道左转绿灯
redax<
=reda;
----主干红灯
redbx<
=redb;
--支干道绿灯
主要功能仿真如下:
a)、reset为1时,初始化。
为0时,会从79倒计时,主干道绿灯亮,支干道红灯亮,sensor为1时,主干道和支干道都为红灯亮:
b)默认情况下倒计时到最后5S时会闪烁显示,并切换到下一状态,继续倒计时:
c)如果reset=0且control为1时,暂停计数,此时若choose为1,则会在0-4之间循环计数,选择调节哪一个时间(t0-t4),若choose改为0,就会暂停计数:
d)此时(reset=0,control=1,choose=0)若选择down=1或up=1,则会减计数(默认值到最小值循环)或加计数(默认值到最大值循环)调整当前选中的时间t:
(当前选的t0,闪烁时间,最后调整为7s)
e)若将control置于0,则会接着倒计时,就像最初初始化时,但此时调整后的时间生效(这里闪烁时间改为7s):
6)显示
process(clk500,reset)
------lcd上显示数字和字符
then---复位时不显示
state<
=write_instr;
LCD_RS<
cnt<
elsifrising_edge(clk500)then---显示数字或字符
casestateis
whenwrite_instr=>
LCD_RS<
casetis
when0=>
data<
0011"
when1=>
when2=>
when3=>
0010"
when4=>
when5=>
1000"
when6=>
0000"
when7=>
0110"
when8=>
when9=>
110
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- FPGA 实验 报告 交通灯 控制器 设计