I paraphrased directly from microchip documentation. -JL > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Byron A Jeff > Sent: Tuesday, January 29, 2002 12:04 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: BSF and BCF use in port pins > > > On Tue, Jan 29, 2002 at 11:23:47AM -0500, Jennifer Loiacono wrote: > > Because of the read-modify-write structure, a write to > PORTx actually writes > > to LATx. > > Yes. > > > A write to the PORT register first triggers a read of the present > > port values, > > Only on a read modify write cycle. Just clarifying. > > > then alters the value in the LAT register, then writes back to > > the port. > > Correct. > > > If another pin on that port is used for bidirectional I/O, it > > could cause problems. For example, if a pin is set as an > input when the > > data is read, the value would overwrite what is already in > the register. > > True. However this will only cause an effect when you turn > that bit back > into an output. Presumably you'd rewrite the latch before doing that. > > > Thus, it is safer to perform bit operations in the > appropriate LAT register. > > ???. You don't have direct access to the LAT register. > > > > > The TRIS bits (direction registers) should not be changed > individually, as > > certain peripherals override the TRIS settings. > > A completely separate point. And since the periperals > override the TRIS > setting, but do not in fact overwrite the TRIS bit, usually > it's irrelavent > what value those overridden bits are set to. > > > > > More information is available in the mid-range manual, in > the I/O Ports > > section (section 9). > > Very true. An invaluable resource. Everyone who programs PIC > should download > a copy from Microchip's site. > > Jen, while you described part of the problem, you missed the > real point. > I covered it in detail here (PASSWORDED SITE. login and > password are both > 'piclist'): > > http://www.infosite.com/~jkeyzer/piclist/2002/Jan/1069.html > > RMW cycle can be trouble because even when a pin is set to an > output, the > pin is read instead of the latch. The problem becomes obvious > when attempting > two consectutive RMW instructions to the same port. The write > of the 1st > instruction and the read of the second instruction happen one > cycle apart. > So it's possible for the 1st write of a bit not be able to > change the pin > before the read of the bit in the next instruction. Result is > that the latch > can be reset back to the value of the pin, nullifying the 1st write. > > Hope this helps, > > BAJ > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.