3x4 Keypad: scanning interrupt...

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!
I have a 3x4 keypad; keypress triggers external int0.
Processor: ATmega8
Compiler : CodeVisionAVR

interrupt [EXT_INT0] void ext_int0_isr(void)
{
 Code = (PINB & 0b111);

 // pull-ups on inputs D7..D4, 0 on outputs B2..B0
 DDRB  |= 0b00000111;
 PORTB &= 0b11111000;   
 DDRD  &= 0b00001111;
 PORTD |= 0b11110000;   

 #asm("nop\nop\nop")

 Code |= (PIND & 0xF0);

 // default state that triggers external int
 DDRB  &= 0b11111000;
 PORTB |= 0b00000111;   
 DDRD  |= 0b11110000;
 PORTD &= 0b00001111;
}

This code works only if I replace the #asm("nop\nop\nop") with delay_ms(5);
Hmmm... I really don't like/want it like that!
Do you guys have a better idea?

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so you way it wont work if you have the #asm line in?
try replacing it with:

#asm
   nop
   nop
   nop
#endasm
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, you need debouncing just like with almost any other switch, and many other input types. And true, you don't want to hang around in an ISR for typical debounce times.

Is your input triggered by "any key pressed"? Are you on battery or other low-power system, sleeping almost all the time?

If both of the above are true, then use the external interrupt as a wake-up and then do a normal multi-sample debounce sequence as has been discussed here many times before, a few ms apart.

If not a low-power app, just keep scanning & debouncing all the time. For a multiplexed keypad, I normally set one set of column strobes, then come back a few ms later & read the rows then set the next column strobe saving the intermediate results. After all columns have been strobed the composite states of all the switches are entered into the debounce mechanism.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Sat. Dec 2, 2006 - 10:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Yes, the interrupt is triggered by "any key pressed".
2. No, the device is not running on batteries.
Thx for help Lee!

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the sugesstion for de - bounce time is right. I had developed an application involving keyboard. I had used a timer routine for that with a time base of 40 millisec. As you have correctly discovered that a delay gets your code moving. Definately think of relieving of ISR.