ee 109 unit 9 lcd
play

EE 109 Unit 9 LCD LCD BOARD 9.3 9.4 How Do We Use It? The EE - PowerPoint PPT Presentation

9.1 9.2 EE 109 Unit 9 LCD LCD BOARD 9.3 9.4 How Do We Use It? The EE 109 LCD Shield The LCD shield is a _____________________ By sending it ______(i.e. _________________ LCD that mounts on top of the Arduino Uno. one at a time)


  1. 9.1 9.2 EE 109 Unit 9 – LCD LCD BOARD 9.3 9.4 How Do We Use It? The EE 109 LCD Shield • The LCD shield is a _____________________ • By sending it ______(i.e. _________________ LCD that mounts on top of the Arduino Uno. one at a time) that it will display for us • The shield also contains five buttons that can • By sending it special _____________to do be used as input sources. things like: – Move the cursor to a __________________ – ________ the screen contents – Upload new fonts/special characters 5 Button Inputs

  2. 9.5 9.6 How Do We Communicate? Commands and Data • The LCD uses a "parallel" interface (4-bits sent per transfer) to • LCD contains ___________ registers which it Command Code communicate with the µC (Note: µC => microcontroller) uses to control its actions: Command and Data Clear LCD 0x01 Curser Home 0x02 • Data is transferred 4 bits at a time and uses 2 other signals • A Register Select (RS) signal determines which (Upper-Left) (Register Select and Enable) to control _________ the 4-bits go register is the destination of the data we send Display On 0x0f and _________ the LCD should capture them it (RS acts like an address selector) Display Off 0x08 – RS = ____, info goes into the command register Move cursor 0x80+i – RS = ____, info goes into the data register to top row, Data lines column i • To perform operations like clear display, move D7 EE 109 is fun! D6 Move cursor 0xc0+i Walk your bike! cursor, turn display on or off, write the D5 to bottom command code to the command register. D4 row, column i Uno • To display characters on the screen, write the Register Select D8 ASCII code for the character to the data D9 register. Enable LCD 9.7 9.8 How Do We Communicate? How Do We Communicate? • To transfer data we send it in two groups of 4 • To transfer data we send it in two groups of 4 – First the ________ 4-bits followed by the _________ 4-bits • RS=0 sets the destination as the command reg. • RS=0 sets the destination as the command reg. • RS=1 sets the destination as the data reg. • RS=1 sets the destination as the data reg. 2 nd 2 nd 1 st 1 st Transfer Transfer Transfer Transfer Address Address Data lines Data lines (Reg. Select) (Reg. Select) 0 0 D7 1 D7 0 0 7 6 5 4 3 2 1 0 1 7 6 5 4 3 2 1 0 0 0 D6 D6 1 1 0 0011 1001 0 0011 1001 0 0 D5 D5 1 Display 0 Display 1 1 D4 D4 Command Reg. Command Reg. HW HW Uno Uno 1 1 0110 0001 Register Select 0 Register Select 1 0 1 D8 D8 Data Reg. Data Reg. D9 D9 Enable Enable LCD LCD

  3. 9.9 9.10 Another View Another View • Data from the Uno is transferred by placing four bits on the data • Data from the Uno is transferred by placing four bits on the data lines (PD[7:4]). lines (PD[7:4]). • The Register Select (RS) line determines whether the data goes • Whether sending info to the "command" or "data" register, the to the LCD’s "Command Register" or "Data Register" LCD still wants a full byte (8-bits) of data so we must do 2 transfers – RS=0 => Command Register RS=1 => Data Register – We always send the upper 4-bits of the desired data first • The Enable (E) line acts as a _________ signal telling the LCD to – Then we transfer the lower 4-bits capture the data and examine the RS bit on the _____ transition – Pulse must be held at 1 for at least 230ns according to LCD datasheet "0000 0101" sent to the "0000 0101" sent to the The first 4-bits of a The first 4-bits of a command register in the LCD command register in the LCD transfer to the data transfer to the data (PB0) RS (PB0) RS register in the LCD register in the LCD (PD[7:4]) Data 0000 0101 0110 (PD[7:4]) Data 0000 0101 0110 (PB1) Enable 230 ns 230 ns (PB1) Enable 230 ns 230 ns 230 ns 230 ns 9.11 9.12 Who's Job Is It? Other LCD Interface • So who is producing the • Other LCD devices may use // Turn on bit 0 of PORTD PORTD |= 0x01 values on the RS and Data – Only one signal (a.k.a. serial link) to communicate // Delay 1 us > 230ns needed lines and the 0-1-0 _delay_us(1); between the µC and LCD transition on the E line? // Turn off bit 0 of PORTD PORTD &= ~(0x01) • This makes wiring easier but requires more complex • _______!! With your This code would produce some software control to "serialize" the 8- or 16-bit numbers voltage pattern like this on PD0 ___________ (setting and used inside the µC clearing _______ bits) (PD0) – 8-data wires plus some other control signals so they can transfer an entire byte Note: The LCD connection doesn't use PD0, you'll need to modify this • This makes writing the software somewhat easier appropriately to generate the E signal

  4. 9.13 9.14 Step 1 • Mount the LCD shield on the Uno without destroying the pins • Download the “test.hex” file and Makefile from the web site, and modify the Makefile to suite your computer. LCD LAB PREPARATION • Run “make test” to download test program to the Uno+LCD. • Should see a couple of lines of text on the screen. 9.15 9.16 LCD API Development Overview Step 2 • Develop a set of functions that will • Write the routines to control the LCD in layers abstract the process of displaying – Top level routines that yours or others code can use: text on the LCD _____________________, __________________, etc. – A set of functions to perform specific – Mid level routines: write a byte to the command register, tasks for a certain module is often write a byte to the data register known as an _______ (application – Low level routines: controls data lines and E to transfer a programming interface) nibble to a register – Once the API is written it gives other • Goal: Hide the ________________ about how the application coders a nice simple interface actually works from the user who only interface to do high-level tasks wants to put a string on the display. • Download the skeleton file and examine the functions outlines on the next slides

  5. 9.17 9.18 High Level API Routines Mid-Level Functions • init_lcd() • writecommand(unsigned char x) – Does all the steps to initialize the LCD – Send the 8-bit byte ‘x’ to the LCD as a command – See the lab writeup and follow it exactly as written – Set RS to 0, send data in two nibbles, delay – Uses: writenibble(), writecommand(), delays – Uses: writenibble() • moveto(unsigned char row, unsigned char col) • writedata(unsigned char x) – Moves the LCD cursor to “row” (1 or 2) and “col” (1-16) – Translates from row/column notation to the format the LCD uses – Send the 8-bit byte ‘x’ to the LCD as data for positioning the cursor (see lab writeup) – Set RS to 1, send data in two nibbles, delay – Uses: writecommand() – Uses: writenibble() • stringout(char *s) – Writes a string of character starting at the current cursor position • Could do as one function – Uses: writedata() – writebyte(unsigned char x, unsigned char rs) 9.19 9.20 Step 3 Low Level Functions • Complete the LCD Lab after first • writenibble(unsigned char x) – Assumes RS is already set appropriately understanding how to use the buttons present – Send four bits from ‘x’ to the LCD on the LCD shield • Takes 4-bits of x and copies them to PD[7:4] (where we've – Information about how to use the buttons is connected the data lines of the LCD) presented in the next slides • Produces a 0-1-0 transition on the Enable signal – Must be consistent with mid-level routines as to which 4 bits to send, MSB or LSB – Uses: logical operations (AND/OR) on the PORT bits

  6. 9.21 9.22 LCD Shield Buttons LCD Shield Buttons • The LCD shield has 5 buttons • You can use the Arduino's _________ converter to sense when a button is • However, they do not produce 5 pressed individual signals like you are used to from previous labs • Each button produces a certain voltage when pressed and the default • They are configured in such a way value of 5V when no button is pressed Button Volts Avg. such that they sum together to (V) 10-bit produce a single ______________ • The table to the right shows the Value which the shield connects to the nominal voltages and 10-bit ADC result Right 0 V 0 5 Button Inputs A0 input of the Arduino => 1 analog – Note these are nominal and could be Up 1.0 V 208 voltage different so it would be best to just split • If the voltage is in _____________ Down 2.0 V 408 the range evenly (e.g. to know the 'Up' A0 we can infer that a particular Left 3.1 V 624 button is pressed check if the 10-bit ADC button is being pressed Select 4.0 V 816 results is between 104 and 308 ) Uno None 5V 1023 9.23 9.24 Making Things Work Together Does your code do the right thing? • Lab 6 required the program to generate an Enable (E) pulse. • Example: The writenibble() routine controls the PB1 bit that is connected to the LCD Enable line. PORTB |= (1 << PB1); // Set E to 1 PORTB &= ~(1 << PB1); // Clear E to 0 • Creates a 0 ➞ 1 ➞ 0 pulse to clock data/commands into LCD. Ensuring the Enable pulse is long enough • But is it a pulse that will work with the LCD? THE DEVIL IN THE DETAILS… • Rumors circulated that the E pulse had to be made longer by putting a delay in the code that generated it. • Don’t Guess. Time to read the manual, at least a little bit.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend