欢迎来到天天文库
浏览记录
ID:49941912
大小:98.14 KB
页数:8页
时间:2020-03-03
《数字电子课程设计--交通灯.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、交通灯设计总结报告一方案设计与论证使用VHDL语言编程,在结构体中制造一个单进程状态机,此状态机只进行单纯的状态转换,每个状态中不涉及控制交通灯的亮灭,交通灯的亮灭在单独的一个进程中进行控制。时钟由20MHZ的晶体分频形成1HZ的秒信号。二.VHDL编程设计LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;使用库函数USEIEEE.STD_LOGIC_UNSIGNED.ALL;USEIEEE.STD_LOGIC_ARITH.ALL;ENTITYTRAFFICISPORT(CLK:INSTD_L
2、OGIC;RST:INSTD_LOGIC;EW_T1:OUTSTD_LOGIC_VECTOR(3DOWNTO0);东西方向秒表的低位EW_T2:OUTSTD_LOGIC_VECTOR(3DOWNTO0);东西方向秒表的高位EW_R:OUTSTD_LOGIC;EW_G:OUTSTD_LOGIC;EW_Y:OUTSTD_LOGIC;NS_T1:OUTSTD_LOGIC_VECTOR(3DOWNTO0);南北方向秒表的低位NS_T2:OUTSTD_LOGIC_VECTOR(3DOWNTO0);南北方向秒表的高位NS_R:OUT
3、STD_LOGIC;NS_G:OUTSTD_LOGIC;NS_Y:OUTSTD_LOGIC;);ENDENTITYTRAFFIC;ARCHITECTUREFUNCOFTRAFFICISTYPESTATE1IS(ST1,ST2,ST3,ST4);利用状态机,定义四种状态ST1,SIGNALSTATE:STATE1;ST2,ST3,ST4SIGNALCLK_1HZ:STD_LOGIC;SIGNALCOUNT1:INTEGERRANGE0TO30;定义秒表为30秒SIGNALCOUNT2:INTEGERRANGE0TO30;B
4、EGINP0:PROCESS(CLK)VARIABLEA:STD_LOGIC_VECTOR(23DOWNTO0);BEGINIF(CLK'EVENTANDCLK='1')THENIF(A="100110001001011001111111")THENCLK_1HZ<=NOTCLK_1HZ;A:=(others=>'0');ELSEA:=A+1;ENDIF;ENDIF;ENDPROCESSP0;P:PROCESS(CLK_1HZ)分频BEGINIF(RST='1')THENSTATE<=ST1;COUNT1<=30;COU
5、NT2<=30;EW_R<='0';EW_G<='1';EW_Y<='0';NS_R<='1';NS_G<='0';NS_Y<='0';ELSIF(CLK_1HZ'EVENTANDCLK_1HZ='1')THENCASESTATEISWHENST1=>EW_R<='0';东西绿灯,南北红灯EW_G<='1';EW_Y<='0';NS_R<='1';NS_G<='0';NS_Y<='0';IF(COUNT1=5)THENSTATE<=ST2;ELSESTATE<=ST1;ENDIF;COUNT1<=COUNT1-1;COU
6、NT2<=COUNT2-1;WHENST2=>EW_R<='0';东西黄灯,南北红灯EW_G<='0';EW_Y<='1';NS_R<='1';NS_G<='0';NS_Y<='0';IF(COUNT2=1)THENSTATE<=ST3;COUNT1<=25;COUNT2<=25;ELSESTATE<=ST2;ENDIF;COUNT2<=COUNT2-1;COUNT1<=COUNT1-1;WHENST3=>EW_R<='1';东西红灯,南北绿灯EW_G<='0';EW_Y<='0';NS_R<='0';NS_G<='1'
7、;NS_Y<='0';IF(COUNT2=5)THENSTATE<=ST4;ELSESTATE<=ST3;ENDIF;COUNT2<=COUNT2-1;COUNT1<=COUNT1-1;WHENST4=>EW_R<='1';东西红灯,南北黄灯EW_G<='0';EW_Y<='0';NS_R<='0';NS_G<='0';NS_Y<='1';IF(COUNT1=1)THENSTATE<=ST1;ELSESTATE<=ST4;ENDIF;COUNT2<=COUNT2-1;COUNT1<=COUNT1-1;WHENOTHERS
8、=>STATE<=ST1;ENDCASE;ENDIF;ENDPROCESSP;P1:PROCESS(CLK_1HZ)BEGINCASECOUNT1ISWHEN0=>EW_T1<="0000";高低位都用四位二进EW_T2<="0000";制表示WHEN1=>EW_T1<="0001";EW_T2<="0000";WH
此文档下载收益归作者所有