Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write in addressing code for IDE app to program. Not counting pushing and pulling registers to the stack, or the lines of code executed by
Write in addressing code for IDE app to program. Not counting pushing and pulling registers to the stack, or the lines of code executed by a subroutine, write the keypad in lines of code or less Initialize Port U address $ so the upper four bits are outputs and the lower four bits are inputs by doing the following: Write value $FO to the Data Direction Register of Port U address $A to make bits inputs and bits outputs. Write value $FO to the Polarity Select Register of Port U address $D to set the pins as a pullup device. Write value soF to the Pull Device Enable Register of Port U address $C to activate the pullup device on pins STEPS TWO THROUGH FOUR SHOULD BE ISOLATED IN A "KEYPAD" SUBROUTINE IN A SEPERATE FILE. Check each row of the keypad by writing a logic low to the output pin of Port U connected to that row and a logic high to the other output pins of Port U Then read back the value to check for a press. Steps: The sequence that needs to be sent to Port U continuously to scan all four rows of the keypad is $ $$DO $E Make this into a constant array. Load the address of the sequence into a register Send a value of the sequence to port U and increment the sequence's address Perform a lms delay You are REQUIRED to use another subroutine for this! Read port U back in this is one of only two times you should read port U If value SxF where x means "don't care" in a digital logic manner is read from the lower nibble, we know no key is pressed in the row currently being "sent". For example if you read $DF you would've just sent $DO and would now know that no key is pressed in the rd row. All rows share the lower nibble being $F hence why we can generalize this process by saying $xF for all rows. However we must "scan" all four rows which means four cases, but if we eliminate the upper nibble we only have to account for one! So mask the upper nibble bits by performing an AND operation on the read value. If the remaining value is equal to $OF branch back to where you will then send the next item in the sequence. If not, you have a key press, and will simply proceed to the next step, the LUT lookuptable portion. But think, you will need the value you read in for the LUT but you just destroyed it by masking it Without reading port U again, how can you save it before the masking so you can retrieve it again after for the LUT?... Go back and add a way to do this. Once all rows are scanned, reset the address of the sequence, and repeat the process. Think: How do you know you have reached the end of the sequence? A terminator? Counter? Etc... What works best here? You will likely need to go back and make some additions to your code for this feature Wait for the button to be released before continuing. Otherwise, what you consider a quick press of the button is enough time for the subroutine to run hundreds of times! This will create the appearance of the button press' value being displayed on both LED nibbles simultaneously. Think about the mouse on your computer: Most 'clicks' don't go through until you release.a Read port U This is the second of ONLY two lines which you should check itb Mask it and see if there is any sort of press. Same as before. Except this time we don't care about the value at all, so theres no need to save.c Now it is the opposite as before... We are waiting for no press. If the input eventually matches $Of only then we will continue. Otherwise you should loop back to the beginning a of this step. This effectively stalls out the code which isn't in the RTI and forces one press at a time, no matter how long If a key is pressed use the lookup table process from Laboratory to check for a match.The index of this match in the sequence corresponds to the key that is being pressed eg if a is pressed on the keypad, the upper nibble with read value $ and the lower nibble will read $Ba This is similar and simpler than the "sending" step, but more details on LUTs are in lecture notes and lab b Load the address of the 'key' sequence and initialize a counter in another register.c Load a value of the array ideally using post auto and compare to your saved value read in as a key press from step d If equal, leave this inner loop, and store your counter as the pressedkey's value. eIf not, increment your counter, and loop back to retrieve and compare the next value in the 'key' arrayf. Make sure you've accounted for your registers, and leave the subroutine Now in your main loop, after calling your keypad subroutine, write code to accomplish the following: The first keypress value displays on the right four LEDs, the second keypress displays on the left four LEDs while maintaining the value of the first keypress, the third keypress displays on the right four LED while maintain the value of the second keypress, and so on This can be accomplished using AND, OR and shift instructions.a The LEDs should NOT flicker!b Think: In order to know if the current key press should go on the left or right, your program must remember what side it did last time! How can you create this behavior exploiting the features of assembly language? How would you do it in C
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started