yousuf14
Newbie level 6
the code in is below for programming the LCD to display using the spartan 3E instead of the pico blaze :
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity LCD is
port(
LCD_RS:out std_logic;
LCD_RW:out std_logic;
LCD_E:out std_logic;
clk:in std_logic;
SF_D:out std_logic_vector(3 downto 0);
S:in std_logic
);
end LCD;
architecture Behavioral of LCD is
signal substate,state,clock,clk1: integer:=0;
begin
process(clk)
begin
clk1<=clk1+1;
if(clk1=0) then
clock<=clock+1;
--WRITE FUCNTION SET COMMAND SF_D<=0x28
if(state=0) then
if(substate=0 and clock=0) then
LCD_RS<='0';
LCD_RW<='0';
SF_D<="0010";
Clock<=0;
substate<=1;
elsif(substate=1 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=2;
elsif(substate=2 and clock=12) then
LCD_E<='0';
substate<=3;
Clock<=0;
elsif(substate=3 and clock=498) then
SF_D<="1000";
Clock<=0;
substate<=4;
elsif(substate=4 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=5;
elsif(substate=5 and clock=12) then
LCD_E<='0';
substate<=0;
state<=1;
Clock<=0;
end if;
--WAIT 2000 CLOCK
elsif(state=1 and clock=2000) then
state<=2;
clock<=0;
--WRITE ENTRY MODE SET COMMAND SF_D<=0x06
elsif(state=2) then
if(substate=0 and clock=0) then
LCD_RS<='0';
LCD_RW<='0';
SF_D<="0000";
Clock<=0;
substate<=1;
elsif(substate=1 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=2;
elsif(substate=2 and clock=12) then
LCD_E<='0';
substate<=3;
Clock<=0;
elsif(substate=3 and clock=498) then
SF_D<="0110";
Clock<=0;
substate<=4;
elsif(substate=4 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=5;
elsif(substate=5 and clock=12) then
LCD_E<='0';
substate<=0;
state<=3;
Clock<=0;
end if;
--WAIT 2000 CLOCK
elsif(state=3 and clock=2000) then
state<=4;
clock<=0;
--WRITE DISPLAY ON/OFF COMMAND SF_D<=0x0C
elsif(state=4) then
if(substate=0 and clock=0) then
LCD_RS<='0';
LCD_RW<='0';
SF_D<="0000";
Clock<=0;
substate<=1;
elsif(substate=1 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=2;
elsif(substate=2 and clock=12) then
LCD_E<='0';
substate<=3;
Clock<=0;
elsif(substate=3 and clock=498) then
SF_D<="1100";
Clock<=0;
substate<=4;
elsif(substate=4 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=5;
elsif(substate=5 and clock=12) then
LCD_E<='0';
substate<=0;
state<=5;
Clock<=0;
end if;
--WAIT FOR 2000 CLOCK
elsif(state=5 and clock=2000) then
state<=6;
clock<=0;
--WRITE CLEAR DISPLAY COMMAND SF_D<=0x HAVE TO FIX THIS
elsif(state=6) then
if(substate=0 and clock=0) then
LCD_RS<='0';
LCD_RW<='0';
SF_D<="0000";-- I HAVE FIXED IT
Clock<=0;
substate<=1;
elsif(substate=1 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=2;
elsif(substate=2 and clock=12) then
LCD_E<='0';
substate<=3;
Clock<=0;
elsif(substate=3 and clock=498) then
SF_D<="0001";-- I HAVE FIXED IT
Clock<=0;
substate<=4;
elsif(substate=4 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=5;
elsif(substate=5 and clock=12) then
LCD_E<='0';
substate<=0;
state<=7;
Clock<=0;
end if;
--WAIT FOR 82,000 CLOCK
elsif(state=7 and clock=82000) then
state<=8;
clock<=0;
--WRITE SET DD RAM ADD SF_D<=0x HAVE TO FIX THIS
elsif(state=8) then
if(substate=0 and clock=0) then
LCD_RS<='0';
LCD_RW<='0';
SF_D<="1000";--IT HAS BEEN FIXED
Clock<=0;
substate<=1;
elsif(substate=1 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=2;
elsif(substate=2 and clock=12) then
LCD_E<='0';
substate<=3;
Clock<=0;
elsif(substate=3 and clock=498) then
SF_D<="0000";-- IT HAS BEEN FIXED
Clock<=0;
substate<=4;
elsif(substate=4 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=5;
elsif(substate=5 and clock=12) then
LCD_E<='0';
substate<=0;
state<=9;
Clock<=0;
end if;
--WAIT FOR 2,000 CLOCK
elsif(state=9 and clock=2000) then
state<=10;
clock<=0;
--WRITE DD RAM ADD SF_D<=0x HAVE TO FIX THIS
elsif(state=10) then
if(substate=0 and clock=0) then
LCD_RS<='1';
LCD_RW<='0';
SF_D<="1000";--IT HAS BEEN FIXED
Clock<=0;
substate<=1;
elsif(substate=1 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=2;
elsif(substate=2 and clock=12) then
LCD_E<='0';
substate<=3;
Clock<=0;
elsif(substate=3 and clock=498) then
SF_D<="0000";-- IT HAS BEEN FIXED
Clock<=0;
substate<=4;
elsif(substate=4 and clock=2) then
LCD_E<='1';
Clock<=0;
substate<=5;
elsif(substate=5 and clock=12) then
LCD_E<='0';
substate<=0;
state<=11;
Clock<=0;
end if;
elsif(state=11)then
state<=11;
clock<=0;
end if;
elsif(clk1=1) then
clk1<=0;
end if;
end process;
end Behavioral;