交通灯VHDL程序
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
PACKaGE traffic1 IS --TYPE color IS (green,yellow,red,unknown);
TYPE state IS (highway_green,
highway_yellow,
general_green,
general_yellow);
END traffic1;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE WORK.traffic1.ALL;
ENTITY traffic IS
--GENERIC(time_long:TIME;
PORT(car_on_general:IN BOOLEAN;
clk:in std_logic;
highway_light:OUT std_logic_vector(2 downto 0);
general_light:OUT std_logic_vector(2 downto 0));
END traffic;
ARCHITECTURE rtl OF traffic IS
SIGNAL present_state:state;
SIGNAL next_state:state;
SIGNAL time_out_long:boolean:=FALSE;
SIGNAL time_out_short:boolean:=FALSE;
SIGNAL start_timer:boolean:=FALSE;
BEGIN
contron:PROCESS(present_state ,car_on_general,time_out_long,time_out_short)
begin
CASE present_state IS
WHEN highway_green=>
if car_on_general and time_out_long then
next_state<=highway_yellow;
end if;
WHEN highway_yellow=>
if time_out_short then
next_state<=general_green;
end if;
WHEN general_green=>
if not car_on_general or time_out_long then
next_state<=general_yellow;
end if;
WHEN general_yellow=>
if time_out_short then
next_state<=highway_green;
end if;
END CASE;
END PROCESS;
start:PROCESS(clk)
BEGIN
IF (clk'event and clk='1') THEN
present_state<=next_state;
END IF;
END PROCESS;
out_put:PROCESS(present_state)
BEGIN
start_timer<= not start_timer;
CASE present_state IS
WHEN highway_green=>
highway_light<= "100";
general_light<= "001";
WHEN highway_yellow=>
highway_light<= "010";
general_light<= "001";
WHEN general_green=>
general_light<= "100";
highway_light<="001";
WHEN general_yellow=>
general_light<="010";
highway_light<="001";
END CASE;
END PROCESS;
time:PROCESS(start_timer)
BEGIN
time_out_long<= FALSE;
time_out_long<= TRUE AFTER 1000 sec;
time_out_short<= FALSE;
time_out_short<= TRUE AFTER 2 sec;
END PROCESS;
END rtl;
共2条
1/1 1 跳转至页
VHDL交通灯
关键词: 交通 state highway general
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |