As I understand, you are making matrix 4x9 to get 36 pins. It will use 9+4=13 in/out pins of PIC16. As it really is in PIC16F84A.
Next, you are planning to configure 4 pins as outputs and 9 pins as inputs before going to sleep mode. And the problem is that controller has only 4 pins that could be set to interrupt-on-change mode, but you need 9.
The solution is very simple. Change the matrix. Set 9 pins as outputs, and 4 pins as inputs. Set all 9 outputs to zero and 4 inputs to pull-up mode before going to sleep mode. These 4 inputs must be PORTB<7:4> pins and they will wake up controller from sleep mode after any key pressing. Next you can instantly change configuration of the matrix to 4 outputs and 9 inputs, make all 12 reading for 3 scan cycles, define the pressed key, and next change back to 4 inputs and 9 outputs matrix, and finally go to sleep.
You are describing the classic matrix approach. As I said this is not a normal matrix, it's a half-charlieplexed matrix.
In this kind of matrix any pin can be connected to any pin with a switch, so you get more buttons for the same pin count.
Half-charlieplexed matrix:- buttons = (N2-N)/2
- Where N is the total number of pins used.
Compare this to the
Classic matrix- buttons = R*C
- Where R is the number of columns and C the number of rows (total number of pins used: R+C).
In this case the remote uses 9 pins in total to get 24 keys (from a possible maximum of 36). The best classic matrix key count using 9 pins would be = 5x4=20 keys.
With the half-charlieplexed matrix, to do a full key scan, one pin must be configured at a time as an output and read all the others.
The problem is, i can't find a static input/output setting to detect any switch in sleep with a pin-change interrupt.
So, a periodic wake up is needed instead of a pin-change interrupt.
The fastest way (minimum time awake) I found is a cycle of 3 scans setting to output low multiple pins and reading the rest (see attached matrix in first post).
So my questions are still the same:Any idea to keep the CPU always in sleep like I use to do with the normal/classic matrix keyboard? Or at least to reduce the number of scans? Remember that I'm not interested in knowing the exact key, just waking up the cpu no matter what key is pressed (later, when the cpu is running, it's no problem to scan the matrix as required to get the exact key).
By the way: The PIC will be a PIC16LF1824 or PIC16LF18324 (both with 14 pin count: 9 for keys, 1 for led, 2 for ir-led and 2 for power supply).