1) To get sample by A/D converter and store it to "capture1[40]" for 40 times.
2) To send above data to PC by UART.
But for loop doesn't work as my expectation.
Code: Select all
void main() {
char buffer[4];
unsigned short i;
unsigned int capture1[40];
ANSEL = 0b00000001; //A/D Converter disable except RA0
ANSELH = 0b00000000; //A/D Converter disable
ADCON0.ADCS1= 1; //Fosc/32
ADCON0.ADCS0= 0;
UART1_Init(115200);
UART1_write_text("START");
UART1_write(0x0d);
UART1_write(0x0a);
for (i=0; i<40; i++)
{
capture1[i] = adc_read(0);
delay_us(300);
}
UART1_write_text("A/D COMPL");
UART1_write(0x0d);
UART1_write(0x0a);
for (i=0; i<40; i++)
{
bytetostr(i, buffer);
UART1_write_text(buffer);
UART1_write_text(",");
WordToStr(capture1[i], buffer);
UART1_write_text(buffer);
UART1_write(0x0d);
UART1_write(0x0a);
}
UART1_write_text("END");
UART1_write(0x0d);
UART1_write(0x0a);
}
START
A/D COMPL
0, 0
END
Only I could get one data. Not 40 data.
I connected LCD and confirmed the final value of "i". And it was 49 or 48 (unstable). I cannot understand why "i" was set as 49.
Is there any careless mistake? Would you give me any advices?
Thank you.