Annotated Keypad Project PDF
Annotated Keypad Project PDF
Files to submit:
• One pdf file
• ASM file
You can:
1. Use a word document and paste in ASM PROGRAM.
2. Convert word document to PDF name this file KEYPAD_ PROJECT.pdf
OBJECTIVES:
1. Learn how to use the Simulator development environment for 68HC12 based
assembly language programming.
2. Interface keypad using MCU 68HC12 IDE and 68HC12 Development board.
1
INTERFACING THE KEYPAD
The Dragon12-Plus-USB board has a built in 4x4 hex keypad that is connected to Port A which
is an 8-bit bi-directional port as shown in Figure 1.0. Note that pins PA0-PA3 are configured
as outputs and pins PA4-PA7 as configured as inputs. These four inputs are pulled up to 5 volts
with four internal pull-up resistors. Thus, if all the key switches are open, the four bits PA4-
PA7 will all read as 1’s. If a zero is written to one of the inputs PA0-PA3 (one column in Figure
1.0) then a key in that column that is pressed will cause the input connected to that row to go
low. This can be read by the MCU to determine which key is pressed.
Figure 1.0
Keypad connections:
PA0 connects COL0 of the keypad.
PA1 connects COL1 of the keypad.
PA2 connects COL2 of the keypad.
PA3 connects COL3 of the keypad.
PA4 connects ROW0 of the keypad.
PA5 connects ROW1 of the keypad.
PA6 connects ROW2 of the keypad.
PA7 connects ROW3 of the keypad.
You are required write an assembly language program to perform the following:
(i) to scan the keyboard key press associated with ALL the numbers and letters.
(ii) to display the binary code for the numbers on PORTB to display the seven segment
numbers and letters.
2
Use the following steps to write your program:
• Configuration setup (KEYPAD).
(i) To use the internal pull-up resistors (COMES WITH THE BOARD) write the
data value $01 to register PUCR.
(ii) Program PA3-PA0 as outputs and PA7-PA4 as inputs using DDRA.
For COL_1:
For COL_2:
3
For COL_3:
4
PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0
Code 0 1 1 1 1 1 1 0
Table 1.0
5
If KEY13 is pressed, write the binary value read on PA7-PA4.
6
If KEY14 is pressed, write the binary value read on PA7-PA4.
7
PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0
Code 0 1 1 1 0 1 1 1
NUMBER PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0 HEX
0 0 0 1 1 1 1 1 1 $3F
1 0 0 0 0 0 1 1 0 $06
2 0 1 0 1 1 0 1 1 $5B
3 0 1 0 0 1 1 1 1 $4F
4 0 1 1 0 0 1 1 0 $66
5 0 1 1 0 1 1 0 1 $6D
6 0 1 1 1 1 1 0 1 $7D
7 0 0 0 0 0 1 1 1 $07
8 0 1 1 1 1 1 1 1 $7F
9 0 1 1 0 1 1 1 1 $6F
LETTER PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0 HEX
A 0 1 1 1 0 1 1 1 $77
b 0 1 1 1 1 1 0 0 $7C
C 0 0 1 1 1 0 0 1 $39
d 0 1 0 1 1 1 1 0 $5E
E 0 1 1 1 1 0 0 1 $79
F 0 1 1 1 0 0 0 1 $71
8
Use the following template:
;----------------------------------------------------------------------------
----
ORG MAIN
STAA PUCR
STAA DDRA
STAA DDRB
STAA DDRP
STAA PORTP
STAA PORTA
9
LDAA PORTA
BEQ DISPLAY_1
BNE CHECK_KEY4
STAA PORTB
JMP START
CMPA #$DE
BEQ DISPLAY_4
BNE CHECK_KEY8
STAA PORTB
JMP START
CMPA #$BE
BEQ DISPLAY_7
BNE CHECK_KEY12
STAA PORTB
JMP START
CMPA #$7E
BEQ DISPLAY_F
BNE COL_1
10
STAA PORTB
JMP START
STAA PORTA
LDAA PORTA
BEQ DISPLAY_2
BNE CHECK_KEY5
STAA PORTB
JMP START
CMPA #$DD
BEQ DISPLAY_5
BNE CHECK_KEY9
STAA PORTB
JMP START
CMPA #$BD
BEQ DISPLAY_8
BNE CHECK_KEY13
STAA PORTB
JMP START
11
CMPA #$7D
BEQ DISPLAY_0
BNE COL_2
STAA PORTB
JMP START
STAA PORTA
LDAA PORTA
BEQ DISPLAY_3
BNE CHECK_KEY6
STAA PORTB
JMP START
CMPA #$DB
BEQ DISPLAY_6
BNE CHECK_KEY10
STAA PORTB
JMP START
CMPA #$BB
BEQ DISPLAY_9
BNE CHECK_KEY14
12
DISPLAY_9: LDAA #$6F
STAA PORTB
JMP START
CMPA #$7B
BEQ DISPLAY_E
BNE COL_3
STAA PORTB
JMP START
STAA PORTA
LDAA PORTA
BEQ DISPLAY_A
BNE CHECK_KEY7
STAA PORTB
JMP START
CMPA #$D7
BEQ DISPLAY_B
BNE CHECK_KEY11
STAA PORTB
JMP START
13
CHECK_KEY11: LDAA PORTA
CMPA #$B7
BEQ DISPLAY_C
BNE CHECK_KEY15
STAA PORTB
JMP START
CMPA #$77
BEQ DISPLAY_D
BNE ELSE
STAA PORTB
JMP START
STAA PORTB
JMP START
14
PICTURES OF THE PROGRAM INPUTS & OUTPUTS
Column 0:
15
16
Column 1:
17
18
Column 2:
19
20
Column 3:
21
22
THEORY:
OBJECTIVE:
➢ To interface a 4x4 keyboard (keypad) using the 68HC12 Development Board.
MATERIALS:
➢ 68HC12 Development Board.
ACTIVITY 1
The first step is to make a truth table for the keyboard. This truth table provides the row and
23
column contacts by which a key is produced. Repeat the process until all the keys are
mapped.
ACTIVITY 2
After you have mapped your keypad set. Write and run a program that scans your keyboard
and displays any key pressed by the user on the SEVEN SEGMENT DISPLAY. Your
program must display keys associated with 0 - 9 as numbers 0 - 9 on SEVEN SEGMENT
DISPLAY while keys 3, 7, 11, 14 and 15 (or you might say 0A - 0F in hex) are displayed as
letters A, b, C, d, E, and F, respectively.
METHODOLOGY:
1. Note the Keyboard shown above is used only as an example in terms of the key
positions.
2. The MCU 68HC12 IDE development environment provides an Editor, an Assembler,
Debugger and Simulator.
Working rules: - Students can work teams of 3 or 4. A student group will submit a single
report with names on the front cover.
24
Assessment:
- The grading will be based on the submitted report.
Software. Write your program in 68HC12 assembler language source code. Document your
program to a professional standard.
QUESTIONS TO ANSWER:
1. What is the purpose of generating the truth table for a given keyboard?
The purpose of generating the truth table for a given keyboard is to understand the
location and binary value of each key, with its corresponding row and column, when
pressed.
3. Based on the keypad hardware, can we ground the Rows instead of the Column?
Based on the keypad hardware, it is possible to ground the rows instead of the
columns, only if each of the four VCCs and 4.7kΩ resistors (i.e. the inputs) are
switched to the four columns, and the four outputs to the four rows instead, since
grounding occurs by providing a logical 0 to the outputs. If this is not possible, then
no, the rows will not be able to be grounded instead of the columns.
25
grounded (is a 0)?
5. True or false. In our N x M matrix keypad program, we cannot press two keys at the
same time.
It is true that we cannot press two keys at the same time in our N x M matrix keypad
program. If we try to press two keys from the same row but different columns, the
respective letter or number for the last key that was pressed will be displayed (no
matter how small the time difference between each press is). Alternatively, if we try
to press two keys from the same column but different rows, the ELSE condition will
run, and all the lights will turn off, resulting in nothing being displayed on the 7-
segment display.
In our program in Activity 2, the internal pull-up resistors are used; therefore, the
default input will be $FF. When a key is pressed, its column will be grounded (i.e. its
value will be changed to logical 0) beforehand and when the circuit is closed (i.e. the
value of its row will change from logical 1 to logical 0 as well), the 8-bit binary value
from all columns and rows will be read by the microcontroller, thereby allowing it to
detect the specific key that is pressed.
After the key is pressed and its value is read by the microcontroller, the value is run
through a while loop in which it is compared to every possible predetermined key
value, until a match is found. Once it is matched, the respective display number or
letter for that key is then output to the 7-segment display; and through this process, a
key press is identified.
No, the key number does not match the hex code number. For example, key 0 has a
hex code value of $EE, which are both different numbers; moreover, it displays the
hex code number $06 (i.e. decimal 1 on the 7-segment display), which is a different
value once more.
26
• THE PROGRAM WILL BE TESTED IN THE LAB USING THE DRAGON
68HC12 DEVELOPMENT BOARD.
27