• No se han encontrado resultados

¿Para qué un índice?

Figure฀5-5฀shows฀the฀connection฀we’ll฀use฀for฀our฀test฀programs.฀Let’s฀run฀through฀the฀function฀and฀con-nection฀of฀each฀pin.฀The฀PIC฀pin฀assignments฀are฀for฀our฀test฀circuit฀and฀may฀be฀adjusted฀as฀needed฀for฀your฀

projects.฀The฀LCD฀pin฀number฀assignments฀apply฀to฀the฀vast฀majority฀of฀LCD฀modules,฀but,฀of฀course,฀you฀

should฀check฀your฀particular฀display฀to฀verify฀the฀assignments.

Figure฀5-5:฀LCD฀module฀connection฀to฀PIC.

LCD฀Pin฀Name LCD฀Pin฀Number PIC฀Pin Comments

VSS 1 None Ground.

VCC 2 None To฀regulated฀+5V฀source.

VEE 3 None

For฀contrast฀adjustment;฀connect฀to฀20K฀potentiometer฀or฀

in฀many฀cases฀can฀be฀directly฀grounded.฀Note฀that฀extended฀

temperature฀range฀displays฀may฀require฀VEE฀to฀be฀connected฀

to฀a฀negative฀supply.

RS 4 B0 Register฀(control/display)฀select฀bit:

R/S=0—Data฀is฀written/read฀to/from฀control฀register.

R/S=1—Data฀is฀written/read฀to/from฀display฀RAM.

R/W 5 B2

Read/Write฀select฀bit:

R/W=0—Write฀data฀to฀RAM.

R/W=1—Read฀data฀from฀RAM.

If฀you฀do฀not฀intend฀to฀read฀from฀the฀LED฀memory฀(very฀

often฀the฀case)฀you฀may฀omit฀this฀connection฀from฀the฀PIC฀

and฀directly฀ground฀the฀LCD’s฀R/S฀pin.

E 6 B1 Enable—the฀clock฀pin฀for฀reading฀and฀writing฀data.

DB0 7 None Data฀bit฀0฀(LSB).฀8-bit฀data฀transfer฀to฀LCD฀is฀not฀supported฀

by฀MBasic’s฀LCDRead฀and฀LCDWrite฀procedures฀so฀DB0…DB3฀

are฀not฀used.

DB1 8 None Data฀bit฀1—not฀used฀in฀4-bit฀transfer.

DB2 9 None Data฀bit฀2—not฀used฀in฀4-bit฀transfer.

DB3 10 None Data฀bit฀3—not฀used฀in฀4-bit฀transfer.

DB4 11 B4

DB4…DB7฀are฀grouped฀together฀into฀a฀nibble฀for฀LCDRead฀

and฀LCDWrite฀procedures.฀We’ll฀use฀PortB.HighNib฀(B4…B7).

DB5 12 B5

DB6 13 B6

DB7 14 B7

LED+ 15 None Connect฀to฀LED฀supply;฀need฀not฀be฀regulated,฀but฀does฀

require฀series฀current฀limiting฀resistor.

LED– 16 None Connect฀to฀ground.

A฀few฀of฀these฀connections฀deserve฀further฀discussion.

Power,฀ground฀and฀bias—VSS฀and฀VCC฀(labeled฀VDD฀in฀some฀LCD฀modules)฀are฀straightforward;฀VSS฀is฀

ground,฀while฀VCC฀is฀connected฀to฀+5฀V.฀฀(Some฀lower฀voltage฀display฀modules฀are฀now฀available;฀of฀

course฀check฀your฀module’s฀data฀sheet฀to฀verify฀that฀it฀requires฀a฀+5฀V฀supply.)฀The฀LCD’s฀logic฀chips฀

are฀powered฀from฀this฀voltage.฀However,฀the฀voltage฀applied฀to฀the฀crystals฀to฀cause฀them฀to฀rotate฀is฀

obtained฀from฀VCC฀(positive)฀and฀VEE฀(negative).฀By฀setting฀VEE฀a฀few฀tenths฀of฀a฀volt฀above฀ground,฀

VDD฀becomes฀negative฀with฀respect฀to฀VEE฀and฀thus฀the฀negative฀voltage฀required฀for฀crystal฀rotation฀is฀

obtained.฀VEE฀determines฀the฀display’s฀contrast,฀so฀it’s฀common฀to฀derive฀VEE฀through฀a฀10฀Kohm฀to฀20฀

kohm฀potentiometer฀resistive฀voltage฀divider,฀as฀shown฀in฀Figure฀5-5.฀The฀desired฀display฀contrast฀can฀

be฀obtained฀by฀varying฀the฀potentiometer฀setting.฀(VEE ฀requires฀only฀a฀few฀hundred฀microamperes฀cur-rent,฀so฀a฀relatively฀high฀value฀potentiometer฀can฀be฀used.)฀I’ve฀found฀that฀almost฀all฀displays฀work฀well฀

at฀room฀temperature฀if฀VEE฀is฀just฀connected฀to฀ground,฀so฀for฀casual฀experimenting฀I’ll฀often฀omit฀the฀

contrast฀adjustment฀potentiometer฀and฀simply฀ground฀VEE.

Extended฀temperature฀range฀LCD฀modules฀(and฀even฀a฀few฀standard฀temperature฀modules)฀require฀a฀separate฀

–7฀V฀supply฀to฀drive฀VEE฀and฀may฀need฀an฀automatic฀compensation฀circuit฀to฀adjust฀VEE ฀as฀the฀ambient฀tempera-ture฀changes.฀฀The฀–7฀V฀supply฀is฀applied฀to฀the฀VEE฀pin฀through฀a฀potentiometer฀for฀contrast฀adjustment.

RS—The฀Register฀Select฀pin฀determines฀whether฀data฀is฀routed฀to฀the฀LCD฀module’s฀control฀register฀or฀dis-play฀RAM.฀For฀example,฀if฀the฀RS฀pin฀is฀high,฀sending฀the฀data฀value฀(hex)฀$28฀to฀the฀LCD฀module฀can฀

cause฀the฀left฀parenthesis฀character฀“(“฀to฀be฀displayed;฀if฀the฀RS฀pin฀is฀low,฀the฀same฀$28฀character฀sets฀

the฀display฀to฀two฀line฀mode.฀Since฀we฀must฀both฀write฀normal฀display฀data฀and฀command฀instructions,฀

the฀RS฀pin฀must฀be฀connected฀to฀a฀PIC฀output฀pin.฀LCDWrite฀automatically฀sets฀or฀clears฀the฀RS฀pin,฀

based฀on฀the฀value฀being฀written฀to฀the฀display.

R/W—Data฀to฀be฀displayed฀is฀held฀in฀read/write฀random฀access฀memory฀in฀the฀LCD฀module.฀MBasic฀allows฀

us฀to฀read฀from฀(LCDRead)฀is฀well฀as฀write฀to฀(LCDWrite)฀the฀LCD฀module’s฀RAM.฀The฀read/write฀

(R/W)฀pin฀determines฀whether฀we฀are฀writing฀data฀to฀the฀module฀(R/W฀is฀low)฀or฀reading฀data฀from฀the฀

module฀(R/W฀is฀high).฀Quite฀often฀we฀need฀not฀read฀data฀from฀the฀LCD฀module฀and฀we฀may฀simply฀

connect฀the฀LCD฀module’s฀R/W฀pin฀to฀ground.฀For฀generality,฀this฀chapter’s฀sample฀programs฀connect฀

the฀R/W฀pin฀to฀a฀PIC฀output฀pin฀so฀both฀LCDRead฀and฀LCDWrite฀operate.

E—Data฀is฀exchanged฀between฀the฀PIC฀and฀the฀LCD฀module฀is฀parallel฀format—that฀is,฀either฀eight฀or฀four฀

bits฀of฀a฀byte฀are฀sent฀simultaneously.฀The฀enable฀(E)฀pin,฀by฀changing฀state฀from฀high฀to฀low,฀informs฀

the฀receiving฀device฀(the฀LCD฀module฀if฀data฀is฀being฀sent฀to฀for฀display)฀that฀the฀data฀pins฀should฀be฀

read.฀We฀can฀consider฀the฀E฀pin฀as฀a฀data฀clock.

Data—Normal฀LCD฀modules฀are฀parallel฀transfer฀devices;฀they฀can฀exchange฀data฀as฀either฀one฀8-bit฀byte฀

or฀two฀4-bit฀nibbles.฀MBasic’s฀LCDRead฀and฀LCDWrite฀functions฀support฀only฀4-bit฀(nibble)฀transfer฀

mode,฀so฀we’ll฀concentrate฀on฀that.฀In฀4-bit฀mode,฀only฀the฀data฀lines฀DB4…DB7฀are฀active.฀To฀transfer฀

a฀byte฀the฀high฀nibble฀is฀transferred฀first฀followed฀by฀the฀low฀nibble.฀Fortunately,฀LCDRead฀and฀ LCD-Write฀take฀care฀of฀these฀details฀for฀us.฀If฀you’ve฀been฀keeping฀track฀of฀how฀many฀pins฀we’ve฀used฀to฀

communicate฀with฀the฀LCD฀module,฀you฀understand฀why฀Basic฀Micro฀chose฀to฀implement฀the฀4-bit฀

mode.฀Even฀so,฀seven฀pins฀must฀be฀devoted฀to฀LCD฀communications฀in฀the฀general฀case,฀dropping฀to฀six฀

if฀we฀wish฀to฀only฀write฀to฀the฀module฀and฀accordingly฀ground฀the฀LCD’s฀R/W฀pin.

The฀only฀thing฀left฀is฀to฀calculate฀the฀LED฀current฀limiting฀resistor’s฀value.฀Figure฀5-6฀shows฀the฀standard฀

LED฀configuration.฀The฀backlight฀consists฀of฀a฀dozen฀or฀more฀LED฀pairs,฀series฀connected,฀with฀a฀forward฀

voltage฀of฀typically฀4.1฀V฀when฀operating฀at฀rated฀current.฀

Our฀TM162YBC6฀backlight฀array฀is฀specified฀at฀4.7฀V฀at฀

the฀rated฀93฀mA฀current,฀a฀higher฀voltage฀than฀typically฀

seen.฀Assuming฀the฀LED฀supply฀is฀connected฀to฀a฀+5฀V฀

regulated฀output,฀we฀may฀quickly฀calculate฀the฀required฀

current฀limiting฀resistor:

฀ ฀ R V V

1 5 4 7A

0 093 3 2

= − . = Ω

. .

We฀will฀use฀the฀closest฀standard฀value,฀3.3฀ohms.

The฀power฀dissipated฀by฀the฀limiting฀resistor฀is:

฀ ฀ P=I R2 1=

(

0 093.

)

2×3 2. =0 027. watts A฀one-quarter฀watt฀resistor฀is฀adequate.

If฀the฀backlight฀LED฀array฀is฀rated฀at฀4.2฀or฀4.3฀V,฀we฀may฀use฀a฀1A฀silicon฀power฀diode฀in฀series฀with฀the฀

LED฀array฀instead฀of฀a฀resistor฀to฀limit฀the฀current.

We฀should฀be฀cautious฀in฀connecting฀devices฀to฀the฀+5฀V฀regulated฀supply฀in฀Basic฀Micro’s฀development฀

boards.฀The฀5฀V฀regulator฀has฀no฀heat฀sink฀and฀its฀measured฀input฀voltage฀is฀13฀V฀(nominal฀12฀V฀“wall฀wart”฀

power฀supply).฀The฀7805’s฀thermal฀resistance฀(junction฀to฀air)฀RθJA฀is฀65°C/W฀and฀the฀maximum฀operating฀

junction฀temperature฀is฀+125°C.฀If฀the฀ambient฀air฀temperature฀is฀25°C,฀we฀can฀permit฀no฀more฀than฀a฀100°C฀

junction฀temperature฀rise฀over฀ambient.฀A฀100°C฀rise฀in฀junction฀temperature฀is฀caused฀by฀100°C/65°C/W,฀or฀

Figure฀5-6:฀LED฀current฀limiting฀resistor.

1.5฀W฀dissipation.฀Since฀the฀voltage฀drop฀across฀the฀regulator฀is฀13฀V–5฀V,฀or฀8฀V,฀1.5฀W฀device฀dissipation฀is฀

reached฀with฀a฀total฀192฀mA฀current฀draw.฀Well฀before฀this฀current฀level฀the฀7805฀will฀become฀hot฀enough฀to฀

burn฀your฀finger,฀so฀it’s฀not฀desirable฀to฀push฀it฀to฀the฀limit.฀But,฀if฀you฀do,฀7805’s฀are฀well฀protected฀by฀in-ternal฀circuitry,฀including฀over-temperature฀shutdown,฀so฀the฀chances฀of฀damaging฀the฀regulator฀are฀minimal.

Documento similar