野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8337|回复: 3

通过寄存器结构体指针来控制寄存器

[复制链接]
发表于 2018-11-7 21:00:04 | 显示全部楼层 |阅读模式
程序编写完过后,没有报错。但是下载到开发版中,灯不亮。看了一下代码,基本和教程上的一样。但是开发板没反应。求助啊!!
找了好久的错,没找到。




#include "stm32f10x.h"

int  main(void)
{
RCC_APB2ENR |= (1<<3);/*GPIO时钟*/
        GPIOB->CRL    &= ~ (0x0f<<(4*0));
        GPIOB->CRL |= ((1)<<(4*0));
        GPIOB->ODR &= ~(1<<0);
}
void SystemInit(void)
{
   
}



#define  PERIPH_BASE    ((unsigned int)0x40000000)
#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_ODR       *(unsigned int*)(GPIOB_BASE +0X0C)
#define  GPIOB_BSRR      *(unsigned int*)(GPIOB_BASE +0X10)
#define  GPIOB_BRR      *(unsigned int*)(GPIOB_BASE +0X14)
   

typedef  unsigned  int  uint32_t;
typedef  unsigned  short  uint16_t;

typedef  struct
{    uint32_t  CRL;
    uint32_t  CRH;
    uint32_t  IDR;
    uint32_t  ODR;
    uint32_t  BSRR;
    uint32_t  BRR;
    uint32_t  LCKR;
}  GPIO_TypeDef;

#define GPIOB  ((GPIO_TypeDef*)GPIOB_BASE)


回复

使用道具 举报

发表于 2018-11-8 08:40:20 | 显示全部楼层
你用的哪一款板子?


回复 支持 反对

使用道具 举报

发表于 2018-11-8 08:40:36 | 显示全部楼层
看看时钟有没有配对
回复 支持 反对

使用道具 举报

发表于 2018-11-8 08:42:12 | 显示全部楼层
把例程代码一行行复制过来代替,代替到能用为止,这样就能知道哪里有区别了
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-28 00:28 , Processed in 0.033713 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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