> = > = > slippyr4 wrote: > >> use LATB to write. > >> = > >> = > > That's a good point. To clarify, what is the impact of me using PORTB > > not LATB? > > > = > Higher risk for read-modify-write related problems. > = Put in another way - Using LATX instead of PORTX gives you no risk for the = RMW = problem. = The RMW problem is caused by a combination of two things: 1. An instruction that is changing just one bit in a register (bsf, bcf) = actually first reads the whole register, changes the bit and then writes ba= ck = the whole register (thus the name Read - Modify - Write). 2. When the register is a PORT register, the value read is actually the log= ic = levels of the physical pins and not necessarily the value that has previous= ly = been written to the port. This can become a problem if the capacitive load on a port pin is relativel= y = high (like the gate on a MOSFET for example) and there are two (or more) bi= t = changes on the same port right after each other. For example: BSF RB,0 BSF RB,1 If RB0 initially was 0, BSF RB,0 now starts to change it to a 1. If the = capacitive load on that pin is high it will take some time for it to rise t= he = voltage to a logic high level. If this time is longer than the time until = another bit in RB is changed, the value that is read back for RB0 will stil= l be = a 0 (as seen by the port logic) and when the whole byte is written back RB0= has = unintentionally been reset back to a 0 again. Newer PICs actually have two registers for one port - The PORT register and= the = LAT register. The LAT register is a latch (or buffer) between the CPU and t= he = PORT register. So if you write a value to the LAT register it is also writt= en = to the PORT register but it is always read back as the same value that was = written independent of how long the PORT register actually takes to change. /Ruben =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Ruben J=F6nsson AB Liros Electronic Box 9124, 200 39 Malm=F6, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist