数字电子课程设计--交通灯_第1页
数字电子课程设计--交通灯_第2页
数字电子课程设计--交通灯_第3页
数字电子课程设计--交通灯_第4页
数字电子课程设计--交通灯_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、东西方向秒表的低位东西方向秒表的高位南北方向秒表的低位南北方向秒表的高位利用状态机,定义四种状态sti,st2,st3,st4定义秒表为30秒交通灯设计总结报告一方案设计与论证使用vhdl语言编程,在结构体屮制造一个单进程状态机,此状态机只 进行单纯的状态转换,每个状态中不涉及控制交通灯的亮灭,交通灯的 亮灭在单独的一个进程中进行控制。时钟由20mhz的晶体分频形成1hz 的秒信号。二.vhdl编程设计library ieee;use ieee.std_logic_1164.all;使用库函数use ieee.std logic unsigned.all;use ieee.std logic

2、arith.all;entity traffic isport(clk:instd_logic;rst: in std_logic;ew_t1 : out std_l0gic_vect0r(3 downto 0);ew_t2: out std_l0gic_vect0r(3 downto 0); ew r : out std logic;ew g : out std logic;ew_y : out std_logic;ns_t1 :out std_l0gic_vect0r(3 downto 0);ns_t2: out std_l0gic_vect0r(3 downto 0); ns r: ou

3、t std logic;ns g : out std logic;mbmm夕ns_y : out std_logic;);end entity traffic;architecture func of traffic istype state 1 is (st1,st2,st3,st4);signal state :state1;signal clk 1hz : std logic;signal count1 : integer range 0 to 30;signal count2 : integer range 0 to 30;beginpo:process(clk)variable a

4、: std_logic_vector(23 downto 0);beginif(clk*event and clk二t) theniffa'loolloooloololloolllllll'hhenclk_1hz<=not clk_1hz; a:=(others=>'0');elsea:=a+1;end if;end if;end process po;p:process(clk_1hz)beginif(rst='1')thenstate<=st1;count1<=30;count2<=30;ew_r<=

5、9;0'ew g<='1'ew_y<='0'ns_r<='1'ns_g<=,0,;ns_y<='o'elsif(clk_1hz'event and clk_1hz='1,)then case state iswhen sti => ew_r<='0'ew_g<='1'ew_y<='0'ns_r<=,1,;ns_g<=*0'ns_y<='o*;if(count1=5)then

6、state<=st2;elsestate<=st1;end if;count1<=count1-1;count2<=count2-1;when st2 =>ew_r<='0'ew_g<='0*;ew_y<='1'ns_r<='1,;ns g<='o'ns_y<='0,;if(count2=1)then分频东西绿灯,南北红灯东西黄灯,南北红灯state<=st3;count1<=25;count2<=25;elsestate<=st2;

7、end if;count2<=count2-1;count1<=count1-1; when st3 =>ew_r<='1'ew_g<='0'ew_y<='0'ns_r<=,0,;ns_g<=,1,;ns_y<='0,;if(count2=5)thenstate<=st4;elsestate<=st3;end if;count2<=count2-1;count1<=count1-1; when st4 => ew_r<='1,;ew_g<

8、;='0'ew_y<='0'ns_r<=,0,;ns_g<='0'ns_y<='1,;if(count1=1)thenstate<=st1;elsestate<=st4; end if;count2<=count2-1;count1<=count1-1;when others => state <= sti;end case;end if;end process p;p1:process(clk_1hz)begincase c0unt1 iswhen 0 =>ew_tl&l

9、t;="0000"东西红灯,南北绿灯东西红灯,南北黄灯高低位都用四位二进制表示when2=>when 3 =>when4=>when 5 =>when 6=>when 7=>when8=>when9=>when 10 =>when 11 =>when 12 =>when 13 =>when 14 =>when 15 =>when 16 =>when 17 =>when 18 =>when 19 =>when 20 =>when 21 =>when 22 =

10、>ew_tlv二 ”0011"ew_t2<=',0000n;ew_tl<="0100,'ew_t2<="0000n;ew_tl<="0101"ew_t2<="0000n;ew_tl<="0110"ew_t2<=',0000n;ew_tl<="0111"ew_t2<="0000n;ew_tl<="1000"ew t2<="0000u;ew_tl<="

11、;1001"ew_t2<="0000n;ew_tl<=h0000"ew_t2<="0001"ew tl<=,0001h;ew_t2<="0001,'ew_tl<=h0010h;ew_t2<="0001"ew_tl<=,0011h;ew_t2<=,0001,1;ew_tl<="0100,'ew_t2<="0001h;ew_tl<=h0101h;ew_t2<="0001"ew_tk=,0

12、110"ew_t2<=',0001n;ew_tl<=h0111h;ew_t2<=,0001"ew_tl<=h1000h;ew t2<="0001n;ew_tl<="1001h;ew_t2<="0001n;ew_tl<=h0000"ew_t2<="0010h;ew tl<=,0001h;ew_t2<="0010,'ew_tl<=,0010h;when 24 =>when 25 =>when 26 =>when 2

13、7 =>when 28 =>when 29 =>when 30 =>ew_tl<="0101"ew_t2<=”0010“;ew_tl<=,0110h;ew_t2<=,0010"ew_tl<=,0111h;ew_t2<=,0010n;ew_tl<="1000"ew_t2<=”0010“;ew_tl<=,1001h;ew_t2<=,0010"ew_tl<=h0000h;ew t2<="0011n;when others => n

14、ull;end case;case count2 iswhen0=>when 1=>when2=>when 3 =>when4=>when5=>when 6=>when7=>when8=>when9=>when 10 =>when 11 =>ns_tl<=,0000n;ns_t2<="0000"ns_tl<="0001"ns_t2<="0000,'ns_tl<="0010h;ns_t2<="0000"

15、ns_tl<=,0011h;ns_t2<="0000h;ns_tl<=,0100n;ns_t2<="0000"ns_tl<=,0101n;ns_t2<=,0000n;ns_tl<=,0110n;ns_t2<="0000"ns_tl<=m0111"ns t2<="0000h;ns_tl<=,1000n;ns_t2<="0000"ns_tl<="1001"ns_t2<="0000"ns

16、tl<="0000"ns_t2<="0001"ns_tl<=,0001,1;when 13 =>when 14 =>when 15 =>when 16 =>when 17 =>when 18 =>when 19 =>when 20 =>when 21 =>when 22 =>when 23 =>when 24 =>when 25 =>when 26 =>when 27 =>when 28 =>when 29 =>when 30 =>

17、;ns_tl<="0100"ns_t2<=,0001"ns_tl<="0101"ns_t2<="0001"ns_tl<="0110"ns_t2<="0001"ns_tl<=,0111"ns_t2<=,0001"ns_tl<=,1000,;ns_t2<="0001"ns_tl<="1001" ns t2<="0001h;ns_tl<=&quo

18、t;0000"ns_t2<="0010"ns_tl<="0001,;ns_t2<="0010"ns tl<="0010"ns_t2<="0010"nstlv-'ooir;ns_t2<="0010"nstivoioo”;ns_t2<="0010"ns_tl<="0101"ns_t2<="0010"ns_tl<=,0110"ns_t2<=

19、"0010"ns_tl<=,0111"ns_t2<=,0010n;ns_tl<="1000"ns_t2<="0010"ns_tl<="1001" ns t2<="0010"ns_tl<="0000"ns_t2<=,0011,'when others => null;end case;end process pl;end architecture func;三.仿真波形 和锁定引脚node namedirectionlocationreservedgroup:1 okinputpin612° ew.goutputpinj143u ew.routputpin.4244一。ewj13outputpin."ewjl3.o453ew.tl outputpin.48ewjl3.o46o ew.t11outputpin.4947ewj1(o)o

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论