EET 2261 Unit 11 Controlling LCD and Keypad

Slides:



Advertisements
Similar presentations
EET 2261 Unit 12 Controlling LCD and Keypad
Advertisements

EET 2261 Unit 14 INCOMPLETE Analog-to-Digital Conversion (ADC) & Digital-to-Analog Conversion (DAC)  Read.  Homework #13 and Lab #13 due next week. 
TK2633 Introduction to Parallel Data Interfacing DR MASRI AYOB.
EET 2261 Unit 8 Seven-Segment Displays; S19 Records; System Clocks
EET 2261 Unit 9 Interrupts  Read Almy, Chapters 17 – 19.  Homework #9 and Lab #9 due next week.  Quiz next week.
EET 1131 Unit 6 Exclusive-OR and Exclusive-NOR Gates  Read Kleitz, Chapter 6.  Do Unit 6 e-Lesson.  Homework #6 and Lab #6 due next week.  Quiz next.
EET 2261 Unit 13 Controlling Stepper Motors and Servos  Read Almy, Chapter 21.  Lab #13 due next week.  Final Exam next week.
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Getting the O in I/O to work on a typical microcontroller Ideas of how to send output signals to the radio controlled car. The theory behind the LED controller.
Getting the O in I/O to work on a typical microcontroller Activating a FLASH memory “output line” Part 1 Main part of Laboratory 1 Also needed for “voice.
EET 2261 Unit 2 HCS12 Architecture
EET 2261 Unit 7 I/O Pins and Ports
Embedded Programming and Robotics Lesson 9 Keypad and LCD Display 1.
16x2 LCD Module on DE2-115 數位電路實驗 TA: 吳柏辰 Author: Trumen.
Parallel Ports of PC Methods of interfacing Examples.
Digital Outputs LCD Display
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC.
KEYBOARD INTERFACING Keyboards are organized in a matrix of rows and columns The CPU accesses both rows and columns through ports. ƒTherefore, with two.
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
Introducing your TI-83/84 Plus Graphing Calculator
Using a SparkFun™ serial LCD with an Arduino
EET 2261 Unit 13 Enhanced Capture Timer
Binary Representation in Text
Binary Representation in Text
EET 1131 Unit 4 Programmable Logic Devices
EECE6017C Lab 1 Introduction to Altera tools and Circuit Simulation
EGR 2131 Unit 4 Combinational Circuits: Analysis & Design
EET 2259 Unit 13 Strings and File I/O
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
Fundamentals of Computer Engineering
LCD AND KEYBOARD INTERFACING
EGR 2261 Unit 10 Two-dimensional Arrays
LCD and Keyboard Interfacing
UNIT – Microcontroller.
Microcontroller Based Digital Code Lock
EGR 2261 Unit 4 Control Structures I: Selection
DIGITAL CALCULATOR USING 8051
Counters Next, we’ll look at different kinds of counters and discuss how to build them. These are not only examples of sequential analysis and design,
Guide To UNIX Using Linux Third Edition
EET 1131 Unit 6 Exclusive-OR and Exclusive-NOR Gates
Microprocessor and Assembly Language
EET 2261 Unit 11 Controlling LCD and Keypad
Interfacing Memory Interfacing.
LCD and Keyboard Interfacing
8255.
LCD and Keyboard Interfacing
EET 2261 Unit 9 Interrupts Read Almy, Chapters 17 – 19.
EET 2261 Unit 14 INCOMPLETE Analog-to-Digital Conversion (ADC) & Digital-to-Analog Conversion (DAC) Read. Homework #13 and Lab #13 due next week. Quiz.
LCD and Keyboard Interfacing
LCD and Keyboard Sepehr Naimi
EET 2261 Unit 12 Controlling Stepper Motors and Servos
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
EET 1131 Unit 3 Basic Logic Gates
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
EET 2261 Unit 8 Seven-Segment Displays
Counters Next, we’ll look at different kinds of counters and discuss how to build them. These are not only examples of sequential analysis and design,
Branch instructions We’ll implement branch instructions for the eight different conditions shown here. Bits 11-9 of the opcode field will indicate the.
Building an SBC-51 The Single Board Computer SBC-51 is a simple 8051 platform for learning and experimenting with the hardware and software development.
8279 – Programmable Keyboard/Display Interface
LCD and Keyboard Interfacing
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
LCD (LIQUID CRISTAL DISPLAY) SCREENS
EET 2259 Unit 13 Strings and File I/O
EGR 2131 Unit 12 Synchronous Sequential Circuits
Counters Next, we’ll look at different kinds of counters and discuss how to build them. These are not only examples of sequential analysis and design,
Registers Today we’ll see some common sequential devices: counters and registers. They’re good examples of sequential analysis and design. They are also.
LCD AND KEYBOARD INTERFACING
ASCII and Unicode.
Presentation transcript:

EET 2261 Unit 11 Controlling LCD and Keypad Read Almy, Appendix E. Homework #11 and Lab #11 due next week. Quiz next week. Handouts: Units 9 & 10 quiz, Unit 11 practice sheet.

Liquid-Crystal Display The Dragon12 board has a liquid-crystal display (LCD) module that lets the programmer display text messages to the user. Datasheet for SHZJ-A162A LCD module The LCD module contains an LCD panel and an LCD microcontroller that has its own memory distinct from the HCS12’s memory. This microcontroller handles most of the work of displaying characters on the LCD panel. Datasheet for S6A0069 LCD controller

Dimensions of Our LCD Panel The S6A0069 can control a variety of LCD panels. Variations include: Number of lines (1 or 2) Number of characters per line (16, 20, 40… ) Size of matrix of dots that make up a character (5x8, 5x11). Our panel has two lines of 16 characters per line, with a 5x8 matrix of dots for each character. If we write a program that uses the LCD, we’ll have to include initialization code to configure the S6A0069 for the panel we’re using.

5x8 Dot Matrix Example The figure to the right shows which of the dots in the 5x8 matrix are lit to display an A. Normally we won’t have to worry about this level of detail. We’ll just send the ASCII code for A to the LCD module, and it will take care of lighting up the correct dots. But we do have the ability to create custom characters if we wish. Contrast with 7-segment displays, where we had to turn on or off each individual segment.

List of LCD Commands (Instructions) See Table 7 on page 16 of the S6A0069 datasheet for a list of all commands that the LCD recognizes. (See pages 12-15 for explanations of these commands.) Most of these commands are used for initialization, such as specifying: Whether our LCD panel has 1 line or 2. Whether it displays characters with a 5x8 dot matrix or a 5x11 matrix. Whether we want the cursor to be visible. Whether we want the cursor to blink.

Interpreting the List of LCD Commands In Table 7, note that the position of the leftmost 1 in the one-byte command code tells you which command you’re dealing with. Example: Any command code whose leftmost 1 is in bit 2 (such as $04, $05, $06, $07) is an Entry Mode Set command. Do Practice Questions 1 through 4.

Typical Initialization Code

I/O Pins on the LCD Module Figure and table from the SHZJ-A162A datasheet. Highlighted signals are the only ones we care about.

LCD Connections on Dragon12 LCD is connected to bits 0 through 5 of the HCS12’s Port K. The LCD’s R/W pin is permanently grounded (through jumper J5), placing the LCD permanently in write mode. Otherwise we’d need two ports to control the LCD. Using only a 4-bit bus saves us pins, but makes our lives a bit harder. Figure from page 4 of the Dragon12 schematic diagrams. Only 4 of the 8 bits on the LCD’s data bus are connected to the HCS12. This is a common practice, to save pins, and it’s why our initialization code starts by switching into 4-bit mode.

Command or Data? We can send two kinds of things to the LCD module: Commands, such as: Clear the display. Move cursor to the 4th position on line 1. Make the cursor blink. Data, which is ASCII code for text to be displayed, such as “Rock on!” We must set Port K bit 0 (which connects to the LCD module’s RS pin) LOW when we’re sending a command, and set it HIGH when we’re sending data.

Executing the Command or Data We must hold Port K bit 1 (which connects to the LCD module’s E pin) LOW most of the time. But after we’ve set the RS line to its correct level, and put a command or data on the bus, we must send a brief LOW-to-HIGH-to-LOW pulse on Port K bit 1. This pulse tells the LCD module to read the command or data that we’ve put on the bus.

Steps for Sending a Command to the LCD To send a command (such as Clear Screen) to the LCD, a program must: Store the upper nibble of the command byte to Port K bits 2-5, and set Port K bit 0 LOW. (Port K Bit 0 tells whether we’re sending a command or data.) Pulse Port K bit 1 HIGH-then-LOW. Store the lower nibble of the command byte to Port K bits 2-5 , and set Port K bit 0 LOW.

Sample Code For Sending a Command (Assumes command byte is in Accumulator A)

Steps for Sending Data to the LCD To send data (such as the character H) to the LCD, a program must: Store the upper nibble of the data byte to Port K bits 2-5, and set Port K bit 0 HIGH. Pulse Port K bit 1 HIGH-then-LOW. Store the lower nibble of the data byte to Port K bits 2-5 , and set Port K bit 0 HIGH. Almost the same as the steps for sending a command.

Code For Sending Data You can easily modify the SendCommand subroutine (on the slide before the previous one) to create a SendData subroutine.

Sample Code for Displaying a Character Assuming we’ve set everything up correctly with our initialization code, and we’ve created the SendCommand and SendData subroutines, we can send text to be displayed. The code below positions the cursor and then sends an H.

ASCII Code As defined in the 1960’s, ASCII code is a 7-bit code, whose values range from $0 to $7F (or %0111 1111). Thus it contains the codes for 128 characters, as shown on page 375 of our textbook. The first 32 codes (from $0 to $1F) and the last code ($7F) were originally defined as non-printable control codes to control Teletype equipment. Many of these control codes are obsolete in today’s world.

Extending the ASCII Code Since the 1960’s, manufacturers have extended the ASCII code in two ways: By redefining some of the now-obsolete control codes. By extending the code from 7 bits to 8 bits, thus allowing for an additional 128 characters. One such widely used extension is the one that IBM used on its PCs: see http://en.wikipedia.org/wiki/Code_page_437. Our LCD module assigns different characters to these codes.

Our LCD Module’s Character Set On our LCD module: Codes $00 through $07 are reserved for user-defined characters. Codes $08 through $1F are unused. Most of the codes in the range $20 through $7F agree with the standard ASCII set. Codes $80 through $9F are unused. Codes $A0 through $FF produce special characters.

CGROM and CGRAM Our LCD module has a character generator read-only memory (CGROM) in which the bit patterns for the built-in characters are permanently stored. It also has a character generator RAM (CGRAM) in which you can define bit patterns for up to 8 custom characters. After programming the CGRAM to define a bit pattern for a custom character, you print the character by printing one of the ASCII codes $00 through $07.

Defining Custom Characters To define the character corresponding to code $00, you must program a bit pattern by writing to locations $00 through $07 in the CGRAM. To define the character corresponding to code $01, you must program a bit pattern by writing to locations $80 through $87 in the CGRAM. And so on. See next slide.

Defining Custom Characters Figure from p. 11 of S6A0069 datasheet (with fixed typo highlighted in yellow.)

Sample Code for Defining a Custom Character To define the A shown on previous slide: -Do Practice Question 5.

Sample Code for Displaying a Custom Character Having defined our A, let’s display it, followed by a standard, built-in A:

Dragon12-Plus2 Keypad Our Dragon12-Plus2 board has a keypad with 16 switches (or keys). If each key were connected to its own I/O pin on the HCS12, that would use 16 I/O pins (two 8-pin ports). But instead the Dragon board uses a standard trick for reading all 16 keys with only 8 I/O pins (one 8-pin port). See next slide….

Dragon12-Plus2 Keypad The switches are arranged in a 4-by-4 matrix. Each row of this matrix is attached to one of the Port A pins PA4 to PA7. Each column of the matrix is attached to one of the Port A pins PA0 to PA3. See diagram on next slide….

Dragon12 Keypad Connections Figure from p. 26 of Dragon12-Plus2 manual.

Configuring the Keypad To use the keypad, we must first configure it: Configure Port A pins 0 to 3 as outputs. (These are the pins connected to the keypad columns.) Configure Port A pins 4 to 7 as inputs. (These are the pins connected to the keypad rows.)

Identifying Which Key is Pressed General idea: Make one column output HIGH at a time (while other columns are LOW), and then check each row input to see if any of them are HIGH. If it is, then we know which key is being pressed. See next slide for modified version of keyboard scan routine from p. 27 of Dragon12 manual. -Do Practice Question 6.

Keyboard Scan Routine Modified from p. 27 of Dragon12 manual. Set PA0 high and PA1, PA2, PA3 low, and then read PA4-PA7. If PA4-PA7 are all low, no key in this column is pressed. If PA7 = high, key 12 is pressed. If PA6 = high, key 8 is pressed. If PA5 = high, key 4 is pressed. If PA4 = high, key 0 is pressed. Set PA1 high and PA0, PA2, PA3 low, and then read PA4-PA7. If PA7 = high, key 13 is pressed. If PA6 = high, key 9 is pressed. If PA5 = high, key 5 is pressed. If PA4 = high, key 1 is pressed. Set PA2 high and PA0, PA1, PA3 low, and then read PA4-PA7. If PA7 = high, key 14 is pressed. If PA6 = high, key 10 is pressed. If PA5 = high, key 6 is pressed. If PA4 = high, key 2 is pressed. Set PA3 high and PA0, PA1, PA2 low, and then read PA4-PA7. If PA7 = high, key 15 is pressed. If PA6 = high, key 11 is pressed. If PA5 = high, key 7 is pressed. If PA4 = high, key 3 is pressed. Modified from p. 27 of Dragon12 manual.

Code That Implements the Keyboard Scan Routine Download the code from http://nreeder.com/eet2261/labs/lab11KeypadNumberToLEDs.txt .

Key Numbers Versus Key Labels On previous slides we’ve been referring to keys by their numbers, starting with key #0 in upper left corner of keypad and ending with key #15 in lower right corner. Don’t confuse these key numbers with the labels on the keys, which are shown at right.

Different from the Textbook’s Keypad Caution: the keypad connections on our Dragon12-Plus2 board are different from the connections assumed in the textbook’s discussion (as shown in the figures on page 340 of the textbook). Therefore, while the general principles of the book’s discussion do apply to our keypad, the details are different.