1. 程式人生 > >中文字元在Keil中導致的錯誤問題(錯誤程式碼:#7 #12-D #20 #223-D #247)

中文字元在Keil中導致的錯誤問題(錯誤程式碼:#7 #12-D #20 #223-D #247)

在寫完串列埠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 編譯的時候就會出錯。

解決:找到那一行,刪除那些不可見的字元即可。