library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity shownum is
port(clock,en : in std_logic;
dp2,dp1 : in std_logic; ---dp2:百位小数点 dp1:个位小数点
numina,numinb,numinc : in std_logic_vector(3 downto 0);
display : out std_logic_vector(6 downto 0);
enout : out std_logic_vector(2 downto 0); 控制使能段
dpout : out std_logic); --小数点输出
end;
architecture decoder of shownum is
signal counter : integer range 0 to 2;
signal counter1 : integer range 0 to 1;
signal num1 : std_logic;
begin
a: process(clock,en)
variable num : std_logic_vector(3 downto 0);
begin
if en='1' then --如果en为高电平时,允许七段数码管显示数字
if rising_edge(clock) then
if counter=2 then
counter<=0;
else
counter<=counter+1;
end if;
case counter is
when 0=>
enout<="110";
num:= numina;
when 1=>
enout<="101";
num:= numinb;
when 2=>
enout<="011";
num:= numinc;
when others=>
enout<="111";
num:= "0000";
end case;
case num is
when"0000"=>display<="1111110";
when"0001"=>display<="0110000";
when"0010"=>display<="1101101";
when"0011"=>display<="1111001";
when"0100"=>display<="0110011";
when"0101"=>display<="1011011";
when"0110"=>display<="1011111";
when"0111"=>display<="1110000";
when"1000"=>display<="1111111";
when"1001"=>display<="1111011";
when others=>display<="0000000";
end case;
end if;
else --en='0'不显示
display<="0000000";
end if;
end process;
b: process(num1) --从这开始是我不能实现的地方,不能将小数点也动态显示
begin
if counter1=1 then
counter1<=0;
else
counter1<=counter1+1;
end if;
case counter is
when 0=>
if dp2='0' and dp1='0' then
enout<="111";num1<=dp2 or dp1;
elsif dp2='0' and dp1='1' then
enout<="101";num1<=dp2 or dp1;
elsif dp2='1' and dp1='0' then
enout<="011" ;num1<=dp2 or dp1;
else
enout<="111";
end if;
when 1=>
if dp2='0' and dp1='0' then
enout<="111";num1<=dp2 or dp1;
elsif dp2='0' and dp1='1' then
enout<="101";num1<=dp2 or dp1;
elsif dp2='1' and dp1='0' then
enout<="011" ;num1<=dp2 or dp1;
else
dpout<='0';
end if;
when others=>null;
end case;
dpout<=num1;
end process;
end;