Page 148 - Making PIC Microcontroller Instruments and Controllers
P. 148
t4O USI|{C UqUD CnYSlAl DISPLAYS! Al{ EXIE DED l FORilAllON RESOUBCE
DEFTNE I,CD RSREG PORTE
DEFINB LCD-RSBI! 0
When we transfer the data, we must enable the transfer by toggling a bit, ard thc port
and bit fbr dojng this are delincd with the following two lines:
DEFINE I,CD EREG PORTE
DEFIIIE LCD-EAII 1
Decide whether we arc going toreaddatalrom, or write data to, the LCD. This is the
read./write bit, and this bit is defined wiih the following two lincs:
DEFINE I,CD RWREG PORTE
DEFINE IJCD RWBIT 2
Most of the time wc do not need to read data from |he LCD, so this bi1 can be made
and leit lowl
LOSI PORTE.2
Set LCD R/W pin to low (if writc only is to be implcmented). If we are,?ol rrdl goirS
r., /ead from the LCD module, the preccding bit can be set and left low, or it can be tied
low with hdrdware. (Doing it this way will save one conlrol ljne on the PIC.)
Since the PIC l6F877Ahas analog capability, tike any o$er similar PIC it will come up
ilr analog mode on stairup and reset. The MCU must be changed 10 digital mode by setting
the appropriate A to-D conaol rcgister bits before we can use the digital capabilities oI the
PIC. We need thc digital tunctions ofPORTE to control thc LCD. This is done with .
a.DCONl = %00000110
This ins[uction makes all of PORTA and PORTE digital (E00000] I1 can also be
will provide different results. For a detailed discussion {)1'
used). Other specifications
!hj., \ee rhe Jrra.hecl \ecrn on A lo D co1\eriiot..
time to initialize itselfaflel startup, so we have to wait
The LCD takes a considerable
about 500 milliseco s before writing to it.Iflhere are a lot of other tasks that will take
place belore the first write to the LCD, this lime can be reduced (A trial-and error
approach can be used to deteminc the minimum timc needed.)
PAUSE 500 i Wait ,5 secs. for LcD to start up
Usually, the first conmand to the LCD is used to clear the display and write |o it on
line 1, bur I am showing it as two lines, \\,herc the 1i$t line clears the display and the second
line positions the cursor at the iirsl positjon on ihe lirst line and prints thc word "Blank."
LcDouT $FE, L r clear the LcD
'Blank- to the 1't line 1't posiiion
LCDOUT $FE, 980, ; writlen
; of the LcD
A11 commands (as opposed to characters) sent to the LCD are preceded by the code
$FE ordecimal254. Somc ofthe codes;re as described in Table 9 1.