6.1 6.2 EE 109 Unit 6 LCD Interfacing LCD BOARD 6.3 6.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
6.5 6.6 How Do We Communicate? How Do We Communicate? • The LCD uses a "parallel" interface (4-bits sent per transfer) to • To send an 8-bit byte we must send it in two groups of 4 bits communicate with the µC (Note: µC => microcontroller) – First the __________ 4-bits followed by the _________ 4-bits • Data is transferred 4 bits at a time and uses 2 other signals • RS=0 sets the destination as the command reg. (Register Select and Enable) to control _______ the 4-bits go and • RS=1 sets the destination as the data reg. ______ the LCD should capture them 2 nd 1 st Transfer Transfer Address Data lines Data lines (Reg. Select) 0 D7 EE 109 is fun! D7 1 0 7 6 5 4 3 2 1 0 0 D6 D6 1 0 0011 1001 0 D5 D5 Display 1 1 D4 D4 Command Reg. HW Uno Uno 1 Register Select 0 Register Select 0 D8 D8 Data Reg. D9 D9 Enable Enable LCD LCD 6.7 6.8 Commands and Data How Do We Communicate? Command Code • LCD contains _______ registers which it uses • To send an 8-bit byte we must send it in two groups of 4 bits Clear LCD 0x01 to control its actions: Command and Data – First the upper 4-bits followed by the lower 4-bits Curser Home 0x02 • A Register Select (RS) signal determines • RS=0 sets the destination as the command reg. (Upper-Left) which register is the destination of the data • RS=1 sets the destination as the data reg. Display On 0x0f we send it (RS acts like an address selector) Display Off 0x08 – RS = ___, info goes into the command register 2 nd Move cursor 0x80+i 1 st Transfer – RS = ___, info goes into the data register Transfer to top row, Address Data lines column i (Reg. Select) • To perform operations like clear display, 0 D7 0 1 7 6 5 4 3 2 1 0 0 D6 Move cursor 0xc0+i move cursor, turn display on or off, write the 1 0 0011 1001 0 D5 to bottom 0 Display command code to the command register. 1 D4 Command Reg. row, column i HW Uno • To display characters on the screen, write 1 0110 0001 Register Select 1 1 D8 the ASCII code for the character to the data Data Reg. D9 register. Enable LCD
6.9 6.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 (Port D bits 7-4). lines (Port D bits 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 0-1-0 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 (PD7-4) Data 0000 0101 0110 (PD7-4) Data 0000 0101 0110 (PB1) Enable 230 ns 230 ns (PB1) Enable 230 ns 230 ns 230 ns 230 ns 6.11 6.12 Who's Job Is It? Other LCD Interface // Turn on bit 0 of PORTD PORTD |= ___ • So who is producing the • Other LCD devices may use // Delay 1 us > 230ns needed // A better way in a few slides values on the RS and Data _delay_us(1); – Only one signal (a.k.a. serial link) to communicate // Turn off bit 0 of PORTD lines and the 0-1-0 PORTD &= _____ between the µC and LCD transition on the E line? This code would produce some • This makes wiring easier but requires more complex voltage pattern like this on PD0 • ______!! With your software control to "serialize" the 8- or 16-bit numbers (PD0) ___________ (setting and used inside the µC clearing PORT bits) – 8-data wires plus some other control signals so Note: The LCD connection doesn't use PD0, you'll need to modify this they can transfer an entire byte appropriately to generate the E signal • This makes writing the software somewhat easier
6.13 6.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. 6.15 6.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 your code or others can use: text on the LCD ______________, ____________, initialize 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 the 4 data lines and E to programming interface) transfer a 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
6.17 6.18 Low Level Functions Mid-Level Functions • lcd_writenibble(unsigned char x) • lcd_writecommand(unsigned char x) – Assumes RS is already set appropriately – Send the 8-bit byte ‘x’ to the LCD as a command – Send four bits from ‘x’ to the LCD – Set RS to 0, send data in two nibbles, delay • Takes 4-bits of x and copies them to PD[7:4] (where we've – Uses: lcd_writenibble() connected the data lines of the LCD) • lcd_writedata(unsigned char x) • SEE NEXT SLIDES ON COPYING BITS – Send the 8-bit byte ‘x’ to the LCD as data • Produces a 0-1-0 transition on the Enable signal – Must be consistent with mid-level routines as to which – Set RS to 1, send data in two nibbles, delay 4 bits to send, MSB or LSB – Uses: lcd_writenibble() – Uses: logical operations (AND/OR) on the PORT bits • Could do as one function – lcd_writebyte(unsigned char x, unsigned char rs) This will be your challenge to write in lab! This will be your challenge to write these two functions in lab! 6.19 6.20 Activity: Code-Along High Level API Routines • lcd_init() • Assuming the lcd_writecommand() and – Mostly complete code to perform initialization sequence lcd_writedata() functions are correctly – See lab writeup for what code you MUST add. written, code the high-level functions: – Uses: lcd_writenibble(), lcd_writecommand() , delays – void lcd_stringout(char* str); • lcd_moveto(unsigned char row, unsigned char col) – Moves the LCD cursor to “row” (0 or 1) and “col” (0-15) – void lcd_moveto(int row, int col); – Translates from row/column notation to the format the LCD uses for 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()
Recommend
More recommend