当前位置:网站首页>STM32学习记录:LED灯闪烁(寄存器版)
STM32学习记录:LED灯闪烁(寄存器版)
2022-07-06 09:25:00 【Bitter tea seeds】
系列文章目录
STM32F103ZE:正点原子精英板,使用寄存器点亮LED
文章目录
前言
主要就是会使用STM3210X的开发手册,会查看板子的原理图,理解总线的概念,会找寄存器。
只是单纯的会调用库是不行的,因为那都是别人封装好的,想成为一名优秀的工程师,一定要会面对底层进行编程。
一、参考开发手册
1.打开正点原子精英板原理图,寻找LED的引脚

可以看到,LED0和LED1分别在GPIOB5和GPIOE5引脚上。
2.打开STM32中文参考手册,进行资料查询
先看看STM32的系统结构
可以发现RCC为控制时钟,且GPIOB和GPIOE都由APB2控制
3.接着看一下RCC寄存器外设APB2时钟使能寄存器
看一下APB2的地址偏置
查看一下GPIOB和GPIOE的位
可以看到,GPIOB是第3位,GPIOE是第6位;
4.查看寄存器映像,寻找地址

5.查看端口输出数据寄存器

6.查看端口配置低寄存器

好啦!查看资料就到这里了,没啥难的,就是会找寄存器就行了。
二、开发步骤
1.点亮LED
代码如下(所示):
RCC时钟地址
#include "stm32f10x.h"
int main(void)
{
*(unsigned int *)0x40021018 |=(1<<3);//RCC地址是0x40021000,APB2偏置是18,所以,打开GPIOB的使能时钟。向←3位.
*(unsigned int *)0X40010C00 |=((1)<<(4*5));//‘|=’ 置1;配置低电平,*5因为在5端口上
*(unsigned int *)0X40010C0C &=~(1<<5);//‘&=~’ 清零;配置端口数据输出
*(unsigned int *)0x40021018 |=(1<<6);//打开GPIOE的使能时钟。向←6位.
*(unsigned int *)0x40011800 |=((1)<<(4*5));
*(unsigned int *)0x4001180C &=~(1<<5);
}
已验证,成功将正点原子精英板LED0、LED1灯点亮
2.让LED灯闪烁
LED.h
代码如下(所示):
#ifndef __led_H
#define __led_H
void LED_Init(void);
#endif
LED.c
代码如下(所示):
#include "stm32f10x.h"
#include "led.h"
void LED_Init(void)
{
RCC->APB2ENR|=1<<3;//->结构体指针;使能B
RCC->APB2ENR|=1<<6;//->结构体指针;使能E
/*GPIOB5*/
GPIOB->CRL&=0xFF0FFFFF;
GPIOB->CRL|=0x00300000;
GPIOB->ODR|=1<<5;
/*GPIOE5*/
GPIOE->CRL&=0xFF0FFFFF;
GPIOE->CRL|=0x00300000;
GPIOE->ODR|=1<<5;
}
main.c
代码如下(所示):
#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
int main(void)
{
delay_init(72);
LED_Init();
while(1)
{
GPIOB->ODR|=1<<5;
delay_ms(500);
GPIOB->ODR=~(1<<5);
delay_ms(500);
GPIOE->ODR|=1<<5;
delay_ms(500);
// GPIOB->ODR=~(1<<5);
GPIOE->ODR=~(1<<5);
delay_ms(500);
}
}
边栏推荐
- ucore lab7 同步互斥 实验报告
- Scoring system based on 485 bus
- C4D quick start tutorial - creating models
- The maximum number of words in the sentence of leetcode simple question
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
- 学习记录:如何进行PWM 输出
- UCORE lab2 physical memory management experiment report
- 如何成为一个好的软件测试员?绝大多数人都不知道的秘密
- FSM和i2c实验报告
- Collection collection and map collection
猜你喜欢
软件测试需求分析之什么是“试纸测试”

Crawler series of learning while tapping (3): URL de duplication strategy and Implementation

Leetcode notes - dynamic planning -day7

The latest query tracks the express logistics and analyzes the method of delivery timeliness
软件测试行业的未来趋势及规划

The wechat red envelope cover designed by the object is free! 16888

学习记录:TIM—基本定时器

Your wechat nickname may be betraying you

Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years

Leetcode notes - dynamic planning -day6
随机推荐
软件测试有哪些常用的SQL语句?
软件测试方法有哪些?带你看点不一样的东西
LeetCode#198. raid homes and plunder houses
LeetCode#62. Different paths
ucorelab4
UCORE lab5 user process management experiment report
Should wildcard import be avoided- Should wildcard import be avoided?
The number of reversing twice in leetcode simple question
The most detailed postman interface test tutorial in the whole network. An article meets your needs
JS --- BOM details of JS (V)
Pedestrian re identification (Reid) - data set description market-1501
Investment operation steps
STM32學習記錄:輸入捕獲應用
JS --- JS function and scope (II)
51 lines of code, self-made TX to MySQL software!
Maximum nesting depth of parentheses in leetcode simple questions
MySQL transactions
学习记录:TIM—电容按键检测
Mysql的事务
What are the commonly used SQL statements in software testing?