Welcome!
cool Welcome PIC fans!
(to Pascal language fans too!)
Documents

Close Documentation

Close How to support PMP

Close Manuals

Close Today's favourites

Technical

Close Tips

Search




Downloads
Google

cadeau.gifTips - The Read-Modify-Write problem on I/O ports

Here 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
Last update : 2008.12.23 5:46 PM
Category : Tips
Page read 4226 times


Print the article Print the article


react.gifReactions to this article

Nobody gave a comment yet.
Be the first one to do it!


Connection...
 
Members List Members : 90

members Visits of the day: (5) Zele    fmy    brico31    PPA    tomywong   

Your Username:

Password:

[ Password lost ? ]


[ Join us ]


  Member online:
  Anonymous online: 1

Total visits Total visits: 137347  

Most ever online
Most ever onlineTotal: 43

The 04/11/2009 @ 08:33


Webmaster - Infos

Ip: 38.107.191.102

Search




Friends News
Support PMP

Sentence to think about :     
^ Top ^