shsn
Junior Member level 3
- Joined
- Nov 28, 2012
- Messages
- 26
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,523
I am having difficulties having both analog input and digital output on the same port on PIC16F716.
On PIC16F716, PORTA (5 pins) can be used for both analog inputs or digital inputs. I would like to have;
RA0/AN0 as analog input and RA2/AN2 as digital output which will be connected to an LED.
Although RA1/AN1 is correctly set as analog input (because it works according to driveLED function) but the LED connected to the RA2/AN2 is not doing anything.
Can anyone point me to the right direction?
Thank you.
On PIC16F716, PORTA (5 pins) can be used for both analog inputs or digital inputs. I would like to have;
RA0/AN0 as analog input and RA2/AN2 as digital output which will be connected to an LED.
Code:
void main() {
TRISA = 0x02; // Initialise PORTA RA2 as INPUT, rest as OUTPUT
TRISB = 0; // Initialise PORTB as OUTPUT
PORTB = 0; // Set PORTB as OUTPUT
do {
adc_val = ADC_read(1);
volts_m = (long)adc_val*5000/256;
driveLED (volts_m);
}
while(1);
}
Although RA1/AN1 is correctly set as analog input (because it works according to driveLED function) but the LED connected to the RA2/AN2 is not doing anything.
Can anyone point me to the right direction?
Thank you.