keypad with C and interrupts

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
tompzone
Posts: 23
Joined: Mon May 23, 2011 4:30 pm
Has thanked: 4 times
Contact:

keypad with C and interrupts

Post 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
Attachments
teclado int.fcf
(7.5 KiB) Downloaded 380 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: keypad with C and interrupts

Post 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.

tompzone
Posts: 23
Joined: Mon May 23, 2011 4:30 pm
Has thanked: 4 times
Contact:

Re: keypad with C and interrupts

Post 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

Post Reply