Page 1 of 1

keypad with C and interrupts

Posted: Wed May 02, 2012 8:27 pm
by tompzone
hi i am having trouble with the interrupt on change, C code trying to make a matrix keypad the lower part of the port is an output and the ioc pins inputs, the idea is to read the columns on the isr, then change the direction so that the outputs are inputs and do the same, the OR them together and i shold give back a number for each key, but apparently the interrupt gets triggered twice and it only returns the colummns, the rows always return 1, but if i keep pressing the keys sometimes it returns the correct number, i am posting the chart to see if you can help me find why the program isnt working

Re: keypad with C and interrupts

Posted: Thu May 03, 2012 10:03 am
by Benj
Hello,

I don't think you can use IOC with a keypad as an output write to the IOC port pins counts as a change which would trigger the interrupt. It would probably be better to simply do a quick scan of the entire keypad every so often using say a timer interrupt to trigger the scan.

Re: keypad with C and interrupts

Posted: Fri May 04, 2012 4:20 am
by tompzone
well i noticed that using the output icon disables the WPU and apparently also the interrupts, so i am switching the direction using the tris registers, and it works, the isr gets serviced, it's just that it is only doing half of the code, unless i press the key several times very quickly, another way of doing it would be to shit a zero and then compare until the zero reaches the input pins, but the direction swap is faster so i am trying to do it that way