当前位置:网站首页>STM32 learning record: LED light flashes (register version)
STM32 learning record: LED light flashes (register version)
2022-07-06 15:41:00 【Bitter tea seeds】
List of articles
STM32F103ZE: Punctual atomic elite board , Use register to light up LED
List of articles
- List of articles
- Preface
- One 、 Refer to the development manual
- 1. Open the schematic diagram of punctual atomic elite board , seek LED The pin of
- 2. open STM32 Chinese Reference Manual , Conduct data inquiry
- 3. Then take a look at RCC Register peripheral APB2 Clock enable register
- 4. View register image , Looking for an address
- 5. Check the port output data register
- 6. Check the port configuration low register
- Two 、 Development steps
Preface
The main thing is to be able to use STM3210X The development manual for , Will check the schematic diagram of the board , Understand the concept of bus , Can find registers .
Simply calling the library is not enough , Because it's all encapsulated by others , Want to be an excellent engineer , Must be able to program at the bottom .
One 、 Refer to the development manual
1. Open the schematic diagram of punctual atomic elite board , seek LED The pin of

You can see ,LED0 and LED1 Respectively in GPIOB5 and GPIOE5 On the pin .
2. open STM32 Chinese Reference Manual , Conduct data inquiry
Have a look first STM32 The system structure of 
You can find RCC To control the clock , And GPIOB and GPIOE All by APB2 control
3. Then take a look at RCC Register peripheral APB2 Clock enable register
to glance at APB2 Address offset of 
Check it out. GPIOB and GPIOE Bit 
You can see ,GPIOB It's No 3 position ,GPIOE It's No 6 position ;
4. View register image , Looking for an address

5. Check the port output data register

6. Check the port configuration low register

All right. ! That's all for checking the information , It's not hard , Just know how to find registers .
Two 、 Development steps
1. Lighten up LED
The code is as follows ( Shown ):
RCC Clock address 
#include "stm32f10x.h"
int main(void)
{
*(unsigned int *)0x40021018 |=(1<<3);//RCC The address is 0x40021000,APB2 The offset is 18, therefore , open GPIOB Enable clock . towards ←3 position .
*(unsigned int *)0X40010C00 |=((1)<<(4*5));//‘|=’ Set up 1; Configure low level ,*5 Because in 5 On port
*(unsigned int *)0X40010C0C &=~(1<<5);//‘&=~’ Zero clearing ; Configure port data output
*(unsigned int *)0x40021018 |=(1<<6);// open GPIOE Enable clock . towards ←6 position .
*(unsigned int *)0x40011800 |=((1)<<(4*5));
*(unsigned int *)0x4001180C &=~(1<<5);
}
Verified , Success will punctual the atomic elite board LED0、LED1 The light is on
2. Give Way LED Light flashing
LED.h
The code is as follows ( Shown ):
#ifndef __led_H
#define __led_H
void LED_Init(void);
#endif
LED.c
The code is as follows ( Shown ):
#include "stm32f10x.h"
#include "led.h"
void LED_Init(void)
{
RCC->APB2ENR|=1<<3;//-> Structure pointer ; Can make B
RCC->APB2ENR|=1<<6;//-> Structure pointer ; Can make 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
The code is as follows ( Shown ):
#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);
}
}
边栏推荐
- 差分(一维,二维,三维) 蓝桥杯三体攻击
- ArrayList set
- LeetCode#268. Missing numbers
- FSM and I2C experiment report
- How to build a nail robot that can automatically reply
- ucore Lab 1 系统软件启动过程
- Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
- cs零基础入门学习记录
- TCP的三次握手与四次挥手
- Market trend report, technological innovation and market forecast of pneumonia drugs obtained by Chinese hospitals
猜你喜欢

Learning record: use stm32f1 watchdog

Leetcode notes - dynamic planning -day6

Learning records: serial communication and solutions to errors encountered

STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)

51 lines of code, self-made TX to MySQL software!

学习记录:如何进行PWM 输出

LeetCode#62. Different paths

MATLAB实例:阶跃函数的两种表达方式
![[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)](/img/3a/aadde60352c42199ba287a6997acfa.jpg)
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)

C语言数组的概念
随机推荐
学习记录:理解 SysTick系统定时器,编写延时函数
Research Report on market supply and demand and strategy of China's land incineration plant industry
Matlab example: two expressions of step function
C语言数组的概念
C 基本语法
C语言是低级和高级的分水岭
ucorelab4
Learning record: how to perform PWM output
What are the software testing methods? Show you something different
数据在内存中的存储&载入内存,让程序运行起来
UCORE Lab 1 system software startup process
ucorelab3
LeetCode#2062. Count vowel substrings in strings
差分(一维,二维,三维) 蓝桥杯三体攻击
STM32学习记录:输入捕获应用
FSM and I2C experiment report
ucore lab7
JS --- BOM details of JS (V)
Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
Research Report of pharmaceutical solvent industry - market status analysis and development prospect prediction