欢迎来到天天文库
浏览记录
ID:57687098
大小:23.50 KB
页数:4页
时间:2020-09-01
《CPLD课程设计交通灯程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;ENTITYjiaotongdengISPORT(clk_in:instd_logic;--4MHzrst:instd_logic;--复位信号light:outstd_logic_vector(7downto0);--RYG_main,RYG_genespk:outstd_logic;LED7S0:outSTD_LOGIC_VECTOR(6downto0);LED7S1:outSTD_LOGIC_VECTO
2、R(6downto0);LED7S2:outSTD_LOGIC_VECTOR(6downto0);LED7S4:outSTD_LOGIC_VECTOR(6downto0));ENDjiaotongdeng;ARCHITECTUREARCOFjiaotongdengIStypestatesis(green_red,yellow_red,red_green,red_yellow);signalstate:states:=green_red;signalnextstate:states;signaldata0:integerrange0to9;sign
3、aldata1:integerrange0to9;signaldata2:integerrange0to9;signaldata3:integerrange0to9;signalclock_buffer:std_logic;signalcount_time:integerrange0to;signalclk:std_logic;signalsec0:integerrange0to9;signalsec1:integerrange0to3;signalsec2:integerrange0to9;signalsec3:integerrange0to3
4、;BEGINspk<='0';frequent:process(clk_in)beginifclk_in'eventandclk_in='1'thenifcount_time=thencount_time<=0;clock_buffer<=notclock_buffer;elsecount_time<=count_time+1;endif;endif;clk<=clock_buffer;--输入1HZ的频率endprocess;light_statment:process(state)--交通信号灯的显示状态begincasestateiswhe
5、ngreen_red=>light<="";nextstate<=yellow_red;data0<=5;data1<=0;data2<=5;data3<=0;whenyellow_red=>light<="";nextstate<=red_green;data0<=4;data1<=2;data2<=9;data3<=2;whenred_green=>light<="";nextstate<=red_yellow;data0<=5;data1<=0;data2<=5;data3<=0;whenred_yellow=>light<="";next
6、state<=green_red;data0<=9;data1<=3;data2<=4;data3<=3;endcase;endprocess;time:process(rst,clk)--记时状态beginifrst='0'then--复位sec0<=9;sec1<=3;sec2<=4;sec3<=3;elsifrising_edge(clk)thenif((sec0=0ANDsec1=0)or(sec2=0ANDsec3=0))thenstate<=nextstate;sec0<=data0;sec1<=data1;sec2<=data2;s
7、ec3<=data3;elseifsec2=0thensec2<=9;sec3<=sec3-1;elsesec2<=sec2-1;endif;ifsec0=0thensec0<=9;sec1<=sec1-1;elsesec0<=sec0-1;endif;endif;endif;endprocess;--LED显示部分process(sec0)begincasesec0isWHEN0=>LED7S0<="";--0WHEN1=>LED7S0<="";--1WHEN2=>LED7S0<="";--2WHEN3=>LED7S0<="";--3WHEN4
8、=>LED7S0<="";--4WHEN5=>LED7S0<="";--5WHEN6=>LED7S0<="";--6WHEN7=>LED
此文档下载收益归作者所有