交通灯EDA代码.docx
- 文档编号:2989265
- 上传时间:2022-11-16
- 格式:DOCX
- 页数:10
- 大小:16.58KB
交通灯EDA代码.docx
《交通灯EDA代码.docx》由会员分享,可在线阅读,更多相关《交通灯EDA代码.docx(10页珍藏版)》请在冰豆网上搜索。
交通灯EDA代码
libraryieee;
useieee.std_logic_1164.all;
usework.all;
entityheadis
port(color_A:
bufferstd_logic_vector(2downto0);
color_B:
bufferstd_logic_vector(2downto0);
Acode_out_high,Acode_out_low:
outstd_logic_vector(6downto0);
Bcode_out_high,Bcode_out_low:
outstd_logic_vector(6downto0);
res,clk,key:
instd_logic);
endhead;
architecturemain_strofheadis
signalput_a,put_b,flag_a,flag_b,load_a,load_b:
std_logic;
signaldata_a,data_b,value_cou_a,value_cou_b:
std_logic_vector(7downto0);
signalAcode_in_high,Acode_in_low,Bcode_in_high,Bcode_in_low:
std_logic_vector(3downto0);
signaldata_bcd_a,data_bcd_b:
std_logic_vector(7downto0);
componentput_numbis--定义置数器
port(res_s,put_a,put_b,clk_s:
instd_logic;
out_sto_a:
bufferstd_logic_vector(7downto0);
out_sto_b:
bufferstd_logic_vector(7downto0));
endcomponent;
componentcounteris--定义计数器
port(res_c,clk_h,com_load,hold:
instd_logic;
in_data:
instd_logic_vector(7downto0);
vec_out:
bufferstd_logic_vector(7downto0);
flag:
outstd_logic);
endcomponent;
componentmux_bcdis--定义BCD码转换器
port(data_1:
instd_logic_vector(7downto0);
res_m,hold_s,clk_m:
instd_logic;
data_bcd:
outstd_logic_vector(7downto0));
endcomponent;
componentmain_colis--定义主控制器
port(hold_1,clk_r,flag_froma,flag_fromb,res_r:
instd_logic;
color_vec_A:
bufferstd_logic_vector(2downto0);
color_vec_B:
bufferstd_logic_vector(2downto0);
puta,putb,loada,loadb:
bufferstd_logic);
endcomponent;
componentcode_sevis--定义七段字型译码器
port(code_in:
instd_logic_vector(3downto0);
code_out:
outstd_logic_vector(6downto0));
endcomponent;
begin
u1:
put_numbportmap(res,put_a,put_b,clk,data_a,data_b);
u2:
counterportmap(res,clk,load_a,key,data_a,value_cou_a,flag_a);
u3:
counterportmap(res,clk,load_b,key,data_b,value_cou_b,flag_b);
u4:
mux_bcdportmap(value_cou_a,res,key,clk,data_bcd_a);
u5:
mux_bcdportmap(value_cou_b,res,key,clk,data_bcd_b);
u6:
main_colportmap(key,clk,flag_a,flag_b,res,color_A,color_B,put_a,put_b,load_a,load_b);
u7:
code_sevportmap(Acode_in_high,Acode_out_high);
u8:
code_sevportmap(Acode_in_low,Acode_out_low);
u9:
code_sevportmap(Bcode_in_high,Bcode_out_high);
u10:
code_sevportmap(Bcode_in_low,Bcode_out_low);
Acode_in_high<=data_bcd_a(7downto4);
Acode_in_low<=data_bcd_a(3downto0);
Bcode_in_high<=data_bcd_b(7downto4);
Bcode_in_high<=data_bcd_b(3downto0);
endmain_str;
libraryieee;--置数器
useieee.std_logic_1164.all;
entityput_numbis
port(res_s,put_a,put_b,clk_s:
instd_logic;
out_sto_a:
bufferstd_logic_vector(7downto0);
out_sto_b:
bufferstd_logic_vector(7downto0));
endput_numb;
architecturertl_stoofput_numbis
begin
process(res_s,put_a,clk_s)
variablein_var:
std_logic_vector(7downto0);
begin
in_var:
=out_sto_a;
if(res_s='0')then
out_sto_a<="00110110";
elsif(clk_s'eventandclk_s='0')then
if(put_a='0')then
casein_varis
when"00110110"=>out_sto_a<="00110001";--55秒后装入50秒
when"00110001"=>out_sto_a<="00000100";--50秒后装入05秒
when"00000100"=>out_sto_a<="00110110";--05秒后再次装入55秒
whenothers=>out_sto_a<="XXXXXXXX";
endcase;
endif;
endif;
endprocess;
process(res_s,put_b,clk_s)--B组计时时间状态机
variablein_var:
std_logic_vector(7downto0);
begin
in_var:
=out_sto_b;
if(res_s='0')then
out_sto_b<="00110001";--复位时A组输出31H(49D),即50秒
elsif(clk_s'eventandclk_s='0')then
if(put_b='0')then
casein_varis
when"00110001"=>out_sto_b<="00110001";--50秒后装入05秒
when"00110001"=>out_sto_b<="00110110";--05秒后装入55秒
when"00110110"=>out_sto_b<="00110001";--55秒后再次装入50秒
whenothers=>out_sto_b<="XXXXXXXX";
endcase;
endif;
endif;
endprocess;
endrtl_sto;
libraryieee;--计数器
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entitycounteris
port(res_c,clk_h,com_load,hold:
instd_logic;
in_data:
instd_logic_vector(7downto0);
vec_out:
bufferstd_logic_vector(7downto0);
flag:
outstd_logic);
endcounter;
architecturertlofcounteris
signalclk_c:
std_logic;
begin
clk_c<=holdandclk_h;
process(clk_c)
begin
if(clk_c'eventandclk_c='1')then
flag<=(notvec_out(0))orvec_out
(1)orvec_out
(2)orvec_out(3)orvec_out(4)
orvec_out(5)orvec_out(6)orvec_out(7);
--计时时间到信号的获取,在0秒输出宽1秒的负脉冲
endif;
endprocess;
process(res_c,clk_c)
variablecount:
integerrange0to255;
begin--复位时计数器重新加载端口计时初始值
if(res_c='0')then
count:
=conv_integer(in_data);
elsif(clk_c'eventandclk_c='1')then
if(com_load='0')then--load命令让计数器加载端口计时初值
count:
=conv_integer(in_data);
else
count:
=count-1;--减1计数
endif;
endif;
vec_out<=conv_std_logic_vector(count,8);--将整型值转换为8位宽的矢量信号
endprocess;
endrtl;
libraryieee;--BCD码转换器
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entitymux_bcdis
port(data_1:
instd_logic_vector(7downto0);
res_m,hold_s,clk_m:
instd_logic;
data_bcd:
outstd_l
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 交通灯 EDA 代码