On 2010-09-22 09:06, David Duffy (AVD) wrote: > On 22/09/2010 4:27 PM, Matt Callow wrote: >> You've not restated the Q as: >> 'But why bother clearing PORTx when clearing LATx is really clearing the= port?' >> >> Which is a completely different Q, (which I don't have an answer for!) > > Sorry, a typo crept in there. I did mean PORTx when I said TRISx earlier= .. > > So to be clarify, I don't understand why Microchip are setting LATx > *and* PORTx during initialisation in their example. Setting PORTx seems > to be totally redundant in devices that have LATx registers. > David... > Yes, that is redundant. B.t.w, *which* datasheet is this ? I'd like to verify the context this was written in. When *writing*, PORTx and LATx are setting the same internal registers in the PIC (the "output latch"). So when writing (CLRF, MOVWF...) it doesn't matter if you use LATx or PORTx, the effect is exactly the same, the data is written in the "output latch". When *reading*, PORTx reads the actual pins and LATx reads the "output latches". The value read can be different if the "output latch" and the actual pin values are different and can give "interesting" results when using BCF/BSF and similar instructions. Note that *ALL* PIC has "output latches", they are just not directly readable on some PICs (those without LATx registers). If not, there wouldn't be anyplace for the PIC to "remember" the value written to the PORT, right ? It's very much the same as the fact that on some (older) PICs the "working register" ("W") is not mapped as a "file register". On PIC18 and the newer PIC16F1xxx there is a mapped "WREG" SFR register that can be used for BCF/BSF/RRF/RLF or similar instructions that are otherwise not usable directly against "W". Jan-Erik. Note that *all* --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .