十字路口交通灯控制器设计报告
姓名:***
学号:************
班级:计122-2
指导教师:***
一、 设计要求
在十字路口,每条道路上各有一组红、黄、绿灯和倒计时显示器,用以指挥车辆和行人有序的通行。
二、 系统功能描述
1、 在十字路口的两个方向上各设一组红黄绿灯。
2、 每个方向上设计一组数码管,以倒计时的方式显示允许通行和禁止的时间。可以自设时间。
3、 允许当特殊情况出现时,比如紧急状态,各方向上均是红灯亮,且数字在闪烁,或者模拟夜间黄灯闪烁。
4、 其他功能自加。
三、 设计方案
时钟脉冲
紧急状态按钮 东西主控制电路
南北主控制电路 译码显示 东西信号灯
南北信号灯
四、 各模块具体设计
1、模块 corner a与b即东西方向与南北方向道路主控制器,其中用type分别列举各个显示灯,并分配起始状态。在每个灯的状态中分别用if语句写出灯亮时的时间高低位转换过程,当时间倒计时为零时,定义好下一个状态。最后转化成的模块和仿真如下图所示:
clkrgyltimh[3..0]timl[3..0]cornerainst clkrgyltimh[3..0]timl[3..0]cornerbinst1
2、模块sel如下图,该模块主要功能是产生对数码管的片选信号。
clksell[2..0]selinst
3、模块xuan主要是将不同数码管要显示的数据在与片选信号相同的时间送到端口。
sel[2..0]d0[3..0]d1[3..0]d2[3..0]d3[3..0]q[3..0]xuaninst
4、模块qiduan主要是将十进制数转换为七段数码管需要的数据。
d[3..0]q0q1q2q3q4q5q6qiduaninst1
5、整体仿真如下图所示:
6、包装好的模块如下图所示:
VCCclk1INPUTVCCclk2INPUTVCCclk3INPUTVCCnoINPUTq0OUTPUTr2OUTPUTq1OUTPUTr1OUTPUTq2OUTPUTy2OUTPUTq3OUTPUTg2OUTPUTq4OUTPUTy1OUTPUTq5OUTPUTg1OUTPUTq6OUTPUTsel[1]OUTPUTsel[0]OUTPUTclk1clk2clk3nosel[2..0]q0r2q1r1q2y2q3g2q4y1q5g1q6Block1instsel[2..0]PIN_13PIN_14PIN_15PIN_16PIN_19PIN_20PIN_21PIN_69PIN_70PIN_71PIN_56PIN_57PIN_63PIN_68PIN_6PIN_7PIN_9PIN_58PIN_61PIN_62
五、 各个模块程序
1、 分频fen
library ieee;
use ieee.std_logic_1164.all;
entity fen is
port(clk:in std_logic;
clk1:out std_logic);
end fen;
architecture fen_arc of fen is
begin
process(clk)
variable cnt:integer range 0 to 5;
begin
if clk'event and clk='1' then
if cnt=5 then
cnt:=0;
clk1<='1';
else
cnt:=cnt+1;
clk1<='0';
end if;
end if;
end process;
end fen_arc;
2、 消抖xiaodou
library ieee;
use ieee.std_logic_1164.all;
entity xiaodou is
port(a,clk1:in std_logic;
b:out std_logic);
end xiaodou;
architecture xiao_arc of xiaodou is
signal tmp1:std_logic;
begin
process(clk1,a)
variable tmp3,tmp2:std_logic;
begin
if clk1'event and clk1='0' then
tmp1<=a;
tmp2:=tmp1;
end if;
b<=tmp1 and clk1;
end process;
end xiao_arc;
3、 紧急按钮no
library ieee;
use ieee.std_logic_1164.all;
entity no is
port(a:in std_logic;
y:out std_logic);
end no;
architecture no_arc of no is
begin
process(a)
variable aa:std_logic;
begin
if a'event and a='1' then
aa:=not aa;
end if;
y<=aa;
end process;
end no_arc;
4、 东西方向道路控制cornera
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cornera is
port(clk:in std_logic;
r,g,y,l:out std_logic;
timh,timl:out std_logic_vector(3 downto 0));
end cornera;
architecture corn_arc of cornera is
type rgyl is(red,yellow,green,guai);
begin
process(clk)
variable a:std_logic;
variable th,tl:std_logic_vector(3 downto 0);
variable state:rgyl;
begin
if clk'event and clk='1' then
case state is
when green=>if a='0' then
th:="0001";
tl:="1001";
a:='1';
g<='1';
r<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
th:="0000";
tl:="0000";
a:='0';
state:=yellow;
end if;
end if;
when red=>if a='0' then
th:="0010";
tl:="1001";
a:='1';
r<='1';
l<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
th:="0000";
tl:="0000";
a:='0';
state:=green;
end if;
end if;
when yellow=>if a='0' then
th:="0000";
tl:="0100";
a:='1';
y<='1';
g<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
th:="0000";
tl:="0000";
a:='0';
state:=guai;
end if;
end if;
when guai=>if a='0' then
th:="0000";
tl:="0100";
a:='1';
l<='1';
y<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
th:="0000";
tl:="0000";