Below I include simplified C code for a function 'read_ADC'.
RB0 is configured as output pin.
The function has to determine the state of RB0; then RB0 is cleared inside this function and other operations with ADC, etc. are implemented.
Then, RB0 must be restored, according to its original state.
Is it ok to check the state of RB0 (which is configued as outout pin) directly on the PORTB register?
The program runs correctly as I expected with the hardware. Do you see anything wrong/drawbacks with this solution? Of course I could update the variable RB0_state throughout the program, anywhere RB0 is changed; but this would require additional works and tests.
RB0 is configured as output pin.
The function has to determine the state of RB0; then RB0 is cleared inside this function and other operations with ADC, etc. are implemented.
Then, RB0 must be restored, according to its original state.
Code:
void read_ADC()
{
if(RB0) // CORRECT ??
RB0_state = 1;
else
RB0_state = 0;
RB0 = 0;
DelayMs(200); // 200 ms
Read_Ch(1); // read ADC
RB0 = RB0_state; // restore RB0
}
Is it ok to check the state of RB0 (which is configued as outout pin) directly on the PORTB register?
The program runs correctly as I expected with the hardware. Do you see anything wrong/drawbacks with this solution? Of course I could update the variable RB0_state throughout the program, anywhere RB0 is changed; but this would require additional works and tests.