Guest User

Untitled

a guest
May 10th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.51 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use ieee.numeric_std.all;
  4.  
  5. entity SevenSegment is
  6.     Port (  clk: in std_logic;
  7.         --seg_value : in  STD_LOGIC_VECTOR (0 to 6);
  8.         seg_value : in  STD_LOGIC_VECTOR (3 downto 0);
  9.         dp_value: in  std_logic_vector(0 to 3);
  10.         seg : out  STD_LOGIC_VECTOR (0 to 6) := "1111111";
  11.         dp: out std_logic;
  12.         an: out std_logic_vector (0 to 3));
  13. end SevenSegment;
  14.  
  15. architecture Behavioral of SevenSegment is
  16. signal clock_7segment:std_logic := '0';
  17. signal current : STD_LOGIC_VECTOR (0 to 6) := "1111111";
  18. begin
  19.     process (clk)
  20.     variable counter: integer := 0;
  21.     begin
  22.         if(clk 'event and clk = '1') then
  23.         if(counter >= 0 and counter < 100) then
  24.             counter := counter +1;
  25.             clock_7segment <= '0';
  26.         elsif (counter < 200) then
  27.             counter := counter +1;
  28.             clock_7segment <= '1';
  29.         else
  30.             counter := 0;
  31.         end if;
  32.         end if;
  33.     end process;
  34.     process (clock_7segment)
  35.     variable state : integer := 0;
  36.  
  37.     begin
  38.     if(clock_7segment'event and clock_7segment = '1') then
  39.         if(state =0) then
  40.             if (seg_value(3) = '0' and
  41.                 seg_value(2) = '0' and  
  42.                  seg_value(1) = '0' and
  43.                  seg_value(0) = '0') then
  44.                 seg <= "0000001";
  45.             else
  46.                 --A 1(0' + 3') + 2(1 + 3'0) + 1'(0'(3+2') + 32')
  47.                 if ( (seg_value(1) = '1' and
  48.                       (seg_value(0) = '0' or
  49.                          seg_value(3) = '0'))
  50.                       or
  51.                       (seg_value(2) = '1' and
  52.                        (seg_value(1) = '1' or
  53.                          (seg_value(3) = '0' and
  54.                          seg_value(0) = '1')))
  55.                       or
  56.                        (seg_value(1) = '0' and
  57.                          ((seg_value(0) = '0' and
  58.                           (seg_value(3) = '1' or
  59.                            seg_value(2) = '0')) or
  60.                           (seg_value(3) = '1' and
  61.                           seg_value(2) = '0')))
  62.                 ) then
  63.                     seg(0) <= '0';
  64.                 else
  65.                     seg(0) <= '1';
  66.                 end if;
  67.                 --B 2'(30'+3') + 3'(1 xnor 0) + 31'0
  68.                 if ((seg_value(3) = '0' and (seg_value(1) = '1' xnor seg_value(0) = '1')) or
  69.                     (seg_value(3) = '1' and seg_value(1) = '0' and seg_value(0) = '1') or
  70.                     (seg_value(2) = '0' and ((seg_value(3) = '1' and seg_value(0) = '0') or seg_value(3) = '0'))) then
  71.                     seg(1) <= '0';
  72.                 else
  73.                     seg(1) <= '1';
  74.                 end if;
  75.                 --C
  76.                 if ((seg_value(3) = '0' and seg_value(1) = '0') or (seg_value(0) = '1' and
  77.                     (seg_value(3) = '0' or seg_value(1) = '0')) or (seg_value(3) = '1' xor
  78.                     seg_value(2) = '1')) then
  79.                     seg(2) <= '0';
  80.                 else
  81.                     seg(2) <= '1';
  82.                 end if;
  83.                 --D 2'(3'0' + 10) + 2(1 xor 0) + 31' , 3'2'0' + 2'10 + 210' + 21'0 + 31'
  84.                 if ((seg_value(3) = '0' and seg_value(2) = '0' and seg_value(0) = '0') or
  85.                     (seg_value(2) = '0' and seg_value(1) = '1' and seg_value(0) = '1') or
  86.                     (seg_value(2) = '1' and seg_value(1) = '1' and seg_value(0) = '0') or
  87.                     (seg_value(2) = '1' and seg_value(1) = '0' and seg_value(0) = '1') or
  88.                     (seg_value(3) = '1' and seg_value(1) = '0')) then
  89.                     seg(3) <= '0';
  90.                 else
  91.                     seg(3) <= '1';
  92.                 end if;
  93.                 --E 0'(2'1' + 1) + 3(2 + 1)
  94.                 if ((seg_value(0) ='0' and (((seg_value(2)='0' and seg_value(1)='0') or
  95.                     seg_value(1)='1'))) or (seg_value(3)='1' and (seg_value(2)='1'  or
  96.                     seg_value(1)='1'))) then
  97.                     seg(4) <= '0';
  98.                 else
  99.                     seg(4) <= '1';
  100.                 end if;
  101.                 --F 3(2'+1) + 1'0' + 2(3'1' + 10')
  102.                 if ((seg_value(3)='1' and (seg_value(2) = '0' or seg_value(1) = '1')) or
  103.                     (seg_value(1)='0' and seg_value(0)='0') or
  104.                     (seg_value(2)='1' and ((seg_value(3) = '0' and seg_value(1)='0') or (seg_value(1) = '1' and seg_value(0)='0')))) then
  105.                     seg(5) <= '0';
  106.                 else
  107.                     seg(5) <= '1';
  108.                 end if;
  109.                 --G 3(2'+0) + 10' + 3'(2 xor 1)
  110.                 if ((seg_value(3) = '1' and (seg_value(2) = '0' or seg_value(0) = '1')) or
  111.                     (seg_value(1) = '1' and seg_value(0)='0') or
  112.                     (seg_value(3)='0' and (seg_value(2)='1' xor seg_value(1)='1'))
  113.                      ) then
  114.                     seg(6) <= '0';
  115.                 else
  116.                     seg(6) <= '1';
  117.                 end if;
  118.             end if;
  119.         --end if;
  120.             --seg <= seg_value (0 to 6);
  121.             dp<=dp_value(0);
  122.             an <= "1110";
  123.             state := state+1;
  124.         elsif (state =1) then
  125.             --seg <=  seg_value (0 to 6) XOR "1111111";
  126.             --seg <= seg_value (7 to 13);
  127.             dp<=dp_value(1);
  128.             an <= "1110";
  129.             state := state+1;
  130.         elsif (state =2) then
  131.             --seg <=  seg_value (0 to 6) XOR "1010101";
  132.             --seg <=  seg_value (14 to 20);
  133.             dp<=dp_value(2);
  134.             an <= "1110";
  135.             state := state+1;
  136.         elsif (state =3) then
  137.             --seg <=  seg_value (0 to 6) XOR "0101010";
  138.             --seg <=  seg_value (21 to 27);
  139.             dp<=dp_value(3);
  140.             an <= "1110";
  141.             state := state+1;
  142.         else
  143.             state := 0;
  144.         end if;
  145.         end if;
  146.     end process;
  147. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment