Computers and Technology
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).

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:00, labrandonanderson00
Ap practice - performance task response the ap create performance task asks you to write about an abstraction that you developed and wrote into your code. most of the time that means identifying a function or procedure you wrote to "manage complexity" in your program. here is the actual prompt from the create performance task: 2d. capture and paste a program code segment that contains an abstraction you developed individually on your own (marked with a rectangle). this abstraction must integrate mathematical and logical concepts. explain how your abstraction manage the complexity of your program. (must not exceed 200 words) below is a segment of code from an "under the sea" program with a rectangle drawn around a portion of the code identifying an abstraction. imagine that you wrote this and are composing an ap response about how this abstraction manages complexity. (note: ignore the requirement that the abstraction integrate "mathematical and logical concepts" for this practice response. just write about managing complexity). explain how the abstraction marked with the rectangle in the code above manage complexity of this program. write your response here submit
Answers: 2
image
Computers and Technology, 22.06.2019 11:10, golderhadashaowtatz
Which are not examples of chronic or persistent stress? moving
Answers: 1
image
Computers and Technology, 22.06.2019 21:50, dijaflame67
Answer the following questions regarding your system by using the commands listed in this chapter. for each question, write the command you used to obtain the answer. a. what are the total number of inodes in the root filesystem? how many are currently utilized? how many are available for use? b. what filesystems are currently mounted on your system? c. what filesystems are available to be mounted on your system? d. what filesystems will be automatically mounted at boot time?
Answers: 1
image
Computers and Technology, 23.06.2019 04:31, tbt81
Type the correct answer in the box. spell all words correctly. the managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an
Answers: 1
Do you know the correct answer?
The keypad (the 4x4 array of buttons in the bottom right corner of the HCS12 board) is connected to...

Questions in other subjects:

Konu
Mathematics, 02.03.2021 08:10