EPM240开发板例程-交通灯.docVIP

  • 14
  • 0
  • 约2.66千字
  • 约 3页
  • 2017-06-08 发布于重庆
  • 举报
EPM240开发板例程-交通灯

EPM240开发板例程 --交通灯 --**************库定义、 包定义******************** LIBRARY ieee; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; --******************实体定义*********************** ENTITY jtd IS PORT clk : in STD_LOGIC;--时钟输入 rst : in STD_LOGIC;--复位键 row : out STD_LOGIC_VECTOR 3 downto 0 ;--输出组控制 r,y,g,bell : out STD_LOGIC ; END jtd; --******************构造体定义********************* ARCHITECTURE led OF jtd IS --纵向路口控制灯为row1和row3;横向路口控制灯为row2和row4 constant yellow_time: integer: 2;--路口的黄灯维持秒数 constant green_time: integer: 10;--路口的绿灯和红灯维持秒数 signal p : integer range 0 to 3;--扫描计数器 signal f : integer range 0 to 3;--状态控制寄存器 signal clk_500 : std_logic;--扫描时钟 signal clk_1h : std_logic;--1s时钟 signal r0,y0,g0 : std_logic;--纵向路口控制信号 signal r1,y1,g1 : std_logic;--横向路口控制信号 BEGIN bell 0; --*************500Hz分频程序******************** process clk variable cnt1 : integer range 0 to 200; variable cnt2 : integer range 0 to 250; begin if clkevent and clk 1 then if cnt1 200 then cnt1: 0; if cnt2 250 then cnt2: 0; clk_500 not clk_500; else cnt2: cnt2+1; end if; else cnt1: cnt1+1; end if; end if; end process; --***********1Hz分频程序和扫描信号产生******************** process clk_500 variable cnt1 : integer range 0 to 250; begin if clk_500event and clk_500 1 then if p 3 then p 0; else p p+1; end if; if cnt1 250 then cnt1: 0; clk_1h not clk_1h; else cnt1: cnt1+1; end if; end if; end process; --************交通灯状态控制进程********************* process rst,clk_1h,clk_500 variable load0,load1 : integer; begin if rst 0 then--复位信号 f 0;load0: green_time;load1: green_time; r0 0;y0 0;g0 1; r1 1;y1 0;g1 0; elsif clk_1hevent and clk_1h 1 then case f is when 0 if load0 0 then --纵向绿灯 load0: yellow_time;f 1; else load0: load0-1; r0 0;y0 0;g0 1; r1 1;y1 0;g1 0; end if; when 1 if load0 0 then --纵向黄灯 load1: yellow_time;f 2; else load0: load0-1; r0 0;y0 1;g0 0; r1 1;y1 0;g1 0; end if; when 2 if load1 0 then --

文档评论(0)

1亿VIP精品文档

相关文档