veegee wrote 2013-03-27 05:59: > I've found my new "jellybean" PIC - the PIC18F14K50. Perfect size, > performance, cost, USB, etc. > > I didn't realize when this happened, This has always been like this on the PIC18 devices. This is also true on the newer ("enhanced") PIC16F1nnn devices. > but apparently, you're supposed to write to the LATx registers in > order to output data via the GPIO... You can write to LATn or PORTn, it doesn't matter, *for a simple write*. Both operations have exactly the same result, LATn is written. Note that "Write LAT or Port" is the same line in the Fig 9-1 in the datasheet! > I've been using the PORTx registers for reading and writing this... Now, *reading* is a different matter! - Reading PORTn reads *the actual physical I/O pin*. - Reading LATn reads the "output latch", that is the LATn register. Note that "Read LAT" and "Read Port" are separate line in Fig 9-1 in the datasheet! Note, there is no real *physical* PORTn registers ! > entire time, on all ranges of PIC > hardware without issues. According to the datasheet, the PORTx and LATx > registers are memory mapped (for this device anyway), so writing to the > PORTx is the same as writing to the LATx registers. Yes, always for a simple write, "usualy" for BSF/BCF or similar RMW instructions. > > What's the deal here? What's the concept behind splitting LATx and PORTx > if they're memory mapped anyway? > Beeing able to write something to the port and read back the same value (LATn) without regard to how the actualy physical pin is driven from the outside. And the only (and important) difference is when *reading*. Reading LATn gives you the value the I/O pin *might* have if everything else is setup accordingly (the pin as "output", not driving it too hard and so on). Reading PORTn gives you the real value of the I/O pin (which might be different then LATn if the I/O pin is shortcurcuited or similar). Jan-Erik. had if --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .