At 15:01 1998-06-27 +1200, you 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 Seem OK to me. Only drawback is the extra current consumption versus speed and drive capacity problem due to the pullup configuration. Also remember that on reset the pins are input, so if you want low on reset use pulldown instead, and out H when you want high. The read-modify-write problem is double: 1) for pins that are inputs, it latches the input state to the uotput latch, so ig you later turn that an output it it will hold the vale it had as input, not perhaps what uou worite to it before. 2) Even if every bit on that port is outputs; if a spike occours that is strong enougth to temporarily change the state on the output pin: If it happens in the beginning of the read-modify-write on the port, that altered state it the one read, and then that false state is reloaded to output. (unless it is the bit you are modifying) A method to eliminate 2) is to make *sure* you will not by any chance ever have a disturbing spike into the output, by example by putting a suitable resistor in series with the putput. /Morgan / Morgan Olsson, MORGANS REGLERTEKNIK, SE-277 35 KIVIK, Sweden \ \ mrt@iname.com, ph: +46 (0)414 70741; fax +46 (0)414 70331 /