中易网

基于VHDL的交通灯控制器的设计

答案:2  悬赏:40  
解决时间 2021-01-16 19:27
  • 提问者网友:不爱我么
  • 2021-01-16 15:53
基于VHDL的交通灯控制器的设计
最佳答案
  • 二级知识专家网友:低血压的长颈鹿
  • 2021-01-16 17:04
---------------------------交通灯控制器设计,led显示规律:东西方向绿灯,而南北方向红灯
---------------------------东西方向绿灯灭,黄灯亮,南北方向仍然红灯
---------------------------南北方向绿灯,而东西方向红灯--------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity jiaotongLED is
generic(-----------------------------------定义灯亮的时间
east_green_cnt:integer:=40;------------东西方向主干道绿灯
east_yellow_cnt:integer:=5;------------东西方向主干道黄灯
south_green_cnt:integer:=30;-----------南北方向支干道绿灯
south_yellow_cnt:integer:=5;-----------南北方向支干道黄灯
exi_cnt:integer:=120);-----------------紧急车辆通行时间
port(clk:in std_logic;
rst:in std_logic;----------------------复位信号
exi_sign:in std_logic;-----------------紧急车辆信号

east_green_led:out std_logic;
east_yellow_led:out std_logic;
east_red_led:out std_logic;
south_green_led:out std_logic;
south_yellow_led:out std_logic;
south_red_led:out std_logic);
end jiaotongLED;

------------------------------------
architecture ex of jiaotongLED is
type states is(s0,s1,s2,s3,s4);
signal state1:states:=s0;
signal state:states:=s0;
signal cnt:integer range 0 to 150;
signal save_cnt:integer;
signal enable_cnt:std_logic:='0';
begin
-----------------------------------------
u1:process(rst,clk)-----------------------------信号灯的时间状态的转换
begin
if rst='1' then-----------------------------判断是否按下复位
state<=s0;
cnt<=1;
elsif clk'event and clk='1' then
if enable_cnt='1' then
cnt<=cnt+1;
else
cnt<=1;
end if;
case state is
when s0=>
if exi_sign='1' then----------------判断是否紧急车辆
save_cnt<=cnt;
state1<=s0;
state<=s4;
elsif(cnt=east_green_cnt)then
state<=s1;
else
state<=s0;
end if;
when s1=>
if exi_sign='1' then
save_cnt<=cnt;
state1<=s1;
state<=s4;
elsif(cnt=east_yellow_cnt)then
state<=s2;
else
state<=s1;
end if;
when s2=>
if exi_sign='1' then
save_cnt<=cnt;
state1<=s2;
state<=s4;
elsif(cnt=south_green_cnt)then
state<=s3;
else
state<=s2;
end if;
when s3=>
if exi_sign='1' then
save_cnt<=cnt;
state1<=s3;
state<=s4;
elsif(cnt=south_yellow_cnt)then
state<=s0;
else
state<=s3;
end if;
when s4=>
if(cnt=exi_cnt)then
cnt<=save_cnt;
state<=state1;
end if;
end case;
end if;
end process u1;
---------------------------------------------------

u2:process(state)--------------------------------------信号灯的状态显示
begin
case state is
when s0=>
east_green_led<='1';
east_yellow_led<='0';
east_red_led<='0';
south_green_led<='0';
south_yellow_led<='0';
south_red_led<='1';
enable_cnt<='1';
if(cnt=east_green_cnt)then
enable_cnt<='0';-----------------------已达到东西方向绿灯亮时间,暂停计数
end if;
when s1=>
east_green_led<='0';
east_yellow_led<='1';
east_red_led<='0';
south_green_led<='0';
south_yellow_led<='0';
south_red_led<='1';
enable_cnt<='1';
if(cnt=east_yellow_cnt)then
enable_cnt<='0';
end if;
when s2=>
east_green_led<='0';
east_yellow_led<='0';
east_red_led<='1';
south_green_led<='1';
south_yellow_led<='0';
south_red_led<='0';
enable_cnt<='1';
if(cnt=south_green_cnt)then
enable_cnt<='0';
end if;
when s3=>
east_green_led<='0';
east_yellow_led<='0';
east_red_led<='1';
south_green_led<='0';
south_yellow_led<='1';
south_red_led<='0';
enable_cnt<='1';
if(cnt=south_yellow_cnt)then
enable_cnt<='0';
end if;
when s4=>
east_green_led<='0';
east_yellow_led<='0';
east_red_led<='1';
south_green_led<='0';
south_yellow_led<='0';
south_red_led<='1';
enable_cnt<='1';
if(cnt=exi_cnt)then
enable_cnt<='0';
end if;
end case;
end process u2;
end ex;

程序已经运行仿真过,应该没有问题,另外加了一个2min紧急车辆的通行时间,不需要的话可以删掉。。。。。
全部回答
  • 1楼网友:举杯邀酒敬孤独
  • 2021-01-16 17:14
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------------------------
entity exp18 is
port( Clk : in std_logic; --时钟输入
Rst : in std_logic; --复位输入
R1,R2 : out std_logic; --红灯输出
Y1,Y2 : out std_logic; --黄灯输出
G1,G2 : out std_logic; --绿灯输出
Display : out std_logic_vector(7 downto 0); --七段码管显示输出
SEG_SEL : buffer std_logic_vector(2 downto 0) --七段码管扫描驱动
);
end exp18;
--------------------------------------------------------------------
architecture behave of exp18 is
signal Disp_Temp : integer range 0 to 15;
signal Disp_Decode : std_logic_vector(7 downto 0);
signal SEC1,SEC10 : integer range 0 to 9;
signal Direction : integer range 0 to 15;

signal Clk_Count1 : std_logic_vector(9 downto 0); --产生0.5Hz时钟的分频计数器
signal Clk1Hz : std_logic;
signal Dir_Flag : std_logic; --方向标志
begin
process(Clk)
begin
if(Clk'event and Clk='1') then
if(Clk_Count1<1000) then
Clk_Count1<=Clk_Count1+1;
else
Clk_Count1<="0000000001";
end if;
end if;
end process;
Clk1Hz<=Clk_Count1(9);
process(Clk1Hz,Rst)
begin
if(Rst='0') then
SEC1<=0;
SEC10<=2;
Dir_Flag<='0';
elsif(Clk1Hz'event and Clk1Hz='1') then
if(SEC1=0) then
SEC1<=9;
if(SEC10=0) then
SEC10<=1;
else
SEC10<=SEC10-1;
end if;
else
SEC1<=SEC1-1;
end if;
if(SEC1=0 and SEC10=0) then
Dir_Flag<=not Dir_Flag;
end if;
end if;
end process;
process(Clk1Hz,Rst)
begin
if(Rst='0') then
R1<='1';
G1<='0';
R2<='1';
G2<='0';
else --正常运行
if(SEC10>0 or SEC1>3) then
if(Dir_Flag='0') then --横向通行
R1<='0';
G1<='1';
R2<='1';
G2<='0';
else
R1<='1';
G1<='0';
R2<='0';
G2<='1';
end if;
else
if(Dir_Flag='0') then --横向通行
R1<='0';
G1<='0';
R2<='1';
G2<='0';
else
R1<='1';
G1<='0';
R2<='0';
G2<='0';
end if;
end if;
end if;
end process;
process(Clk1Hz)
begin
if(SEC10>0 or SEC1>3) then
Y1<='0';
Y2<='0';
elsif(Dir_Flag='0') then
Y1<=Clk1Hz;
Y2<='0';
else
Y1<='0';
Y2<=Clk1Hz;
end if;
end process;
process(Dir_Flag)
begin
if(Dir_Flag='0') then --横向
Direction<=10;
else --纵向
Direction<=11;
end if;
end process;
process(SEG_SEL)
begin
case (SEG_SEL+1) is
when "000"=>Disp_Temp<=Direction;
when "001"=>Disp_Temp<=Direction;
when "010"=>Disp_Temp<=SEC10;
when "011"=>Disp_Temp<=SEC1;
when "100"=>Disp_Temp<=Direction;
when "101"=>Disp_Temp<=Direction;
when "110"=>Disp_Temp<=SEC10;
when "
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息