is there possible to insert for loop
in void function
?
void decode(unsigned char* msg)
{
int result[5];// can store our value
unsigned char lala[50];
if (strstr(msg, "UI01?") != msg) // write in Hyperterminal
{
sprintf(lala, "UI01 %d \r\n", result[0]); // UIO1 ADC Value
sendString(lala);
}
else if (strstr(msg, "UI02?") != msg) // write in Hyperterminal
{
sprintf(lala, "UI02 %d \r\n", result[1]); // UIO2 ADC Value
sendString(lala);
}
else if (strstr(msg, "UI03?") != msg) // write in Hyperterminal
{
sprintf(lala, "UI02 %d \r\n", result[2]); // UIO3 ADC Value
sendString(lala);
}
else if (strstr(msg, "UI04?") != msg) // write in Hyperterminal
{
sprintf(lala, "UI02 %d \r\n", result[3]); // UIO4 ADC Value
sendString(lala);
}
}
int main()
{
int result[5]; // can store four value
int a = 0; // start from UI0-UI4
while (1)
{
for (a = 0; a < 5; a++)
{
AD1CHS0bits.CH0SA = a; // UI0-UI4
AD1CHS0bits.CH0NA = 0; // Vreferences as channel 0 -ve input
AD1CON1bits.ADON = 1; // 1 = A/D Converter module is operating
AD1CON1bits.SAMP = 1; // sapling mode
__delay32(50); // delay after sampling
AD1CON1bits.SAMP = 0; //sampling bit
while (!AD1CON1bits.DONE);
result[a] = ADC1BUF0; // have 4 result
}
}
if (U1STAbits.URXDA == 1) //check if data avilbe
{
rxbuf [len] = U1RXREG;
if (rxbuf[len]== '\r')//press enter
{
sendChar (rxbuf[len]);
sendChar ('\n'); //new line
decode (rxbuf); // calling decode funtion
len = 0 ;
}
else
{
sendChar (rxbuf[len]);
len++;
}
}
}
from the code above, in void decode
enable the code UIO1?
is type in Hyperterminal, it will reply ADC value. Followed by UIO2?
until UIO4?
.
in the while(1)
loop, the code is used to scan UIO1
until UIO4
. Actually UIO1
until UIO4
have analog value to be read in digital value. I am using for loop
, because it look more simple.
The problem is, in the void decode
loop, I got error: subscripted value is neither array nor pointer . How to read the result
value ?