vhdl语言实现【篮球比赛数字记分牌】,源程序如下,仿真结果及电路连接图如图所示
--由于两个队的记分牌是一样的,所以这里只设计一个队(命名为A队)的记分牌,另一个队的记
--分牌可直接调用这个模块就可以了。
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--*-------------------------------------------------------*--
ENTITY counter_A IS
PORT(clk : in std_logic; --时钟
clr : in std_logic; --异步清零信号
score_A_2 : in std_logic; --进球得分2分
score_A_1 : in std_logic; --发球得分1分
error_A_2 : in std_logic; --纠错后减掉2分
error_A_1 : in std_logic; --纠错后减掉1分
led7_1 : out std_logic_vector(6 downto 0);--显示个位的数码管
led7_2 : out std_logic_vector(6 downto 0);--显示十位的数码管
led7_3 : out std_logic_vector(6 downto 0));--显示百位的数码管
End counter_A;
--*------------------------------------------------------*--
ARCHITECTURE arch OF counter_A IS
signal Q1 : std_logic_vector(3 downto 0); --个位计数器
signal Q2 : std_logic_vector(3 downto 0); --十位计数器
signal Q3 : std_logic_vector(3 downto 0); --百位计数器
begin
P1 : process(clk,clr)
begin
if clr='0' then --clr=0时计数器清零;
Q1 <= "0000";
Q2 <= "0000";
Q3 <= "0000";
elsif clk'event and clk='0' then
if score_A_2 ='1' then
Q1 <= Q1+"0010";
if Q1="1000" then
Q1 <= "0000";
Q2 <= Q2+1;
if Q2="1001" then
Q2 <= "0000";
Q3 <= Q3+1;
end if;
elsif Q1="1001" then
Q1 <= "0001";
Q2 <= Q2+1;
if Q2="1001" then
Q2 <= "0000";
Q3 <= Q3+1;
end if;
end if;
elsif score_A_1 ='1' then
Q1 <= Q1 + "0001";
if Q1="1001" then
Q1 <= "0000";
Q2 <= Q2+1;
if Q2="1001" then
Q2 <= "0000";
Q3 <= Q3+1;
end if;
end if;
elsif error_A_2 ='1' then
Q1 <= Q1 - "0010";
if Q1="0001" then
Q1 <= "1001";
Q2 <= Q2-1;
elsif Q1="0000" then
Q1 <="1000";
Q2 <= Q2-1;
end if;
elsif error_A_1 ='1' then
Q1 <= Q1 - "0001";
if Q1="0000" then
Q1 <= "1001";
Q2 <= Q2-1;
end if;
end if;
end if;
end process P1;
--*------------------------------------------------------------
led1 : process(Q1,clr) --个位数码管显示进程段
begin
if clr='0' then
led7_1 <= "0000000";
else
case Q1 is
when"0000"=>led7_1<="1111110";
when"0001"=>led7_1<="0110000";
when"0010"=>led7_1<="1101101";
when"0011"=>led7_1<="1111001";
when"0100"=>led7_1<="0110011";
when"0101"=>led7_1<="1011011";
when"0110"=>led7_1<="1011111";
when"0111"=>led7_1<="1110000";
when"1000"=>led7_1<="1111111";
when"1001"=>led7_1<="1111011";
when others=>led7_1<="0000000";
end case;
end if;
end process led1;
--*------------------------------------------------------------
led2 : process(Q2,clr) --十位数码管显示进程段
begin
if clr='0' then
led7_2 <= "0000000";
else
case Q2 is
when"0000"=>led7_2<="1111110";
when"0001"=>led7_2<="0110000";
when"0010"=>led7_2<="1101101";
when"0011"=>led7_2<="1111001";
when"0100"=>led7_2<="0110011";
when"0101"=>led7_2<="1011011";
when"0110"=>led7_2<="1011111";
when"0111"=>led7_2<="1110000";
when"1000"=>led7_2<="1111111";
when"1001"=>led7_2<="1111011";
when others=>led7_2<="0000000";
end case;
end if;
end process led2;
--*------------------------------------------------------------
led3 : process(Q3,clr) --百位数码管显示进程段
begin
if clr='0' then
led7_3 <= "0000000";
else
case Q3 is
when"0000"=>led7_3<="1111110";
when"0001"=>led7_3<="0110000";
when"0010"=>led7_3<="1101101";
when"0011"=>led7_3<="1111001";
when"0100"=>led7_3<="0110011";
when"0101"=>led7_3<="1011011";
when"0110"=>led7_3<="1011111";
when"0111"=>led7_3<="1110000";
when"1000"=>led7_3<="1111111";
when"1001"=>led7_3<="1111011";
when others=>led7_3<="0000000";
end case;
end if;
end process led3;
end arch;
--*-------------------------------------------------------*--