0% found this document useful (0 votes)
286 views

VHDL Code For LCD Display

The document describes an experiment to display a name on an LCD screen using a Universal VTU trainer protoboard. It provides the required apparatus including software tools and hardware components. It then provides the VHDL code implementation for an LCD module including entity declaration, architecture, state machines, signals, and processes to initialize and write characters to the LCD screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
286 views

VHDL Code For LCD Display

The document describes an experiment to display a name on an LCD screen using a Universal VTU trainer protoboard. It provides the required apparatus including software tools and hardware components. It then provides the VHDL code implementation for an LCD module including entity declaration, architecture, state machines, signals, and processes to initialize and write characters to the LCD screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment No.

— 17

AIM
To display our name on the LCD screen of Universal VTU trainer
protoboard.

Apparatus Required
Software Xilinx
– ISE iMPACT
Xilinx (M.63c)
ISE Project 12.2 (M.63c) 12.2
Navigator
Xilinx ISim Simulator (M.63c) 12.2
Hardware MTE Universal VTU trainer MXS3FK-VTU
– protoboard.
Code implementation

--libraries to be used are specified here


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use
IEEE.STD_LOGIC_UNSIGNED.ALL;

entity lcd is
Port ( RS:out
LCD_DB:std_logic;
out --WE
std_logic_vector(7
RW:out downto --ADR(0)
0);--DB( 7 through 0)
std_logic; --GCLK2
CLK:in std_logic; --ADR(1)
--ADR1:out --ADR(2)
std_logic; --CSC
--ADR2:out --OE
std_logic;
rst:in std_logic ); --BTN
--rdone:
--CS:out out std_logic);
std_logic; --WriteDone output to work
with DI05std_logic;
OE:out test
end lcd;

architecture Behavioral of lcd is

-- Component Declarations

-- Local Type Declarations

-- Symbolic names for all possible states of the state


machines.
--LCD control state machine
type mstate is (
stFunctionSet, --Initialization states
stDisplayCtrlSet,
stDisplayClear,
stPowerOn_Delay, --Delay states
stFunctionSet_Delay,
stDisplayCtrlSet_Delay,
stDisplayClear_Delay,
stInitDne, --Display charachters and perform standard
operations
stCharDelay
stActWr, --Write delay for operations
--stWait --Idle state
);

--Write control state machine


type wstate is (
stRW, --set up RS and RW
stEnable, --set up E
stIdle --Write data on DB(0)-DB(7)
);

-- Signal Declarations and Constants

--These constants are used to initialize the LCD pannel.

--FunctionSet:
--Bit 0 and 1 are arbitrary
--Bit 2: Displays font type(0=5x8, 1=5x11)
--Bit 3: Numbers of display lines (0=1, 1=2)
--Bit 4: Data length (0=4 bit, 1=8 bit)
--Bit 5-7 are set
--DisplayCtrlSet:
--Bit 0: Blinking cursor control (0=off, 1=on)
--Bit 1: Cursor (0=off, 1=on)
--Bit 2: Display (0=off, 1=on)
--Bit 3-7 are set
--DisplayClear:
--Bit 1-7 are set
signal clkCount:std_logic_vector(5 downto 0);
signal activateW:std_logic:= '0'; --Activate Write
sequence signal count:std_logic_vector(16 downto 0):=
"00000000000000000";
--15 bit count variable for timing delays
signal delayOK:std_logic:= '0'; --High when count has reached
the
--right delay time
signal OneUSClk:std_logic;--Signal is treated as a 1 MHz clock
signal stCur:mstate:= stPowerOn_Delay; --LCD control state
machine signal stNext:mstate;
signal stCurW:wstate:= stIdle; --Write control state machine
signal stNextW:wstate;
signal writeDone:std_logic:= '0'; --Command set finish

type LCD_CMDS_T is array(integer range <>) of std_logic_vector(9


downto 0);
1 => "00"&X"0C",
constant --Display ON,
LCD_CMDS : LCD_CMDS_T := (Cursor OFF, Blink OFF
0 => "00"&X"3C",
2 => "00"&X"01", --Clear Display --Function Set
3 => "00"&X"02", --return home

4 => "10"&X"50", --P


5 => "10"&X"72", --r
6 => "10"&X"61", --a
7 => "10"&X"76", --v
8 => "10"&X"65", --e
9 => "10"&X"65", --e
10 => "10"&X"6E", --n
11 => "10"&X"48", --space

12 => "10"&X"56", --V


13 => "10"&X"61", --a
14 => "10"&X"69", --i
15 => "10"&X"73", --s
16 => "10"&X"68", --h
17 => "10"&X"6E", --n
18 => "10"&X"61", --a
19 => "10"&X"76", --v
20 => "10"&X"20", --space
21 => "10"&X"20", --space
22 => "10"&X"20", --space
23 => "00"&X"18"); --Shifts left

signal lcd_cmd_ptr : integer range 0 to LCD_CMDS'HIGH + 1 := 0;


begin

-- This process counts to 50, and then resets. It is used to


divide
-- the clock signal
time. process (CLK,
oneUSClk)
begin
if (CLK = '1' and CLK'event) then
clkCount <= clkCount + 1;
end if;
end process;
-- This makes oneUSClock peak once
every 1 microsecond

oneUSClk <= clkCount(5);


-- This process incriments the count variable unless delayOK = 1.
process (oneUSClk, delayOK)
begin
if (oneUSClk = '1' and oneUSClk'event) then
if delayOK = '1' then
count <= "00000000000000000";
else
count <= count + 1;
end if;
e
n
d
i
f
;
e
n
d
p
r
o
c
e
s
s
;

--This goes high when all commands have been run


writeDone <= '1' when (lcd_cmd_ptr =
LCD_CMDS'HIGH)
end if;
end if;
end process;

-- Determines
when count has gotten
to the right number,
-- depending on
"00100111001010010")
the state. or --20050
(stCur = stFunctionSet_Delay and count =
"00000000000110010")
delayOK <= or
'1' --50
when ((stCur = (stCur = stDisplayCtrlSet_Delay and count =
"00000000000110010") or --50
stPowerOn_Delay and (stCur = stDisplayClear_Delay and count =
count =
"00000011001000000") or --1600
(stCur = stCharDelay and count =
"11111111111111111")) --Max Delay for character writes
and shifts
"00000000000100101"))--37 --(stCur = stCharDelay and count
else '0'; =
This is proper delay between
-- This process runs the LCD to
writes status
ram. state machine
process (oneUSClk, rst)
begin
if oneUSClk = '1' and oneUSClk'Event then
if rst = '1' then
stCur <= stPowerOn_Delay;
else
stCur <= stNext;
end if;
e
n
d
i
f
;
e
n
d
p
r
o
c
e
s
s
;

-- This
process generates
the sequence of
outputs needed to
-- initialize and write to the LCD screen
process (stCur, delayOK, writeDone,
lcd_cmd_ptr)
begin

case stCur is

-- Delays the state machine for 20ms which is


needed for proper startup.
when stPowerOn_Delay =>
if delayOK = '1' then
stNext <= stFunctionSet_Delay;

-- Gives the proper delay of 37us between the function set and
-- the display control set.
when stFunctionSet_Delay =>
RS <= LCD_CMDS(lcd_cmd_ptr)(9);
RW <= LCD_CMDS(lcd_cmd_ptr)
(8);
LCD_DB <= LCD_CMDS(lcd_cmd_ptr)
(7 downto 0);
activateW <= '0';
if delayOK = '1' then
stNext <=
stDisplayCtrlSet;
else
stNext <= stFunctionSet_Delay;
end if;

-- Issuse the display control set as follows


-- Display ON, Cursor OFF, Blinking Cursor OFF.
when stDisplayCtrlSet =>
RS <=
LCD_CMDS(lcd_cmd_ptr)(9); RW
<= LCD_CMDS(lcd_cmd_ptr)(8);
LCD_DB <=
LCD_CMDS(lcd_cmd_ptr)(7 downto
0);
activateW <= '1';
stNext <=
stDisplayCtrlSet_Delay;

-- Gives the proper delay of 37us between the


display control set
-- and the Display Clear command.
when stDisplayCtrlSet_Delay =>
RS <=
LCD_CMDS(lcd_cmd_ptr)(9); RW
<= LCD_CMDS(lcd_cmd_ptr)(8);
LCD_DB <=
LCD_CMDS(lcd_cmd_ptr)(7 downto
0);
activateW <= '0';
if delayOK = '1' then
stNext <=
stDisplayClear;
else
stNext <= stDisplayCtrlSet_Delay;
end if;

-- Issues the display clear command.


when stDisplayClear =>
RS <=
LCD_CMDS(lcd_cmd_ptr)(9); RW
<= LCD_CMDS(lcd_cmd_ptr)(8);
LCD_DB <=
LCD_CMDS(lcd_cmd_ptr)(7 downto
0);
activateW <= '1';
stNext <=
stDisplayClear_Delay;

-- Gives the proper delay of 1.52ms between


the clear command
-- and the state where you are clear to do normal
operations. when stDisplayClear_Delay =>
when stInitDne =>
RS <= LCD_CMDS(lcd_cmd_ptr)(9);
RW <= LCD_CMDS(lcd_cmd_ptr)
(8);
LCD_DB <= LCD_CMDS(lcd_cmd_ptr)
(7 downto 0);
activateW <= '0';
stNext <= stActWr;

when stActWr =>


RS <= LCD_CMDS(lcd_cmd_ptr)(9);
RW <= LCD_CMDS(lcd_cmd_ptr)
(8);
LCD_DB <= LCD_CMDS(lcd_cmd_ptr)
(7 downto 0);
activateW <= '1';
stNext <= stCharDelay;

-- Provides a max delay between


instructions.
when stCharDelay =>
RS <= LCD_CMDS(lcd_cmd_ptr)(9);
RW <= LCD_CMDS(lcd_cmd_ptr)
(8);
LCD_DB <= LCD_CMDS(lcd_cmd_ptr)
(7 downto 0);
activateW <= '0';
if delayOK = '1' then
stNext <= stInitDne;
else
stNext <= stCharDelay;
end if;
end case;

end process;

-- This process runs the write state


machine process (oneUSClk, rst)
begin
if oneUSClk = '1' and oneUSClk'Event then
if rst = '1' then
stCurW <= stIdle;
else
stCurW <= stNextW;
end if;
e
n
d
i
f
;
e
n
d
p
r
o
c
e
s
s
;

-- This
when stEnable =>
OE <= '0';
--CS <= '0';
--ADR2 <= '0';
--ADR1 <= '0';
stNextW <= stIdle;

-- Waiting for the write command from the instuction state


machine when stIdle =>
--ADR2 <= '0';
--ADR1 <= '0';
--CS <= '1';
OE <= '1';
if activateW = '1' then
stNextW <= stRw;
else
stNextW <= stIdle;
end if;
end case;
end process;

end Behavioral;

The user constraints given are as follows:

net lcd_db(0) loc


= p46; net lcd_db(1)
loc = p43; net
lcd_db(2) loc = p44;
net lcd_db(3) loc = p40;
net lcd_db(4) loc =
p42; net lcd_db(5) loc
= p37; net lcd_db(6)
loc = p39; net
lcd_db(7) loc = p35;
net rs loc = p48;
net rw loc = p50;
net oe loc =
p45; net clk loc =
p76; net rst loc =
p190;

RTL Schematic generated by Xilinx ISE Project Navigator

You might also like