-1
\$\begingroup\$

This question already has an answer here:

I have this function for a 4x4 keypad:

 uint8_t GetKeyPressed()
 {
  uint8_t r,c;

  KEYPAD_PORT|= 0X0F;

  for(c=0;c<4;c++)
  {
     KEYPAD_DDR&=~(0X7F);

     KEYPAD_DDR|=(0X40>>c);
     for(r=0;r<4;r++)
     {
        if(!(KEYPAD_PIN & (0X08>>r)))
        {
           return (r*4+c);
        }
     }
  }

return 0XFF;//Indicate No key pressed
}

Is it ok, or it has some bugs in it ?

\$\endgroup\$

marked as duplicate by TonyM, Chris Stratton, Dave Tweed Oct 9 at 12:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ As you well know, this is not a free design house, homework-answering service or an on-line technical encyclopedia, copied out to you on demand. People will help you take the next step if your question shows you've done as much as you possibly could on your own - which yours doesn't, I'm afraid. Please edit your question and greatly improve it. Show your work and findings so far in considerable detail with a schematic. The schematic tool here is easy to use. The better the quality of question, the better the quality of the answers you will attract. \$\endgroup\$ – TonyM Oct 9 at 6:23
  • 1
    \$\begingroup\$ Well, we answered your other question about this keypad. Please take the time to understand it, and you will see the bug here. \$\endgroup\$ – the busybee Oct 9 at 6:57
-1
\$\begingroup\$

Yes it has bugs. At least it fails to scan the column outputs in the correct 0x80,0x40,0x20,0x10 sequence.

\$\endgroup\$
  • \$\begingroup\$ So what should I do ? \$\endgroup\$ – Danial Oct 9 at 5:44
  • 1
    \$\begingroup\$ Re-write your code and debug it. That is what all experienced engineers have learned so much from. Also this is not a "please write my code for me " forum. \$\endgroup\$ – Oldfart Oct 9 at 5:59
  • \$\begingroup\$ That is quite a broad question, and the answer to that depends on if you need to learn something to do it yourself or get someone to code for you. I don't know where you are stuck with this. The code of your previous 3x4 matrix scanning question was thoroughly commented and explained, so what parts are still unclear as you seem to want to expand it to 4x4 matrix? Is it the bitwise logical operations? Bit shifts? Compound statements? AVR IO port register usage? The code tries to be very clever and tight, but you can use simpler code you understand. \$\endgroup\$ – Justme Oct 9 at 6:05
-1
\$\begingroup\$

Given that you have no specifications for how this code should perform if it compiles, it's ok!

It looks to me like it may behave strangely if the user presses two buttons at the same time, but I can't say for sure if that's a bug or not.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.