I'm using a PIC16F688 to read from analog channel 2 and average the values of the pressure sensor and then convert the 4 bytes to digital using ASCII character method.
I don't need any kind of delay after sending the results to UART1_Write(temp[i]).
My problem is that the UART 13 is not working properly as carriage return. The output from terminal looks like this: 000000000 0000 0000 000000000 when tt should be sending pure 0000 every time (and depending on my pressure on the sensor, from 0000 to 1023).
char *temp = "0000";
unsigned int adc_value;
int i;
int average = 0;
void main()
{
OSCCON = 0x77; //8MHz
ANSEL = 0b00000100; //ANS2
CMCON0 = 0X07;
TRISA = 0b00001100;
UART1_Init(9600);
Delay_ms(100);
while (1) //infinte loop
{
average=0;
for(i=0;i<10;i++){
average+= ADC_Read(2);
}
average/=10;
temp[0] = average/1000+48;
temp[1] = (average/100)%10+48;
temp[2] = (average/10)%10+48;
temp[3] = average%10+48;
for (i=0;i<4; i++){
UART1_Write(temp[i]);
}
UART1_Write(13); // back slash
//delay_ms(10);
}
}