Welcome!
Welcome PIC fans! (to Pascal language fans too!) Documents
Technical
Search
Downloads
The last 5 downloads
The last 5 most downloaded
Google
|
Tips - The Read-Modify-Write problem on I/O portsHere is an excellent article on this problem that everybody should be aware of. Mainly the problem is that when you read a PIC PORTx I/O, you read the input buffer, not the output latch for pins that are defined as outputs. Some latest processors have separate output latches named LATx that are readable. In this case, the read-modify-write problem does not apply, just use PORTx for inputs and LATx for outputs. How problems may occur: if the output pin has some load that makes the requested level to not be reached (by an excessive pullup or pulldown, by a capacitive load such as a mosfet gate) the "input" may not reflect immediately (or never at least) what you "output"; so a code like: setb PORTA, 0 setb PORTA, 1 may write back a 0 on PORTA.0 at the 2nd instruction (yes, a setb reads the whole port, changes the bit and writes back to the whole port). another example: movlw h'FF' movwf PORTA xorwf PORTA, f After this, all pins should be 0, may be not... What about PMP? PMP allows direct port write that maps directly to the shortest processor's instructions, so the above remarks applies: PORTA := 0; PORTA.0 := true; PORTA.1 := false; may write back a 0 on PORTA.0 at the 2nd instruction. Workarounds: The simplest way is... Do not use such constructions... Well, the 2nd simplest way is using a shadow register: SHADA := 0; SHADA.0 := true; SHADA.1 := false; PORTA := SHADA; where SHADA is a global byte variable that will reference / hold all manipulations on PORTA, and that is systematicaly copied to PORTA. To do list: Future implementation of PMP should contain some mechanism to automatically use a shadow register that should be activated by a compiler directive (since this is time / code consuming and everybody does not need it). Creation date : 2007.06.24 6:14 PM
| Connection...
Visits of the day: (5)[ Password lost ? ] [ Join us ] Member online: Anonymous online: 1 Total visits: 137347 Most ever online
Total: 43The 04/11/2009 @ 08:33 Webmaster - Infos
Ip: 38.107.191.102 Search
Friends News
Support PMP
|




Welcome PIC fans!
Documentation

Tips - The Read-Modify-Write problem on I/O ports
Visits of the day: (5)
Anonymous online: 1
Total visits: 137347
Total: 43
Top 
