FPGA实验8实验八---用有限状态机设计交通灯代码(共9页)_第1页
FPGA实验8实验八---用有限状态机设计交通灯代码(共9页)_第2页
FPGA实验8实验八---用有限状态机设计交通灯代码(共9页)_第3页
FPGA实验8实验八---用有限状态机设计交通灯代码(共9页)_第4页
FPGA实验8实验八---用有限状态机设计交通灯代码(共9页)_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

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

文档简介

1、状态机:LIBRARY ieee;USE ieee.std_logic_1164.ALL;USE ieee.std_logic_unsigned.ALL;ENTITY xhd ISPort(clk : in std_logic; ra,rb,ya,yb,ga,gb : out std_logic );END xhd;Architecture a of xhd istype state is (S0,S1,S2,S3);signal presentstate,nextstate : state;signal tmp1,tmp2 : integer range 0 to 30;signal tim

2、eout1,timeout2: std_logic;signal q: std_logic_vector(21 downto 0);signal sec: std_logic;Begin-get 1 hz clock pulseprocess(clk)beginif clkevent and clk=1 then q=q+1; end if;sec=q(21); -get 1 hz clock pulseend process;timing: process(sec)beginif secevent and sec=1 then if tmp1=29 then timeout1=1; time

3、out2=0; tmp1=0; else if timeout1=1 then if tmp2=4 then timeout2=1; timeout1=0; tmp2=0; else tmp2=tmp2+1; end if; else tmp1 if timeout1=0 then nextstate=s0; ra=0; ya=0; ga=1; rb=1; yb=0; gb=0; else nextstate if timeout2=0 then nextstate=s1; ra=0; ya=1; ga=0; rb=1; yb=0; gb=0; else nextstate if timeou

4、t1=0 then nextstate=s2; ra=1; ya=0; ga=1; rb=0; yb=0; gb=1; else nextstate if timeout2=0 then nextstate=s3; ra=1; ya=0; ga=0; rb=0; yb=1; gb=0; else nextstate nextstate=s0; timeout1=0; timeout20);Cy=0;Elsif CnEvent and Cn=1 thenIf En=1 thenIf Cqi 1001 thenCqi :=Cqi+1; Cy=0; elsif cqi=1001then Cy0);e

5、nd If;end If;end If;Dout0);CY=0;Elsif CLKEvent and CLK=1 thenIf EN=1 thenIf Cq 0101 thenCq :=Cq+1; CY=0; elsif cq=0101then CY0);end If;end If;end If;DOUT DOUT DOUT DOUT DOUT DOUT DOUT DOUT DOUT DOUT DOUT DOUT=0000000; END CASE; END PROCESS;END behave;修改同上,编译,封装仿真波形如图所示:分频(1):library ieee;use ieee.st

6、d_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity fenpin isport ( CLK:in std_logic; FCLK:out std_logic);end fenpin;architecture bhv of fenpin is signal CK:std_logic; begin process(CLK) variable counter:integer range 0 to 100000; beginif(CLKEVENT AND CLK=1) THEN IF(

7、counter=99999)THEN counter:=0;CK=NOT CK; ELSE counter:=counter+1; end if; end if; end process; FCLK=CK; end bhv;分频(2):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity fenpin isport ( clk,clr:in std_logic; q:buffer std_logic);end fenpin;architecture b of fenpin is signal counter:integer range 0 to 49999; begin process(clr,clk) begin if(CLK=1 AND clkEVENT) THEN IF clr=1 the

温馨提示

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

评论

0/150

提交评论