Monday, July 20, 2009

Please correct my KeyBoard Interface code

I am interfacing the keyboard with LCD on spartan-3e kit every thing is going well but when i dump the code on the kit to check it i am facing a problem: The problem is when i am typing the keyboard(KB) characters each and every character is getting displayed but on the same address that is, when i press A on KeyBoard it is displayed on the 00(1st) location on the LCD screen & later when i press B it is also displayed on the same 00(1st) location on the LCD screen by overwrighting A (but it must be displayed next to A).Can any one please fix my code

Code: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity KB_2 is Port ( FPGAclk,rst : in STD_LOGIC; Lcd_on : in STD_LOGIC; KB_Clk : inout STD_LOGIC; KB_Data : inout STD_LOGIC; sf_ce0 : out STD_LOGIC; rs : out STD_LOGIC; rw : out STD_LOGIC; en : out STD_LOGIC; q_LED : out STD_LOGIC_VECTOR (7 downto 0); q : out STD_LOGIC_VECTOR (3 downto 0)); end KB_2; architecture KB_2 of KB_2 is --********************************************************************************-- --**************************KEY BOARD SIGNAL DECLARATION**************************-- --********************************************************************************-- signal KBD_Temp : STD_LOGIC_VECTOR (7 downto 0):="00000000"; signal KBD_Temp2 : STD_LOGIC_VECTOR (7 downto 0):="00000000"; signal count_KB : INTEGER range 0 to 43; --********************************************************************************-- --**************************LCD SIGNAL DECLARATION********************************-- --********************************************************************************-- signal lcd_temp : STD_LOGIC_VECTOR (5 downto 0); signal lcd_stuff : STD_LOGIC_VECTOR (6 downto 0) := "0000000" ; signal lcd_count : STD_LOGIC_VECTOR (26 downto 0):= "000000000000000000000000000"; signal lcd_en : STD_LOGIC := '0' ; signal b : STD_LOGIC := '1' ; begin --**********************************************************************************-- --****************************Scan Code Detection Process*************************-- --**********************************************************************************-- Process Begin wait until KB_Clk='0' and KB_Clk'event; count_KB <= count_KB+1; if (count_KB >= 1 and count_KB < count_kb ="10)" fpgaclk="'1'">KBD_Temp2<=X"41"; --A when X"32"=>KBD_Temp2<=X"42"; --B when X"21"=>KBD_Temp2<=X"43"; --C when X"23"=>KBD_Temp2<=X"44"; --D when X"24"=>KBD_Temp2<=X"45"; --E when X"2B"=>KBD_Temp2<=X"46"; --F when X"34"=>KBD_Temp2<=X"47"; --G when X"33"=>KBD_Temp2<=X"48"; --H when X"43"=>KBD_Temp2<=X"49"; --I when X"3B"=>KBD_Temp2<=X"4A"; --J when X"42"=>KBD_Temp2<=X"4B"; --K when X"4B"=>KBD_Temp2<=X"4C"; --L when X"3A"=>KBD_Temp2<=X"4D"; --M when X"31"=>KBD_Temp2<=X"4E"; --N when X"44"=>KBD_Temp2<=X"4F"; --O when X"4D"=>KBD_Temp2<=X"50"; --P when X"15"=>KBD_Temp2<=X"51"; --Q when X"2D"=>KBD_Temp2<=X"52"; --R when X"1B"=>KBD_Temp2<=X"53"; --S when X"2C"=>KBD_Temp2<=X"54"; --T when X"3C"=>KBD_Temp2<=X"55"; --U when X"2A"=>KBD_Temp2<=X"56"; --V when X"1D"=>KBD_Temp2<=X"57"; --W when X"22"=>KBD_Temp2<=X"58"; --X when X"35"=>KBD_Temp2<=X"59"; --Y when X"1A"=>KBD_Temp2<=X"5A"; --Z when X"0E"=>KBD_Temp2<=X"60"; --` when X"16"=>KBD_Temp2<=X"31"; --1 when X"1E"=>KBD_Temp2<=X"32"; --2 when X"26"=>KBD_Temp2<=X"33"; --3 when X"25"=>KBD_Temp2<=X"34"; --4 when X"2E"=>KBD_Temp2<=X"35"; --5 when X"36"=>KBD_Temp2<=X"36"; --6 when X"3D"=>KBD_Temp2<=X"37"; --7 when X"3E"=>KBD_Temp2<=X"38"; --8 when X"46"=>KBD_Temp2<=X"39"; --9 when X"45"=>KBD_Temp2<=X"30"; --0 when X"55"=>KBD_Temp2<=X"3D"; --= when X"4E"=>KBD_Temp2<=X"2D"; --- when X"54"=>KBD_Temp2<=X"5B"; --[ when X"5B"=>KBD_Temp2<=X"5D"; --] when X"4C"=>KBD_Temp2<=X"3B"; --; when X"52"=>KBD_Temp2<=X"27"; --' when X"41"=>KBD_Temp2<=X"2C"; --, when X"49"=>KBD_Temp2<=X"2E"; --. when X"4A"=>KBD_Temp2<=X"2F"; --/ when X"29"=>KBD_Temp2<=X"20"; --space when others=>null; end case; q_LED <= KBD_Temp2; end if; end process; --********************************************************************************-- --++++++++++++++++++++++++++LCD Initialisation Process++++++++++++++++++++++++++++-- --********************************************************************************-- process begin wait until FPGAclk ='1' and FPGAclk'event; lcd_count <=lcd_count + "0000000000000000000000001"; sf_ce0 <= '1'; case lcd_count(24 downto 18) is --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- --*************************LCD Commands for Initialisation************************-- --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- when "0000000" => lcd_temp <= "000011";--3 when "0000001" => lcd_temp <= "000011";--3 when "0000010" => lcd_temp <= "000011";--3 when "0000011" => lcd_temp <= "000010";--2 when "0000100" => lcd_temp <= "000010"; when "0000101" => lcd_temp <= "001000";--28 when "0000110" => lcd_temp <= "000000"; when "0000111" => lcd_temp <= "000110";--06 when "0001000" => lcd_temp <= "000000"; when "0001001" => lcd_temp <= "001100";--0c when "0001010" => lcd_temp <= "000000"; when "0001011" => lcd_temp <= "000001";--01 when "0001100" => lcd_temp <= "001000"; when "0001101" => lcd_temp <= "000000";--80 1st line addr when "0001110" => lcd_temp <= "000000"; when "0001111" => lcd_temp <= "001100";--return cursor home --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- --*************************Sending Data To LCD************************************-- --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- when "0011000" => lcd_temp(5 downto 4) <= "10"; lcd_temp(3 downto 0) <=KBD_Temp2(7 downto 4); when "0011001" => lcd_temp(5 downto 4) <= "10"; lcd_temp(3 downto 0) <=KBD_Temp2(3 downto 0); when "0011010" => lcd_temp(5 downto 4) <= "10"; lcd_temp(3 downto 0) <="0010"; when "0011011" => lcd_temp(5 downto 4) <= "10"; lcd_temp(3 downto 0) <="0000"; -- space when "0011100" => lcd_temp(5 downto 4) <= "10"; lcd_temp(3 downto 0) <="0010"; when "0011101" => lcd_temp(5 downto 4) <= "10"; lcd_temp(3 downto 0) <="0000"; -- space when others =>lcd_temp <= "010000"; end case; --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- --*************************LCD enable pin operation & assigning data to output****-- --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- b<= lcd_count(17) or lcd_count(16); lcd_en <= b and not lcd_temp(4);--lcd enable pin process lcd_stuff(6) <= lcd_en; lcd_stuff(5 downto 0) <= lcd_temp; (en,rs,rw,q(3),q(2),q(1),q(0)) <= lcd_stuff; end process; end KB_2;

No comments:

Post a Comment