John Chung wrote : > Brooke, > subwf ms_counter,W > btfsc STATUS,Z <-bit test file skip when clear. > banksel PORTB ; NEED banksel here or bcf PORTB,7 > ; bcf PORTB,7 ; heart beat off PC4 Testing > > > I find the code as follows. When the ms_counter result > is non zero it skips banksel and bcf. But when it is > zero it executes banksel. Now the thing is bcf and > banksel has to go hand in hand. Select the correct > bank for PORTB before using PORTB. No, that was not the problem. Note that the bcf is commented out... Alan B. Pearce wrote : > >OTOH, you might be having issues with context saving at > >the start of the ISR. Can you post the first 10 or so > >lines of the ISR, or maybe the entire ISR? > > That was my immediate thought too. I bet you are not > saving-restoring the banksel register in the ISR. No, that wasn't the problem either. (B.t.w, what is "the banksel register" ?) The problem was simply that the BTFCS sometimes skipped the first line in the context-restore code... It was perfectly clear if one looked at the full code example and removed all commented out code and left the BTFSC in place. Then the first instruction after the BTFSC (that sometimes would be skipped) was the line that fetched the saved PCLATH value. When that line was skipped, PCLATH was "restored" using whatever was left-over from the SUBWF instruction earlier in the ISR (right before the BTFSC...) I thought this was cleared out yesterday. Regards, Jan-Erik. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist