打印

实现 RCC 这个外设的 寄存器结构体声明,把时钟相关的代码改成寄存器结...

[复制链接]
228|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
河童|  楼主 | 2019-10-30 17:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我这个亲自自己试过了没有报错,而且灯还是亮的
作业题目:实现 RCC 这个外设的 寄存器结构体声明,把时钟相关的代码改成寄存器结构体操作的方式
这是主函数文件:
#include "stm32f10x.h"

int main (void)
{
        // 打开 GPIOB 端口的时钟
        RCC->APB2ENR  |=  ( (1) << 3 );        
        
        // 配置IO口为输出
        GPIOB->CRL &=  ~( (0x0f) << (4*0) );
        GPIOB->CRL |=  ( (1) << (4*0) );
        
        // 控制 ODR 寄存器
        GPIOB->ODR &= ~(1<<0);
        //GPIOB->ODR |= (1<<0);
}

void SystemInit(void)
{
        // 函数体为空,目的是为了骗过编译器不报错
}

这是头文件:

// 用来存放STM32寄存器映射的代码

// 外设  perirhral

#define  PERIPH_BASE               ((unsigned int)0x40000000)
#define  APB1PERIPH_BASE           PERIPH_BASE
#define  APB2PERIPH_BASE          (PERIPH_BASE + 0x10000)
#define  AHBPERIPH_BASE           (PERIPH_BASE + 0x20000)                //0x4002 0000
#define  RCC_BASE                (AHBPERIPH_BASE + 0x1000)                //0x4002 1000
#define  GPIOB_BASE              (APB2PERIPH_BASE + 0x0C00)
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)

typedef struct
{
        uint32_t CR;
        uint32_t CFGR;
        uint32_t CIR;
        uint32_t APB2RSTR;
        uint32_t APB1RSTR;
        uint32_t AHBENR;
        uint32_t APB2ENR;
        uint32_t APB1ENR;
        uint32_t BDCR;
        uint32_t CSR;
}RCC_TypeDef;

#define RCC   ((RCC_TypeDef*)RCC_BASE)

使用特权

评论回复

相关帖子

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

本版积分规则

452

主题

452

帖子

0

粉丝