Efficient Method for Sensing Key Press (16F877A & ASM)

Discussion in 'Embedded Systems and Microcontrollers' started by the_guth, Jan 5, 2010.

  1. the_guth

    Thread Starter New Member

    Sep 8, 2008
    Hi there,

    I'm messing around with a 16F877A.

    Generally speaking, out of the two methods of scanning a matrix of keys (rows and columns) after sensing an interrupt versus using a timer based interrupt to periodically scan state changes on inputs which is the most efficient? I only need four keys so between these two methods I don't think I'll save any pins.

    I know there is a multitude of different ways to do this, some very exotic and requiring few pins but as im beginner to moderate with skills I only would consider these two.

    Any thougts would be much appreciated.
  2. Markd77

    Senior Member

    Sep 7, 2009
    I'd go for the interrupt method myself, makes the rest of the program more simple. There is another method which is to poll the RBIF bit with the interrupt turned off. I'd recommend having a search for debouncing otherwise you might get some unexpected results.
  3. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    I'd use a hybrid method;

    Have the buttons on Port B and use the interrupt-on-change to wake up the processor.

    Directly read the port to input, and do the appropriate debounce timing, on the switches.

    That way, you only have one standard routine doing the switch inputs and whatever functions they actually cause, and you can have a separate routine doing the power control & timeout after the switch operations have completed.