- 21
- 0
- 约4.79千字
- 约 6页
- 2023-03-12 发布于湖北
- 举报
EDA 技术交通灯课程设计
设计一个交通灯控制器要求:
A 方向为主干道,B 方向为支干道。分设红(R)、黄(Y)、绿(G)和左拐(L)四盏灯。1 表示灯亮,0 表示灯灭。四灯的点亮顺序为:绿灯→黄灯→左拐灯→ 黄灯→红灯,A 方向四个时间为 55 秒(红)、40 秒(绿)、5(黄)秒和 15(左拐灯)秒;B 方向的四个时间为 65 秒(红)、30 秒(绿)、5 秒(黄)和 15(左拐灯)秒。时间要改变只要改变计数器的预知数即可。
*/信号定义与说明: CLK:同步时钟
EN :使能信号,为 1,则控制器开始工作
LAMPA[3:0]:控制A 方向的 4 盏灯的亮灭;其中LAMPA(0)到 LAMPA(3)分别控制 A 方向的左拐灯、绿灯、黄灯和红灯。
LAMPB[3:0]:控制 B 向的 4 盏灯的亮灭;其中 LAMPB0)到 LAMPB3)分别控制 B 向的左拐灯、绿灯、黄灯和红灯。
ACOUNT[7:0]:用于A 方向交通灯的时间显示,宽 8 位,可驱动 2 个数码管。BCOUNT[7:0]:用于 B 向交通灯的时间显示,宽 8 位,可驱动 2 个数码管。
(上电)计数常数赋值
(上电)计数
常数赋值
等待时钟信号
赋初始状态
否
等 待 使 能 位
EN=1
计数值更新
是
状态更新
是
Tempa=0?
输出更新
否
Tempa=1
是
Tempa=
0
计数值- 1 =
0?
否
计数值-1
1、交通灯 VHDL 语言程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity traffic is
port( clk,en:in std_logic;
lampa,lampb:out std_logic_vector(3 downto 0); acount,bcount:out std_logic_vector(7 downto 0));
end entity;
architecture exemplar of traffic is
signal numa,numb:std_logic_vector(7 downto 0); signal tempa,tempb:std_logic;
signal counta,countb:std_logic_vector(2 downto 0);
signal ared,bred,agreen,bgreen,ayellow,byellow,aleft,bleft:std_logic_vector(7 downto 0);
begin
acount = numa; bcount = numb;
x1: process(en) begin
if en = 0 then
ared =
ayellow =
agreen =
aleft =
bred =
byellow =
bgreen =
bleft =
end if; end process; x2:process(clk,en)
begin
if clk =1 and clkevent then if en =1 then
if tempa =0 then tempa = 1; case (counta) is
when 000 = numa = agreen;lampa = 0010;counta = 001; when 001 = numa = ayellow;lampa = 0100;counta = 010; when 010 = numa = aleft;lampa = 0001;counta = 011; when 011 = numa = ayellow;lampa = 0100;counta = 100; when 100 = numa = ared;lampa = 1000;counta = 000; when others = lampa = 1000;
end case;
else
if (numa 1) then
if numa(3 downto 0) = 0 then numa(3 downto 0) = 1001;
numa(7 downto 4) = numa(7 downto 4) - 1;
else
numa(3 downto 0) = numa(3 downto 0) - 1;
else
end if;
if numa = 1 then
tempa = 0;
nu
原创力文档

文档评论(0)