中文字符在Keil中导致的错误问题(错误代码:#7 #12-D #20 #223-D #247)

本文记录了STM32串口程序在Keil编译过程中遇到的27个错误和13个警告,并详细展示了错误信息。通过分析发现错误主要集中在main.c文件中,包括语法错误和未定义标识符等问题。文章还提供了网友提出的解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在写完串口chen程序bian编译时发现报错  27 Error(s), 13 Warning(s),主要错误还在main.c中,通过百度发现主要是 #7错误,错误提示如下:

 

*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Rebuild target 'Demo'
assembling startup_stm32f10x_hd.s...
compiling core_cm3.c...
compiling misc.c...
compiling stm32f10x_bkp.c...
compiling system_stm32f10x.c...
compiling stm32f10x_cec.c...
compiling stm32f10x_adc.c...
compiling stm32f10x_can.c...
compiling stm32f10x_crc.c...
compiling stm32f10x_dma.c...
compiling stm32f10x_dbgmcu.c...
compiling stm32f10x_dac.c...
compiling stm32f10x_flash.c...
compiling stm32f10x_exti.c...
compiling stm32f10x_fsmc.c...
compiling stm32f10x_gpio.c...
compiling stm32f10x_pwr.c...
compiling stm32f10x_iwdg.c...
compiling stm32f10x_rtc.c...
compiling stm32f10x_i2c.c...
compiling stm32f10x_rcc.c...
compiling stm32f10x_sdio.c...
compiling stm32f10x_spi.c...
compiling stm32f10x_wwdg.c...
compiling main.c...
..\..\User\usart\bsp_usart1.h(11): error:  #7: unrecognized token
  void Usart_SendByte( USART_TypeDef *pUSARTx, uint8_t ch);
..\..\User\usart\bsp_usart1.h(11): error:  #130: expected a "{"
  void Usart_SendByte( USART_TypeDef *pUSARTx, uint8_t ch);
..\..\User\usart\bsp_usart1.h(12): error:  #7: unrecognized token
  void Usart_SendString( USART_TypeDef *pUSARTx, char *str);
..\..\User\main.c(50): warning:  #12-D: parsing restarts here after previous syntax error
  { 
..\..\User\main.c(52): error:  #20: identifier "b" is undefined
      for(c=0;c<b;c++)
..\..\User\main.c(59): warning:  #223-D: function "SPI_SPI2_Config" declared implicitly
    SPI_SPI2_Config();
..\..\User\main.c(60): warning:  #223-D: function "MS_Config" declared implicitly
      MS_Config();
..\..\User\main.c(61): warning:  #223-D: function "EXTI_IO_Config" declared implicitly
      EXTI_IO_Config();
..\..\User\main.c(62): warning:  #223-D: function "TIM2_Configuration" declared implicitly
      TIM2_Configuration();
..\..\User\main.c(88): error:  #20: identifier "INCTCD_num" is undefined
      INCTCD_num = 0x0140;
..\..\User\main.c(89): error:  #20: identifier "PSUMCD_num" is undefined
      PSUMCD_num = 19125/INCTCD_num;  //INCTAB_num * PSUMAB_num;              //17ms PSUMCD_num的值由 INCTCD_num决定
..\..\User\main.c(91): error:  #20: identifier "INCTAB_num" is undefined
      INCTAB_num = 0x4AB5;
..\..\User\main.c(92): error:  #20: identifier "PSUMAB_num" is undefined
    PSUMAB_num = 19125/INCTAB_num;  //INCTAB_num * PSUMAB_num;              //17ms    PSUMCD_num的值由 INCTCD_num决定
..\..\User\main.c(94): warning:  #223-D: function "Spi_Write" declared implicitly
   Spi_Write(0x24,0x0d00 | PSUMAB_num);     //0x0dff    
..\..\User\main.c(115): error:  #20: identifier "flag1" is undefined
          if(flag1==0)  // 
..\..\User\main.c(118): error:  #20: identifier "INCTAB_num" is undefined
             INCTAB_num = INCTAB_num - 50;   //加速  只需要把改值按照 速度曲线变化就可以改变速度,现在演示的是线性的速度变化
..\..\User\main.c(124): error:  #20: identifier "PSUMAB_num" is undefined
             PSUMAB_num = 19125/INCTAB_num;
..\..\User\main.c(125): warning:  #223-D: function "Spi_Write" declared implicitly
             Spi_Write(0x24,0x0d00 | PSUMAB_num);     //0x0dff    
..\..\User\main.c(129): error:  #20: identifier "INCTCD_num" is undefined
                   INCTCD_num = INCTCD_num+ 30;
..\..\User\main.c(134): error:  #20: identifier "PSUMCD_num" is undefined
                   PSUMCD_num = 19125/INCTCD_num;
..\..\User\main.c(156): error:  #20: identifier "INCTAB_num" is undefined
             INCTAB_num = INCTAB_num + 30;    //减速
..\..\User\main.c(162): error:  #20: identifier "PSUMAB_num" is undefined
             PSUMAB_num = 19125/INCTAB_num;
..\..\User\main.c(163): warning:  #223-D: function "Spi_Write" declared implicitly
             Spi_Write(0x24,0x0d00 | PSUMAB_num);     //0x0dff    
..\..\User\main.c(167): error:  #20: identifier "INCTCD_num" is undefined
                   INCTCD_num  = INCTCD_num - 50;
..\..\User\main.c(172): error:  #20: identifier "PSUMCD_num" is undefined
                   PSUMCD_num = 19125/INCTCD_num;
..\..\User\main.c(205): warning:  #223-D: function "Delay" declared implicitly
          Delay(60);
..\..\User\main.c(209): error:  #20: identifier "flag1" is undefined
          flag1 = !flag1;
..\..\User\main.c(216): warning:  #223-D: function "Delay" declared implicitly
          Delay(60);
..\..\User\main.c(220): warning:  #223-D: function "MS_Rest" declared implicitly
               MS_Rest();
..\..\User\main.c(221): warning:  #223-D: function "MS_Int1" declared implicitly
               MS_Int1();
..\..\User\main.c(224): error:  #20: identifier "INCTCD_num" is undefined
              INCTCD_num = 0x0120;
..\..\User\main.c(225): error:  #20: identifier "PSUMCD_num" is undefined
              PSUMCD_num = 19125/INCTCD_num;  //INCTAB_num * PSUMAB_num;              //5ms
..\..\User\main.c(227): error:  #20: identifier "INCTAB_num" is undefined
              INCTAB_num = 0x4AB5;
..\..\User\main.c(228): error:  #20: identifier "PSUMAB_num" is undefined
              PSUMAB_num = 19125/INCTAB_num;  //INCTAB_num * PSUMAB_num;              //5ms    
..\..\User\main.c: 12 warnings, 22 errors
compiling stm32f10x_usart.c...
compiling bsp_usart1.c...
..\..\User\usart\bsp_usart1.h(11): error:  #7: unrecognized token
  void Usart_SendByte( USART_TypeDef *pUSARTx, uint8_t ch);
..\..\User\usart\bsp_usart1.h(11): error:  #130: expected a "{"
  void Usart_SendByte( USART_TypeDef *pUSARTx, uint8_t ch);
..\..\User\usart\bsp_usart1.h(12): error:  #7: unrecognized token
  void Usart_SendString( USART_TypeDef *pUSARTx, char *str);
..\..\User\usart\bsp_usart1.c(28): warning:  #12-D: parsing restarts here after previous syntax error
  {
..\..\User\usart\bsp_usart1.c(89): error:  #20: identifier "SendBuff" is undefined
          DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SendBuff;
..\..\User\usart\bsp_usart1.c(128): error:  #247: function "Usart_SendByte"  has already been defined
          void Usart_SendByte( USART_TypeDef *pUSARTx, uint8_t ch)
..\..\User\usart\bsp_usart1.c: 1 warning, 5 errors
compiling stm32f10x_it.c...
compiling stm32f10x_tim.c...
compiling bsp_SPI.c...
compiling bsp_41908.c...
compiling bsp_exti.c...
compiling bsp_TiMbase.c...
"..\..\Output\Template.axf" - 27 Error(s), 13 Warning(s).
Target not created.
Build Time Elapsed:  00:00:03

 

 

 

 

引用网友解决办法:

..\main.c(173): error:  #7: unrecognized token

这个错误可能是拷贝的时候,中间有中文,或者其他不能识别的,看不见的字符。keil 编译的时候就会出错。

解决:找到那一行,删除那些不可见的字符即可。

<think>根据用户的问题描述,当前项目是一个基于STM32F407ZGT6的音乐播放器,使用VS1053解码,SD卡存储音乐文件,LCD显示,蜂鸣器提示,以及使用4位AD模拟键盘模块(四个按键)进行控制。用户遇到了编译错误,提示多个函数未定义。同时,用户还提到在adc_key.h中出现了“unrecognized token”编译错误。 我们将分为两部分解决: 1. 解决adc_key.h中的“unrecognized token”错误(可能是语法错误,比如缺少分号、括号不匹配等,需要检查该头文件) 2. 实现所有未定义的函数(根据之前提供的函数框架,结合STM32标准外设库进行编写) 由于用户使用的是STM32F4系列,且固件库为en.stsw-stm32065_v1-9-0(即STM32F4xx_DSP_StdPeriph_Lib_V1.9.0),我们将使用该库进行开发。 步骤: 1. 首先检查adc_key.h文件,修复可能的语法错误(用户未提供具体内容,我们只能给出常见错误的修复建议)。 2. 编写缺失的函数:LCD_Init, VS1053_Init, VS1053_Play_Process, GetSysTick, Play_Next, Play_Prev, VS1053_VolumeDown, LCD_DrawNumber, LCD_DrawString。 注意:由于硬件连接可能不同,以下代码基于常见的连接方式,请根据实际电路调整。 一、修复adc_key.h中的“unrecognized token”错误 常见原因: - 缺少分号(特别是在结构体或枚举定义后) - 宏定义错误(例如,多行宏定义没有使用反斜杠\) - 使用了中文字符(如全角字符) - 头文件重复包含或条件编译错误 建议检查adc_key.h,确保没有明显的语法错误。例如: ```c #ifndef __ADC_KEY_H #define __ADC_KEY_H #include "stm32f4xx.h" // 定义按键对应的ADC值范围 #define KEY1_MIN 0 #define KEY1_MAX 1000 // ... 其他按键范围 // 函数声明 void ADC_KEY_Init(void); uint8_t Get_ADKey(void); #endif /* __ADC_KEY_H */ ``` 二、编写缺失的函数 1. LCD_Init函数:初始化LCD(假设使用FSMC接口驱动ILI9341) 2. VS1053_Init函数:初始化VS1053(包括GPIO、SPI、复位等) 3. VS1053_Play_Process函数:播放过程(从文件读取数据并发送到VS1053) 4. GetSysTick函数:获取系统滴答定时器的当前值(用于按键消抖等) 5. Play_Next和Play_Prev函数:切换歌曲 6. VS1053_VolumeDown函数:音量减小(注意:VS1053的音量寄存器是反向的,0为最大音量,0xFFFF为最小音量) 7. LCD_DrawNumber和LCD_DrawString:在LCD上显示数字和字符串 由于代码较长,我们分模块编写: 注意:以下代码需要根据实际硬件连接进行调整。 首先,确保已经包含必要的头文件,并配置好系统时钟(特别是FSMC、SPI、ADC的时钟)。 1. LCD初始化(基于FSMC): 假设使用FSMC Bank1,NOR/SRAM Bank1(即NE1),地址范围为0x60000000。 由于LCD初始化序列较长,这里仅给出框架,具体初始化命令序列请参考ILI9341数据手册。 2. VS1053初始化: 硬件连接假设: - RST: PB6 - DREQ: PB5(输入) - XCS: PB7(片选,低电平有效) - XDCS: PB8(数据片选,低电平有效) - SPI: SPI2 (PB13=SCK, PB14=MISO, PB15=MOSI) 3. 播放处理函数:从文件读取数据并发送到VS1053,注意等待DREQ信号。 4. 系统滴答定时器:我们使用SysTick作为系统时钟,GetSysTick函数返回当前SysTick计数器的值。 5. 歌曲切换:需要维护当前曲目索引和曲目列表,这里假设已经定义好相关变量。 6. 音量控制:VS1053的音量寄存器(SPI_VOL)是16位寄存器,高8位左声道,低8位右声道,值越大音量越小。 7. LCD显示函数:需要实现字符和字符串显示,这里假设已经实现了LCD_DrawChar函数。 由于代码量较大,以下只给出关键部分: 注意:以下代码中,VS1053的SPI读写函数(VS1053_WriteReg, VS1053_ReadReg, VS1053_SelectData, VS1053_Deselect等)需要自行实现。 开始编写代码:</think>### 基于STM32F407ZGT6的音乐播放器系统实现 #### 1. 解决adc_key.h编译错误 "unrecognized token"错误通常由语法问题引起,以下是修复后的AD按键模块头文件: ```c // adc_key.h #ifndef __ADC_KEY_H #define __ADC_KEY_H #include "stm32f4xx.h" // 按键值定义 typedef enum { KEY_NONE = 0, KEY_PLAY_PAUSE, KEY_VOL_UP_PREV, KEY_VOL_DOWN_NEXT, KEY_MENU_BACK } KeyStatus; // 函数声明 void ADC_KEY_Init(void); KeyStatus Get_ADKey(void); #endif /* __ADC_KEY_H */ ``` #### 2. LCD显示模块初始化 (`LCD_Init`) ```c // lcd.c void LCD_Init(void) { // 初始化GPIO和FSMC RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE); RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; // 配置数据线 PD0-PD15, PE0-PE15 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); // 配置控制线: NOE->PD4, NWE->PD5, NE1->PD7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; GPIO_Init(GPIOD, &GPIO_InitStructure); // FSMC配置 FSMC_NORSRAMInitTypeDef FSMC_InitStructure; FSMC_NORSRAMTimingInitTypeDef Timing; Timing.FSMC_AddressSetupTime = 3; Timing.FSMC_AddressHoldTime = 0; Timing.FSMC_DataSetupTime = 6; Timing.FSMC_BusTurnAroundDuration = 0; Timing.FSMC_CLKDivision = 0; Timing.FSMC_DataLatency = 0; Timing.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_InitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_InitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_InitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; FSMC_InitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_InitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_InitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_InitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_InitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_InitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_InitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_InitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_InitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_InitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_InitStructure.FSMC_ReadWriteTimingStruct = &Timing; FSMC_InitStructure.FSMC_WriteTimingStruct = &Timing; FSMC_NORSRAMInit(&FSMC_InitStructure); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); // ILI9341初始化序列 LCD_WriteCmd(0xCF); LCD_WriteData(0x00); LCD_WriteData(0xC1); LCD_WriteData(0x30); // ... 完整初始化序列 LCD_Clear(WHITE); } ``` #### 3. VS1053音频解码芯片初始化 (`VS1053_Init`) ```c // vs1053.c void VS1053_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; // 初始化控制引脚 (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值