当前位置:网站首页>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);
}
}
边栏推荐
- Accounting regulations and professional ethics [1]
- LeetCode#36. Effective Sudoku
- 通俗地理解什么是编程语言
- 动态规划前路径问题
- Es6--- two methods of capturing promise status as failed
- Research Report on market supply and demand and strategy of Chinese hospital cleaning chemicals industry
- Preface to the foundations of Hilbert geometry
- ArrayList集合
- Crawler series (9): item+pipeline data storage
- Cost accounting [16]
猜你喜欢

Learning record: use STM32 external input interrupt

Learning record: how to perform PWM output

入门C语言基础问答

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

Your wechat nickname may be betraying you

Learning record: STM32F103 clock system overview working principle

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

数据在内存中的存储&载入内存,让程序运行起来

洛谷P1102 A-B数对(二分,map,双指针)
Automated testing problems you must understand, boutique summary
随机推荐
China's PCB connector market trend report, technological innovation and market forecast
差分(一维,二维,三维) 蓝桥杯三体攻击
Want to change jobs? Do you know the seven skills you need to master in the interview software test
程序员的你,有哪些炫技的代码写法?
Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
How to become a good software tester? A secret that most people don't know
Research Report on market supply and demand and strategy of Chinese hospital cleaning chemicals industry
Cost accounting [18]
Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
C 基本语法
洛谷P1102 A-B数对(二分,map,双指针)
Cost accounting [22]
Accounting regulations and professional ethics [5]
HDU - 6024 Building Shops(女生赛)
Your wechat nickname may be betraying you
Research Report on pharmaceutical R & D outsourcing service industry - market status analysis and development prospect forecast
Jupyter installation and use tutorial
Eslint--- error: newline required at end of file but not found (EOL last) solution
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
UCORE Lab 1 system software startup process