Ruben J=F6nsson wrote: >> Ruben J=F6nsson wrote: >>>>>> MOVF PORTB,W >>>>>> MOVWF SHADOWB >>>>>> MOVLW B'100' >>>>>> IORWF SHADOWB,W >>>>>> MOVWF PORTB >>> Yes, there still could be problems if the interrupt is just after IORWF = >>> SHADOWB,W. Then changes done in the interrupt routine will be undone wh= en >> the = >>> non interrupt code does MOVWF PORTB. The key is, appart from using a sh= adow >>> register, is to never read back from the port to the shadow register. >> Hmmm you are right. But I don't understand your solution? >> >> BSF shadow, 0 >> MOVFW shadow >> =3D=3D=3D> interrupt here >> MOWF port >> >> This sequence does not read the port, but changes made by the interrupt = >> would still be lost. >> >> -- = > = > Yes, you are right. I only thought about manipulating the shadow register = > itself. Not actually copying it out to the port. The copying will require= that = > interrupts are disabled if the copying can be done from both non isr and = isr = > code. > = > It will work if you don't need to copy, that is if you don't need a shado= w = > register. But then you have to be aware of the rmw issue. Unless you have= a = > latch register in the hardware, that is. > = > However, the initial point was that even with a latch register (or shadow = > register) you have to be aware of interrupts if some bits in the register= can = > be manipulated by the isr code while other bits are manipulated by non is= r code = > at the same time. > = > /Ruben = > A nice way to solve this (and if the I/O pins do not have to e switched fast, such as e.g. indicator LEDs), is to only BSF/BCF the "shadow" bits in the main code, and only copy to the port in the ISR. That way you can manipulate the indicator-LED bits wherever there is a need, and have a safe update of the PORTx register in a single place in the ISR. Jan-Erik. > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D > Ruben J=F6nsson > AB Liros Electronic > Box 9124, 200 39 Malm=F6, Sweden > TEL INT +46 40142078 > FAX INT +46 40947388 > ruben@pp.sbbs.se > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist