當前位置:編程學習大全網 - 編程語言 - 用VHDL編程實現4位LED數碼管動態顯示

用VHDL編程實現4位LED數碼管動態顯示

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;

  • 上一篇:重慶有哪些夜市值得推薦?
  • 下一篇:NDS 無限邊界:超級機器人大戰OG傳說 攻略
  • copyright 2024編程學習大全網