I'm working on a wall control project that runs on a battery. Therefore, I want the system to be in sleep mode while there is no user input.

I'm using a PIC18F45Q43 which has 3 external interrupts, but I have 4 action buttons that should wake the system up from sleep.

Is it possible to put the PIC in sleep mode and poll for the 4th button at the same time? I know that sounds counterintuitive, but maybe there is a way?

Or will it be power efficient to have a timer interrupt wake the PIC McmCU up and check if the 4th button got pressed?

Please guide. Power saving is a critical requirement.


1 Answer 1


Search on "keyboard matrix" or "keyboard scan" for some of the ages-old solutions in multiplexing keys into fewer I/O lines.

At the cost of some circuit and software complexity, you can make a 2x2 keyboard matrix and hold the "scan lines" for both columns active. Run the row outputs into two of your three interrupt lines. Then any button push will cause an interrupt, and on wake-up you can scan the keys.

  • \$\begingroup\$ I'll know which row is pressed, but since both scan lines (columns) are active; how can I determine which column had the keypress? \$\endgroup\$
    – mrs15
    Commented Dec 18, 2022 at 20:52
  • \$\begingroup\$ A 2x2 keypad matrix requires four I/O pins, same as four separate inputs to read key states (although that will also require a common connection to GND or Vdd). Those four inputs can be configured for IOC (Interrupt On Change) to wake up the device. \$\endgroup\$
    – PStechPaul
    Commented Dec 18, 2022 at 21:20
  • 1
    \$\begingroup\$ I was going by the OP's assertion that there were only three available interrupt pins. If more pins can be configured as interrupts -- yes, by all means, that's an easier way. \$\endgroup\$
    – TimWescott
    Commented Dec 18, 2022 at 21:24
  • 1
    \$\begingroup\$ @mrs15 once the thing is away, do a proper scan. \$\endgroup\$
    – TimWescott
    Commented Dec 18, 2022 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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