打印

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

[复制链接]
252|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Spikess|  楼主 | 2020-4-24 16:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
程序编写完过后,没有报错。但是下载到开发版中,灯不亮。看了一下代码,基本和教程上的一样。但是开发板没反应。求助啊!!
找了好久的错,没找到。




#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)

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

417

主题

421

帖子

0

粉丝