基于VHDL語言的交通灯设计程序.docVIP

  • 8
  • 0
  • 约9.76千字
  • 约 8页
  • 2016-11-27 发布于重庆
  • 举报
基于VHDL語言的交通灯设计程序

library ieee; -----分频电路 use ieee.std_logic_1164.all; entity fen is port(clk:in std_logic; clk1:out std_logic); ---实体端口声明 end fen; architecture fen_arc of fen is ---结构体描述开始 begin process(clk) --进程开始 variable cnt:integer range 0 to 99; begin if clkevent and clk=1 then ---高电平到 if cnt=99 then cnt:=0; ---0开始计数 clk1=1; --输出高电平 else cnt:=cnt+1; ---加计数 clk1=0; --输出低电平 end if; end if; end process; ---进程描述结束 end fen_arc; ---结构体描述结束 --------------------------------------------------A路控制 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity Alu is port(clk:in std_logic; ar,ag,al,ay:out std_logic; ----红、绿、黄、左转 timas,timag:out std_logic_vector(3 downto 0)); ----十位、个位计数 end Alu; architecture alu_arc of Alu is type rgly is(red,green,left,yellow); ---灯亮顺序为红、绿、左转、黄 begin process(clk) variable a:std_logic; ----变量声明 variable ts,tg:std_logic_vector(3 downto 0); variable state:rgly; begin if clkevent and clk=1 then ---高电平 case state is when green=if a=0 then --绿灯状态 ts:=0010; --十位计2 tg:=0100; --个位计4 a:=1; ag=0; ar=1; else if not(ts=0000 and tg=0001) then --若计数值不为1 if tg=0000 then --若个位为1 tg:=1001; --个位置9 ts:=ts-1; --十位自减1 else tg:=tg-1; --个位自减1 end if; else ts:=0000; tg:=0000; a:=0; state:=left; ---转为左转灯状态 end if; end if; when left=if a=0 then ---------------左转灯 ts:=0000; -----------十位置0

文档评论(0)

1亿VIP精品文档

相关文档