On Sun, 18 Jan 2004, Olin Lathrop wrote: > > Here is a slightly modified snippet from some of my working code: > > ; > ; Process port B change interrupt. > ; > dbankif gbankadr > movf lastb, w ;make temp copy of previous input bits > movwf ireg2 > dbankif portb > movf portb, w ;end the mismatch condition > bcf intcon, rbif ;clear the interrupt condition > movf portb, w ;get base value for next change detect > dbankif gbankar > movwf lastb ;update last IR input bits state > xorwf ireg2 ;make flags for changed bits in IREG2 Wouldn't it be faster to do this? ;dbank stuff movf PORTB,W bcf INTCON,RBIF movf PORTB,W ;get base value for next change detect ;dbank stuff xorwf lastb,W ;get differences from last time xorwf lastb,F ;save this one as the new last movwf ireg2 ;save the differences Saves a cycle. And if the variables are not in bank 0, an additional 1 or two cyles are saved (depending on which part is used). Also, I'm not convinced that the port needs to be read twice (but I could be wrong). According to the data sheet (of an F84), the I/O pins are sampled with two transparent latches. One latch pass D to Q when the port is being read, while the other passes D to Q when the port is not being read. The interrupt flag is the xor of these two latches. Thus, in the worst case (when the I/O changes at the same time the port is being read), the ' bcf INTCON,RBIF' may momentarily clear the interrupt condition, but the interrupt will persist. Reading the I/O port again (like in the code snippet above) will clear the interrupt condition. However, suppose the I/O port changes two cycles after the 'bcf INTCON,RBIF'? You're back in the same boat... In my opinion, I think this is all that's needed: ;dbank stuff movf PORTB,W ;get base value for next change detect bcf INTCON,RBIF ;dbank stuff xorwf lastb,W ;get differences from last time xorwf lastb,F ;save this one as the new last movwf ireg2 ;save the differences If there's a race condition, then the interrupt may trigger again. If so, the code will immediately re-enter the interrupt routine after the RETFIE instruction. Am I missing something? Scott -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics