STM32F103 入门篇 8-寄存器点亮LED讲解

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

高电平低电平都可以输出在这里插入图片描述
在这里插入图片描述
只能输出低电平
在这里插入图片描述
VSS GND
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
配置工作模式:推挽 开漏 复用
控制GPIO:高低电平

立即数寻址方式主要用来给寄存器或存储单元赋值

stm32f10x.h

// 外设 peripheral
#define PERIPH_BASE 			  ((unsigned int )0x40000000)
#define APB1_PERIPH_BASE    PERIPH_BASE	 		
#define APB2_PERIPH_BASE    (PERIPH_BASE + 0x10000)
#define AHB_PERIPH_BASE 		(APB2_PERIPH_BASE + 0x10000)

#define RCC_BASE 						(AHB_PERIPH_BASE + 0x1000)
#define GPIOA_BASE					(APB2_PERIPH_BASE + 0x0800)

#define RCC_APB2ENR					*(unsigned int*)(RCC_BASE + 0x18)
#define GPIOA_CRL					*(unsigned int*)(GPIOA_BASE + 0x00)
#define GPIOA_CRH					*(unsigned int*)(GPIOA_BASE + 0x04)
#define GPIOA_ODR					*(unsigned int*)(GPIOA_BASE + 0x0C)

main.c

#include "stm32f10x.h"

int main(void)
{
#if 0	
	//打开GPIOA端口的时钟
	*(unsigned int *)0x40021018 |= ( (1) << 2); 
	//配置 IO口 为输出
	*(unsigned int *)0x40010804 &= ~( (0c0f) << (4*0) );	//先清零
	*(unsigned int *)0x40010804 |= ( (1) << (4*0) ); 
	//控制 ODR 寄存器
	*(unsigned int *)0x4001080C &= ~(1<<7);
#else
	
		//打开GPIOA端口的时钟
	RCC_APB2ENR |= ( (1) << 2); 
	//配置 IO口 为输出
	GPIOA_CRH	|= ( (1) << (4*0) ); 
	//控制 ODR 寄存器
	GPIOA_ODR &= ~(1<<7);
	
#endif
	
	
}
void SystemInit(void)
{
	// 函数体为空 目的是骗过编译器不报错
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值