EDA代码.docx
- 文档编号:9674490
- 上传时间:2023-05-20
- 格式:DOCX
- 页数:20
- 大小:75.64KB
EDA代码.docx
《EDA代码.docx》由会员分享,可在线阅读,更多相关《EDA代码.docx(20页珍藏版)》请在冰点文库上搜索。
EDA代码
1彩灯显示系统
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entitylightis
port(clk1:
instd_logic;--100KHZ
light:
bufferstd_logic_vector(7downto0));--8个彩灯
endlight;
architecturebehvoflightis
constantlen:
integer:
=7;
signalbanner:
std_logic;--节拍转换
signalclk,clk2,clk3:
std_logic;--辅助时钟信号
signalsave:
std_logic_vector(10downto0);--计数
begin
clk<=(save(10)andbanner)or(clk2andnotbanner);--循环时钟
clk3<=save(10);--分频时钟
process(clk1)
begin
ifclk1'eventandclk1='1'then
save<=save+1;
endif;
endprocess;
process(clk3)
begin
ifclk3'eventandclk3='1'then
clk2<=notclk2;
endif;
endprocess;
process(clk)
variableflag:
bit_vector(1downto0):
="00";
begin
ifclk'eventandclk='1'then
ifflag="00"then--一开始是全0或者重新开始时
iflight(7downto0)="000000000"then--当灯是全灭的时候
light<="11111111";
else
light<="00000000";--全亮之后全灭,转为下一种状态
flag:
="01";
endif;
elsifflag="01"then--依次点亮每一盏
iflight="00000000"then--刚开始全灭的时候,点亮
light<='1'&light(lendownto1);
else
light<=light(0)&light(lendownto1);
endif;
iflight
(1)='1'then
flag:
="10";
endif;
elsifflag="10"then--四个四个亮
iflight
(1)='0'then--上一个状态后最低位是0
light<="10101010";
else
light<="01010101";
flag:
="11";
endif;
elsifflag="11"then--重新开始
light<="00000000";
banner<=notbanner;--换节拍
flag:
="00";
else
flag:
="00";
endif;
endif;
endprocess;
endbehv;
其引脚分配如下:
2交通灯
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytrafficis
port(clk0,clkk:
instd_logic;
din:
instd_logic;--din表示从干道是否有车
dout:
outstd_logic_vector(7downto0);--七段数码管值
scan:
outstd_logic_vector(5downto0);--数码管扫描参数
light:
outstd_logic_vector(7downto0)--彩灯输出
);
endtraffic;
architectureaoftrafficis
signalflag,temp:
std_logic;
signaltime1,data,time2:
std_logic_vector(3downto0):
="0000";
begin
scan<="0000"&temp&(nottemp);--只有两个数码管显示
process(clkk)--不断交替选中两个数码管,并且显示时间的各位,十位
begin
ifclkk'eventandclkk='1'then
temp<=nottemp;
iftemp='1'then
data<=time1;
elsedata<=time2;
endif;
endif;
endprocess;
process(clk0,din)--三十秒计时time1个位,time2十位
begin
ifclk0'eventandclk0='1'then
ifdin='1'then--从干道有车时才开始计时,然后开始红绿灯轮流交替
iftime1="0000"then
iftime2="0000"then
time1<="1001";
time2<="0010";
flag<=notflag;
elsetime2<=time2-1;
time1<="1001";
endif;
elsetime1<=time1-1;
endif;
endif;
endif;
endprocess;
process(time1,flag,time2,clk0)
begin--flag=1表示主干道正在通行
ifdin='1'then
iftime1<"0100"andflag='1'andtime2="0000"then--后三秒
light<='0'&clk0&"000100";--黄红(黄灯跟着时钟节奏闪)
elsiftime1<"1010"andflag='1'then--前面27秒
light<="00100100";--绿红
elsiftime1<"0100"andflag='0'andtime2="0000"then--开始主干道为红灯。
后三秒
light<="100000"&clk0&'0';--红黄(黄灯跟着时钟节奏闪)
elsiftime1<"1010"andflag='0'then--前面27秒
light<="10000001";--红绿
elsenull;
endif;
else
light<="00100100";
endif;
endprocess;
--在数码管上显示时间
process(data)
begin
casedatais
when"0000"=>dout<="00111111";
when"0001"=>dout<="00000110";
when"0010"=>dout<="01011011";
when"0011"=>dout<="01001111";
when"0100"=>dout<="01100110";
when"0101"=>dout<="01101101";
when"0110"=>dout<="01111101";
when"0111"=>dout<="00000111";
when"1000"=>dout<="01111111";
when"1001"=>dout<="01101111";
when"1010"=>dout<="01110111";
when"1011"=>dout<="01111100";
when"1100"=>dout<="00111001";
when"1101"=>dout<="01011110";
when"1110"=>dout<="01111001";
when"1111"=>dout<="00000000";
whenothers=>dout<="00000000";
endcase;
endprocess;
enda;其引脚分配如下:
3抢答器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
packagepackagexpis
functiontransform(a:
std_logic_vector)
returnstd_logic_vector;
end;
packagebodypackagexpis
functiontransform(a:
std_logic_vector)
returnstd_logic_vectoris
variabletemp:
std_logic_vector(3downto0);
begin
caseais
when"0001"=>temp:
="0001";--1
when"0010"=>temp:
="0010";--2
when"0100"=>temp:
="0011";--3
when"1000"=>temp:
="0100";--4
whenothers=>null;
endcase;
returntemp;
endfunctiontransform;
end;
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
usework.packagexp.all;
entitymyansweris
port(a,b,c,d,rst,op,clk,clk1:
instd_logic;--a,b,c,d代表选手,一个时钟用来计时,一个时钟用来刷新数码管
scan:
outstd_logic_vector(5downto0);--数码管动态扫描
dout:
outstd_logic_vector(7downto0)--数码管段码
);
endmyanswer;
architecturebehvofmyansweris
signaltemp:
std_logic_vector(2downto0);
signaltime1:
std_logic_vector(3downto0);--十位秒数计时
signaltime2:
std_logic_vector(3downto0);--个位秒数计时
signalright:
std_logic_vector(3downto0);--正确选手号码寄存器
signalwrong:
std_logic_vector(3downto0);--错误选手号码寄存器
signaldin:
std_logic_vector(3downto0);
signaldataout:
std_logic_vector(3downto0);
signalanswerflag:
std_logic;--进入30秒回答问题计时标志
signalerrorflag:
std_logic;--违规标志
signaltimeoutflag:
std_logic;--抢答超时信号标志
signalfirstflag:
std_logic;--刚刚抢答成功标志
signallong:
std_logic;
begin
din<=a&b&c&d;
process(clk1)
begin
ifclk1'eventandclk1='1'then
iftemp="101"then
temp<="000";
else
temp<=temp+1;
endif;
endif;
endprocess;
process(temp)--动态扫描
begin
casetempis
when"000"=>dataout<=wrong;scan<="000001";
when"001"=>dataout<="0000";scan<="000010";
when"010"=>dataout<=right;scan<="000100";
when"011"=>dataout<="0000";scan<="001000";
when"100"=>dataout<=time2;scan<="010000";
when"101"=>dataout<=time1;scan<="100000";
whenothers=>null;
endcase;
endprocess;
process(rst,op,din)--抢答逻辑判断
begin
ifrst='1'then--初始化时
errorflag<='0';
answerflag<='0';
firstflag<='0';
right<="0000";wrong<="0000";
elsifop='0'then--违规抢答
ifdin/="0000"andwrong="0000"then
errorflag<='1';
wrong<=transform(din);
endif;
elsiftimeoutflag='0'andright="0000"then--还未超时且无人抢答(可以抢答)
ifdin/="0000"then--有人抢答
answerflag<='1';
firstflag<='1';
right<=transform(din);
endif;
else
null;
endif;
endprocess;
process(op,clk,rst,firstflag)--计时逻辑
begin
ifrst='0'then
ifop='1'then--下了抢答命令
ifclk'eventandclk='1'anderrorflag='0'then--没有人违规的情况下继续倒计时
ifanswerflag='0'then--五秒倒计时阶段
iftime2>"0000"then
time2<=time2-1;
else
timeoutflag<='1';
endif;
elsiffirstflag='1'andtime1="0000"andlong='1'then--三十秒倒计时阶段,如果刚进入
time1<="0011";time2<="0000";
else--正常30秒计时阶段
iftime2="0000"then
iftime1>"0000"then
time1<=time1-1;time2<="1001";
else
null;
endif;
else
time2<=time2-1;
endif;
endif;
iftime1/="0000"then--改变long标志位
long<='0';
endif;
endif;
endif;
else
time1<="0000";time2<="0101";
timeoutflag<='0';
long<='1';
endif;
endprocess;
process(dataout)
begin
casedataoutis
when"0000"=>dout<="00111111";--0
when"0001"=>dout<="00000110";--1
when"0010"=>dout<="01011011";--2
when"0011"=>dout<="01001111";--3
when"0100"=>dout<="01100110";--4
when"0101"=>dout<="01101101";--5
when"0110"=>dout<="01111101";--6
when"0111"=>dout<="00000111";--7
when"1000"=>dout<="01111111";--8
when"1001"=>dout<="01101111";--9
when"1010"=>dout<="01110111";--a
when"1011"=>dout<="01111100";--b
when"1100"=>dout<="00111001";--c
when"1101"=>dout<="01011110";--d
when"1110"=>dout<="01111001";--e
when"1111"=>dout<="01110001";--f
whenothers=>dout<="00000000";
endcase;
endprocess;
endbehv;
其引脚分配如下:
4进制转换器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
packagepackagexpis
functiontransform(a:
integer)
returnstd_logic_vector;
end;
packagebodypackagexpis
functiontransform(a:
integer)
returnstd_logic_vectoris
variabletemp:
std_logic_vector(7downto0);
begin
caseais
when0=>temp:
="00111111";--0
when1=>temp:
="00000110";--1
when2=>temp:
="01011011";--2
when3=>temp:
="01001111";--3
when4=>temp:
="01100110";--4
when5=>temp:
="01101101";--5
when6=>temp:
="01111101";--6
when7=>temp:
="00000111";--7
when8=>temp:
="01111111";--8
when9=>temp:
="01101111";--9
whenothers=>null;
endcase;
returntemp;
endfunctiontransform;
end;
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
usework.packagexp.all;
entityy2_10is
port(clk:
std_logic;--数码管扫描时钟
a,b,c,d,e,f,g,h:
instd_logic;--8位二进制数
scan:
outstd_logic_vector(5downto0);--数码管扫描参数
light:
outstd_logic_vector(7downto0)--彩灯输出
);
endy2_10;
architecturebehvofy2_10is
signaldin:
std_logic_vector(7downto0);--输入的八位二进制数
signalt:
std_logic_vector(2downto0);--动态扫描参数
signald3,d2,d1:
std_logic_vector(7downto0);--存储十进制数的百位,十位,个位
signalresult:
integerrange0to255;
begin
proce
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- EDA 代码
![提示](https://static.bingdoc.com/images/bang_tan.gif)