0% found this document useful (0 votes)
33 views27 pages

Annotated Keypad Project PDF

Uploaded by

zurichsmith.zs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views27 pages

Annotated Keypad Project PDF

Uploaded by

zurichsmith.zs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

`

SEPTEMBER -DECEMBER 2024

Course Code and Title: CMOR 2001 Computer Organization

Programme: BASc Computer Engineering

Due Date: 10/11/2024


LIMITATIONS: NO EXTENSION

TERM PROJECT: KEYBOARD INTERFACING

CMOR2001: COMPUTER ORGANISATION


Group Members: Nafeesa Ali-Matthew - 103055
Gabriel Samaroo - 102612
Keldon Williams - 98452

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.

• Configuration setup (SEVEN SEGMENT).

(i) Program PORTB and PORTP (to output ports).


(ii) Program DIGIT3 to display by outputting %11111110 ($FE) to PORTP.

This is an example for COL_0:

(i) Output %11111110 ($FE) to PORTA.


(ii) Read the value from PORTA (note: if no key is pressed, the value read will be
$FE).
(iii) Use the compare instructions to determine which key is pressed.
(iv) Display the SEVEN SEGMENT binary value of the key pressed.
(v) If none of the keys from this column is pressed, move on to check for COL_1.

Continue Algorithm for the remaining columns

For COL_1:

(i) Output %11111101 ($FD) to PORTA.


(ii) Read the value from PORTA (note: if no key is pressed, the value read will be
$FD).
(iii) Use the compare instructions to determine which key is pressed.
(iv) Display the SEVEN SEGMENT binary value of the key pressed.
(v) If none of the keys from this column is pressed, move on to check for COL_2.

For COL_2:

(i) Output %11111011 ($FB) to PORTA.


(ii) Read the value from PORTA (note: if no key is pressed, the value read will be
$FB).
(iii) Use the compare instructions to determine which key is pressed.
(iv) Display the SEVEN SEGMENT binary value of the key pressed.
(v) If none of the keys from this column is pressed, move on to check for COL_3.

3
For COL_3:

(i) Output %11110111 ($F7) to PORTA.


(ii) Read the value from PORTA (note: if no key is pressed, the value read will be
$F7).
(iii) Use the compare instructions to determine which key is pressed.
(iv) Display the SEVEN SEGMENT binary value of the key pressed.
(v) If no key is pressed, turn off ALL the LEDs connected to PORTB.

The program should be in a while loop.

Fill out Table 1.0 (for COL_0).

If KEY0 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 1 0 1 1 1 0

∴ The value is $EE.

If KEY4 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 0 1 1 1 1 0

∴ The value is $DE.

If KEY8 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 0 1 1 1 1 1 0

∴ The value is $BE.

If KEY12 is pressed, write the binary value read on PA7-PA4.

4
PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0
Code 0 1 1 1 1 1 1 0

∴ The value is $7E.

Table 1.0

CONTINUE FIILING OUT THE TABLES FOR THE REMAINING 12 KEYS.


CREATE YOUR OWN TABLE

Table for COL_1:

If KEY1 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 1 0 1 1 0 1

∴ The value is $ED.

If KEY5 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 0 1 1 1 0 1

∴ The value is $DD.

If KEY9 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 0 1 1 1 1 0 1

∴ The value is $BD.

5
If KEY13 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 0 1 1 1 1 1 0 1

∴ The value is $7D.

Table for COL_2:

If KEY2 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 1 0 1 0 1 1

∴ The value is $EB.

If KEY6 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 0 1 1 0 1 1

∴ The value is $DB.

If KEY10 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 0 1 1 1 0 1 1

∴ The value is $BB.

6
If KEY14 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 0 1 1 1 1 0 1 1

∴ The value is $7B.

Table for COL_3:

If KEY3 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 1 0 0 1 1 1

∴ The value is $E7.

If KEY7 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 1 0 1 0 1 1 1

∴ The value is $D7.

If KEY11 is pressed, write the binary value read on PA7-PA4.

PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Code 1 0 1 1 0 1 1 1

∴ The value is $B7.

If KEY15 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

∴ The value is $77.

TABLE REPRESENTING THE NUMBERS AND LETTERS THAT THE KEYS


WILL DISPLAY:

KEY0 displays 1. KEY8 displays 7.


KEY1 displays 2. KEY9 displays 8.
KEY2 displays 3. KEY10 displays 9.
KEY3 displays A. KEY11 displays C.
KEY4 displays 4. KEY12 displays F.
KEY5 displays 5. KEY13 displays 0.
KEY6 displays 6. KEY14 displays E.
KEY7 displays B. KEY15 displays D.

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:

PORTP EQU $0258 ;PORTP data register

DDRP EQU $025A ;PORTP direction register

PORTA EQU $0000 ;PORTA

DDRA EQU $0002 ;PORTA direction register

PORTB EQU $0001 ;PORTB

DDRB EQU $0003 ;PORTB direction register

PUCR EQU $000C ;port pull-up control register

MAIN EQU $2000

;----------------------------------------------------------------------------
----

;the code starts here

ORG MAIN

BEGIN: LDAA #$01 ;setting internal pull up control resistors

STAA PUCR

LDAA #$0F ;setting PA7-PA4 as input and PA3-PA0 as output

STAA DDRA

LDAA #$FF ;setting PORTB to output (LEDs)

STAA DDRB

LDAA #$FF ;setting PORTP to output (7-segment pins)

STAA DDRP

LDAA #$FE ;setting DIGIT3 (PP0) to display

STAA PORTP

START: LDAA #$FE ;testing column 0

STAA PORTA

9
LDAA PORTA

CMPA #$EE ;checking for KEY0

BEQ DISPLAY_1

BNE CHECK_KEY4

DISPLAY_1: LDAA #$06

STAA PORTB

JMP START

CHECK_KEY4: LDAA PORTA

CMPA #$DE

BEQ DISPLAY_4

BNE CHECK_KEY8

DISPLAY_4: LDAA #$66

STAA PORTB

JMP START

CHECK_KEY8: LDAA PORTA

CMPA #$BE

BEQ DISPLAY_7

BNE CHECK_KEY12

DISPLAY_7: LDAA #$07

STAA PORTB

JMP START

CHECK_KEY12: LDAA PORTA

CMPA #$7E

BEQ DISPLAY_F

BNE COL_1

DISPLAY_F: LDAA #$71

10
STAA PORTB

JMP START

COL_1: LDAA #$FD ;testing column 1

STAA PORTA

LDAA PORTA

CMPA #$ED ;checking for KEY1

BEQ DISPLAY_2

BNE CHECK_KEY5

DISPLAY_2: LDAA #$5B

STAA PORTB

JMP START

CHECK_KEY5: LDAA PORTA

CMPA #$DD

BEQ DISPLAY_5

BNE CHECK_KEY9

DISPLAY_5: LDAA #$6D

STAA PORTB

JMP START

CHECK_KEY9: LDAA PORTA

CMPA #$BD

BEQ DISPLAY_8

BNE CHECK_KEY13

DISPLAY_8: LDAA #$7F

STAA PORTB

JMP START

CHECK_KEY13: LDAA PORTA

11
CMPA #$7D

BEQ DISPLAY_0

BNE COL_2

DISPLAY_0: LDAA #$3F

STAA PORTB

JMP START

COL_2: LDAA #$FB ;testing column 2

STAA PORTA

LDAA PORTA

CMPA #$EB ;checking for KEY2

BEQ DISPLAY_3

BNE CHECK_KEY6

DISPLAY_3: LDAA #$4F

STAA PORTB

JMP START

CHECK_KEY6: LDAA PORTA

CMPA #$DB

BEQ DISPLAY_6

BNE CHECK_KEY10

DISPLAY_6: LDAA #$7D

STAA PORTB

JMP START

CHECK_KEY10: LDAA PORTA

CMPA #$BB

BEQ DISPLAY_9

BNE CHECK_KEY14

12
DISPLAY_9: LDAA #$6F

STAA PORTB

JMP START

CHECK_KEY14: LDAA PORTA

CMPA #$7B

BEQ DISPLAY_E

BNE COL_3

DISPLAY_E: LDAA #$79

STAA PORTB

JMP START

COL_3: LDAA #$F7 ;testing column 3

STAA PORTA

LDAA PORTA

CMPA #$E7 ;checking for KEY3

BEQ DISPLAY_A

BNE CHECK_KEY7

DISPLAY_A: LDAA #$77

STAA PORTB

JMP START

CHECK_KEY7: LDAA PORTA

CMPA #$D7

BEQ DISPLAY_B

BNE CHECK_KEY11

DISPLAY_B: LDAA #$7C ;displaying lowercase 'b'

STAA PORTB

JMP START

13
CHECK_KEY11: LDAA PORTA

CMPA #$B7

BEQ DISPLAY_C

BNE CHECK_KEY15

DISPLAY_C: LDAA #$39

STAA PORTB

JMP START

CHECK_KEY15: LDAA PORTA

CMPA #$77

BEQ DISPLAY_D

BNE ELSE

DISPLAY_D: LDAA #$5E ;displaying lowercase 'd'

STAA PORTB

JMP START

ELSE: LDAA #$00 ;turning OFF all lights

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.

KEY PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0


Row_3 Row_2 Row_1 Row_0 Col_3 Col_2 Col_1 Col_0
0 0 0 0 1 0 0 0 1
1 0 0 0 1 0 0 1 0
2 0 0 0 1 0 1 0 0
3 0 0 0 1 1 0 0 0
4 0 0 1 0 0 0 0 1
5 0 0 1 0 0 0 1 0
6 0 0 1 0 0 1 0 0
7 0 0 1 0 1 0 0 0
8 0 1 0 0 0 0 0 1
9 0 1 0 0 0 0 1 0
10 0 1 0 0 0 1 0 0
11 0 1 0 0 1 0 0 0
12 1 0 0 0 0 0 0 1
13 1 0 0 0 0 0 1 0
14 1 0 0 0 0 1 0 0
15 1 0 0 0 1 0 0 0

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.

TIME-SCALE, ASSESSMENT AND OTHER RULES

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.

SPECIFIC REQUIREMENTS FOR PROJECT

Objective: Design a simple microcomputer KEYPAD interface, as described above. The


design is to be presented in a quality standard report showing:

Product requirements specification - Assembler language source code program. - Include


screen shots.

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.

2. What is the purpose of grounding each COLUMN in keyboard interfacing?

The purpose of grounding each column in keyboard interfacing is to be able to detect


which key is pressed from the respective rows. This is because when the column is
grounded (i.e. logical 0) and the circuit is closed by pressing a key, the connecting
row will also be read as logical 0, allowing the system to determine which exact key
was 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.

4. What is the input to the microcontroller if no key is pressed and no COLUMN is

25
grounded (is a 0)?

The input to the microcontroller if no key is pressed an no column is grounded will be


$FF (i.e. all logical 1’s with no logical 0’s) which indicates that no columns were
grounded and no keys from the respective rows were pressed.

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.

6. In your program in Activity 2, how is the key press detected?

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.

7. In your program in Activity 2, how is a key press identified?

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.

8. Does the Key number match the Hex code number?

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.

IMPORTANT POINTS TO NOTE:

• WRITE COMMENTS FOR YOUR PROGRAM.

26
• THE PROGRAM WILL BE TESTED IN THE LAB USING THE DRAGON
68HC12 DEVELOPMENT BOARD.

PICTURE OF THE LAB TEST APPROVAL FOR OUR KEYPAD PROJECT

27

You might also like