当前位置:网站首页>STM32 lighting procedure
STM32 lighting procedure
2022-07-25 23:59:00 【lintax】
STM32- Lighting procedure
Recently learned to use STM32, Make a note .
Rigid contact , Let's start with the lighting procedure . MCU lighting program , It's equivalent to learning language hello world Procedure .
First, let's briefly introduce the development environment , The chip type is STM32F030C8, The integrated development environment uses Keil5 MDK-ARM, Simulator use JLINK.
Light the light , First determine the pin connecting the lamp . On my board is PA0 The next one led The lamp .
In the program , Namely GPIO_Pin_0 了 . For scalability , Or say , For the convenience of modifying pins , I used a function to encapsulate . as follows :
int get_gpios(){
return GPIO_Pin_0 ;// Connected to the lamp gpio Pin , There can be multiple
}
Light the light , That is, set this pin to output , And control its high and low levels . Let's set the initialization first :
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Can make GPIOA The clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* To configure LED Corresponding pins PA1*/
GPIO_InitStructure.GPIO_Pin = get_gpios();
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIOA->BSRR = get_gpios() ;// Lights up
}
The specific realization of flashing , I also wrote a function , Convenient to call later :
int flag_led_on=0;
void LED_toggle(){
flag_led_on = 1 - flag_led_on;
if(flag_led_on!=0){
GPIOA->BRR = get_gpios() ; //reset
} else {
GPIOA->BSRR = get_gpios() ; //set
}
}
such , The main function is completed , The rest is to call in the main loop .
The main function is very simple :
int main(void)
{
LED_Init();// Lamp initialization
while(1){
Delay(1600000);// Time delay 1s
LED_toggle(); //LED Flip
}
}
Here is a new function :Delay(), Is a delay function . To simplify the code , So the delay function does not use a timer , It's a simple cycle of waiting . as follows :
void Delay(uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
thus , This lighting procedure is completed , Is it simple .
in addition , Briefly explain why the delay function is used 1600000 Is the parameter .
I passed the experiment , It is found that the time set to this value is basically 1s.
however , On different boards , The program is optimized differently , Or the writing method of delay code is different , Will lead to the difference of delay time . The specific value can be adjusted according to the actual operation .
in the future , I will carefully analyze the reason of this value .
This demo Project code for , You can get it from the following address :
https://download.csdn.net/download/lintax/10734630
边栏推荐
- Exercise (2) create a set to store the elements "1", "$", "2", "$", "3", "$", "4"“
- 如何用yolov5 做个闯红灯监控的智能交通系统(1)
- 回溯——77. 组合
- 面试重点——传输层的TCP协议
- Pytorch学习记录(一):Pytorch 简介
- SIGIR‘22 推荐系统论文之图网络篇
- Prometheus 运维工具 Promtool (二) Query 功能
- 死信队列 和消息TTL过期代码
- Ratio of learning_ add,ratio_ subtract,ratio_ multiply,ratio_ Use of divide
- BGR and RGB convert each other
猜你喜欢

Loading process such as reflection

二叉树——257. 二叉树的所有路径

死信队列 和消息TTL过期代码

行为型模式之责任链模式

开放API生态系统面临的十个威胁

二叉树——111. 二叉树的最小深度

Payment terms in SAP message No. vg202 IDoc e1edk18 have been transferred: check data

What is the difference between'1 and'b1 when assigning values

redis-扩展数据类型(跳跃表/BitMaps/HyperLogLog/GeoSpatial)

什么是奇偶校验?如何用C语言实现?
随机推荐
Pytorch学习记录(一):Pytorch 简介
Lua script Wireshark plug-in to resolve third-party private protocols
Ratio of learning_ add,ratio_ subtract,ratio_ multiply,ratio_ Use of divide
[debug bug] JS: getFullYear is not a function
Data intensive application system design - Application System Overview
你还在用浏览器自带书签?这款书签插件超赞
注解@Autowired源码解析
How does JS judge whether the current date is within a certain range
二叉树——530.二叉搜索树的最小绝对差
二叉树——257. 二叉树的所有路径
2022-07-18 study notes of group 5 self-cultivation class (every day)
Leetcode 0919. complete binary tree inserter: array representation of complete binary tree
[learning notes] solid works operation record
Are you still using your browser's own bookmarks? This bookmark plugin is awesome
[learning notes] unreal 4 engine introduction (IV)
Write a select drop-down list
[day.2] Joseph Ring problem, how to use arrays to replace circular linked lists (detailed explanation)
指针函数的demo
Topsis与熵权法
二叉树——654. 最大二叉树