Question

This code listens to keypresses and displays the ASCII code of the key pressed on the...

This code listens to keypresses and displays the ASCII code of the key pressed on the LEDs. Port A needs to be connected to the keypad and port D needs to be connected to the LED port.

I need you Modify the code such that the array is cleared when the ‘*’ key is pressed and an LED is turned on when the ‘#’ key is pressed.

#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h> // Delay header
#define KEY_PRT PORTA //Keyboard port, DDR, PIN
#define KEY_DDR DDRA
#define KEY_PIN PINA
unsigned char keypad[4][3] = {{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
int main ()
{
   unsigned char colloc, rowloc;
   DDRD = 0xFF;
   KEY_DDR = 0xFF;
   KEY_PRT = 0x0F;
   while(1)
   {
       while(1)
       {
           KEY_DDR = 0xF0;
           KEY_PRT = 0xFF;
           do
           {
               KEY_PRT &= 0x0F; //Ground all columns
               asm("NOP");
               rowloc = (KEY_PIN & 0x0F); //read all rows
           }while(rowloc != 0x0F); //check until all keys are released
           do
           {
               //PORTD = 0b00000100;
               do
               {
                   //PORTD = 0b00001000;
                   _delay_ms(20);
                   rowloc = (KEY_PIN & 0x0F); //see if any key is pressed
               }while(rowloc == 0x0F);//keep checking for key press
               _delay_ms (20); //delay for debounce
               rowloc = (KEY_PIN & 0x0F); //read rows
           }while(rowloc == 0x0F); //wait for key press
           KEY_PRT = 0x3F; //ground column 0
           asm("NOP");
           rowloc = (KEY_PIN & 0x0F); //read the rows
          
           if(rowloc != 0x0F) //column detected
           {
               colloc = 0; //save column location
               break; // exit while loop
           }
           KEY_PRT = 0x5F; // ground column 1
           asm("NOP");
           rowloc = (KEY_PIN & 0x0F); //read the rows
           if(rowloc != 0x0F)
           {
               colloc = 1; //save column location
               break;
           }
           KEY_PRT = 0x6F; // ground column 2
           asm("NOP");
           rowloc = (KEY_PIN & 0x0F);
           if(rowloc != 0x0F) //read the rows
           {
               colloc = 2; //save column location
               break;
           }
       }
       //Check row and send result to port D
       if(rowloc == 0x0E)
       PORTD = keypad[0][colloc];
       else
       if(rowloc == 0x0D)
       PORTD = keypad[1][colloc];
       else
       if(rowloc == 0x0B)
       PORTD = keypad[2][colloc];
       else
       PORTD = keypad[3][colloc];
   }
   return 0;
}

Homework Answers

Answer #1

1)For clearing array:

It will be efficient to first convert the array to vector and use the clear() function.

Code for this part:

// converting array to vector.

#include iostream

#include vector

int main(){

std::vector<int> V;

V.insert(V.begin(),std::begin(keypad),std::end(keypad));

for(int j:V){std::cout<<i<<“”;}return 0;}

//for erasing the contents of vector.

V.clear();

2)For the LED on:

int pin=13;

void process()

{pinmode(pin,OUTPUT);}

void process2(){

digitalWrite(pin,HIGH);

delay(800);

digitalWrite(pin,LOW);

delay(800);

}

Know the answer?
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
Similar Questions
currently the code contacts the server 1 time and exits. Modify the code so that the...
currently the code contacts the server 1 time and exits. Modify the code so that the program contacts the server five times before exiting. /* client.c - code for example client program that uses TCP */ #ifndef unix #define WIN32 #include <windows.h> #include <winsock.h> #else #define closesocket close #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #endif #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #define PROTOPORT 5193 /* default protocol port number */ extern int errno; char...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
This is my code and can you please tell me why it's not working? By the...
This is my code and can you please tell me why it's not working? By the way, it will work if I reduce 10,000,000 to 1,000,000. #include <iostream> using namespace std; void radixSort(int*a, int n) { int intBitSize = sizeof(int)<<3; int radix = 256; int mask = radix-1; int maskBitLength = 8;    int *result = new int[n](); int *buckets = new int[radix](); int *startIndex = new int[radix]();    int flag = 0; int key = 0; bool hasNeg =...
C++ Fix my code This code is for imitating the round robin cpu scheduling algorithim using...
C++ Fix my code This code is for imitating the round robin cpu scheduling algorithim using linked lists. Currently I am able to input processes and store / display them properly. The issue begins somewhere after I have displayed the processlist (I get a segmentation fault (core dumped) or the code doesnt seem to run). I have marked the location of where I think the issue begins with a comment. Please fix the code so that it is working properly....
Description The word bank system maintains all words in a text file named words.txt. Each line...
Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a new word into the word bank. No insertion should be made...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...