Figure5-5showstheconnectionwe’lluseforourtestprograms.Let’srunthroughthefunctionandcon-nectionofeachpin.ThePICpinassignmentsareforourtestcircuitandmaybeadjustedasneededforyour
projects.TheLCDpinnumberassignmentsapplytothevastmajorityofLCDmodules,but,ofcourse,you
shouldcheckyourparticulardisplaytoverifytheassignments.
Figure5-5:LCDmoduleconnectiontoPIC.
LCDPinName LCDPinNumber PICPin Comments
VSS 1 None Ground.
VCC 2 None Toregulated+5Vsource.
VEE 3 None
Forcontrastadjustment;connectto20Kpotentiometeror
inmanycasescanbedirectlygrounded.Notethatextended
temperaturerangedisplaysmayrequireVEEtobeconnected
toanegativesupply.
RS 4 B0 Register(control/display)selectbit:
R/S=0—Dataiswritten/readto/fromcontrolregister.
R/S=1—Dataiswritten/readto/fromdisplayRAM.
R/W 5 B2
Read/Writeselectbit:
R/W=0—WritedatatoRAM.
R/W=1—ReaddatafromRAM.
IfyoudonotintendtoreadfromtheLEDmemory(very
oftenthecase)youmayomitthisconnectionfromthePIC
anddirectlygroundtheLCD’sR/Spin.
E 6 B1 Enable—theclockpinforreadingandwritingdata.
DB0 7 None Databit0(LSB).8-bitdatatransfertoLCDisnotsupported
byMBasic’sLCDReadandLCDWriteproceduressoDB0…DB3
arenotused.
DB1 8 None Databit1—notusedin4-bittransfer.
DB2 9 None Databit2—notusedin4-bittransfer.
DB3 10 None Databit3—notusedin4-bittransfer.
DB4 11 B4
DB4…DB7aregroupedtogetherintoanibbleforLCDRead
andLCDWriteprocedures.We’llusePortB.HighNib(B4…B7).
DB5 12 B5
DB6 13 B6
DB7 14 B7
LED+ 15 None ConnecttoLEDsupply;neednotberegulated,butdoes
requireseriescurrentlimitingresistor.
LED– 16 None Connecttoground.
Afewoftheseconnectionsdeservefurtherdiscussion.
Power,groundandbias—VSSandVCC(labeledVDDinsomeLCDmodules)arestraightforward;VSSis
ground,whileVCCisconnectedto+5V.(Somelowervoltagedisplaymodulesarenowavailable;of
coursecheckyourmodule’sdatasheettoverifythatitrequiresa+5Vsupply.)TheLCD’slogicchips
arepoweredfromthisvoltage.However,thevoltageappliedtothecrystalstocausethemtorotateis
obtainedfromVCC(positive)andVEE(negative).BysettingVEEafewtenthsofavoltaboveground,
VDDbecomesnegativewithrespecttoVEEandthusthenegativevoltagerequiredforcrystalrotationis
obtained.VEEdeterminesthedisplay’scontrast,soit’scommontoderiveVEEthrougha10Kohmto20
kohmpotentiometerresistivevoltagedivider,asshowninFigure5-5.Thedesireddisplaycontrastcan
beobtainedbyvaryingthepotentiometersetting.(VEE requiresonlyafewhundredmicroamperescur-rent,soarelativelyhighvaluepotentiometercanbeused.)I’vefoundthatalmostalldisplaysworkwell
atroomtemperatureifVEEisjustconnectedtoground,soforcasualexperimentingI’lloftenomitthe
contrastadjustmentpotentiometerandsimplygroundVEE.
ExtendedtemperaturerangeLCDmodules(andevenafewstandardtemperaturemodules)requireaseparate
–7VsupplytodriveVEEandmayneedanautomaticcompensationcircuittoadjustVEE astheambienttempera-turechanges.The–7VsupplyisappliedtotheVEEpinthroughapotentiometerforcontrastadjustment.
RS—TheRegisterSelectpindetermineswhetherdataisroutedtotheLCDmodule’scontrolregisterordis-playRAM.Forexample,iftheRSpinishigh,sendingthedatavalue(hex)$28totheLCDmodulecan
causetheleftparenthesischaracter“(“tobedisplayed;iftheRSpinislow,thesame$28charactersets
thedisplaytotwolinemode.Sincewemustbothwritenormaldisplaydataandcommandinstructions,
theRSpinmustbeconnectedtoaPICoutputpin.LCDWriteautomaticallysetsorclearstheRSpin,
basedonthevaluebeingwrittentothedisplay.
R/W—Datatobedisplayedisheldinread/writerandomaccessmemoryintheLCDmodule.MBasicallows
ustoreadfrom(LCDRead)iswellaswriteto(LCDWrite)theLCDmodule’sRAM.Theread/write
(R/W)pindetermineswhetherwearewritingdatatothemodule(R/Wislow)orreadingdatafromthe
module(R/Wishigh).QuiteoftenweneednotreaddatafromtheLCDmoduleandwemaysimply
connecttheLCDmodule’sR/Wpintoground.Forgenerality,thischapter’ssampleprogramsconnect
theR/WpintoaPICoutputpinsobothLCDReadandLCDWriteoperate.
E—DataisexchangedbetweenthePICandtheLCDmoduleisparallelformat—thatis,eithereightorfour
bitsofabytearesentsimultaneously.Theenable(E)pin,bychangingstatefromhightolow,informs
thereceivingdevice(theLCDmoduleifdataisbeingsenttofordisplay)thatthedatapinsshouldbe
read.WecanconsidertheEpinasadataclock.
Data—NormalLCDmodulesareparalleltransferdevices;theycanexchangedataaseitherone8-bitbyte
ortwo4-bitnibbles.MBasic’sLCDReadandLCDWritefunctionssupportonly4-bit(nibble)transfer
mode,sowe’llconcentrateonthat.In4-bitmode,onlythedatalinesDB4…DB7areactive.Totransfer
abytethehighnibbleistransferredfirstfollowedbythelownibble.Fortunately,LCDReadand LCD-Writetakecareofthesedetailsforus.Ifyou’vebeenkeepingtrackofhowmanypinswe’veusedto
communicatewiththeLCDmodule,youunderstandwhyBasicMicrochosetoimplementthe4-bit
mode.Evenso,sevenpinsmustbedevotedtoLCDcommunicationsinthegeneralcase,droppingtosix
ifwewishtoonlywritetothemoduleandaccordinglygroundtheLCD’sR/Wpin.
TheonlythingleftistocalculatetheLEDcurrentlimitingresistor’svalue.Figure5-6showsthestandard
LEDconfiguration.ThebacklightconsistsofadozenormoreLEDpairs,seriesconnected,withaforward
voltageoftypically4.1Vwhenoperatingatratedcurrent.
OurTM162YBC6backlightarrayisspecifiedat4.7Vat
therated93mAcurrent,ahighervoltagethantypically
seen.AssumingtheLEDsupplyisconnectedtoa+5V
regulatedoutput,wemayquicklycalculatetherequired
currentlimitingresistor:
R V V
1 5 4 7A
0 093 3 2
= − . = Ω
. .
Wewillusethecloseststandardvalue,3.3ohms.
Thepowerdissipatedbythelimitingresistoris:
P=I R2 1=
(
0 093.)
2×3 2. =0 027. watts Aone-quarterwattresistorisadequate.IfthebacklightLEDarrayisratedat4.2or4.3V,wemayusea1Asiliconpowerdiodeinserieswiththe
LEDarrayinsteadofaresistortolimitthecurrent.
Weshouldbecautiousinconnectingdevicestothe+5VregulatedsupplyinBasicMicro’sdevelopment
boards.The5Vregulatorhasnoheatsinkanditsmeasuredinputvoltageis13V(nominal12V“wallwart”
powersupply).The7805’sthermalresistance(junctiontoair)RθJAis65°C/Wandthemaximumoperating
junctiontemperatureis+125°C.Iftheambientairtemperatureis25°C,wecanpermitnomorethana100°C
junctiontemperatureriseoverambient.A100°Criseinjunctiontemperatureiscausedby100°C/65°C/W,or
Figure5-6:LEDcurrentlimitingresistor.
1.5Wdissipation.Sincethevoltagedropacrosstheregulatoris13V–5V,or8V,1.5Wdevicedissipationis
reachedwithatotal192mAcurrentdraw.Wellbeforethiscurrentlevelthe7805willbecomehotenoughto
burnyourfinger,soit’snotdesirabletopushittothelimit.But,ifyoudo,7805’sarewellprotectedbyin-ternalcircuitry,includingover-temperatureshutdown,sothechancesofdamagingtheregulatorareminimal.