OpenVINOTM,给你看得见的未来!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » VHDL交通灯

共2条 1/1 1 跳转至

VHDL交通灯

工程师
2007-04-26 22:40:00    评分

交通灯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;




关键词: 交通     state     highway     general         

工程师
2007-04-27 06:15:00    评分
2楼

老程序了,给高手看这个帖确实比较失败

给初学者的哦

[em01][em01][em01]

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]