subject
Computers and Technology, 26.01.2021 04:20 fjarbo

The keypad (the 4x4 array of buttons in the bottom right corner of the HCS12 board) is connected to PORTA, as described by the picture at the bottom of page 26 in the board's user manual. The easiest way to scan the keyboard is to set up PA0-PA3 as outputs, and PA4-PA7 as inputs. Then you send a nibble (4 bits) to PA0-PA3 with one 0 in it to connect that entire column of switches to ground. Then you read the PA4-PA7 bits to see if any of its bits are low, which means the switch in that column corresponding to that bit has been pressed (can you see why by looking at the schematic in the manual?).
For example, to test if KEY13 has been pressed, you’d send %1101 = $D to PA3-PA0. Then read PA7-PA4, and if they equal %0111 = $7, KEY13 has been pressed.
The subroutine to do this is :
KeyScan
CLRB
LDX #keycodes
KS1 LDAA B, X ;load next value from array
STAA PORTA ;send to keyboard (input bits are ignored)
ANDA #$F0 ;save high nibble
STAA temp
LDAA #10 ;wait for debounce
KS2 DECA
BNE KS2
LDAA PORTA ;read the keyboard (output bits are ignored)
ANDA #$F0 ;check high nibble
CMPA temp
BEQ KS3 ;they match, this key has been pressed
INCB ;else, increment array index
CMPB #$10 ;continue until B=$10
BNE KS1 ;not done scanning array
KS3 RTS
This subroutine either returns the value of the key that was pressed in accumulator B, or the value $10 in accumulator B if no key was pressed.
Some questions you’ll have to determine on your own :
What is "temp"? How will it have to be declared?
The array "keycodes" consists of the following constant values :
$7D,$EE,$ED,$EB,$DE,$DD,$DB,$BE,$BD ,$BB,$E7,$D7,$B7,$77,$7E,$7B
How will it have to be declared?
The goal of this project is to read the keypad, and display the key that was pressed on the LCD screen. You should press the keys from 0-15 as shown in the schematic in the user manual, and take a picture of the board showing the LCD screen. Don’t worry about the non-number characters, they’re ok. Also, the value of the key returned is NOT the same as the switch value in the picture in the manual or on the board.
Start with your program from project #9, it has all the LCD code you’ll need.
To initialize the keypad, you’ll have to set bits 4-7 in PORTA as inputs, and bits 0-3 as outputs.
You’ll also need to enable the on-board pullup resistors by using the instruction : "BSET PUCR,$01"
In your main, you’ll have to implement the following pseudo-code :
Do forever
DO
JSR KeyScan
UNTIL (B <> $10) ;wait for key to be pressed ("<>" means "not equal")
Add $30 to B ;convert it to ASCII for the LCD screen
Transfer B to A
Send A to the LCD screen as a character
DO
JSR KeyScan
UNTIL (B = $10) ;wait for key to be un-pressed
A "DO UNTIL" loop is very similar to a "WHILE" loop, except that you check to see if the loop should stop at the bottom of the loop, instead of the top of the loop. If you had a "DO UNTIL" loop that called a subroutine that set accumulator A to 0 or 1, and you wanted to keep calling it until A was 1, in pseudo-code this is :
DO
JSR CheckDone
UNTIL (A = 1)
In assembler, that would look like this :
Loop JSR CheckDone
CMPA #1
BNE Loop
Note that like an IF/THEN statement, the branch at the bottom of the loop in assembler (not equal) is the opposite of the comparison in the pseudo-code (equal).

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:00, jcastronakaya
Apex q: what does a low employment rate indicate? a. not many people are earning high salaries b. not many people are going to college c. not many people are renting their homes d. not many people have jobs
Answers: 2
image
Computers and Technology, 22.06.2019 10:30, robert7248
You have a large, late-model pick-up truck with a rear seat. the pick-up truck weighs 6,500 pounds. the florida seat belt law
Answers: 1
image
Computers and Technology, 22.06.2019 22:00, suewignall
During physical science class ben and jerry connected three identical lightbulbs in parallel to a battery where happens when ben removes one of the lightbulbs from it’s socket
Answers: 2
image
Computers and Technology, 23.06.2019 12:40, melaniem50
Curriculum exam to process a resident's payment, you must click on onesite payments home page. from the a. reports b. my settings o c. transactions o d. rent tab
Answers: 1
You know the right answer?
The keypad (the 4x4 array of buttons in the bottom right corner of the HCS12 board) is connected to...

Questions in other subjects: