On 2010-09-22 13:55, Rolf wrote: > On 10-09-22 01:02 AM, David Duffy (AVD) wrote: >> Up until now, I've only used the older (lower end?) PICs >> >> I think I understand the difference between PORTx and LATx, but in one >> data sheet Microchip show port B being initialised like so: >> >> BANKSEL PORTB >> CLRF PORTB >> BANKSEL LATB >> CLRF LATB >> BANKSEL ANSELB >> CLRF ANSELB >> BANKSEL TRISB >> CLRF TRISB >> >> Why bother clearing TRISB when you would be only writing to LATB anyway? >> David... >> >> > > Good point. All writes to PORTx are written to the latch anyway, so clrf > PORTx is identical to clrf LATx > > The port pin diagrams indicate that fact as well. > > Further, all analog pins read as '0', all digital pins read the state of > the signal (which for outputs may be a mis-match to the LATx value if > you have slow-changing signal lines...). > > But, in all cases, clrf PORTx =3D=3D clrf LATx > > On the other hand, it's not an error to do it twice... and further, > operations other than 'clrf' on PORTx will/may produce a different > result than the same operation on LATx... No, all *write-only* operations works the same against PORTx or LATx. Such as CLRF and MOVWF. Read-Modify-Write operations may work differently. Such as BCF, BSF and all and/or/xor operations on a file reg. Jan-Erik. > so perhaps it is good practice > to treat them 'both' explicitly in the initialization routine... No, there is absolutly no reason for that. > > Rolf --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .