Sie sind auf Seite 1von 13

Special topic #1: LCD Module on DE2 Board

In this section, an application example of FSM for LCD display will be presented. In order to
use the LCD module on DE board, appropriate data communication between F!"# and LCD
module is re$uired. %ne can desi&n an FSM to achie'e this communication. First, F!"# lo&ic
&enerates di&ital cloc( si&nals )hours, minutes, and seconds*+ then an FSM desi&ned in F!"#
deli'ers the di&ital cloc( si&nals to LCD module, accordin& to interface re$uirements, such as
data format and timin& constraints.
1. LCD module on DE2 board
%n the #ltera DE F!"# de'elopment board, there is a Li$uid Crystal Display )LCD*
module that can be used to display text by sendin& appropriate commands from F!"# chip to the
LCD module. ,here is a built-in controller .D//012 in the LCD module to dri'e the display. ,he
interface between F!"# chip and the LCD module is shown in Fi&.3.
Fi&.3 ,he interface between F!"# chip and LCD module
LCD4%5 )hi&h-acti'e* turns on the power of LCD module.
LCD46L%5 controls the LCD bac( li&ht.
LCD4D#,# 72809 is an 1-bit data bus for their data communication.
LCD4:; defines the direction of data bus )LCD4:;<3 for read8 from LCD to F!"#+
LCD4:;<2 for write8 from F!"# to LCD*.
LCD4E5 is a read=write enable si&nal, i.e., a fallin& ed&e on LCD4E5 is re$uired for a data
read=write operation.
LCD4:S is a Data=Command select si&nal, i.e., LCD4D#,# 72809 is data for display when
LCD4:S is >3?+ LCD4D#,# is a command )display clear, cursor shift and address information
etc.* if LCD4:S is >2?.
FPGA
L
C
D

d
i
s
p
l
a
y
(
c
o
n
t
r
o
l
l
e
r

H
D
4
4
7
8
0
i
n
c
l
u
d
e
d
)
LCD_ON
LCD_BLON
LCD_RW
LCD_RS
LCD_EN
LCD_DATA[0:7]
,he F!"# pin assi&nment of the interface is shown in ,able.3.3.
,able 3.3 LCD related pin assi&nments on DE
2. Function description of LCD module
1) Registers, DDRAM, and CR!M in LCD module
,he controller .D//012, built in LCD module, plays an important role in the LCD display
tas(. ,he controller communicates with F!"#, and controls the LCD display. ,he bloc( dia&ram
of .D//012 is shown in Fi&..
,he .D//012 has two 1-bit re&isters )I:, and D:* to store information sent from F!"#.
,he operation and selection of two re&isters are defined by ,able 3.. ,he I: )instruction
re&ister* stores instruction codes, such as display clear, cursor shift, and address information for
display data :#M )DD:#M* and character &enerator :#M )C":#M*. ,he I: can only be
written from F!"#. ,he D: )data re&ister* temporarily stores data to be written into DD:#M or
C":#M and temporarily stores data read from DD:#M or C":#M. .ere we only consider the
situation that data are written into DD:#M or C":#M. So, in our followin& discussion,
LCD4:; is always set to >2? for writin& only, unless otherwise stated. 6y LCD4:S, the data
LCD4D#,# 72809 is interpreted either as instruction codes )when LCD4:S<2* or as display data
)when LCD4:S<3*.
Fi&. .D//012 bloc( dia&ram

,able 1. :e&ister Selection
Fi&.@ the relationship between DD:#M addresses and positions on LCD
,he address counter )#C* recei'es an initial address throu&h I: based on a
command=instruction code, and assi&ns and updates addresses to both DD:#M and C":#M.
,he DD:#M is used to store the display data represented in 1-bit character codes and sent from
F!"#. Each address of DD:#M corresponds to a position on the LCD. ,he relationship between
DD:#M addresses and positions on LCD is shown in Fi&. @ )-by-3A character display*.
C"aracter enerator R!M #CR!M)$ ,he C":%M &enerate Bx1 dot or Bx32 dot
character patterns from 1-bit character codes. See ,able 3.@. For example, in order to display on
the first line position B, 1Ch@ should be written into the address )#C* 1Ch2/ of DD:#M.
,able 3.@ C":%M pattern )Bx1 dots*
2) %nstruction table
,able 3./ includes all a'ailable instructions to control LCD. ,he M!D=F!"# will send a
se$uence of instructions to LCD with appropriate timin& constraints. ,he instructions are di'ided
into two types8 3* command+ * data transfer. ,he command instructions ):S<2* are used to
initialiEe the LCD or set re$uired address. ,he data transfer instructions are used to send the data
)to be displayed on LCD* to LCD or read the data information from :#M in LCD built-in
controller ).D//012*.
,able 3./ Instruction table
&) 'iming re(uirements
,he M!D=F!"# should meet the followin& timin& re$uirements when it communicates with
LCD. For write operation #:=;<2*, a ne&ati'e ed&e of E )i.e. LCD4E5* is re$uired to send D6
)i.e. LCD4D#,# 72809* to LCD, as shown in Fi&./. For read operation, it is the same except that
:=; needs to be >3?.
Fi&. / ;ritin& operation
& %nitiali)ing of LCD
F!"# chip needs to send a series of initialiEation commands to initialiEe the LCD. ,hese
commands include function set, display off, display clear, and entry mode set. ,he datasheet
pro'ides a typical initialiEation process shown in Fi&.B.
Fi&. B InitialiEation steps
*. F+Acore LCD,Displa-$ LCD panel c"aracter displa-
C!M+!.E.' LCD4Display
+!R').ex4Display4Data8 %. /'D,L!%C,0EC'!R
))5um4.ex4Di&itsF/*-3 D!1.'! 2*+
reset, cloc(4/1M.E8 %. /'D,L!%C+
LCD4:S, LCD4E8 !2' /'D,L!%C+
LCD4:;8 %.!2' /'D,L!%C+
D#,#46DS8 %.!2' /'D,L!%C,0EC'!R)0 D!1.'! 2**+
E.D C!M+!.E.'3
,he LCD4Display core is used to display static #SCII characters and chan&in& hex 'alues
from hardware on the DECs 3A by line LCD display panel. ,he coreCs G.DL code can be
confi&ured internally by the user to display different #SCII strin&s and hex data fields.
Instructions can be found in comments in the coreCs G.DL code. # "eneric, Num_Hex_Digits, is
used to set the siEe of the .ex4Display4Data input )i.e., Each hex di&it displayed re$uires a /-bit
si&nal*. ,he LCD controller datasheet contains information on &raphics characters and LCD
commands. # state machine is used to send data and commands to the LCD controller and to
&enerate the re$uired handsha(e si&nals.
.ex4Display4Data contains the /-bit hexadecimal hardware si&nal 'alues to con'ert to
#SCII hex di&its and send to the LED display. ,he "eneric, 5um4.ex4Di&its, adHusts the siEe of
the input hex data.
LI6:#:I IEEE+
DSE IEEE.S,D4L%"IC433A/.all+
DSE IEEE.S,D4L%"IC4#:I,..all+
DSE IEEE.S,D4L%"IC4D5SI"5ED.all+
-- S;1 )"L%6#L :ESE,* resets LCD
E5,I,I LCD4Display IS
-- Enter number of li'e .ex hardware data 'alues to display
-- )do not count #SCII character constants*
"E5E:IC)5um4.ex4Di&its8 Inte&er8< *+

--
!%:,)reset, cl(4/1MhE 8 I5 S,D4L%"IC+
.ex4Display4Data 8 I5 S,D4L%"IC4GEC,%:))5um4.ex4Di&itsF/*-3 D%;5,% 2*+
LCD4:S, LCD4E 8 %D, S,D4L%"IC+
LCD4:; 8 %D, S,D4L%"IC+
D#,#46DS 8 I5%D, S,D4L%"IC4GEC,%:)0 D%;5,% 2**+
E5D E5,I,I LCD4Display+
#:C.I,EC,D:E a %F LCD4Display IS
,I!E character4strin& IS #::#I ) 2 ,% @3 * %F S,D4L%"IC4GEC,%:) 0 D%;5,% 2 *+
,I!E S,#,E4,I!E IS ).%LD, FD5C4SE,, DIS!L#I4%5, M%DE4SE,, !rint4Strin&,
LI5E, :E,D:54.%ME, D:%!4LCD4E, :ESE,3, :ESE,,
:ESE,@, DIS!L#I4%FF, DIS!L#I4CLE#:*+
SI"5#L state, next4command8 S,#,E4,I!E+
SI"5#L LCD4display4strin& 8 character4strin&+
-- Enter new #SCII hex data abo'e for LCD Display
SI"5#L D#,#46DS4G#LDE, 5ext4Char8 S,D4L%"IC4GEC,%:)0 D%;5,% 2*+
SI"5#L CLJ4C%D5,4/22.K8 S,D4L%"IC4GEC,%:)3L D%;5,% 2*+
SI"5#L C.#:4C%D5,8 S,D4L%"IC4GEC,%:)/ D%;5,% 2*+
SI"5#L CLJ4/22.K4Enable,LCD4:;4I5, 8 S,D4L%"IC+
SI"5#L Line34chars, Line4chars8 S,D4L%"IC4GEC,%:)30 D%;5,% 2*+
6E"I5
LCD4display4strin& M< )
-- #SCII hex 'alues for LCD Display
-- Enter Li'e .ex Data Galues from hardware here
-- LCD DIS!L#IS ,.E F%LL%;I5"8
------------------------------
--N Count<OO N
--N D!@ N
------------------------------
-- Line 3
OP/@P,OPAFP,OP0BP,OPAEP,OP0/P,OP@DP,
OP2P Q .ex4Display4Data)0 D%;5,% /*,OP2P Q .ex4Display4Data)@ D%;5,% 2*,
OP2P,OP2P,OP2P,OP2P,OP2P,OP2P,OP2P,OP2P,
-- Line
OP//P,OP/BP,OP@P,OP2P,OP2P,OPB0P,OPFEP,OP2P,
OP2P,OP2P,OP2P,OP2P,OP2P,OP2P,OP2P,OP2P*+
-- 6IDI:EC,I%5#L ,:I S,#,E LCD D#,# 6DS
D#,#46DS M< D#,#46DS4G#LDE ;.E5 LCD4:;4I5, < R2R ELSE PKKKKKKKKP+
-- &et next character in display strin&
5ext4Char M< LCD4display4strin&)C%5G4I5,E"E:)C.#:4C%D5,**+
LCD4:; M< LCD4:;4I5,+
!:%CESS
6E"I5
;#I, D5,IL CLJ4/1M.KREGE5, #5D CLJ4/1M.K < R3R+
IF :ESE, < R2R ,.E5
CLJ4C%D5,4/22.K M< OP22222P+
CLJ4/22.K4Enable M< R2R+
ELSE
IF CLJ4C%D5,4/22.K M OP2E#A2P ,.E5
CLJ4C%D5,4/22.K M< CLJ4C%D5,4/22.K S 3+
CLJ4/22.K4Enable M< R2R+
ELSE
CLJ4C%D5,4/22.K M< OP22222P+
CLJ4/22.K4Enable M< R3R+
E5D IF+
E5D IF+
E5D !:%CESS+
!:%CESS )CLJ4/1M.K, reset*
6E"I5
IF reset < R2R ,.E5
state M< :ESE,3+
D#,#46DS4G#LDE M< OP@1P+
next4command M< :ESE,+
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R3R+
ELSIF CLJ4/1M.KREGE5, #5D CLJ4/1M.K < R3R ,.E5
-- State Machine to send commands and data to LCD DIS!L#I
IF CLJ4/22.K4Enable < R3R ,.E5
C#SE state IS
-- Set Function to 1-bit transfer and line display with Bx1 Font siEe
-- see .itachi .D//012 family data sheet for LCD command and timin& details
;.E5 :ESE,3 <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP@1P+
state M< D:%!4LCD4E+
next4command M< :ESE,+
C.#:4C%D5, M< P22222P+
;.E5 :ESE, <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP@1P+
state M< D:%!4LCD4E+
next4command M< :ESE,@+
;.E5 :ESE,@ <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP@1P+
state M< D:%!4LCD4E+
next4command M< FD5C4SE,+
-- EO,:# S,#,ES #6%GE #:E 5EEDED F%: :ELI#6LE !DS.6D,,%5 :ESE, %F LCD
;.E5 FD5C4SE, <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP@1P+
state M< D:%!4LCD4E+
next4command M< DIS!L#I4%FF+
-- ,urn off Display and ,urn off cursor
;.E5 DIS!L#I4%FF <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP21P+
state M< D:%!4LCD4E+
next4command M< DIS!L#I4CLE#:+
-- Clear Display and ,urn off cursor
;.E5 DIS!L#I4CLE#: <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP23P+
state M< D:%!4LCD4E+
next4command M< DIS!L#I4%5+
-- ,urn on Display and ,urn off cursor
;.E5 DIS!L#I4%5 <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP2CP+
state M< D:%!4LCD4E+
next4command M< M%DE4SE,+
-- Set write mode to auto increment address and mo'e cursor to the ri&ht
;.E5 M%DE4SE, <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP2AP+
state M< D:%!4LCD4E+
next4command M< !rint4Strin&+
-- ;rite #SCII hex character in first LCD character location
;.E5 !rint4Strin& <T
state M< D:%!4LCD4E+
LCD4E M< R3R+
LCD4:S M< R3R+
LCD4:;4I5, M< R2R+
-- #SCII character to output
IF 5ext4Char)0 D%;5,% /* =< OP2P ,.E5
D#,#46DS4G#LDE M< 5ext4Char+
ELSE
-- Con'ert /-bit 'alue to an #SCII hex di&it
IF 5ext4Char)@ D%;5,% 2* TL ,.E5
-- #SCII #...F
D#,#46DS4G#LDE M< OP/P Q )5ext4Char)@ D%;5,% 2*-L*+
ELSE
-- #SCII 2...L
D#,#46DS4G#LDE M< OP@P Q 5ext4Char)@ D%;5,% 2*+
E5D IF+
E5D IF+
state M< D:%!4LCD4E+
-- Loop to send out @ characters to LCD Display )3A by lines*
IF )C.#:4C%D5, M @3* #5D )5ext4Char =< OPFEP* ,.E5
C.#:4C%D5, M< C.#:4C%D5, S3+
ELSE
C.#:4C%D5, M< P22222P+
E5D IF+
-- Uump to second lineV
IF C.#:4C%D5, < 3B ,.E5 next4command M< line+
-- :eturn to first lineV
ELSIF )C.#:4C%D5, < @3* %: )5ext4Char < OPFEP*
,.E5
next4command M< return4home+
ELSE next4command M< !rint4Strin&+ E5D IF+
-- Set write address to line character 3
;.E5 LI5E <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OPC2P+
state M< D:%!4LCD4E+
next4command M< !rint4Strin&+
-- :eturn write address to first character postion on line 3
;.E5 :E,D:54.%ME <T
LCD4E M< R3R+
LCD4:S M< R2R+
LCD4:;4I5, M< R2R+
D#,#46DS4G#LDE M< OP12P+
state M< D:%!4LCD4E+
next4command M< !rint4Strin&+
-- ,he next three states occur at the end of each command or data transfer to the LCD
-- Drop LCD E line - fallin& ed&e loads inst=data to LCD controller
;.E5 D:%!4LCD4E <T
LCD4E M< R2R+
state M< .%LD+
-- .old LCD inst=data 'alid after fallin& ed&e of E line
;.E5 .%LD <T
state M< next4command+
E5D C#SE+
E5D IF+
E5D IF+
E5D !:%CESS+
E5D a+

Das könnte Ihnen auch gefallen