From: "Debbie" > PICers - here's something that really had me stumped for a couple of days. > I wrote code to operate a camera. It configs the OPTION_REG and the INTCON as > shown, then waraps up housekeeping functions and goes to sleep to wait for an > interrupt on RB0 or RB6/RB7 keychange as case may be. > > What nearly drove me nuts was the hardware kept self interrupting all the time, > yet the simulator (MPLAB) behaved normally. ie It went to sleep, stayed > asleep. The protoboard hardware version (4MHz) would get to the sleep instruc > then jump to the ISR. Even if I left GIE cleared. This is pretty much impossible. If GIE is clear, ints aren't going to fire. > I "cured" (?) it by changing the OPTION_REG from b'10000111' to b'00001000' > > What I can't figure out is why? When you disable the INTCON (GIE=0), then it > shouldn't make any difference what you have in OPTION_REG? The OPTION reg shouldn't have any effect whatsoever on your port change interrupts. Chances are much more likely that you have left the watchdog running accidentally or have interrupts occurring while you are switched to bank1, but the ISR doesn't know it and it blindly smacks up the wrong registers. Or the ISR switches back to bank0, but doesn't properly save/restore the context info causing the main level code suffer psychotic episodes. Stuff like this won't always show up in simulations. > Any ideas what's going on? ie are there any restrictions on what you can out > into the option register v/v interrupts? When you use port change ints, you have to read the port as well as clearing the RBIF flag. Otherwise the interrupt will trigger again because a mismatch condition still exists against the magical hidden shadow reg that holds the original pin values. You have to read the port before clearing the RBIF, or it will instantly change back to a 1 causing the int to fire again as soon as you execute the RETFIE. This reloads the magical hidden shadow reg. ;-) The simulator may not get this right, it wouldn't be the first thing it didn't "simulate". -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist