Вы находитесь на странице: 1из 6

Electrical and Computer Engineering

CME 331 Microprocessor Embedded System


Khan Wahid
Last updated: October 18, 2013

Lab 4: Design of a 4x4 Keypad Interface with LCD Display

Safety:
In this lab, voltages used are less than 15 volts and this is not normally dangerous to humans.
However, you should assemble or modify a circuit when power is disconnected and do not touch
a live circuit if you have a cut or break in the skin.

Learning outcome:
This lab provides an opportunity to be familiarized with an ARM CortexM4F microcontroller
(MCU) and its interfacing with a TFT LCD display which uses ST7735 driving chip. A
Stellaris LM4F120 LaunchPad is used that has a Cortex LM4F120H5QR microprocessor. The
LCD uses SPI interface to connect to the Launchpad. At the end of the lab, the students will be
able to print characters and shapes on a TFT LCD display and design an interface for a 4x4
keypad.

Required hardware:

Materials Equipment
None Stellaris LM4F120 LaunchPad
1.8 TFT LCD Display (ST7735R)
4x4 Keypad

Checkpoints: Throughout this manual, wherever you find a sign, it means that there is
something that you need to (a) show to your instructor and/or (b) observe, measure, and explain
in your lab notebook.

Lab description:
The lab has two parts. In the first part, you will be familiarized with the TFT LCD display. A
project template is provided on the course website [1]. You will use the template and built-in
library functions to print various characters and shapes. In the second part, you will design a 4x4
keypad interface. In the end, you will combine both parts to print the letter found through the
keypad interface on the LCD display.


Part 1: Interfacing with the TFT LCD Display

1.8" 18-bit TFT Colour LCD:
Graphical displays are becoming more popular these days and they are easy to use due to ease of
communication between microcontroller and display module. The 1.8 TFT LCD display we are
using in the lab has 128 x 160 colour pixels [4]. It uses a ST7735 driver chip and SPI interface to
connect with the host microcontroller. The ST7735R driver can display full 18-bit colour
CME 331 Laboratory 2

(262,144 shades). It uses 3.3V supply. There is a microSD card holder in the LCD module where
you can load/save full colour bitmaps from/to a FAT16/FAT32 formatted microSD card.
However, we will not use any microSD card in this lab. Fig. 1 below shows the LCD display
connected with the LaunchPad.


(a) (b)
Fig. 1 18-bit TFT LCD display showing (a) UofS logo; (b) arbitrary shapes

The Stellaris microcontroller includes four Synchronous Serial Interface (SSI) modules. Each
SSI module is a master or slave interface for synchronous serial communication with peripheral
devices that have Freescale SPI, MICROWIRE, or Texas Instruments synchronous serial
interfaces. The operation of the SSI interface will be covered in the class.

In this lab, all the codes required to properly configure the SSI module and interface the LCD
display are given in the project template. As such, the LCD is ready to use. You will simply use
the built-in library functions (given in the LCD function reference_v1.0.pdf) to print various
characters and draw shapes.

Procedure:
1. First of all, download the project template (Test_4a_testingLCD_webposting.zip) provided
on the course website. Unzip it and open testingLCD.uvproj in Keil uVision. There are five
key files in this project as described below:

testingLCD.c contains the main C-code
ST7735.c contains C-code for TFT display driver (includes Port A and SSI interface)
ST7735.h header file of the TFT display driver
Systick.c configuration file for Systick timer
Systick.h header file for Systick timer

**Do not make any changes to these files (except testingLCD.c) unless instructed**. Consult
the LCD data sheet (ST7735R_V0.2.pdf) for more details. A snapshot of the project is given
in Fig. 2.

2. Obtain from the support office the required hardware for the lab. Connect the LCD display
with the LaunchPad. The connection diagram is given in Fig. 3.
CME 331 Laboratory 3


Fig. 2 Snapshot of testingLCD.uvproj in Keil uVision

TFT LCD
Display
ST7735R
LITE
MISO
SCK
MOSI
TFT_CS
CARD_CS
D/C
RESET
VCC
GND
3.3V
PA2 / SSI0Clk
PA5 / SSI0Tx
PA3 / SSI0Fss
PA6
PA7
3.3V
GND

Fig. 3 Connection diagram

3. Go back to Keil and build the project. You may ignore the warning(s). Now load (download)
the code into the microprocessor. Turn it on. The LCD should display number 1 printed in
green on black background.

4. Open testingLCD.c and take a moment to review the code. Modify the code to rotate the
screen by using ST7735_SetRotation() function.

Consult LCD function reference_v1.0.pdf (posted on the course website) for instructions on
how to use the library functions.

CME 331 Laboratory 4

5. Fill the screen (background) with white colour using ST7735_FillScreen() function. Change
the background and foreground of the text and the font size using ST7735_DrawChar()
function. Note that, the character passed through the function is in ASCII value.
6. Modify the code to print HELLO WORLD on the LCD with BLUE text colour
(font size 2) on black background. Modify the code to make the entire line blink
continuously. Show it to your instructor.

7. Modify the code to draw a rectangle with length of 100 pixels and width of 50 pixels filled
with red colour. Use ST7735_FillRect() function.

8. Modify the code to draw the same size rectangle (100 x 50 pixels) with red line but no-
fill. Hints: You will have to draw four lines (two horizontal and two vertical) using
ST7735_DrawFastHLine() and ST7735_DrawFastVLine() functions. Show it to your
instructor.

9. Draws a circle with white line centered at (60, 60) with radius of 30 pixel. Show it to
your instructor.

10. [Optional] Can you fill the circle with any color (say Blue)?

More information on the display coordinates and graphics library can be found in adafruit-
gfx-graphics-library.pdf [1][5].


Part 2: Design of 4x4 Keypad Interface (refer to Assignment 4)

In this part, you will integrate the 4x4 keypad interface with your LCD code. The objective is to
print the letters found through the keypad on the LCD display. By now, you must have written
and tested the C-code to interface the 4x4 keypad in your assignment 4. If you have not done it,
please refer to assignment 4 and complete the code before proceeding to the next section.

Procedure:
1. In your assignment, you displayed the letters found from the keypad on ADMs 7-segment
display that is connected to Port B. However, here you will display the letters on the LCD; as
a result, you will not need to configure PortB. Simply, copy your C-code corresponding to
keypad scanning and paste it into the testingLCD.c file that you have used in Part 1.

For example, the code segments you need are: definitions and initialization of Port C and D,
2-D keypad array, and scan_key() function.

2. Make proper changes to your main() function. Make sure to activate the clock on Ports B, C,
and D using SYSCTL_RCGC2.

CME 331 Laboratory 5

3. The keys you are reading are all 4-bit binary (one hex digit). So, in order to use the
ST7735_DrawChar() function, you need to change the key read value from hex to ASCII
character. A hex2char() function is already given in testingLCD.c file. You should use this
function for the desired conversion. An example is shown below:

ST7735_DrawChar(10, 10, hex2char(key_read), ST7735_GREEN, 0, 3);

4. Obtain one 4x4 Keypad from the ECE support office and connect it with the LaunchPad. The
pin out diagram is given in Fig. 4(a). The experimental setup is shown in Fig. 4(b).

5. Press any key and observe the displayed character on the LCD display. Show your code
and the hardware to your instructor.

LM4F120
LaunchPad
PD3
PD2
PD1
PD0
PC4
PC5
PC6
PC7
ROW0
ROW1
ROW2
ROW3
COL3
COL2
COL0
COL1
4x4 Keypad
1
0 1 2 3
4 5 6 7
8 9 A B
C D E F
1 NC
2 COL0
3 COL1
4 COL2
5 COL3
6 ROW0
7 ROW1
8 ROW2
9 ROW3
10 NC
2 3 4 5 6 7 8 9 10

(a) (b)
Fig. 4 (a) Pin out diagram of the keypad; (b) Experimental setup with keypad and LCD display


6. 4-digit Digital Lock: Implement a 4-digit key-lock with the keypad and the LCD
display. The lock key (value) will be stored in the ROM (using software). The LCD displays
the keys as they are entered by the user. If it matches with the stored lock key, the LCD will
display a success message; otherwise, it will display wrong.
CME 331 Laboratory 6

References:
1. CME331 class website: https://www.engr.usask.ca/classes/CME/331
2. LM4F120H5QR Datasheet (Aug 29, 2012): http://www.ti.com/lit/gpn/lm4f120h5qr
3. Stellaris LM4F120 LaunchPad User Manual (SPMU289ARevised December 2012):
http://www.ti.com/tool/sw-ek-lm4f120xl
4. 1.8" 18-bit color TFT LCD display with microSD (ST7735R):
http://www.adafruit.com/products/358
5. Adafruit GFX Graphics Library: http://learn.adafruit.com/adafruit-gfx-graphics-library


Appendix A: LaunchPad interface
The pin-out diagram of the LaunchPad is given below. Although the LM4F120H5QR MCU has
43 GPIO, only 35 of them are available through the LaunchPad. They are: 6 pins of Port A (PA2-
PA7), 8 pins of Port B (PB0-PB7), 4 pins of Port C (PC4-PC7), 6 pins of Port D (PD0-PD3,
PD6-PD7), 6 pins of Port E (PE0-PE5), and 5 pins of Port F (PF0-PF4). In addition, there are
two ground, one 3.3V, one 5V (VBUS), and one reset pins available on the LaunchPad.

Pins PC0-PC3 are left off as they are used for JTAG debugging. Pins PA0-PA1 are also left off
as they are used to create a virtual COM port to connect the LaunchPad to PC. ***These pins
should not be used for regular I/O purpose.*** Besides, in the LaunchPad, PD0 and PD1 are
connected with PB6 and PB7 respectively with a 0 resistor (i.e., short circuit, p.20 in [3]). So,
user needs to pay special attention when using Ports B and D at the same time.
3.3V
PB5
PB0
PB1
PE4
PE5
PB4
PA5
PA6
PA7
VBUS
GND
PD0
PD1
PD2
PD3
PE1
PE2
PE3
PF1
PF2
PF3
PB3
PC4
PC5
PC6
PC7
PD6
PD7
PF4
GND
PB2
PE0
PF0
RST
PB7
PB6
PA4
PA3
PA2
J1 J3 J4 J2


Fig. x Header pins on the LaunchPad (EK-LM4F120XL)



END

Вам также может понравиться