EDA技术实验报告
实验二:
设计一个两人抢答器,用A,B表示两个人,分别为A和B设置了分数清零按钮clr1和clr2,并设置了清除灯亮按键rset。首先通过判断按键的快慢来决定A或B来回答问题,再根据回答者给出的答案来判断应该加多少分,add1为10分,add2为20分,add3为30分。 这个用一个CASE语句来实现。 源代码: library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity zq is
port(a1,a2:in std_logic; b1,b2,b3:in std_logic;
res1,res2,res3,res4:in std_logic; led1,led2:out std_logic;
c1,c2:out std_logic_vector(4 downto 0) ); end;
architecture one of zq is
signal q1:std_logic_vector(4 downto 0); signal q2:std_logic_vector(4 downto 0); signal q3:std_logic; signal q4:std_logic;
constant x:std_logic_vector:=
zq:process (a1,a2,res1,res2) begin
if (a1='1'and a2='0') then q3
elsif (a1='0'and a2='1') then q3
if res1= '1' then q3
if res2= '1' then q4
jifen:process (b1,b2,b3,res3,res4) begin
if res3='1' then q1
if res4='1' then q2
else q2
if (q3='1' and b1='1') then q1
elsif (q3='1' and b2='1') then q1
if (q4='1' and b1='1') then q2
elsif (q4='1' and b2='1') then q2
c1
实验三:
设计一个含有正点报时和闹钟的时钟,首先时钟的计时,用了三个嵌套的if 语句,当 时,分,秒不符合进位的条件时,本身自加一,循环直到进位后清零再循环。整点报时是当分为零和秒为零时才显示。为闹钟设计三个输入,分别对应时,分,秒,当输入与程序中的时,分,秒一一对应时,显示闹钟。 源代码: library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sz is
port(res,clk:in std_logic;
b1,b2,b3:in std_logic_vector(5 downto 0); d:buffer std_logic;
led1:buffer std_logic_vector(5 downto 0); c1,c2,c3:buffer std_logic_vector(5 downto 0) ); end;
architecture one of sz is begin
process (res,d,led1,b1,b2,b3,c1,c2,c3) variable q1: std_logic_vector(5 downto 0);
variable q2: std_logic_vector(5 downto 0); variable q3: std_logic_vector(5 downto 0); begin
if res='1'then q1:= (others=>'0');q2:= (others=>'0');q3:= (others=>'0'); elsif clk'event and clk='1'then if q3
if q1
else q1:=(others=>'0');q2:=q2+1;end if;
else q2:=(others=>'0');q3:=q3+1;led1'0'); end if;
if (b1=q3) and (b2=q2) and (b3=q1) then d
c1
end architecture one; 仿真图:
实验四:
设计一个红绿灯,分为两种特殊情况(复位和特殊状态)和四种正常状态 四种正常状态的状态转换图如下
TB=0
令st0为GA,RB,st1,st2,st3对应接下来的循环状态。用一个mealy机来实现状态转换。特殊情况和复位用一个if‐elsif语句来实现。
源代码 library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity gry is
port( reset,clk,s: in std_logic; lr1,lr2,ly1,ly2,lg1,lg2: out std_logic;
count1, count2: out std_logic_vector(5 downto 0));end; architecture one of gry is
signal qr1,qr2,qg1,qg2,qy1,qy2:std_logic_vector (5 downto 0) signal l:std_logic_vector (5 downto 0); type states is (st0,st1,st2,st3,st4); signal pst,p: states;begin
regcom:process(clk,reset,pst)begin if clk'event and clk='1'then
if reset='1' then pst
when st0=> if qg1>0 then pst
when st1=> if qy1>0 then pst
when st2=> if qg2>0 then pst
when st3=> if qy2>0 then pst
仿真图