1

Error (10482): VHDL error at keypad.vhd(53): object "code" is used but not declared

Error (10558): VHDL error at keypad.vhd(53): cannot associate formal port "code" of mode "out" with an expression

First of all, I'm sorry for my bad English.()

I was making a program which consists of keypad.vhd & keypad_scan.vhd & d_7seg.vhd keypad_scan.vhd is continuing to scan the keypad. d_7seg.vhd only shows numbers on four 7-segments. Then keypad.vhd is a main part that acts like when I press a button(0~9), the number shows on LSB 7-segment pushing the previous number to the left.

I don't understand why it doesn't work. Here're my codes.

keypad.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity keypad is
    port( clk_1k : in std_logic;
            col : in std_logic_vector(2 downto 0);
            row : out std_logic_vector(3 downto 0);
            seg_com : out std_logic_vector(3 downto 0);
            seg_data : out std_logic_vector(7 downto 0));
end keypad;

architecture input_keypad_arch of keypad is

    component keypad_scan is
        port( clk_1k : in std_logic;
                col : in std_logic_vector(2 downto 0);
                row : buffer std_logic_vector(3 downto 0);
                strobe : out std_logic;
                code : out std_logic_vector(3 downto 0));    <--- 'code' is a troublemaker....
    end component;
    
    component d_7seg is
        port( clk : in std_logic;
                d0 : in integer range 0 to 9;
                d1 : in integer range 0 to 9;
                d2 : in integer range 0 to 9;
                d3 : in integer range 0 to 9;
                seg_com : out std_logic_vector(3 downto 0);
                seg_data : out std_logic_vector(7 downto 0));
    end component;
    
    signal key : std_logic_vector(3 downto 0);
    signal d0, d1, d2, d3 : integer range 0 to 9;
    signal strobe : std_logic;
    
begin
    p_shift : process(strobe, key)
    begin
        if(key = "1010" or key = "1011") then
            d0 <= 0;
            d1 <= 0;
            d2 <= 0;
            d3 <= 0;
        elsif strobe'event and strobe = '1' then
            d3 <= d2;
            d2 <= d1;
            d1 <= d0;
            d0 <= conv_integer(key);
        end if;
    end process;
    
    keyin : keypad_scan port map(clk_1k, col, row, strobe, code);
    disp : d_7seg port map(clk, d0, d1, d2, d3, seg_com, seg_data);
end input_keypad_arch;

keypad_scan.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity keypad_scan is
    port( clk_1k : in std_logic;
            col : in std_logic_vector(2 downto 0);
            row : buffer std_logic_vector(3 downto 0);
            strobe : out std_logic;
            code : out std_logic_Vector(3 downto 0));
end keypad_scan;

architecture keypad_scan_arch of keypad_scan is
    signal scan : integer range 0 to 3;
    signal k : std_logic_vector(0 to 11);
    signal t1 : std_logic;
    
begin
    p_scan : process(clk_1k)
    begin
        if clk_1k'event and clk_1k = '1' then
            if scan /= 3 then
                scan <= scan + 1;
            else
                scan <= 0;
            end if;
        end if;
    end process;
    
    p_row : process(clk_1k, scan)
    begin
        if clk_1k'event and clk_1k = '1' then
            case scan is 
                when 0 => row <= "0001";
                when 1 => row <= "0010";
                when 2 => row <= "0100";
                when 3 => row <= "1000";
            end case;
        end if;
    end process;
    
    p_r0 : process(clk_1k, row)
    begin
        if clk_1k'event and clk_1k = '1' and row = "0001" then
            k(1) <= col(0);
            k(2) <= col(1);
            k(3) <= col(2);
        end if;
    end process;
    
    p_r1 : process(clk_1k, row)
    begin
        if clk_1k'event and clk_1k = '1' and row = "0010" then
            k(4) <= col(0);
            k(5) <= col(1);
            k(6) <= col(2);
        end if;
    end process;
    
    p_r2 : process(clk_1k, row)
    begin
        if clk_1k'event and clk_1k = '1' and row = "0100" then
            k(7) <= col(0);
            k(8) <= col(1);
            k(9) <= col(2);
        end if;
    end process;
    
    p_r3 : process(clk_1k, row)
    begin
        if clk_1k'event and clk_1k = '1' and row = "1000" then
            k(10) <= col(0);
            k(0) <= col(1);
            k(11) <= col(2);
            
        end if;
    end process;
    
    p_stb : process(clk_1k, k, t1)
        variable sin : std_logic;
    begin
        sin := not (k(0) or k(1) or k(2) or k(3) or k(4) or k(5) or k(6) or k(7) or k(8) or k(9) or k(10) or k(11));
        if clk_1k'event and clk_1k = '1' then
            t1 <= sin;
        end if;
        strobe <= sin or (not t1);
    end process;
    
    p_enc : process(k)
    begin
        if k(11) = '1' then code <= "1011";
        elsif k(10) = '1' then code <= "1010";
        elsif k(9) = '1' then code <= "1001";
        elsif k(8) = '1' then code <= "1000";
        elsif k(7) = '1' then code <= "0111";
        elsif k(6) = '1' then code <= "0110";
        elsif k(5) = '1' then code <= "0101";
        elsif k(4) = '1' then code <= "0100";
        elsif k(3) = '1' then code <= "0011";
        elsif k(2) = '1' then code <= "0010";
        elsif k(1) = '1' then code <= "0001";
        elsif k(0) = '1' then code <= "0000";
        else code <= "1111";
        end if;
    end process;
end keypad_scan_arch;

d_7seg.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity d_7seg is
    port( clk : in std_logic;
            d0 : in integer range 0 to 9;
            d1 : in integer range 0 to 9;
            d2 : in integer range 0 to 9;
            d3 : in integer range 0 to 9;
            seg_com : out std_logic_vector(3 downto 0);
            seg_data : out std_logic_vector(7 downto 0));
end d_7seg;

architecture d_7seg_arch of d_7seg is
    signal scan : integer range 0 to 3 := 0;
    
        function dec_7_seg(bcd : integer range 0 to 9) return std_logic_vector is
            variable res : std_logic_vector(7 downto 0);
            
        begin
            if(bcd = "0000") then res := "00111111";
            elsif(bcd = "0001") then res := "00000110";
            elsif(bcd = "0010") then res := "01011011";
            elsif(bcd = "0011") then res := "01001111";
            elsif(bcd = "0100") then res := "01100110";
            elsif(bcd = "0101") then res := "01101101";
            elsif(bcd = "0110") then res := "01111101";
            elsif(bcd = "0111") then res := "00100111";
            elsif(bcd = "1000") then res := "01111111";
            elsif(bcd = "1001") then res := "01100111";
            else res := "11000000";
            end if;
            return res;
        end dec_7_seg;
        
begin
    p_scan : process(clk)
    begin
        if clk'event and clk = '1' then
            if scan /= 3 then
                scan <= scan + 1;
            else
                scan <= 0;
            end if;
        end if;
    end process;
    
    p_disp : process(scan, d0, d1, d2, d3)
    begin
        case scan is
            when 0 => 
                seg_data <= dec_7_seg(d0);
                seg_com <= "1110";
            when 1 => 
                seg_data <= dec_7_seg(d1);
                seg_com <= "1101";
            when 2 => 
                seg_data <= dec_7_seg(d2);
                seg_com <= "1011";
            when 3 =>
                seg_data <= dec_7_seg(d3);
                seg_com <= "0111";
            when others =>
                seg_data <= x"00";
                seg_com <= "1111";
        end case;
    end process;
end d_7seg_arch;

If you need more details, please write comments. I'm sorry for my bad English.

Community
  • 1
  • 1
김정우
  • 23
  • 4
  • 5
    You have not declared signal `code`. – Matthew Taylor Nov 20 '19 at 16:21
  • Your English is great! What you need to do with these sorts of error messages is to go to the line number it mentions (53 in this case), and look *really* carefully at what is happening on that line. Check every part of it, and often you can work out the problem for yourself in much less time than it takes to write a detailed SO question like the one you have asked here. If there are many errors, start with the first one. – scary_jeff Nov 21 '19 at 09:11
  • Hi, Matthew. I really appreciate you to reply my question and I'm so sorry to comment you too late. I solved this problem thanks to your advice. Thank you. – 김정우 Sep 05 '20 at 07:21

0 Answers0