PIC12F683 question

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Thanks for your advice THE_RB, it's really appreciated :)

As a rule on PIC 10/12/16F you should NEVER write to a single bit on an output port.

It is good form to always use a shadow register, set or clr the bits in that shadow register and then write it once to the PORT as a whole register.

....
 

takao21203

Joined Apr 28, 2012
3,702
As a rule on PIC 10/12/16F you should NEVER write to a single bit on an output port.

It is good form to always use a shadow register, set or clr the bits in that shadow register and then write it once to the PORT as a whole register.

Not only does that fix RMW faults like the one you had, it also allows some benefits like ensuring all the PORT pins change at the same instant and in one single instruction. That can be useful in making manual PWM outputs and LED multiplexing etc.
In many cases it does not matter.

There was the case when I removed instructions from an I2C interface, so in the end, I only modified the TRIS register. On the 16f5x, indeed the TRIS bits can not be set individually :)

At first the code looks weird but the waveform is correct, since the pullup resistors would preset the bit to "1". I figured out, changing the port bit itself wasn't required in many instances.

I have actually done this many time, for software synchronous serial port. Individual bits are changed of course. But besides older chips I have around here, only extended midrange 16F chips are used now. The RMW issue isn't that dramatic, you just need to be aware of it as a potential trouble source (among countless many other things).

I have some 16f54 codes which actually do not use loops, the serial data is transfered using a long row of port bit modification instructions. All done by changing individual bits. Maybe RMW is the reason why I need one or two compensation resistors.
 
Last edited:
Top