Presentation is loading. Please wait.

Presentation is loading. Please wait.

EET 2261 Unit 11 Controlling LCD and Keypad

Similar presentations


Presentation on theme: "EET 2261 Unit 11 Controlling LCD and Keypad"— Presentation transcript:

1 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.

2 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

3 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.

4 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.

5 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 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.

6 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.

7 Typical Initialization Code

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

9 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.

10 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.

11 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.

12 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.

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

14 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.

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

16 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.

17 ASCII Code As defined in the 1960’s, ASCII code is a 7-bit code, whose values range from $0 to $7F (or % ). 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.

18 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 Our LCD module assigns different characters to these codes.

19 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.

20 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.

21 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.

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

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

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

25 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….

26 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….

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

28 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.)

29 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.

30 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.

31 Code That Implements the Keyboard Scan Routine
Download the code from .

32 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.

33 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.


Download ppt "EET 2261 Unit 11 Controlling LCD and Keypad"

Similar presentations


Ads by Google