野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 27558|回复: 11

神级编译错误,实在是搞不清楚了main.c error: #18: expected a ")"

[复制链接]
发表于 2016-9-22 20:35:07 | 显示全部楼层 |阅读模式
  1. [code]
  2. #define PERIPH_BASE (unsigned int 0x40000000)

  3. #define AHBPERIPH_BASE (PERIPH_BASE+20000)
  4. #define APB2PERIPH_BASE (PERIPH_BASE+10000)
  5. #define APB1PERIPH_BASE PERIPH_BASE

  6. #define RCC_BASE (AHBPERIPH_BASE+1000)
  7. #define GPIOB_BASE (AHBPERIPH_BASE+0X00)

  8. #define RCC_APB2 *(unsigned int*)(RCC_BASE+0X18)
  9. #define GPIOB_CRL *(unsigned int*)(GPIOB_BASE+0X00)
  10. #define GPIOB_CRH *(unsigned int*)(GPIOB_BASE+0X04)
  11. #define GPIOB_BSRR *(unsigned int*)(GPIOB_BASE+0X10)

  12. #include "stm32f10x.h"
  13. int main(void)
  14. {
  15.         // 打开 GPIOB 端口的时钟
  16.         RCC_APB2  |=  ( (1) << 3 );
  17.        
  18.         // 配置IO口为输出
  19.         GPIOB_CRL &=  ~( (0x0f) << (4*0) );
  20.         GPIOB_CRL |=  ( (1) << (4*0) );
  21.        
  22.         // 控制 ODR 寄存器
  23.         GPIOB_BSRR |= (1<<16);
  24. }

  25. void SystemInit(void)
  26. {

  27. }

复制代码
[/code]
回复

使用道具 举报

发表于 2016-9-23 08:42:42 | 显示全部楼层
把编译提示的前后几行一行一行注释掉,再编译,找出具体是哪一行的问题,然后重新输入下
如果那一行有用到宏的话,把宏也重新写一遍

回复 支持 反对

使用道具 举报

发表于 2016-9-23 09:32:48 | 显示全部楼层
#define PERIPH_BASE (unsigned int 0x40000000)
这是何意?
回复 支持 反对

使用道具 举报

发表于 2016-9-23 09:36:17 | 显示全部楼层
Light_Gor 发表于 2016-9-23 09:32
#define PERIPH_BASE (unsigned int 0x40000000)
这是何意?

这不就是宏定义嘛
回复 支持 反对

使用道具 举报

发表于 2016-9-23 13:56:20 | 显示全部楼层
jack_zhou 发表于 2016-9-23 13:03
#define PERIPH_BASE (unsigned int *)0x40000000  这样才对

其实一开始应该是这样写才对:#define PERIPH_BASE (unsigned int)(0x40000000)
回复 支持 反对

使用道具 举报

发表于 2016-9-23 17:40:14 | 显示全部楼层
新手帮顶!!!谢谢火哥的教程带我入门
回复 支持 反对

使用道具 举报

发表于 2016-11-29 12:19:14 | 显示全部楼层
Light_Gor 发表于 2016-9-23 09:32
#define PERIPH_BASE (unsigned int 0x40000000)
这是何意?

强制转化类型
回复 支持 反对

使用道具 举报

发表于 2016-11-29 12:21:11 | 显示全部楼层
这段代码有问题吗?我写的也编译出了(main.c error: #18: expected a ")" )这个问题,还没解决
回复 支持 反对

使用道具 举报

发表于 2016-11-29 15:33:41 | 显示全部楼层

强制类型转换难道不需要括号?
b = unsigned int a;
这样写对吗?
回复 支持 反对

使用道具 举报

发表于 2016-11-29 16:48:36 | 显示全部楼层
fire 发表于 2016-9-23 13:56
其实一开始应该是这样写才对:#define PERIPH_BASE (unsigned int)(0x40000000)

#define        PERIPH_BASE                                                                                                                                (unsigned        int)(0x4000 0000)
#define        APB1PERIPH_BASE                                                                                        PERIPH_BASE       
#define        APB2PERIPH_BASE                                                                                        (PERIPH_BASE        +        0x10000)
#define        AHBPERIPH_BASE                                                                                                (PERIPH_BASE        +        0x20000)

#define        RCC_BASE                                                                                                                                                        (AHBPERIPH_BASE        +        0x1000)
#define        GPIOB_BASE                                                                                                                                 (APB2PERIPH_BASE        +        0x0C00)

#define        RCC_APB2ENR                                                                                                                *(unsigned        int*)(RCC_BASE        +        0x18)
       
#define        GPIOB_CRL                                                                                                                                        *(unsigned        int*)(GPIOB_BASE        +        0x00)
#define        GPIOB_CRH                                                                                                                                        *(unsigned        int*)(GPIOB_BASE        +        0x04)
#define        GPIOB_IDR                                                                                                                                                *(unsigned        int*)(GPIOB_BASE        +        0x08)
#define        GPIOB_ODR                                                                                                                                        *(unsigned        int*)(GPIOB_BASE        +        0x0C)
#define        GPIOB_BSRR                                                                                                                                *(unsigned        int*)(GPIOB_BASE        +        0x10)
#define        GPIOB_BRR                                                                                                                                        *(unsigned        int*)(GPIOB_BASE        +        0x14)
#define        GPIOB_LCKR                                                                                                                                *(unsigned        int*)(GPIOB_BASE        +        0x18)





#include        "stm32f10x.h"

int        main(void)
{

                        //&acute;ò&iquest;&ordf;GPIO&para;&Euml;&iquest;&Uacute;&micro;&Auml;&Ecirc;±&Ouml;&Oacute;
        RCC_APB2ENR                |=                        (                                (1)                        <<                3                        );
       
                //&Aring;&auml;&Ouml;&Atilde;IO&iquest;&Uacute;&Icirc;&ordf;&Ecirc;&auml;&sup3;&ouml;
        GPIOB_CRL                |=                (                                (1)                                <<                (4*0)                                );

                //&acute;ò&iquest;&ordf;ODR&frac14;&Auml;&acute;&aelig;&AElig;÷
        GPIOB_ODR                &=                                ~(1<<0);
       

}
                       
void        SystemInit(void)
{
       
}

我是看程序按照你的写法写的,但是报错mian\main.c(8): error:  #18: expected a ")"
          *(unsigned        int*)(
CC_BASE        +        0x18)|=                (1)                <<                0                        ;
mian\main.c(11): error:  #18: expected a ")"
          *(unsigned        int*)(
PIOB_BASE        +        0x00)                |=                                        (1)                                <<                0                                ;
mian\main.c(14): error:  #18: expected a ")"
          *(unsigned        int*)(
PIOB_BASE        +        0x0C)        &=                                ~(1<<0);
mian\main.c: 0 warnings, 3 errors
".\Objects\Light.axf" - 3 Error(s), 0 Warning(s).
回复 支持 反对

使用道具 举报

发表于 2020-8-21 17:38:43 | 显示全部楼层
阿猫与阿狗 发表于 2016-11-29 16:48
#define        PERIPH_BASE                                                                                                                                (unsigned        int)(0x4000 0000)
#define        APB1PERIPH_BASE                                                                                        P ...

(unsigned int)(0x4000 0000)这个里边不能有空格,去掉空格就编译通过了!
回复 支持 1 反对 0

使用道具 举报

发表于 2021-4-26 21:33:48 | 显示全部楼层
穿拖鞋的Lee 发表于 2020-8-21 17:38
**** 作者被禁止或删除 内容自动屏蔽 ****

我也出了这个问题,就是把空格去掉就好了,感谢!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-6-14 19:19 , Processed in 0.040726 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表