欢迎来到天天文库
浏览记录
ID:40574334
大小:37.00 KB
页数:4页
时间:2019-08-04
《vhdl实现交通灯》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、LED.、数码管交通灯libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entityjiaotongdengisport(clk:instd_logic;rst:instd_logic;en_led:outstd_logic_vector(3downto0);en_seg:outstd_logic_vector(1downto0);data_led:outstd_logic_vector(2downto0);dat
2、a_seg:outstd_logic_vector(7downto0));endjiaotongdeng;architecturebehavofjiaotongdengissignalsaomiao:integerrange0to1;signaltim:integerrange0to59;signalred_tim:integerrange0to59;signalgreen_tim:integerrange0to40;signaltim_ge:integerrange0to9;signaltim_shi:integerrange0to5;signalcnt_
3、led:integerrange0to2:=0;signalyew_tim:integerrange0to20;signaltmp:integerrange0to2;beginen_led<="0000";p1:process(clk)variablecnt:integerrange0to7999999;beginifclk'eventandclk='1'thenifcnt=7999999thencnt:=0;ifcnt_led=0thenifred_tim=0thenred_tim<=10;tmp<=1;ifcnt_led=2thencnt_led<=0;
4、elsecnt_led<=cnt_led+1;endif;elsered_tim<=red_tim-1;endif;elsifcnt_led=1thenifyew_tim=0thenyew_tim<=20;tmp<=2;ifcnt_led=2thencnt_led<=0;elsecnt_led<=cnt_led+1;endif;elseyew_tim<=yew_tim-1;endif;elsifcnt_led=2thenifgreen_tim=0thengreen_tim<=40;tmp<=0;ifcnt_led=2thencnt_led<=0;elsecn
5、t_led<=cnt_led+1;endif;elsegreen_tim<=green_tim-1;endif;endif;elsecnt:=cnt+1;endif;endif;endprocess;p2:process(clk,rst)-variablecnn1:integerrange0to7999;beginifrst='0'thencnn1:=0;elsifclk'eventandclk='1'thenifcnn1=7999thencnn1:=0;ifsaomiao=1thensaomiao<=0;elsesaomiao<=saomiao+1;end
6、if;elsecnn1:=cnn1+1;endif;endif;endprocess;p3:process(saomiao,tim)variabletim_tmp:integerrange0to59;begintim_tmp:=conv_integer(tim);casetim_tmpiswhen50to59=>tim_shi<=5;tim_ge<=tim_tmp-50;--0when40to49=>tim_shi<=4;tim_ge<=tim_tmp-40;when30to39=>tim_shi<=3;tim_ge<=tim_tmp-30;when20to
7、29=>tim_shi<=2;tim_ge<=tim_tmp-20;when10to19=>tim_shi<=1;tim_ge<=tim_tmp-10;whenothers=>tim_shi<=0;tim_ge<=tim_tmp;endcase;endprocess;p4:process(clk,saomiao)functionb_to_seg7(bcd8421:integerrange0to9)returnstd_logic_vectorisvariableseg7:std_logic_vector(7downto0);begincasebcd8421is
8、when0=>seg7:="00000011";wh
此文档下载收益归作者所有