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

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 11:30
In cell h5 enter a formula that will calculate the percentage of attendees that went to the altamonte springs job fair in 2018.
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
Draw the resistor’s voltage and current phasors at t=15ms. draw the vectors with their tails at the origin. the orientation of your vectors will be graded. the exact length of your vectors will not be graded.
Answers: 2
question
Computers and Technology, 24.06.2019 20:20
Write python code that prompts the user to enter his or her age and assigns the user’s input to an integer variable named age.
Answers: 1
question
Computers and Technology, 24.06.2019 22:00
Is the process of organizing data to reduce redundancy. a. normalization b. primary keying c. specifying relationships d. duplication
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
question
Mathematics, 12.03.2021 16:30
question
Arts, 12.03.2021 16:30
Questions on the website: 13722362