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, 22.06.2019 00:30
Jenny wants to look at row 345 and compare it to row 17. what can she do if she wanted to easily adjust to see both at once?
Answers: 3
question
Computers and Technology, 23.06.2019 02:30
Experimental data that is expressed using numbers is said to be
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Which best describes the role or restriction enzymes in the analysis of edna a. to break dna into fragments that vary in size so they can be sorted and analyzed b. to amplify small amounts of dna and generate large amounts of dna for analysis c. to purify samples of dna obtained from the environment so they can be analyzed d. to sort different sizes of dna fragments into a banding pattern that can be analyzed
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
From excel to powerpoint, you can copy and paste a. cell ranges and charts, one at a time. b. cell ranges and charts, simultaneously. c. charts only. d. cell ranges only.
Answers: 3
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
Biology, 04.09.2020 23:01
question
Mathematics, 04.09.2020 23:01
question
Mathematics, 04.09.2020 23:01
Questions on the website: 13722360