Exp 4 LCD
Exp 4 LCD
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity chardisplay is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
data : out STD_LOGIC_VECTOR (7 downto 0);
en : out STD_LOGIC;
rs : out STD_LOGIC);
end chardisplay;
begin
process(clk, reset)
begin
if reset = '1' then
state <= 0;
index <= 0;
data <= (others => '0'); -- Default value for data
en <= '0'; -- Default value for enable
rs <= '0'; -- Default value for register select
counter <= 0;
elsif rising_edge(clk) then
case state is
when 0 =>
rs <= '0'; -- Instruction mode
data <= "00111000"; -- Function set: 8-bit mode, 2
lines, 5x8 dots
en <= '1'; -- Enable signal high for
initialization
state <= 1;
when 1 =>
en <= '0'; -- Disable enable after the
command
counter <= counter + 1;
if counter >= clk_div then
counter <= 0;
rs <= '0'; -- Instruction mode
data <= "00001100"; -- Display ON, cursor OFF
en <= '1'; -- Enable signal high for next
command
state <= 2;
end if;
when 2 =>
en <= '0'; -- Disable enable after the
command
counter <= counter + 1;
if counter >= clk_div then
counter <= 0;
rs <= '0'; -- Instruction mode
data <= "00000001"; -- Clear display
en <= '1'; -- Enable signal high for clear
command
state <= 3;
end if;
when 3 =>
en <= '0'; -- Disable enable after the
command
counter <= counter + 1;
if counter >= clk_div then
counter <= 0;
if index < 13 then -- For " WELCOME I2IT" (13
characters with leading space)
rs <= '1'; -- Data mode
data <= msg(index); -- Send character from the
message array
en <= '1'; -- Enable signal high for
character data
index <= index + 1;
else
state <= 4; -- Finished displaying message
end if;
end if;
when 4 =>
en <= '0'; -- Stay in this state to do
nothing
end if;
end process;
end Behavioral;