Wow, thanks. I can't think of any more questions to ask :) That's what I call a good answer! Thx, Steve > > I'm looking for some clairity on what the Latch does in the PIC18 > > devices. > > The PORT register is the immediate state of the port pins, whereas the LAT > register holds what you want the output pins to be. > > This means on reading, PORT will reflect the actual pin voltage in real > time, and LAT simply acts as a RAM location. In other words, LAT always > reads back what you last set it to. > > However, LAT is most useful for writing. A parallel 8 bit write to either > register will have the same effect (MOVWF PORTB for example), but there is > a > significant difference on bit manipulation (BCF PORTB, 2 for example). > All > writes to PORT are actually read/modify/writes. This matters when the > final > write doesn't update all the bits, or you are performing an arithmetic > operation where the original bit values effect the result. In those cases, > the read will read the instantaneous value of the port pins, which is NOT > necessarily what you last set them to. The pin input and output circuits > are independent. The pin input circuits read the actual pin voltage. If > the external circuit is forcing the pin to a particular state, then this > state will be read whether the drivers are trying to drive to that state or > not. Note that this can happen for short times even with a normal external > circuit. The output drivers can only source/sink a finite current, and > there is always some capacitance from a port pin to ground. This means > that > after being set to a different state, the port pin will take a finite > amount > of time to reach that new state. If a read occurs before it reached the > new > state, then the read will return the old value, not the value just written. > To make matters worse, the write to the port register is done near the end > of the instruction cycle, and the read is done near the beginning. If I > remember right, there is only one Q cycle of time between the write from > one > instruction and the read from the next. This amounts to 1/4 instruction > time, not a whole instruction time as you might expect. > > For example, on a 20MHz 16F: > > clrf portb ;set all port B pins to 0V > ... > ; > ; A "long" time later: > ; > bsf portb, 1 ;set RB1 to 5V > bsf portb, 2 ;and then RB2 also to 5V 200nS later > > The second BSF will quite likely set RB1 back to 0V. Can you see why? > > However, if these BSF were done on LATB instead of PORTB, then they would > have the intended effect. > > > ***************************************************************** > Embed Inc, embedded system specialists in Littleton Massachusetts > (978) 742-9014, http://www.embedinc.com > > -- > 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: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu