Electronic – What causes turning ON a single output pin on Microchip PIC16F690 to spontaneously turn OFF another pin on the same port

hi-tech-compilermicrochippicprogramming

What causes turning ON a single output pin on Microchip PIC16F690 to spontaneously turn OFF another pin on the same port? I can work around this problem by writing a byte to the entire port, controlling all pins simultaneously, instead of just a bit to control the pin state. I'm using the Hi-Tech C compiler here. I am determining the state of the pin with 9 LEDs each consuming 3 mA. This is way below the max power specs.

The mplab header file has the 0 pin on port A declared as such:

volatile       bit RA0  @ ((unsigned)&PORTA*8)+0;

I am turning the pin on by writing a high value to it.

RA0 = 1;

Is the problem that the complier is treating the "1" as a byte and writing to the whole port?
Do I need to cast it? If so, shouldn't have the complier given me an error?

RA0 = (bit) 1;

If I write to the whole port everything works as expected:

PORTA = 0b00000001;

Best Answer

It's the well-known read-modify-write problem, you will find details in the data sheet. You have to write to the whole register, as you have found. The 18F and 16-bit devices don't have the problem. There is a good description on page 2 in this document. Changing bits in a "shadow" register then writing the register to the output port is often used to get round the problem.

Related Topic