gpt4 book ai didi

c - 语法错误 - 标记 ";"插入到 "{"之前

转载 作者:行者123 更新时间:2023-11-30 15:39:51 25 4
gpt4 key购买 nike

我为 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
}
}
}

最佳答案

您在 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
}
}
}

祝你好运!

注意 - 它可能只是复制/粘贴,但当您使用正确的缩进时,确保您拥有正确数量的左括号/大括号会容易得多。每个左大括号后始终缩进至少 1 个(可能是 2-4 个空格)。这应该对将来有所帮助!

关于c - 语法错误 - 标记 ";"插入到 "{"之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21284825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com