好文档 - 专业文书写作范文服务资料分享网站

FPGA实验报告-交通灯控制器设计

天下 分享 时间: 加入收藏 我要投稿 点赞

t0:=5; t1:=79; t2:=20; t3:=20; t4:=10;

elsif control='1' then--可调节时间或暂停 if rising_edge(cnt_clk) then --2 if choose ='1' then –选择t0-t4中的哪一个 3 if m=4 then --4 m:=0;---m在0-4之间循环 else m:=m+1; end if; --4 t<=m;--显示m else --choose为0时调节所选时间 3 if up='1' then --tx增大 --4 if m =0 then --调整t0,即闪烁时间,上限为7s, if t0=7 then --6 t0:=5; else t0:=t0+1; end if; --6 t<=t0;--显示t0 elsif m=1 then--调整t1,上限99s if t1=99 then --6 t1:=79; else t1:=t1+1; end if; --6 t<=t1;--显示t1 elsif m=2 then--调整t2,上限为30s if t2=30 then --6 t2:=20; else t2:=t2+1; end if; --6 t<=t2;--显示t2 elsif m=3 then --调整t3,上限为30s if t3=30 then --6 t3:=20; else t3:=t3+1; end if; --6 t<=t3;--显示t3

5 5

elsif m=4 then--调整t4,上限为15s if t4=15 then --6 t4:=10; else t4:=t4+1; end if; --6 t<=t4;--显示t4 end if; --5 elsif down='1' then --tx减小 4 if m =0 then ----调整t0,即闪烁时间,下限为2s, if t0=2 then --6 t0:=5; else t0:=t0-1; end if; --6 t<=t0;---显示t0 elsif m=1 then----调整t1,下限为39秒 if t1=39 then --6 t1:=79; else t1:=t1-1; end if; --6 t<=t1;--显示t1 elsif m=2 then ----调整t2,下限为10s if t2=10 then --6 t2:=20; else t2:=t2-1; end if; --6 t<=t2;---显示t2 elsif m=3 then -----调整t3,下限10s if t3=10 then --6 t3:=20; else t3:=t3-1; end if;--6 t<=t3;---显示t3 elsif m=4 then----调整t4,下限8s if t4=8 then --6 t4:=10; else t4:=t4-1; end if;--6 t<=t4; --显示t4 end if; --5 end if; --4 end if; --3 end if; --2

elsif rising_edge(cnt_clk) then --此时reset=0

5 6

if countnum=t1+t2+t3+t4 then --2记数到整周期时,记数器清零 countnum<=0; else countnum<=countnum+1; ---计数器小于整周期时,正常记数 end if; --2 if sensor='1' then --2 sensor信号有效期间,表示紧急情况两组路灯都为红灯

reda<='1'; redb<='1'; greena<='0'; greenb<='0'; greena1<='0'; greenb1<='0'; else if countnum<=t1-t0 then--3主干道绿灯亮且非闪烁,支干道红灯亮

reda<='0'; greena<='1'; greena1 <= '0'; redb<='1'; greenb<='0'; greenb1<='0'; elsif countnum<=t1 then --主干道绿灯亮且闪烁,支干道红灯亮 reda<='0'; greena<=not greena; greena1<= '0'; redb<='1'; greenb<='0'; greenb1<='0'; elsif countnum<=t1+t2-t0 then --主干道左转绿灯亮且非闪烁,支干道红灯亮

reda<='0'; greena<='0'; greena1 <= '1'; redb<='1'; greenb<='0'; greenb1<='0'; elsif (countnum<=t1+t2) then --主干道左转绿灯亮且闪烁,支干道红亮

reda<='0'; greena<='0'; greena1 <= not greena1; redb<='1';

7

greenb<='0'; greenb1<='0'; elsif (countnum<=t1+t2+t3-t0) then --支干道绿灯亮且非闪烁,主干道红灯亮

reda<='1'; greena<='0'; greena1 <= '0'; redb<='0'; greenb<='1'; greenb1<='0'; elsif (countnum<=t1+t2+t3) then --支干道绿灯亮且闪烁,主干道红灯亮

reda<='1'; greena<='0'; greena1 <= '0'; redb<='0'; greenb<=not greenb; greenb1<='0'; elsif (countnum<=t1+t2+t3+t4-t0) then --支干道左转绿灯亮且非闪烁,主干道红灯亮

reda<='1'; greena<='0'; greena1 <= '0'; redb<='0'; greenb<='0'; greenb1<='1'; elsif (countnum<=t1+t2+t3+t4) then --支干道左转绿灯亮且闪烁,主干道红灯亮

reda<='1'; greena<='0'; greena1 <= '0'; redb<='0'; greenb<='0'; greenb1<=not greenb1; end if; --3 end if; --2

----下面将正计数转换为倒计数----- if countnum<=t1 then --2 count:=t1-countnum; ---主干道绿灯亮,支干道红灯亮时倒计时 elsif countnum<=t1+t2 then ---主干道左转绿灯亮,支干道红灯亮时倒计时

count:=t1+t2-countnum; elsif countnum<=t1+t2+t3 then----支干道绿灯亮,主干道红灯亮 时倒计时

8

count:=t1+t2+t3-countnum; elsif countnum<=t1+t2+t3+t4 then---支干道左转绿灯亮,主干道红灯亮 时倒计时

count:=t1+t2+t3+t4-countnum; end if; --2

----上面将正计数转换为倒计数---- t<=count;---显示count end if; --1

-----以下代码为分位译码----- if t>=90 then --1 cntnumh<=9; cntnuml<=t-90; elsif t>=80 then cntnumh<=8; cntnuml<=t-80; elsif t>=70 then cntnumh<=7; cntnuml<=t-70; elsif t>=60 then cntnumh<=6; cntnuml<=t-60; elsif t>=50 then cntnumh<=5; cntnuml<=t-50; elsif t>=40 then cntnumh<=4; cntnuml<=t-40; elsif t>=30 then cntnumh<=3; cntnuml<=t-30; elsif t>=20 then cntnumh<=2; cntnuml<=t-20; elsif t>=10 then cntnumh<=1; cntnuml<=t-10; else cntnumh<=0; cntnuml<=t; end if;--1 -----以上代码为分位译码----- ---各信号赋给各输出的交通灯 greenax<=greena;----主干绿灯 greenay<=greena1;---主干左转绿灯

9

FPGA实验报告-交通灯控制器设计

t0:=5;t1:=79;t2:=20;t3:=20;t4:=10;elsifcontrol='1'then--可调节时间或暂停ifrising_edge(cnt_clk)then--2ifchoose='1'then–选择t0-t4中的哪一个3ifm=4then--
推荐度:
点击下载文档文档为doc格式
6cst03qejj9uewv2soay
领取福利

微信扫码领取福利

微信扫码分享