EE 109 LCDs - University Of Southern California

2y ago
16 Views
2 Downloads
771.25 KB
35 Pages
Last View : 26d ago
Last Download : 3m ago
Upload by : Jenson Heredia
Transcription

6.1EE 109 Unit 6LCD Interfacing

6.2LCD BOARD

6.3The EE 109 LCD Shield The LCD shield is a 16 character by 2 row LCDthat mounts on top of the Arduino Uno. The shield also contains five buttons that canbe used as input sources.5 Button Inputs

6.4How Do We Use It? By sending it data (i.e. ASCII characters one ata time) that it will display for us By sending it special commands to do thingslike:– Move the cursor to a specific location– Clear the screen contents– Upload new fonts/special characters

6.5How Do We Communicate? The LCD uses a "parallel" interface (4-bits sent per transfer) tocommunicate with the µC (Note: µC microcontroller) Data is transferred 4 bits at a time and uses 2 other signals(Register Select and Enable) to control where the 4-bits go andwhen the LCD should capture themD7D6D5D4Data linesEE 109 is fun!UnoD8D9Register SelectEnableLCD

6.6How Do We Communicate? To send an 8-bit byte we must send it in two groups of 4 bits– First the upper 4-bits followed by the lower 4-bits RS 0 sets the destination as the command reg. RS 1 sets the destination as the data reg.2nd1stTransfer TransferD7D6D5D4Data lines10010011Register Select 00UnoD8D9EnableAddress(Reg. Select)7 6 5 4 3 2 1 0000111001Command Reg.1Data Reg.LCDDisplayHW

6.7Commands and Data LCD contains two 8-bit registers which it usesto control its actions: Command and Data A Register Select (RS) signal determineswhich register is the destination of the datawe send it (RS acts like an address selector)– RS 0, info goes into the command register– RS 1, info goes into the data register To perform operations like clear display,move cursor, turn display on or off, write thecommand code to the command register. To display characters on the screen, writethe ASCII code for the character to the dataregister.CommandCodeClear LCD0x01Curser Home(Upper-Left)0x02Display On0x0fDisplay Off0x08Move cursorto top row,column i0x80 iMove cursorto bottomrow, column i0xc0 i

6.8How Do We Communicate? To send an 8-bit byte we must send it in two groups of 4 bits– First the upper 4-bits followed by the lower 4-bits RS 0 sets the destination as the command reg. RS 1 sets the destination as the data reg.2nd1stTransfer TransferD7D6D5D4Data lines00010110Register Select 11UnoD8D9EnableAddress(Reg. Select)7 6 5 4 3 2 1 0000111001Command Reg.101100001Data Reg.LCDDisplayHW

6.9Another View Data from the Uno is transferred by placing four bits on the datalines (Port D bits 7-4). The Register Select (RS) line determines whether the data goesto the LCD’s "Command Register" or "Data Register"– RS 0 Command RegisterRS 1 Data Register The Enable (E) line acts as a "clock" signal telling the LCD tocapture the data and examine the RS bit on the 0-1-0 transition– Pulse must be held at 1 for at least 230ns according to LCD datasheet(PB0) RS(PD7-4) Data(PB1) Enable"0000 0101" sent to thecommand register in the LCD0000230 ns0101230 nsThe first 4-bits of atransfer to the dataregister in the LCD0110230 ns

6.10Another View Data from the Uno is transferred by placing four bits on the datalines (Port D bits 7-4). Whether sending info to the "command" or "data" register, theLCD still wants a full byte (8-bits) of data so we must do 2transfers– We always send the upper 4-bits of the desired data first– Then we transfer the lower 4-bits(PB0) RS(PD7-4) Data(PB1) Enable"0000 0101" sent to thecommand register in the LCD0000230 ns0101230 nsThe first 4-bits of atransfer to the dataregister in the LCD0110230 ns

6.11Who's Job Is It?// Turn on bit 0 of PORTDPORTD So who is producing thevalues on the RS and Datalines and the 0-1-0transition on the E line? You!! With your digital I/O(setting and clearing PORTbits)// Delay 1 us 230ns needed// A better way in a few slidesdelay us(1);// Turn off bit 0 of PORTDPORTD & This code would produce somevoltage pattern like this on PD0(PD0)Note: The LCD connection doesn'tuse PD0, you'll need to modify thisappropriately to generate the Esignal

6.12Other LCD Interface Other LCD devices may use– Only one signal (a.k.a. serial link) to communicatebetween the µC and LCD This makes wiring easier but requires more complexsoftware control to "serialize" the 8- or 16-bit numbersused inside the µC– 8-data wires plus some other control signals sothey can transfer an entire byte This makes writing the software somewhat easier

6.13LCD LAB PREPARATION

6.14Step 1 Mount the LCD shield on theUno without destroying thepins Download the “test.hex” fileand Makefile from the website, and modify the Makefileto suite your computer. Run “make test” to downloadtest program to the Uno LCD. Should see a couple of lines oftext on the screen.

6.15Step 2 Develop a set of functions that willabstract the process of displayingtext on the LCD– A set of functions to perform specifictasks for a certain module is oftenknown as an API (applicationprogramming interface)– Once the API is written it gives otherapplication coders a nice simpleinterface to do high-level tasks Download the skeleton file andexamine the functions outlines onthe next slides

6.16LCD API Development Overview Write the routines to control the LCD in layers– Top level routines that your code or others can use: writea string to LCD, move the cursor, initialize LCD, etc.– Mid level routines: write a byte to the command register,write a byte to the data register– Low level routines: controls the 4 data lines and E totransfer a nibble to a register Goal: Hide the ugly details about how the interfaceactually works from the user who only wants to puta string on the display.

6.17Low Level Functions lcd writenibble(unsigned char x)– Assumes RS is already set appropriately– Send four bits from ‘x’ to the LCD Takes 4-bits of x and copies them to PD[7:4] (where we'veconnected the data lines of the LCD) SEE NEXT SLIDES ON COPYING BITS Produces a 0-1-0 transition on the Enable signal– Must be consistent with mid-level routines as to which4 bits to send, MSB or LSB– Uses: logical operations (AND/OR) on the PORT bitsThis will be your challenge to write in lab!

6.18Mid-Level Functions lcd writecommand(unsigned char x)– Send the 8-bit byte ‘x’ to the LCD as a command– Set RS to 0, send data in two nibbles, delay– Uses: lcd writenibble() lcd writedata(unsigned char x)– Send the 8-bit byte ‘x’ to the LCD as data– Set RS to 1, send data in two nibbles, delay– Uses: lcd writenibble() Could do as one function– lcd writebyte(unsigned char x, unsigned char rs)This will be your challenge to write these two functions in lab!

6.19High Level API Routines lcd init()– Mostly complete code to perform initialization sequence– See lab writeup for what code you MUST add.– Uses: lcd writenibble(), lcd writecommand(), delays lcd moveto(unsigned char row, unsigned char col)– Moves the LCD cursor to “row” (0 or 1) and “col” (0-15)– Translates from row/column notation to the format the LCD usesfor positioning the cursor (see lab writeup)– Uses: lcd writecommand() lcd stringout(char *s)– Writes a string of character starting at the current cursor position– Uses: lcd writedata()

6.20Activity: Code-Along Assuming the lcd writecommand() andlcd writedata() functions are correctlywritten, code the high-level functions:– void lcd stringout(char* str);– void lcd moveto(int row, int col);

6.21To implement writenibble() these slides will help you COPYING BITS

6.22Copying Multiple Bits Suppose we want to copy a portionof a variable or register into anotherBUT WITHOUT affecting the otherbits Example: Copy the lower 4 bits of Xinto the lower 4-bits of PORTB butleave the upper 4-bits of PORTBUNAFFECTED Assignment doesn't work since it willoverwrite ALL bits of PORTB– PORTB x; // changes all bits of PORTBx0 1 0 0 0 0 1 1PORTB? ? ? ? ? ? ? ?PORTB? ? ? ? 0 0 1 1Desired ResultPORTB0 1 0 0 0 0 1 1PORTB x;Result

6.23Copying Into a Register Solution use these steps: Step 1: Define a mask that has 1’swhere the bits are to be copied#defineMASKBITS0x0f Step 2: Clear those bits in thedestination register using the MASKxStep 1Step 2MASKBITS 0 0 0 0 1 1 1 1PORTB? ? ? ? ? ? ? ?& 1 1 1 1 0 0 0 0PORTB & MASKBITS Step 3: Mask the appropriate fieldof x and then OR it with thedestination, PORTB0 1 0 0 0 0 1 1Step 3PORTB? ? ? ? 0 0 0 0x0 1 0 0 0 0 1 1 PORTB0 0 0 0 1 1 1 10 0 0 0 0 0 1 1? ? ? ? 0 0 0 0PORTB? ? ? ? 0 0 1 1& MASKBITSPORTB (x & MASKBITS);Result

6.24Do We Need Step 2 Yes!!! Can't we just do step 1 and 3 andOR the bits of x into PORTB#define MASKBITS0x0fPORTB (x & MASKBITS); No, because what if the destination(PORTB) already had some 1'swhere we wanted 0's to go Just OR'ing wouldn't change thebits to 0 That's why we need step 2 Step 2: Clear those bits in thedestination register using the MASKPORTB & MASKBITS;x0 1 0 0 0 0 1 1PORTB? ? ? ? 1 1 1 0What if PORTB justhappened to have thesebits initiallyStep 1 & 3x PORTB0 0 0 0 1 1 1 10 0 0 0 0 0 1 1? ? ? ? 1 1 1 0PORTB? ? ? ? 1 1 1 1& MASKBITSResult0 1 0 0 0 0 1 1

6.25Copying To Different Bit Locations What if the source bits are in adifferent location than thedestination– Ex. Copy lower 4 bits of x to upper 4bits of PORTB Step 1: Define a mask that has 1’swhere the bits are to be copied#defineMASKBITSxStep 1Step 21 1 1 1 0 0 0 0PORTB? ? ? ? ? ? ? ?PORTB0 0 0 0 ? ? ? ?x0 1 0 0 0 0 1 1Step 3x 4PORTB & MASKBITS Step 3: Shift the bits of x to alignthem appropriately, then performthe regular step 3PORTB ((x 4) & MASKBITS);MASKBITS & 0 0 0 0 1 1 1 10xf0 Step 2: Clear those bits in thedestination register using the MASK0 1 0 0 0 0 1 1 PORTB1 1 1 1 0 0 0 00 0 1 1 0 0 0 00 0 0 0 ? ? ? ?PORTB0 0 1 1 ? ? ? ?& MASKBITSResult0 0 1 1 0 0 0 0

6.26Coding a Byte Transfer to the LCDTransferByte76543210data a b c d e f g hwritenibble a b c d e f g hwritenibble e f g h ? ? ? ?7writenibble6543210lcdbits ? ? ? ? ? ? ? ?PORTD ? ? ? ? ? ? ? ?2nd1stTransfer TransferD7D6D5D4Data lines00010110Register Select 11UnoD8D9EnableAddress(Reg. Select)7 6 5 4 3 2 1 0000111001Command Reg.101100001Data Reg.LCDDisplayHW

6.27Ensuring the Enable pulse is long enoughTHE DEVIL IN THE DETAILS

6.28Making Things Work TogetherDoes your code do the right thing? LCD lab required the program to generate an Enable (E) pulse. Example: The writenibble() routine controls the PB1 bit that isconnected to the LCD Enable line.PORTB (1 PB1);PORTB & (1 PB1);// Set E to 1// Clear E to 0 Creates a 0 1 0 pulse to clock data/commands into LCD. But is it a pulse that will work with the LCD? Rumors circulated that the E pulse had to be made longer byputting a delay in the code that generated it. Don’t Guess. Time to read the manual, at least a little bit.

6.29Making Things Work TogetherCheck the LCD controller datasheetTiming PWEHtAHtEfEVIH1VIL1VIH1VIL1tErDB0 to DB7tDSWVIH1VIL1VIL1tHValid datatcycEFigure 27 Write OperationVIH1VIL1HD44780U

6.30Making Things Work TogetherCheck the generated code Can check the code generated by the compiler to see what ishappening. For the creation of the E pulse the compiler generated thiscode:SBI PORTB, 1CBI PORTB, 1; Set Bit Immediate, PORTB, bit 1; Clear Bit Immediate, PORTB, bit 1 According to the manual, the SBI and CBI instructions eachtake 2 clock cycles 16MHz 62.5nsec/cycle, so pulse will be high for 125nsec

6.31Making Things Work TogetherCheck with the oscilloscope

6.32Making Things Work TogetherExtend the pulse At 125nsec, the E pulse it not long enough although it mightwork on some boards. Can use delay us() or delay ms() functions but these arelonger than needed since the minimum delay is 1 us ( 1000ns) and we only need 230 ns Trick for extending the pulse by a little bit:PORTB (1 PB1);PORTB (1 PB1);PORTB & (1 PB1);// Set E to 1// Add another 125nsec to the pulse// Clear E to 0

6.33Making Things Work TogetherBetter looking pulse

6.34Making Things Work TogetherExtend the pulse (geek way) Use the “asm” compiler directive to embed low levelassembly code within the C code. The AVR assembly instruction “NOP” does nothing, and takes1 cycle to do it.PORTB (1 PB1);asm(“nop”::);asm(“nop”::);PORTB & (1 PB1);// Set E to 1// NOP delays another 62.5ns// Clear E to 0

6.35Making Things Work TogetherDon’t guess that things will work When working with a device, make sure you know what typesof signals it needs to see–––––VoltageCurrentPolarity (does 1 mean enable/true or does 0)Duration (how long the signal needs to be valid)Sequence (which transitions comes first, etc.) Have the manufacturer’s datasheet for the device available– Most of it can be ignored, but some parts are critical– Learn how to read it When in doubt follow the acronym used industry-wide:RTFM (read the *!@ -ing manual)

LCD API Development Overview Write the routines to control the LCD in layers –Top level routines that your code or others can use: write a string to LCD, move the cursor, initialize LCD, etc. –Mid level routines: write a byte to the command register, write a byte to the data register –Low level routines: controls the 4 data lines and E to

Related Documents:

Many LCDs also come with an LCD controller that does the conversion between the MPU interface and the RGB signals. Some chips are both drivers and controllers. The role of the controller is to constantly refresh the LCD. Table 1 lists the differences between LCDs that integrate controllers and LCDs that need an MPU LCD controller. Table 1.

Botsuana Fijo Botswana Fixed 0.109 0.036 Brasil móvil Brazil Mobile 0.109 0.010 Brasil Fijo Brazil Fixed 0.010 0.010 Islas Vírgenes Británicas móvil British Virgin Islands Mobile 0.109 0.109 Islas Vírgenes Británicas Fijo British Virgin Islands Fixed 0.036 0.109 Brunei Darussalam móvil Brunei Darussalam Mobile 0.073 0.049 Brunei Darussalam Fijo Brunei Darussalam Fixed 0.073 0.012

6.4 Structure (Aggregates and Agglomerates) 108 6.4.1 n-Dibutyl Phthalate Absorption Number (D 6854) 108 6.5 General Methods 109 6.5.1 Volatiles (D 6738) 109 6.5.2 pH Value (D 6739) 109 6.6 Organosilanes 109 6.6.1 Determination of Residue on Ignition (D 6740) 109

Sep 13, 2018 · 109 Stay Puft Marshmallow Man 109 GITD Stay Puft (SDCC 14) 109 Toasted Stay Puft 109 Pink Stay Puft (Fugitive) 109 GITD Pink Stay Puft (Fugitive) . (Target) 507 Imperator Furiosa 507 Imperator Furiosa Goggles *Chase* 508 509 Max Rockantsky 510 Blood Bag 511 Nux w/ Goggles (Funko-Shop) 512 Nux

Replacement Parts for Window Sash Series 8500 Replacement Double-Hung Window Top Sash Parts - continued Weatherstripping (Sides of Top Sash) 109-20-WB1295NW-6 (White) 109-20-WB1295NG-6 (Grey) Weatherstripping (Top Sash Lift Rail) 109-20-W21195NW-6 (White) 109-20-W31195NG-6 (Grey) Weatherstripping (Top Sash Lock Rail) 109-20-W21325NW-6 (White)

Franzis Verlag, Poing 2010 Verlag C.H. Beck im Internet: www.beck.de ISBN 978 3 7723 4277 6 schnell und portofrei erhältlich bei beck-shop.de DIE FACHBUCHHANDLUNG. Frank Sichla Schaltungssammlun g Über 350 erprobte Schaltungen für Labor, Entwicklung, Anwendung und Ausbildung LEDs, LCDs und

LCDs are now found in products as small as mobile phones and as large as 42-inch flat panel screens. This white paper identifies the major types of LCDs, describes the technology in detail, shows how it works, and identifies major

LCDS Board of Directors 2011-2012 Frank Huybers, President Adrian Vermeiren, 1st Vice President Tony Hogervorst, 2nd Vice President Kari Lupton, Secretary Frank Backx, Treasurer Greg Bond, Director John Douglas, Director Orrin Farr, Director Corrine Nauta, Director Tom Saul, Director Terry Taylor, Director Nick Wells, Director Lisa Freer, Staff Representative .