varunme
Advanced Member level 3
My code for updating UART with ADC not working,
Code:
// char text[12];
long tlong;
int i;
unsigned int adc_rd;
char *text = "000.0000";
void main(){
CMCON |= 0x07; // turn off comparators
ADCON1 |= 0x0C; // Set AN2 channel pin as analog
TRISA2_bit = 1; // input
UART1_Init(9600); // Initialize UART1 module at 9600 bps
Delay_ms(100); // Wait for UART 1module to stabilize
UART1_Write_Text("Start");
UART1_Write(13);
UART1_Write(10);
while(1)
{
adc_rd = ADC_read(2); // get ADC value from 2nd channel
tlong = (long)adc_rd * 5000; // covert adc reading to milivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
//UART1_Write_Text(tlong); //delay_ms(500);
longtostr(tlong,text);
for (i=0;i<strlen(text);i++)
UART1_Write(text[i]);
delay_ms(500);
}
}