文档详情

2014交通灯实验报告参考.doc

发布:2016-11-19约6.81千字共9页下载文档
文本预览下载声明
5.6 交通灯控制器程序设计与仿真实验用基本的寄存器和门电路搭成的电路corna(corna.vhd),信号灯模块corna源程序如下: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity corna is Port ( clk : in std_logic; r : out std_logic; g : out std_logic; y : out std_logic; timh : out std_logic_vector(3 downto 0); timl : out std_logic_vector(3 downto 0)); end corna; architecture Behavioral of corna is type rgy is (yellow,green,red); --初态为黄灯 begin process(clk) variable a:std_logic:=0; variable th,tl:std_logic_vector(3 downto 0); --计数高低位 variable state:rgy; begin if clkevent and clk=1 then case state is --状态机开始 when green = if a=0 then th:=0010; tl:=0100; a:=1; g=0; r=1; else if not(th=0000 and tl=0001) then -- if语句处理显示时间 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:=0001; tl:=1001; a:=1; r=0; y=1; 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; g=1; --初始态的设置,黄灯亮,绿灯,红灯熄。 y=0; r=1; else if not(th=0000 and tl=0001) then if tl=0000 then tl:=1001; th:=th-1;
显示全部
相似文档