野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 25215|回复: 4

求助!新手照着火哥视频代码敲的,点不亮LED灯

[复制链接]
发表于 2021-7-12 20:43:19 | 显示全部楼层 |阅读模式
新手才开始学STM32,用的指南者,照着火哥构建库函数雏形敲的代码,结果LED灯不亮。但是用之前的寄存器映射的代码又可以点亮。是我代码哪里敲错了吗?还请各位大佬帮忙看看。谢谢啦!
#include "stm32f10x.h"                  // Device header
int main(void)
{
#if 0
        //打开GPIOB端口的时钟
        *(unsigned int *) 0x40021018 |= (1<<3);       
        //配置IO口为输出
        *(unsigned int *) 0x40010C00 &= ~((0x0F)<<(4*5));
        *(unsigned int *) 0x40010C00 |= ((1)<<(4*5));
        //控制ODR寄存器
        *(unsigned int *) 0x40010C0C &= ~(1<<0);
#elif 0
        //打开GPIOB端口的时钟
        RCC_APB2ENR |= (1<<3);       
        //配置IO口为输出
        GPIOB_CRL &= ~((0x0F)<<(4*1));//先将寄存器清零
        GPIOB_CRL |= ((1)<<(4*5));
        //控制ODR寄存器
        GPIOB_ODR &= ~(1<<0);
//        GPIOB_BSRR &= ~(1<<0);   后两句实现效果与第一句相同
//        GPIOB_BRR &= ~(1<<0);       

#elif 1
        //打开GPIOB端口的时钟
        RCC->APB2ENR |= (1<<3);       
        //配置IO口为输出
        GPIOB->CRL &= ~((0x0F)<<(4*1));//先将寄存器清零
        GPIOB->CRL |= ((1)<<(4*0));
        //控制ODR寄存器
        GPIOB->ODR &= ~(1<<0);       
#endif
        //置位:|=;清零:&=~
}
void SystemInit(void)
{
        //函数体为空,是为骗过编译器不报错
}



// 用来存储STM32寄存器映射的代码
// 外设  PERIPHERAL

#define PERIPHER_BASE                        (unsigned int)0x40000000
#define APB1_PERIPHER_BASE                PERIPHER_BASE       
#define APB2_PERIPHER_BASE                PERIPHER_BASE + 0x10000
#define AHB_PERIPHER_BASE                PERIPHER_BASE + 0x20000

#define RCC_BASE                                AHB_PERIPHER_BASE + 0x1000
#define GPIOB_BASE                                APB2_PERIPHER_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)

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)






野火论坛202107122040594991..png
回复

使用道具 举报

发表于 2021-7-14 20:28:25 | 显示全部楼层
兄弟你是不是对着抄错了??
野火论坛202107142028186773..png
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-7-15 10:19:46 | 显示全部楼层
Richar 发表于 2021-7-14 20:28
兄弟你是不是对着抄错了??

这里已经改过了,还是点不亮,我和火哥视频的代码比对了,一模一样还是点不亮
回复 支持 反对

使用道具 举报

发表于 2021-7-20 08:30:12 | 显示全部楼层
你改成什么样了?
回复 支持 反对

使用道具 举报

发表于 2021-7-21 11:12:27 | 显示全部楼层
计量看见了就

回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-24 08:37 , Processed in 0.028053 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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