Question

Given the following code and keypad layout, what will the function GetKey() return when it is run while keys 2, 3, 7, B, E, and F are pressed?


0 Assert PORT keypad row o o PORTkeypad row11 PORT2 keypad row2 2 4 Assert Assert Assert keypad row 3 3 PORTx 3] Vcc 4 10 K Read kevpad column 0 PORTx 4] Vcc 10 K Read keypad column 1 PORTx[5) Vcc 10 K Read keypad col umn 2 PORTx[6] Vcc 10 K Read keypad column 3 PORTx[7]

DDRH = 0x0F;
RDRH = 0x00;
PERH = 0x00;
PIEH = 0x00;
PTH = 0x0F;


unsigned char GetKey(void)
{ unsigned char KeyMask[16] =
{ 0xEE, 0xDE, 0xBE, 0x7E,
0XED, 0xDD, 0xBD, 0x7D,
0xEB, 0xDB, 0xBB, 0x7B,
0xE7, 0xD7, 0xB7, 0x77
};
int i;
char Key;

for (Key=0, i=0; i<16; i++)
{ PTH = KeyMask[i];
if (PTH == KeyMask[i])
{ if (i<10) Key = ‘0’ + i;
else Key = ‘A’+ i - 10;
}
}
PTH = 0x0F;
return (Key);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I just saw a code ...and it used common.h header and used the function getKey() ..to get the keys pressed ....
For up he used a macro like UPKEY , DOWNKEY etc...
The code isnt compiling on my system i guess common.h is not ansi ...I want to implement the same thing ..In my maze game these are the keys used for the direction
W--up,s -- down,a ---left,d--right.
I want to use the cursor keys for that ....any ANSI fucntion that can help me with it ....The function GetKey() return when it is run while keys 2, 3, 7, B, E, and F are pressed ,it returns the value of getKey() function from the above circuit diagram when 2 is pressed it returns o+2,when 3 is pressed it returns 0+3, when 7 is pressed it returns o+7,when B is pressed it returns A+55,when E is pressed it returns A+59, when F is pressed it returns A+70. As in the above code in for loop the given condition of if statements says that value of i should be i<10 so we implement the above conditions on given values of 2,3,7 for alphabates we concerders their ASSCCi then the conditon is in else statement so it follows A+i-10 in this answer can be finded out. Thank you Hope the above imformation is enough to understand the concept and finding the getKey() function returns value.

Add a comment
Know the answer?
Add Answer to:
Given the following code and keypad layout, what will the function GetKey() return when it is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is for Java. Create ONE method/function that will return an array containing the row and...

    This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...

  • Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner...

    Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following...

    This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following c code into mips #include <stdio.h> #include <string.h> char cipherText[200] = "anything"; int countNumberOfCharInCipher(char*); int countNumberOfCharInCipher(char* cText) { return strlen(cText);    } int countSpaces(int numberOfChar, char input[]) { int spaceCounter =0; for(int i=0; i < numberOfChar; i++) { if(input[i] == 32) spaceCounter++; } return spaceCounter; } void decrypt(int numberOfChar, int key, char * cipherText, char * plainText) { int j = 0; int i =0;...

  • Question 1: Pointers You are given the following C code and memory diagram. The “contents” column...

    Question 1: Pointers You are given the following C code and memory diagram. The “contents” column of the memory diagram shows the value of the variable. Update the “contents” column of the memory diagram for each assignment in main(). long *pt; long data;    long buffer[4]; void main(void){   pt = &buffer[1];   *pt = 1234;   data = *pt; } address      contents   variable 0x20000000 0x00000000    pt 0x20000004 0x00000000    data 0x20000008 0x00000000    buffer[0] 0x2000000C 0x00000000    buffer[1] 0x20000010 0x00000000    buffer[2] 0x20000014 0x00000000    buffer[3]...

  • I need help modifying this program. How would I make sure that the methods is being...

    I need help modifying this program. How would I make sure that the methods is being called and checked in my main method? Here is what the program needs to run as: GDVEGTA GVCEKST The LCS has length 4 The LCS is GVET This is the error that I'm getting: The LCS has length 4 // I got this right The LCS is   //the backtrace is not being called for some reason c++ code: the cpp class: /** * calculate...

  • The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing its functionality, rewrite the program by replacing the 2D array card [5...

    The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing its functionality, rewrite the program by replacing the 2D array card [52] [2] with a double pointer char **card and replacing the code between line 12 and line 26 with a function. The function prototype could be void shuffleCards (char **, char [, char [) 1 7/Shuffling cards 2 4 using namespace std; 6 main() #include #include <cstdlib> <iostream>...

  • This is due in a few hours I don't know if I did this correctly can you double check my code to see if my return statements are fine and I follow the instructions accurately. Thank you!!! Modify m...

    This is due in a few hours I don't know if I did this correctly can you double check my code to see if my return statements are fine and I follow the instructions accurately. Thank you!!! Modify my code if anything return statement seems misplaced or inaccurately called. Here is my code: int write_sudoku_board(const char file_name[ ], int board[9][9]) { int number; int i,j; int a = 9; FILE* fp = fopen("sudoku.txt", "w"); int count = 0; for(i =...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT