我为ADC写了一个函数来读取齿轮值。我经常遇到这个错误,但我不知道该怎么做..建议? 我的代码是:
void MAIN_vInit(void)
{
void read_bremspedal(); //This is my ADC read function prototype
PSW_IEN = 0;
/// -----------------------------------------------------------------------
/// Configuration of the System Clock:
/// -----------------------------------------------------------------------
/// - VCO clock used, input clock is connected
/// - input frequency is 8,00 MHz
MAIN_vUnlockProtecReg(); // unlock write security
MAIN_vChangeFreq(); // load PLL control register
// -----------------------------------------------------------------------
// SCU Interrupt Disable configuration:
// -----------------------------------------------------------------------
SCU_INTDIS = 0xFFFF; // SCU Interrupt Disable Register
// -----------------------------------------------------------------------
// Initialization of the Peripherals:
// -----------------------------------------------------------------------
// initializes the Parallel Ports
IO_vInit();
// initializes the Capture / Compare Unit 61 (CCU61)
CCU61_vInit();
// initializes the Analog / Digital Converter (ADC0)
ADC0_vInit();
// initializes the MultiCAN Module (CAN)
CAN_vInit();
// -----------------------------------------------------------------------
// Initialization of the Bank Select registers:
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// SCU Interrupt Source Selection configuration:
// -----------------------------------------------------------------------
SCU_ISSR = 0x0000; // SCU Interrupt Source Select Register
// USER CODE BEGIN (Init,3)
// USER CODE END
MAIN_vLockProtecReg(); // lock write security
// globally enable interrupts
PSW_IEN = 1;
}
while(1)
{
// USER CODE BEGIN (Main,13)
//Bremspedal
void read_bremspedal(){ //syntax error - token ";" inserted before "{"
ADC0_vStartSeq0ReqChNum(0,0,1,3);
uwbremsen = ADC0_uwGetResultData(RESULT_REG_1);
uwbremsen >>= 4;
if(uwbremsen) { // wenn gebremest!
CAN_MODATA4LL = uwbremsen;
CAN_vTransmit(4); //Rekuperation signal senden
IO_vSetPin(IO_P10_0); // Nicht Schalten signal
}
}
}
答案 0 :(得分:1)
在while循环中定义函数“void read_bremspedal(){”。此外,您正在尝试编写一个完全不在任何函数内部的while循环。反转代码行,它应该工作。以下至少应该编译:
void read_bremspedal(){
// USER CODE BEGIN (Main,13)
//Bremspedal
while(1) {
ADC0_vStartSeq0ReqChNum(0,0,1,3);
uwbremsen = ADC0_uwGetResultData(RESULT_REG_1);
uwbremsen >>= 4;
if(uwbremsen) { // wenn gebremest!
CAN_MODATA4LL = uwbremsen;
CAN_vTransmit(4); //Rekuperation signal senden
IO_vSetPin(IO_P10_0); // Nicht Schalten signal
}
}
}
祝你好运!
注意 - 它可能只是复制/粘贴,但是当你使用适当的缩进时,确保你有正确数量的打开和关闭parens / braces更容易。每个打开的花括号后,始终缩进至少1(可能是2-4个空格)。这对未来的某些人应该有所帮助!