Hi, Gavin Jackson Wrote: > Hi there > > I would just like some opinions on this. Does this > solve the read-modify-write problem. > > All PIC pins have external pull-ups. When the program > starts the instruction CLRF PORTX is issued to write a > logic '0' to the data latch. If you want a logic '1' on the > port you simply make it an input, by writing a '1' in the > TRISX register corresponding to the bit position. > If you want a logic '0' you make the port pin an output and as > the data latch already contains a '0' you know that the pin > will pull the external pull-up to ground. > > You no longer read and modify the PORT, but rather the > TRIS register for that port. > > Any thoughts on this method? > > Regards > > Gavin No, it doesn't. Suppose you want RB0 to be a 0 and RB1 to be a 1. According to your scheme, you will make RB0 an output and RB1 an input. This will have the desired effect. Now, lets say you do a bsf RB0. This instruction will (1) Read PORTB, (2) set bit 0 and (3) Write the result back to PORTB. When PORTB is read, RB1 will read as a high because of the external pull-up. Thus RB0's output latch value will be set to 1 in step 3. If you now make RB0 low (set it to an output), it will thus stay high. The only way (I know of) to beat this, is to use a ram register (shadow register) to hold the contents of the output latches of the port. If you want to perform a bit modify, perform it on the shadow register and transfer the register to the port: bsf Shadow_PORTB movf Shadow_PORTB, W movwf PORTB Hope this helps, Niki