I'm using the PIC12F675 to read two single pole single throw switches. Every time either switch is pushed I use interrupt on change to see that a switch was pressed.
My problem is I don't see an IOC status register in this chip to know which switch was pushed. I've read the datasheet over and over and don't see it.
Am I missing something? How do I figure out which switch was pushed?
I think it works similar to the portb change interrupt on the pic16f877a. When a switch is pressed you just read the port to see which one.... There is only one GPIE and one GPIF....
You need to keep a copy of the previous value of the port and then work out which one has changed state. Assuming you're using the pullups and your switches are to ground, you would do the following.
Code:
ISR
call delay ;probably needed for debounce
state = GPIO ;read port only once
changed = state xor previous ;find bits that have changed
newpresses = changed and previous ;keep only bits that were 1 previously (must have gone 1->0)
previous = state ;update previous
if newpresses.0 = 1 then ;test if button on GPIO,0 was pressed
;code for bit 0 of GPIO
endif
The above is pseudo code but should be followable.
Edit, for active high switches change newpresses = changed and previous to newpresses = changed and state.