The EE 109 LCD Shield

Similar documents
The EE 109 LCD Shield

6.1. EE 109 Unit 6. LCD Interfacing

EE 109 Unit 4. Microcontrollers (Arduino) Overview

Embedded Systems and Software. LCD Displays

FPGA Interfacing of HD44780 Based LCD Using Delayed Finite State Machine (FSM)

12.1. Unit 12. Exceptions & Interrupts

ECE 4510/5530 Microcontroller Applications Week 9

AN1745. Interfacing the HC705C8A to an LCD Module By Mark Glenewinkel Consumer Systems Group Austin, Texas. Introduction

Embedded Systems and Software

LCD Display. Other I/O. LCD display Flash ROM SPI EPROM Keyboard (PS/2) UART connectors DAC ADC. 2-line, 16 character LCD display

LCD AND KEYBOARD INTERFACING

Dragon12 LCD Displays Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) Dragon12 LCD Display. The Dragon12 board has a 16 character x 2 line display

Dragon12 LCD Displays Huang Sections 7.8 Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) ATD_10B8C Block User Guide. Dragon12 LCD Display

EMBEDDED HARDWARE DESIGN. Tutorial Interfacing LCD with Microcontroller /I

Dragon12 LCD Displays Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) Dragon12 LCD Display. The Dragon12 board has a 16 character x 2 line display

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

IAS0430 MICROPROCESSOR SYSTEMS

Adafruit VL53L0X Time of Flight Micro-LIDAR Distance Sensor Breakout

19.1. Unit 19. Serial Communications

Serial Communications

Lab 5: LCD and A/D: Digital Voltmeter

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

Programming Microcontroller Assembly and C

LCDs. Embedded Systems Interfacing. 20 September 2011

EE251: Thursday September 20

DOT MATRIX CHARACTER LCD MODULE USER S MANUAL

// sets the position of cursor in row and column

Introduction. Unit 4. Numbers in Other Bases in C/C++ BIT FIDDLING. Microcontrollers (Arduino) Overview Digital I/O

Cab Bus Communications Protocol

LABORATORY MANUAL Interfacing LCD 16x2, Keypad 4x4 and 7Segment Display to PIC18F4580

Laboratory 3 Working with the LCD shield and the interrupt system

ADC to I 2 C. Data Sheet. 10 Channel Analog to Digital Converter. with output via I 2 C

Getting Started Guide

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR Intermediate Development Board. Product Manual. Contents. 1) Overview 2) Features 3) Using the board 4) Troubleshooting and getting help

LCD03 - I2C/Serial LCD Technical Documentation

Alphanumeric LCD display module 24 characters by 2 line. General description

Lab 5: LCD and A/D: Digital Voltmeter

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

AVR Board Setup General Purpose Digital Output

MICROPROCESSOR AND MICROCONTROLLER BASED SYSTEMS

LCD. Configuration and Programming

DIGITAL HUMIDITY SENSOR HYT-131

AN703. Micro64/128. Accessing the 36k of SRAM 12/3/04

CPEG300 Embedded System Design. Lecture Interface with Peripheral Devices

Laboratory 1 Introduction to the Arduino boards

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

Embedded Systems and Software

CLCD1 Serial 1 wire RS232 LCD development board

Logosol Joystick Node LS-731

Lab Overview. Lab Details. ECEN 4613/5613 Embedded System Design Week #7 Spring 2005 Lab #4 2/23/2005

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

SC1602LC 16x2 Large Characters RS232 LCD Module. User s Manual. Large Viewing Area 99mm x 24mm. Large Character Size. 4.84mm x 9.66mm.

Unit 13 Timers and Counters

AVR ISA & AVR Programming (I)

How2Use DT-AVR ATMEGA168 BMS. By: IE Team. Picture 1 The layout of DT-AVR ATMEGA168 BMS

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

RS 232 PINOUTS. 1. We use RJ12 for all of our RS232 interfaces (Link-2-Modbus & Link-2-PC- Serial/RS232). The diagram below shows our pin out.

Winford Engineering ETH32 Protocol Reference

LCD03 - I2C/Serial LCD Technical Documentation

Embedded programming, AVR intro

commodore semiconductor group NMOS 950 Rittenhouse Rd., Norristown, PA Tel.: 215/ TWX: 510/ (MEMORY, I/O, TIMER ARRAY)

Application Note. Interfacing the CS5521/22/23/24/28 to the 68HC05. Figure 1. 3-Wire and 4-Wire Interfaces

Exam 1. Date: February 23, 2016

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

1/Build a Mintronics: MintDuino

Principle and Interface Techniques of Microcontroller

Power Driver 16 v2. Version 2.0 July 5, 2017

EE389 EDL Report, EE Deptt., IIT Bombay, Nov RF linked Handheld Terminal

Laboratory 10. Programming a PIC Microcontroller - Part II

PSIM Tutorial. How to Use SPI in F2833x Target. February Powersim Inc.

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

Embedded Systems and Software

EE 109 Unit 20. IEEE 754 Floating Point Representation Floating Point Arithmetic

Microcontrollers. Outline. Class 1: Serial and Digital I/O. March 7, Quick Tour of the Board. Pins, Ports, and Their Registers

Interface DAC to a PC. Control Word of MC1480 DAC (or DAC 808) 8255 Design Example. Engineering 4862 Microprocessors

INTERFACING 16 2 LCD WITH 8051

The Atmel ATmega328P Microcontroller

Lab Report for Sensor Calibration using a PIC16F84 GROUP MEMBERS ALFRED MAZHINDU SIMBARASHE CHIWESHE

MICROPROCESSORS A (17.383) Fall Lecture Outline

C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipkit\homework Sheets.docx

Device: FDRV-04S. This document version: v1. Matches module version: v2 [2 Oct 2015] Document revision date: 9 November 2015

LABORATORY 1 INTRODUCTION TO 8085 MICROPROCESSOR DEVELOPMENT SYSTEM BOARD

Digital Circuits 7: MCUs... how do they work?

Fall 2017 Project Assignment Speed Trap

Parallel Display Specifications Revision 1.0

LDR_Light_Switch2 -- Overview

ECE 375: Computer Organization and Assembly Language Programming

University of Florida EEL 4744 Spring 2011 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 31 March Apr-11 1:29 PM

17. I 2 C communication channel

SX1509 I/O Expander Breakout Hookup Guide

ZL10AVR. Versatile Evaluation Board for AVR Microcontrollers

Microcontroller and Embedded Systems:

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

STEPD StepDuino Quickstart Guide

Floating Point. EE 109 Unit 20. Floating Point Representation. Fixed Point

Goal: We want to build an autonomous vehicle (robot)

Lab-3: LCDs Serial Communication Analog Inputs Temperature Measurement System

Layman definition: Gadgets and devices Technical definition: Self-controlled devices Usually, such systems consist of I/O (input/output) devices such

University of Florida EEL 4744 Fall 1998 Dr. Eric M. Schwartz

Transcription:

EE 109 Unit 7 LCD 1

LCD BOARD 2

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

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

5 How Do We Communicate? The LCD uses a "parallel" interface (4-bits sent per transfer) to communicate 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 and when the LCD should capture them Uno D7 D6 D5 D4 Data lines EE 109 is fun! Walk your bike! D8 D9 Register Select Enable LCD

6 Commands and Data LCD contains two 8-bit registers which it uses to control its actions: Command and Data A Register Select (RS) signal determines which register is the destination of the data we 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 the command code to the command register. To display characters on the screen, write the ASCII code for the character to the data register. Command Clear LCD Curser Home (Upper-Left) Display On Display Off Move cursor to top row, column i Move cursor to bottom row, column i Code 0x01 0x02 0x0f 0x08 0x80+i 0xc0+i

7 How Do We Communicate? To transfer data we send it in two groups of 4 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. Uno D7 D6 D5 D4 D8 D9 Data lines Register Select Enable 2 nd Transfer 1 0 0 1 0 1 st Transfer 0 0 1 1 0 Address (Reg. Select) 0 1 7 6 5 4 3 2 1 0 0011 1001 Command Reg. Data Reg. LCD Display HW

8 How Do We Communicate? To transfer data we send it in two groups of 4 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. Uno D7 D6 D5 D4 D8 D9 Data lines Register Select Enable 2 nd Transfer 0 0 0 1 1 1 st Transfer 0 1 1 0 1 Address (Reg. Select) 0 1 7 6 5 4 3 2 1 0 0011 0110 LCD 1001 Command Reg. 0001 Data Reg. Display HW

9 Another View Data from the Uno is transferred by placing four bits on the data lines (PD[7:4]). The Register Select (RS) line determines whether the data goes to the LCD s "Command Register" or "Data Register" RS=0 => Command Register RS=1 => Data Register The Enable (E) line acts as a "clock" signal telling the LCD to 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 (PB0) RS "0000 0101" sent to the command register in the LCD The first 4-bits of a transfer to the data register in the LCD (PD[7:4]) Data 0000 0101 0110 (PB1) Enable 230 ns 230 ns 230 ns

10 Another View Data from the Uno is transferred by placing four bits on the data lines (PD[7:4]). Whether sending info to the "command" or "data" register, the LCD still wants a full byte (8-bits) of data so we must do 2 transfers We always send the upper 4-bits of the desired data first Then we transfer the lower 4-bits (PB0) RS "0000 0101" sent to the command register in the LCD The first 4-bits of a transfer to the data register in the LCD (PD[7:4]) Data 0000 0101 0110 (PB1) Enable 230 ns 230 ns 230 ns

11 Who's Job Is It? So who is producing the values on the RS and Data lines and the 0-1-0 transition on the E line? You!! With your digital I/O (setting and clearing PORT bits) // Turn on bit 0 of PORTD PORTD = 0x01 // Delay 1 us > 230ns needed _delay_us(1); // Turn off bit 0 of PORTD PORTD &= ~(0x01) This code would produce some voltage pattern like this on PD0 (PD0) Note: The LCD connection doesn't use PD0, you'll need to modify this appropriately to generate the E signal

12 Other LCD Interface Other LCD devices may use Only one signal (a.k.a. serial link) to communicate between the µc and LCD This makes wiring easier but requires more complex software control to "serialize" the 8- or 16-bit numbers used inside the µc 8-data wires plus some other control signals so they can transfer an entire byte This makes writing the software somewhat easier

LCD LAB PREPARATION 13

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. Run make test to download test program to the Uno+LCD. Should see a couple of lines of text on the screen.

15 Step 2 Develop a set of functions that will abstract the process of displaying text on the LCD A set of functions to perform specific tasks for a certain module is often known as an API (application programming interface) Once the API is written it gives other application coders a nice simple interface to do high-level tasks Download the skeleton file and examine the functions outlines on the next slides

16 LCD API Development Overview Write the routines to control the LCD in layers Top level routines that yours or others code can use: write a string to LCD, initialize LCD, etc. Mid level routines: write a byte to the command register, write a byte to the data register Low level routines: controls data lines and E to transfer a nibble to a register Goal: Hide the ugly details about how the interface actually works from the user who only wants to put a string on the display.

17 Low Level Functions 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've connected 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 which 4 bits to send, MSB or LSB Uses: logical operations (AND/OR) on the PORT bits

18 Mid-Level Functions 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: writenibble() 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: writenibble() Could do as one function writebyte(unsigned char x, unsigned char rs)

19 High Level API Routines init_lcd() Does all the steps to initialize the LCD See the lab writeup and follow it exactly as written Uses: writenibble(), writecommand(), delays 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 uses for positioning the cursor (see lab writeup) Uses: writecommand() stringout(char *s) Writes a string of character starting at the current cursor position Uses: writedata()

COPYING BITS 20

21 Copying Multiple Bits Suppose we want to copy a portion of a variable or register into another BUT WITHOUT affecting the other bits Example: Copy the lower 4 bits of X into the lower 4-bits of PORTB but leave the upper 4-bits of PORTB UNAFFECTED Assignment doesn't work since it will overwrite ALL bits of PORTB PORTB = x; // changes all bits of PORTB x 0 1 0 0 0 0 1 1 PORTB???????? PORTB???? 0 0 1 1 Desired Result PORTB 0 1 0 0 0 0 1 1 PORTB = x; Result

22 Copying Into a Register Solution use these steps: Step 1: Define a mask that has 1 s where the bits are to be copied #define MASKBITS 0x0f Step 2: Clear those bits in the destination register using the MASK PORTB &= ~MASKBITS Step 3: Mask the appropriate field of x and then OR it with the destination, PORTB PORTB = (x & MASKBITS); Step 1 Step 2 Step 3 x 0 1 0 0 0 0 1 1 MASKBITS = 0 0 0 0 1 1 1 1 PORTB???????? & 1 1 1 1 0 0 0 0 PORTB???? 0 0 0 0 x 0 1 0 0 0 0 1 1 & MASKBITS 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 PORTB???? 0 0 0 0 Result PORTB???? 0 0 1 1

23 Do We Need Step 2 Yes!!! Can't we just do step 1 and 3 and OR the bits of x into PORTB #define MASKBITS 0x0f PORTB = (x & MASKBITS); No, because what if the destination (PORTB) already had some 1's where wanted 0's to go Just OR'ing wouldn't change the bits to 0 That's why we need step 2 Step 2: Clear those bits in the destination register using the MASK PORTB &= ~MASKBITS; Step 1 & 3 Result PORTB???? 1 1 1 0 What if PORTB just happened to have these bits initially x 0 1 0 0 0 0 1 1 & MASKBITS 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 PORTB???? 1 1 1 0 PORTB???? 1 1 1 1

24 Copying To Different Bit Locations What if the source bits are in a different location than the destination Ex. Copy lower 4 bits of x to upper 4 bits of PORTB Step 1: Define a mask that has 1 s where the bits are to be copied #define MASKBITS 0xf0 Step 2: Clear those bits in the destination register using the MASK PORTB &= ~MASKBITS Step 3: Shift the bits of x to align them appropriately, then perform the regular step 3 PORTB = ((x<<4) & MASKBITS); Step 1 Step 2 Step 3 Result x 0 1 0 0 0 0 1 1 MASKBITS = 1 1 1 1 0 0 0 0 PORTB???????? & 0 0 0 0 1 1 1 1 PORTB 0 0 0 0???? x 0 1 0 0 0 0 1 1 x << 4 0 0 1 1 0 0 0 0 & MASKBITS 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 PORTB 0 0 0 0???? PORTB 0 0 1 1????

25 Step 3 Complete the LCD Lab after first understanding how to use the buttons present on the LCD shield Information about how to use the buttons is presented in the next slides

26 LCD Shield Buttons The LCD shield has 5 buttons However, they do not produce 5 individual signals like you are used to from previous labs They are configured in such a way such that they sum together to produce a single analog voltage which the shield connects to the A0 input of the Arduino If the voltage is in certain range we can infer that a particular button is being pressed 5 Button Inputs => 1 analog voltage A0 Uno

27 LCD Shield Buttons You can use the Arduino's A-to-D converter to sense when a button is pressed Each button produces a certain voltage when pressed and the default value of 5V when no button is pressed The table to the right shows the nominal voltages and 8-bit ADC result Note these are nominal and could be different so it would be best to just split the range evenly (e.g. to know the 'Up' button is pressed check if the 8-bit ADC results is between 26 and 77) Button Volts (V) Avg. 8-bit Value Right 0 V 0 Up 1.0 V 52 Down 2.0 V 104 Left 3.1 V 156 Select 4.0 V 208 None 5V 255

28 Ensuring the Enable pulse is long enough THE DEVIL IN THE DETAILS

29 Making Things Work Together Does 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 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. But is it a pulse that will work with the LCD? 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.

Making Things Work Together 30 Timing Characteristics Check the LCD controller datasheet HD44780U RS VIH1 VIL1 VIH1 VIL1 t AS t AH R/W VIL1 VIL1 PW EH t AH t Ef E VIH1 VIL1 VIH1 VIL1 VIL1 t Er t DSW t H DB0 to DB7 VIH1 VIL1 Valid data VIH1 VIL1 t cyce Figure 27 Write Operation

31 Making Things Work Together Check the generated code Can check the code generated by the compiler to see what is happening. For the creation of the E pulse the compiler generated this code: SBI PORTB, 1 ; Set Bit Immediate, PORTB, bit 1 CBI PORTB, 1 ; Clear Bit Immediate, PORTB, bit 1 According to the manual, the SBI and CBI instructions each take 2 clock cycles 16MHz 62.5nsec/cycle, so pulse will be high for 125nsec

Making Things Work Together 32 Check with the oscilloscope

33 Making Things Work Together Extend the pulse At 125nsec, the E pulse it not long enough although it might work on some boards. Can use _delay_us() or _delay_ms() functions but these are longer than needed since the minimum delay is 1 us (=1000 ns) and we only need 230 ns Trick for extending the pulse by a little bit: PORTB = (1 << PB1); // Set E to 1 PORTB = (1 << PB1); PORTB &= ~(1 << PB1); // Clear E to 0 // Add another 125nsec to the pulse

Making Things Work Together 34 Better looking pulse

35 Making Things Work Together Extend the pulse (geek way) Use the asm compiler directive to embed low level assembly code within the C code. The AVR assembly instruction NOP does nothing, and takes 1 cycle to do it. PORTB = (1 << PB1); // Set E to 1 asm( nop ::); asm( nop ::); PORTB &= ~(1 << PB1); // Clear E to 0 // NOP delays another 62.5ns

36 Making Things Work Together Don t guess that things will work When working with a device, make sure you know what types of signals it needs to see Voltage Current Polarity (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)

37 Logical Operations Bit # 7 6 5 4 3 2 1 0 Transfer Byte data 7 6 5 4 3 2 1 0 a b c d e f g h v???????? & writenibble a b c d e f g h v??????? 0 writenibble e f g h???? v???????? writenibble lcdbits 7 6 5 4 3 2 1 0???????? v 1??????? PORTD???????? v???????? ^ 0 0 0 0 1 1 1 1 v????????