是否可以在for loop
中插入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++;
}
}
}
从上面的代码中,在void decode
启用代码UIO1?
的类型为Hyperterminal,它将回复ADC值。随后是UIO2?
,直到UIO4?
。
在while(1)
循环中,代码用于扫描UIO1
直到UIO4
。实际上UIO1
直到UIO4
具有以数字值读取的模拟值。我正在使用for loop
,因为它看起来更简单。
问题是,在void decode
循环中,我收到错误:下标值既不是数组也不是指针。如何阅读result
值?
答案 0 :(得分:0)
qemu-arm
和result
中的result
是两个不同的变量。
如果您希望decode
了解decode
result
,请将其作为参数传递:
main