文档详情

交通灯程序vhdl语言.doc

发布:2025-04-15约5.83千字共10页下载文档
文本预览下载声明

11045550黄灯亮绿灯亮红灯亮黄灯亮红灯亮绿灯亮东西方向:

110

45

55

0

黄灯亮

绿灯亮

红灯亮

黄灯亮

红灯亮

绿灯亮

110100550南北方向:

110

100

55

0

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityjiaotongdengis--定义实体

port(jin:instd_logic;

rst:instd_logic;--为高电平时,计数器停止计数,四个方向都是红灯

clk:instd_logic;--计数时钟

clk1khz:instd_logic;

a:outstd_logic_vector(2downto0);--南北方向红黄绿灯

b:东西方向红黄绿灯sel:接三位译码器xianshi:八段数字显示

b:东西方向红黄绿灯

sel:接三位译码器

xianshi:八段数字显示

xianshi:outstd_logic_vector(7downto0));

constantnumber1:integer:=10;

constantnumber2:integer:=45;

endjiaotongdeng;

architecturefunc1ofjiaotongdengis

signalcount:std_logic_vector(2downto0);

signalten:std_logic_vector(7downto0);

signalone:std_logic_vector(7downto0);

begin

sel=count;--信号count的值赋给译码器

process(clk,rst)

variabletemp1:integerrange0to45;--变量temp1控制倒计时的秒

variabletemp2:integerrange0to3;--变量temp2控制方向的转换

variabley:integerrange0to1;--变量y控制45s和10s之间的转换

begin

if(rst=1)then--rst=‘1’,特殊紧急情况

--东西南北方向全为红灯a=100;

--东西南北方向全为红灯

b=001;

temp1:=0;

temp2:=0;

elsif(clkeventandclk=1)then

if(jin=0)then

temp1:=temp1+1;

if(temp1=number1andtemp2=0)then--LED灯的循环控制

a=010;

b=100;

temp1:=0;

temp2:=temp2+1;

y:=1;

elsif(temp1=number2andtemp2=1)then

a=001;

b=100;

temp1:=0;

temp2:=temp2+1;

y:=0;

elsif(temp1=number1andtemp2=2)then

a=100;

b=010;

temp1:=0;

temp2:=temp2+1;

y:=1;

elsif(temp1=number2andtemp2=3)then

a=100;

b=001;

temp1:=0;

temp2:=0;

y:=0;

endif;

else

a=100;b=100;

endif;

endif;

if(temp1=0andy=1)then--倒计时的时间控制

ten

one----------------45--45秒倒计时

elsif(temp1=1andy=1)then

ten

one----------------44

elsif(temp1=2andy=1)then

ten

one-----

显示全部
相似文档