野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12483|回复: 3

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

[复制链接]
发表于 2017-7-17 16:46:51 | 显示全部楼层 |阅读模式


我这个亲自自己试过了没有报错,而且灯还是亮的
作业题目:实现 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)






回复

使用道具 举报

 楼主| 发表于 2017-7-17 16:53:06 | 显示全部楼层
看了下一集视频,结果发现这个马上就有了。呃呃呃额额
回复 支持 反对

使用道具 举报

发表于 2017-7-18 08:57:16 | 显示全部楼层
撸起袖子加油干
回复 支持 反对

使用道具 举报

发表于 2022-3-15 22:53:52 | 显示全部楼层
我用的霸道,跟着书上得代码敲,结果代码缺斤少两,大家都是看视频的吗
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-28 23:30 , Processed in 0.059321 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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