Keyboard PS2

Discussion in 'Embedded Systems and Microcontrollers' started by bacho31, Nov 5, 2010.

  1. bacho31

    Thread Starter New Member

    Nov 5, 2010
    1
    0
    Hi,
    i have the following code:

    Code ( (Unknown Language)):
    1.  
    2. Library altera,IEEE,lpm;
    3. use altera.maxplus2.all;
    4. use IEEE.STD_LOGIC_1164.all;
    5. USE lpm.lpm_components.ALL;
    6. use IEEE.STD_LOGIC_ARITH.all;
    7. use IEEE.STD_LOGIC_signed.all;
    8. entity Keyboard is
    9.   Generic(DATA_LENGTH : integer := 9);
    10.        port( reset : in std_Logic;
    11.              Keyboard_DATA, Keyboard_CLOCK : in std_logic;
    12.              clock : in std_Logic;
    13.              parity_D,stopbit_D : out std_logic;
    14.              key_stroke : out std_logic;
    15.              k_data_D : out std_logic_vector(7 downto 0);
    16.                key_ascii_D : out std_logic_vector(7 downto 0));
    17. end Keyboard;
    18. architecture behavioral of Keyboard is
    19.     signal k_data : std_logic_vector(DATA_LENGTH downto 0);
    20.     signal key_ascii : std_logic_vector(5 downto 0);
    21.     signal receive_key : std_logic := '0';
    22.     signal start,stop_getkey : std_logic := '0';
    23.     signal cnt : std_logic_vector(3 downto 0) := "0000";
    24.     signal filter : std_logic_vector(7 downto 0);
    25.     signal keyboard_clk_filt : std_logic;
    26.     signal parityok : std_logic := '0';
    27.     signal shift_key : std_logic := '0';
    28.   -- Function Defined to Check the parity of the input signal.
    29.   -- If the parity is correct, a '1' is returned else it is a '0';          
    30.     function paritycheck(p_data : in std_logic_vector(8 downto 0)) return std_logic is
    31.           variable Result: std_logic :='0';
    32.     begin
    33.       xor_loop:
    34.       FOR N IN p_data'range LOOP
    35.          Result := Result xor p_data(N);
    36.       END LOOP xor_loop;
    37.       return Result;
    38.     end function paritycheck;
    39.     begin
    40. process (start, clock, cnt)
    41. variable cntclk : std_logic_vector(14 downto 0);
    42. begin
    43. wait until clock'event and clock = '1';
    44. if start = '0' or cnt = "0000" then
    45.    cntclk := "000000000000000";
    46.    stop_getkey <= '0';
    47. else
    48.    cntclk := cntclk + 1;
    49.    if cntclk = "100111010000100" then
    50.       stop_getkey <= '1';
    51.    end if;
    52. end if;
    53. end process;
    54. process
    55. begin
    56.   wait until clock'event and clock='0';
    57.   filter(6 downto 0) <= filter(7 downto 1);
    58.   filter(7) <= keyboard_clock;
    59.   if filter = "00000000" then keyboard_clk_filt <= '0';
    60.   else keyboard_clk_filt <= '1';
    61.   end if;
    62. end process;
    63. process
    64. variable cnter : std_logic_vector(3 downto 0) := "0000";
    65. begin
    66.   wait until keyboard_clk_filt'event and keyboard_clk_filt = '0';
    67.  
    68.   if keyboard_data ='0' and start = '0' then --(start = '0' or stop_getkey = '1') then
    69.     start <= '1';
    70.     cnter := "0000";
    71.     k_data <= "0000000000";
    72.   else
    73.     if start = '1' then
    74.         cnter := cnter + 1;
    75.     case cnter(3 downto 0) is
    76.      when "0001" => k_data(0) <= Keyboard_DATA;
    77.      when "0010" => k_data(1) <= Keyboard_DATA;
    78.      when "0011" => k_data(2) <= Keyboard_DATA;
    79.      when "0100" => k_data(3) <= Keyboard_DATA;
    80.      when "0101" => k_data(4) <= Keyboard_DATA;
    81.      when "0110" => k_data(5) <= Keyboard_DATA;
    82.      when "0111" => k_data(6) <= Keyboard_DATA;
    83.      when "1000" => k_data(7) <= Keyboard_DATA;
    84.      when "1001" => k_data(8) <= Keyboard_DATA;
    85.      when others => k_data(9) <= Keyboard_DATA;
    86.            start <= '0';
    87.            receive_key <= not receive_key;      
    88.     end case;  
    89.   end if;
    90.   end if;        
    91.   cnt <= cnter;
    92. end process;  -- keyboard clock process
    93. scancode_rom: lpm_rom
    94.       GENERIC MAP ( lpm_widthad => 8,
    95.        [COLOR=Red]lpm_numwords => "256",[/COLOR]
    96.         lpm_outdata => "UNREGISTERED",
    97.         lpm_address_control => "UNREGISTERED",
    98. -- Reads in mif file for character generator data
    99.          lpm_file => "scancode.mif",
    100.          lpm_width => 6)
    101.       PORT MAP ( --inclock => clock,
    102.                  address => k_data(7 downto 0),
    103.                  q => key_ascii);
    104. parityok <= paritycheck(k_data(8 downto 0));
    105. process
    106.   variable tmp_stroke, cur_key, break_code : std_logic := '0';
    107. begin
    108.   wait until clock'event and clock ='1';
    109.   if reset = '1' then
    110.     key_ascii_D <= "00100000";
    111.   else
    112.     k_data_d <= k_data(7 downto 0);
    113.     if cur_key /= receive_key then
    114.         cur_key := receive_key;
    115.         parity_D <= parityok;
    116.         stopbit_D <= k_data(9);        
    117.            if break_code = '0' then
    118.             if k_data(7 downto 0) = "11110000" then
    119.                 break_code := '1';
    120.             else
    121.                 --do we have a valid key?
    122.                 --if k_data(9) = '1' and parityok = '1' then
    123.                 -- stop bit and parity check out ok
    124.                 -- the return, backspace, and shift keys all return key_ascii value
    125.                 -- of "111111" since these characters are not mapped directly to the
    126.                  -- tiny character generator ROM.  Therefore, we assume (by default) that
    127.                 -- any key_ascii value not "111111" is a valid mapped key.
    128.                    if key_ascii /= "111111" then
    129.                        key_ascii_D(7 downto 0) <= "00" & key_ascii(5 downto 0);
    130.                      tmp_stroke := not tmp_stroke;
    131.                         key_stroke <= tmp_stroke;
    132.                       elsif k_data(7 downto 0) = "01011010" or  -- return
    133.                          k_data(7 downto 0) = "01100110" then  --backspace
    134.                        key_ascii_D(7 downto 0) <= k_data(6 downto 5) & "000000";
    135.                        tmp_stroke := not tmp_stroke;
    136.                           key_stroke <= tmp_stroke;
    137.                    end if;
    138.                    if k_data(7 downto 0) = "00010010" or --Left Shift
    139.                       k_data(7 downto 0) = "01011001" then  -- Right Shift
    140.                      shift_key <= '1';
    141.                    end if;
    142.                 --end if; -- if k_data(9)
    143.               end if; -- if k_data(7 downto 0)
    144.       else
    145.             break_code := '0';
    146.             -- turn off shift during the break portion
    147.              if --k_data(9) = '1' and parityok = '1' and
    148.                (k_data(7 downto 0) = "00010010" or
    149.                 k_data(7 downto 0) = "01011001") then
    150.                shift_key <= '0';
    151.             end if;
    152.   end if; -- if break_code
    153.   end if; -- if cur_key
    154. end if; -- if reset
    155. end process;
    156. end behavioral;
    157.  
    The problem is taht show me the next:

    Error (10515): VHDL type mismatch error at keyboard.vhd(94): natural type does not match string literal

    This error is in the line with red color.

    please helpme....PD: I need show the keyboard in monitor with PS2 connector....is the code correct???

    thanks.....
     
    Last edited by a moderator: Nov 5, 2010
  2. jamesbowman

    New Member

    Nov 6, 2010
    1
    0
    Looks like you don't need those quotes around "256".
     
Loading...