Page 1 of 1

Reading keypad with PORT int (IOC)

Posted: Tue Apr 24, 2012 3:50 am
by tompzone
hi i am trying to read a keypad with interrupts on a pic 16f877a (mainly because polling is to slow), to read it i am using the internal resistors, the columns are connected here (RB4-7), the LSB are outputing a logical 0, so when i press the key the interrupt occur, then in the isr, first i dissable the int then i store the content of the port on a variable and mask it so the output pins doesnt affect, then i switch the direction so now the inputs are outputs and send another logical 0, because the pullups are active i should be able to detect witch button was pressed, so now i read the content and store it on a temporal variable, then i OR it together and i get my 8 bit code of the key.

well that's the algorithm but it only reads the first values, the rest of them just gives me only logical 1's, and the algorithm works as i hace used it on a HSC12 so it should work here.

i am using only C because if i use the icons disable the WPU (i think that the output icon makes all the pins of the port outputs even if i mask the output) so this is the code i am using.

first i enable the WPU
i enable the PORT int
then i set the port and output a 0

trisb=0xf0;
portb=0;

then i go into the main
my isr is the following

intcon.RBIE=0;
delay_ms(30);
FCV_TECLADO=portb;
FCV_TECLADO=FCV_TECLADO&0xF0;
trisb=0xF;
delay_ms(30);
portb=0;
FCV_TEMP=portb;
FCV_TEMP=FCV_TEMP&0xF;
FCV_TECLADO=FCV_TEMP|FCV_TECLADO;
trisb=0xF0;
portb=0;
intcon.RBIE=1;

any ideas on why it's not reading the contents proprely after the direction switch?

Re: Reading keypad with PORT int (IOC)

Posted: Thu Aug 09, 2012 2:36 pm
by Enamul
Hi,
You can have a look at this following post...It might help you..
http://www.matrixmultimedia.com/mmforum ... 26&t=10657
Enamul