欢迎来到天天文库
浏览记录
ID:28519130
大小:61.50 KB
页数:8页
时间:2018-12-10
《基于VHDL语言的交通灯设计程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.libraryieee;-----分频电路useieee.std_logic_1164.all;entityfenisport(clk:instd_logic;clk1:outstd_logic);---实体端口声明endfen;architecturefen_arcoffenis---结构体描述开始beginprocess(clk)--进程开始variablecnt:integerrange0to99;beginifclk'eventandclk='1'then---高电平到ifcnt=99thencnt:
2、=0;---0开始计数clk1<='1';--输出高电平elsecnt:=cnt+1;---加计数clk1<='0';--输出低电平endif;endif;endprocess;---进程描述结束endfen_arc;---结构体描述结束--------------------------------------------------A路控制libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityAluisport
3、(clk:instd_logic;ar,ag,al,ay:outstd_logic;----红、绿、黄、左转timas,timag:outstd_logic_vector(3downto0));----十位、个位计数endAlu;architecturealu_arcofAluistyperglyis(red,green,left,yellow);---灯亮顺序为红、绿、左转、黄beginprocess(clk)variablea:std_logic;----变量声明variablets,tg:std_logi
4、c_vector(3downto0);variablestate:rgly;beginifclk'eventandclk='1'then---高电平casestateiswhengreen=>ifa='0'then--绿灯状态....ts:="0010";--十位计2tg:="0100";--个位计4a:='1';ag<='0';ar<='1';elseifnot(ts="0000"andtg="0001")then--若计数值不为1iftg="0000"then--若个位为1tg:="1001";--个位置9
5、ts:=ts-1;--十位自减1elsetg:=tg-1;--个位自减1endif;elsets:="0000";tg:="0000";a:='0';state:=left;---转为左转灯状态endif;endif;whenleft=>ifa='0'then---------------左转灯ts:="0000";-----------十位置0tg:="1001";--------------个位置9a:='1';aL<='0';ag<='1';elseifnot(ts="0000"andtg="0001")
6、theniftg="0000"thentg:="1001";ts:=ts-1;elsetg:=tg-1;endif;elsets:="0000";tg:="0000";a:='0';state:=yellow;----转为黄灯状态endif;endif;....whenyellow=>ifa='0'then-----黄灯状态ts:="0000";---十位置0tg:="0100";----个位置9a:='1';ay<='0';aL<='1';elseifnot(ts="0000"andtg="0001")the
7、niftg="0000"thentg:="1001";ts:=ts-1;elsetg:=tg-1;endif;elsets:="0000";tg:="0000";a:='0';state:=red;endif;endif;whenred=>ifa='0'then--------红灯状态ts:="0011";----十位置3tg:="1001";---个位置9a:='1';ar<='0';ay<='1';elseifnot(ts="0000"andtg="0001")theniftg="0000"thentg:=
8、"1001";ts:=ts-1;elsetg:=tg-1;endif;elsets:="0000";tg:="0000";a:='0';state:=green;endif;....endif;endcase;timas<=ts;timag<=tg;endif;endprocess;endalu_arc;-----------------------------------------
此文档下载收益归作者所有