2、计时模块JSQ
本系统的计时器电路既有计时初始值的预置功能,又有减计数功能。其中,初始值的预置功能是将两位数分解成两个数分别进行预置。 其VHDL源程序如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity jsq is port(CLR, ,EN,CLK: in std_logic; Qa:out std_logic_vector(3 downto 0); --ge wei Qb:out std_logic_vector(3 downto 0)); --shi wei end entity jsq; architecture art of jsq is begin process(CLK) is variable tmpa: std_logic_vector(3 downto 0); variable tmpb: std_logic_vector(3 downto 0); begin if (CLR='1') then tmpa:=\tmpb:=\--清零,倒计时60秒 elsif( CLK'event and CLK='1') then if en='1' then--计时开始 if tmpa=\then--遇到9则自动变为0,否则减一 tmpa:=\ if tmpb=\then tmpb:=\ else tmpb:=tmpb-1; end if; else tmpa:=tmpa-1; end if; end if; end if; Qa<=tmpa; Qb<=tmpb; end process; end architecture art; JSQCLRQA[3..0]LDNQB[3..0]ENCLKTA[3..0]TB[3..0]inst
5
图2.3.1 计时模块(JSQ)仿真波形框图
图2.3.0 计时模块(JSQ)仿真波形
3、记分模块JFQ
抢答计分电路的设计一般按一定数制进行加减即可,但随着计数数目的增加,要将计
数数目分解成十进制并进行译码显示会变得较为复杂。为了避免该种情况,通常是将一个大的进制分解为数个十进只以内的进制数,并将计数器级联。但随着数位的增加,电路的接口也会相应增加。因此,本设计采用IF语句从低往高判断是否有进位,以采取响应的操作,既减少了接口,又简化了设计。 其VHDL源程序如下: library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity jfq is
port(RST: in std_logic; ADD: in std_logic;
CHOS: in std_logic_vector(3 downto 0); out1: out std_logic_vector(3 downto 0)); end entity jfq ; architecture art of jfq is begin
process(RST,ADD,CHOS) is
variable points_a0: std_logic_vector(3 downto 0); variable points_b0: std_logic_vector(3 downto 0); variable points_c0: std_logic_vector(3 downto 0); variable points_d0: std_logic_vector(3 downto 0); begin
if (ADD'event and ADD='1') then if RST='1' then
6
points_a0:=\ points_b0:=\ points_c0:=\ points_d0:=\ elsif CHOS=\then if points_a0=\then points_a0:=\ else
points_a0:=points_a0+1; end if;
elsif CHOS=\then if points_b0=\then points_b0:=\ else
points_b0:=points_b0+1; end if;
elsif CHOS=\then if points_c0=\then points_c0:=\ else
points_c0:=points_c0+1; end if;
elsif CHOS=\then if points_d0=\then points_d0:=\ else
points_d0:=points_d0+1; end if; end if; end if;
if CHOS=\then out1<=points_a0; elsif CHOS=\then out1<=points_b0; elsif CHOS=\then out1<=points_c0; elsif CHOS=\then out1<=points_d0; elsif CHOS=\then out1<=\end if; end process;
7
END ARCHITECTURE ART; 图2.4.0 记分模块(JFQ)仿真波形 JFQRSTOUT1[3..0]ADDCHOS[3..0]inst 图2.4.1 记分模块(JFQ)仿真波形模块框图 4 、译码器显示模块YMQ 译码器的VHDL源程序如下: LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY YMQ IS PORT(AIN4: IN STD_LOGIC_VECTOR(3 DOWNTO 0); DOUT7: OUT STD_LOGIC_VECTOR(6 DOWNTO 0)); END YMQ; ARCHITECTURE ART OF YMQ IS BEGIN PROCESS(AIN4) BEGIN CASE AIN4 IS WHEN \ --0 WHEN \ --1 WHEN \ --2 WHEN \ --3 WHEN \ --4 WHEN \ --5 WHEN \ --6 WHEN \ --7 WHEN \ --8 8
WHEN \ --9 WHEN OTHERS=>DOUT7<=\ END CASE; END PROCESS; END ARCHITECTURE ART; 图2.5.0 译码器显示模块(YMQ)仿真波形 YMQAIN4[3..0]DOUT7[6..0]inst 图2.5.1译码器显示模块(YMQ)框图 六、抢答器的动态实现的程序和仿真 1、记时功能 LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY jfq IS PORT(RST: IN STD_LOGIC; ADD:IN STD_LOGIC; CHOS:IN STD_LOGIC_VECTOR (3 DOWNTO 0); PP2,PP1,PP0:OUT STD_LOGIC_VECTOR (3 DOWNTO 0)); 9