You are on page 1of 7

LCD

311 LCD background


MosL ofLen a mlcroconLroller program musL lnLeracL wlLh Lhe user by uslng lnpuL and ouLpuL
devlces LhaL wlll communlcaLe dlrecLly wlLh Lhe human belng Cne of Lhe mosL common
devlces ls Lhe LCu Lhe LCu ls generally used Lo ouLpuL cerLaln LexL or message Lo Lhe user
1he Pu44780 was chosen slnce lL ls one of Lhe sLandard dlsplays generally used ln lndusLry
and oLher appllcaLlons whlch are LexLbased MosL common LCu dlsplays are 16x2 or 20x2
Lhls means 16 or 20 characLers per llne by 2 llnes consequenLly Lhe 16x2 was chosen for Lhls
Lhesls slnce Lhere lsnL Lhe need Lo dlsplay more Lhan 16 characLers per llne uslng one llne
for Lhe volLage and Lhe oLher llne for Lhe currenL dlsplay(LargeL and acLual values) 1hls
devlce ls deslgned for lnLerfaclng wlLh mlcroconLroller sysLems and ln Lhls ower Supply lL
wlll be lnLerfaced wlLh Lhe C8031l020
uesplLe Lhe facL LhaL Lhls LCu ls one of Lhe mosL commonly used models when deallng wlLh
dlfferenL manufacLures Lhe devlce mlghL vary a blL ln Lerms of lnLerfaclng lorLunaLely a
very popular sLandard exlsLs whlch allows us Lo communlcaLe wlLh Lhe vasL ma[orlLy of LCus
regardless of Lhelr manufacLurer 1he sLandard ls referred Lo as Pu44780u whlch refers Lo
Lhe conLroller chlp whlch recelves daLa from an exLernal source (ln Lhls case Lhe 8031) and
communlcaLes dlrecLly wlLh Lhe LCu

D44780 |n Descr|pt|ons





oftware Des|gn and |mp|ementat|on
321 LCD oftware Lxp|anat|on
llrsL Lhe LCu has Lo be lnlLlallzed ln 88lL mode 1hls ls done by dolng a sequence of delays
LogeLher wlLh Lhe handllng of Lhe Lnable llne and by seLLlng 8S and 8W Lo 0 1he handllng
of Lhe enable conLrol llne ls used Lo noLlfy Lhe LCu LhaL Lhe user ls ready for lL Lo execuLe an
lnsLrucLlon LhaL Lhe same user has prevlously prepared on Lhe daLa bus and on Lhe conLrol
llnes
When communlcaLlng wlLh Lhe LCu Lhe enable llne musL always be pulsed slnce oLherwlse
Lhe LCu wlll noL know LhaL youll be sendlng daLa Lo lL 1hls requlres LhaL Lhe enable llne ls
seL before and reseL afLer each lnsLrucLlon ls senL Lo Lhe LCu regardless of wheLher Lhe
lnsLrucLlon ls read/wrlLe LexL/lnsLrucLlon So lL ls lmporLanL LhaL before any lnLeracLlon wlLh
Lhe LCu Lhe Lnable llne musL be pulled low
AfLer pulslng Lhe enable llne one musL ensure LhaL Lhe dlsplay ls cleared 1hls wlll also be
done as a sequence of sLeps so Lhe clearlng of Lhe screen musL be made as a baslc funcLlon
so LhaL lL can be used frequenLly
1hen afLer Lhe screen ls cleared Lhe daLa wlll be wrlLLen on Lhe LCu ln Lhe wrlLlng process
Lhe LCu sLaLus wlll be checked Lo see wheLher lLs busy or noL
1he LCu memory can be represenLed wlLh Lhe followlng memory map
Above as seen from Lhe memory map Lhe locaLlons marked ln blue shows Lhe vlslble
characLer dlsplay whlch ls 16 characLers long by 2 llnes and each box conLalns lLs memory
address SubsequenLly lf one wanLs Lo wrlLe aL a cerLaln poslLlon on Lhe LCu Lhe locaLlon
can be referred wlLh Lhe correspondlng address 8uL Lhls counLs only for Lhe flrsL llne whlch
sLarLs aL poslLlon 00h Llll Lhe 16Lh characLer whlch ls aL address 0lh 47 Lhen Lhe flrsL
characLer of Lhe second llne ls aL address 40h Lherefore we need Lo order Lhe LCu Lo puL
Lhe cursor poslLlon aL Lhe second llne
1he seL cursor poslLlon" lnsLrucLlon ls 80h so Lhls value musL be added LogeLher wlLh Lhe
acLual deslred cursor poslLlon 1o sum up for Lhe word Pello Lo be wrlLLen from Lhe flrsL
characLer ln Lhe flrsL llne ln Lhe program one should allocaLed Lhe world aL 00h+80h 80h
Lherefore Lhe word world ls seL aL poslLlon 40h+80h C0h















SofLware used

Maln rogram
#lnclude C8031l020h /* speclal funcLlon reglsLers 8032 */
//#lnclude uualuarLsh /* speclal funcLlon reglsLers 8032 */
#lnclude lcdh

#lnclude sLdloh
#lnclude sLdllbh

//#deflne S?SCLk 22118400 // S?SCLk frequency ln Pz
#deflne delay 1
#deflne uA1A 4


//
// S?SCLk_lnlL
//
//
// 1hls rouLlne lnlLlallzes Lhe sysLem clock Lo use an 221184MPz crysLal
// as lLs clock source
//
vold S?SCLk_lnlL (vold)

unslgned lnL l // delay counLer

CSCxCn 0x67 // sLarL exLernal osclllaLor wlLh
// 221184MPz crysLal

for (l0 l 236 l++) // walL for osclllaLor Lo sLarL
#lfndef SlMuLA1C8
whlle (!(CSCxCn 0x80)) // WalL for crysLal osc Lo seLLle
#endlf
CSClCn 0x88 // selecL exLernal osclllaLor as S?SCLk
// source and enable mlsslng clock
// deLecLor


//
// ulSA8LL_WaLchdog
//
//
// ulsables Lhe waLchdog Llmer
//
vold ulSA8LL_WaLchdog (vold)

LA 0
Wu1Cn 0xuL
Wu1Cn 0xAu
LA 1




//
// C81_lnlL
//
//
// Conflgure Lhe Crossbar and ClC porLs
//

////////////////////////////////////////////////////////////////////////////
vold C81_lnlL (vold)

x880 0x04 // Lnable uA81 0
x881 0x00
x882 0x40 // Lnable crossbar and weak pullups
0MuCu1 | 0x01 // enable 1x0 as a pushpull ouLpuL
1MuCu1 | 0x40 // enable 16 (LLu) as pushpull ouLpuL

//3MuCu1 | 0x80 // 37 ls opendraln

2 | 0x08 // SeL 23 laLch Lo 1
1 | 0xll
x882 0x40 // Lnable crossbar and enable
// weak pullups

/////////////////////////////////////////////////////////////////////////////


vold lcdcmd(unslgned char value)

LuA1A value
rs 0
rw 0
en 1
MSuelay(1)
en 0


vold lcddaLa(unslgned char value)

LuA1A value
rs 1
rw 0
en 1
MSuelay(1)
en 0
reLurn



vold MSuelay(unslgned lnL lLlme)

unslgned lnL l[
for (l 0 l lLlmel++)
for ([ 0 [ 22190[++)



//
// MAln 8ouLlne
//
vold maln (vold)
ulSA8LL_WaLchdog ()
S?SCLk_lnlL ()
// SeLupuA81(0 113200 1) /* SeL up uA81 0 aL 113200 baud uslng 1lmer 1 */
///////////////////////////////////////////////////////////////////////////////////
C81_lnlL ()

2MuCu1 0xll
74Cu1 0xll
// 3MuCu1 0xll
///////////////////////////////////////////////////////////////////////////////////

lcdcmd(0x38) // lnlLlallzaLlon sLeps for Lhe lcd
MSuelay(delay)

lcdcmd(0x0l)
MSuelay(delay)

lcdcmd(0x01)
MSuelay(delay)

lcdcmd(0x06)
MSuelay(delay)

lcdcmd(0x80)
MSuelay(delay)
lcddaLa(0)
MSuelay(delay)
lcddaLa()
MSuelay(delay)
MSuelay(delay)
lcddaLa(0)
MSuelay(delay)
lcddaLa(0)
MSuelay(delay)

lcdcmd(0x89)
MSuelay(delay)
lcddaLa(P)
MSuelay(delay)
lcddaLa(L)
MSuelay(delay)
MSuelay(delay)
lcddaLa(?)

lcdcmd(0xC0)
MSuelay(delay)
lcddaLa(u)
MSuelay(delay)
lcddaLa(u)
MSuelay(delay)
lcddaLa(u)
MSuelay(delay)
lcddaLa(L)
MSuelay(delay)


////////////////////////////////////////////////////////////////////////////////
whlle (1)
/*
lf (SW1 1) // lf swlLch depressed

LLu1 1 // 1urn on LLu

else lf (SW10)

LLu1 0 // Llse Lurn lL off

*/
////////////////////////////////////////////////////////////////////////////////







LCDh
#lfndef __lcd_P__
#deflne __lcd_P__


#deflne CCn18CL 2

blL slo_porL 0

sfr LuA1A 0x84
sblL rs CCn18CL0
sblL rw CCn18CL1
sblL en CCn18CL2
//sblL busy 37

////////////////////////////////////////////// ////////////////////////

sblL LLu1 16 // Lhe on board LLu found on pln 16
//sblL SW1 23 // 23 86 SW1 1 means swlLch pressed

///////////////////////////////////////////// ////////////////////////
//
// luncLlon 8C1C1?LS
//
vold S?SCLk_lnlL (vold)
vold C81_lnlL (vold)
vold ulSA8LL_WaLchdog (vold)
vold lcdcmd(unslgned char value)
vold lcddaLa(unslgned char value)
vold MSuelay(unslgned lnL lLlme)
vold program(vold)
vold lcdready(vold)

/*

vold lcdcmd(unslgned char value)
vold lcddaLa(unslgned char value)
vold MSuelay(unslgned lnL lLlme)
vold lcd_wrlLeSLrlng (char *sLr)
*/

#endlf

You might also like