当前位置:网站首页>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);
}
}
边栏推荐
- Cost accounting [22]
- 通俗地理解什么是编程语言
- Cost accounting [14]
- Research Report on medical anesthesia machine industry - market status analysis and development prospect prediction
- Learning record: use stm32f1 watchdog
- China's PCB connector market trend report, technological innovation and market forecast
- Research Report on market supply and demand and strategy of geosynthetics industry in China
- HDU - 6024 Building Shops(女生赛)
- LeetCode#237. Delete nodes in the linked list
- MATLAB实例:阶跃函数的两种表达方式
猜你喜欢
FSM和i2c实验报告
LeetCode#19. Delete the penultimate node of the linked list
C语言必背代码大全
程序员的你,有哪些炫技的代码写法?
JS --- all knowledge of JS objects and built-in objects (III)
Unpleasant error typeerror: cannot perform 'ROR_‘ with a dtyped [float64] array and scalar of type [bool]
Optimization method of path problem before dynamic planning
STM32学习记录:输入捕获应用
Eslint--- error: newline required at end of file but not found (EOL last) solution
TCP的三次握手与四次挥手
随机推荐
JS --- detailed explanation of JS DOM (IV)
Want to change jobs? Do you know the seven skills you need to master in the interview software test
Cost accounting [20]
Automated testing problems you must understand, boutique summary
Cost accounting [21]
0-1背包问题(一)
Cost accounting [23]
E. Breaking the Wall
Cost accounting [14]
Stm32 dossiers d'apprentissage: saisie des applications
Research Report on market supply and demand and strategy of China's land incineration plant industry
STM32學習記錄:輸入捕獲應用
STM32 learning record: play with keys to control buzzer and led
STM32 learning record: input capture application
China chart recorder market trend report, technology dynamic innovation and market forecast
Report on the market trend, technological innovation and market forecast of printing and decorative paper in China
Learning record: how to perform PWM output
China's earthwork equipment market trend report, technical dynamic innovation and market forecast
Eslint--- error: newline required at end of file but not found (EOL last) solution
China's earthwork tire market trend report, technical dynamic innovation and market forecast