PORTB interrupt-on-change feature

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

PORTB interrupt-on-change feature

Postby Sytan » Tue Jan 11, 2011 10:02 pm

Hi all,

I'm using 16F876A in my project. Below is my doubt about interrupt-on-change feature in PIC.

As we know, in PIC16F876A has 4 pin (RB4:RB7) have interrupt-on-change feature. My question is how can we determine which pin is causing interrupt if more than 1 pin use as input for interrupt-on-change? FYI, they are sharing RBIF flag. I have done with 1 input but now having problem to adding 1 more input into my project. Is there any method we can use to determine which pin causing the interupt in ISR?
FYI, i use that as my software uart input (to sense HIGH to LOW voltage level at the start bit) from rfid reader, not to sense button where we can determine interrupt pin easily by reading PORTB again.

Any suggestion is welcomed.Thanks in advanced.
Sytan
Apprentice
 
Posts: 33
Joined: Mon Jun 07, 2010 3:10 pm

Re: PORTB interrupt-on-change feature

Postby aurora » Tue Jan 11, 2011 10:12 pm

Sytan WROTE:FYI, i use that as my software uart input (to sense HIGH to LOW voltage level at the start bit) from rfid reader, not to sense button where we can determine interrupt pin easily by reading PORTB again.

Can you explain a bit more on the last sentence? A bit confuse here.
A quick way, would be to read RB4:RB7 and store it immediately when the interrupt happen. Put it at the first line of your ISR.

For UART, I think that uC should have a RX interrupt function?
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: PORTB interrupt-on-change feature

Postby Sytan » Tue Jan 11, 2011 10:40 pm

Hi aurora,thanks for your swift reply.
Oh, one of the example from microchip is button sensing using interrupt-on-change feature.The code reads PORTB again to check which pin causing the interrupt if i'm not mistaken.

My RX pin is occupied and i don't want to waste the processing power in waiting command so i chose this option. I did try the method you suggested. But it doesn't return any info,i guess the start bit already changed by the time PORTB is being read? Maybe i'll try it again to double confirm the result.
Sytan
Apprentice
 
Posts: 33
Joined: Mon Jun 07, 2010 3:10 pm

Re: PORTB interrupt-on-change feature

Postby aurora » Tue Jan 11, 2011 10:51 pm

It should take only a few clock cycle from interrupt to reading port B. If you can make sure that the input last a few clock cycle (maybe like 10-20), you should be able to read it in time. If it is keypad, perhaps try pressing it a bit longer? As we are talking, a few clock cycle is actually on few uS :!:
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests

cron