当前位置:网站首页>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
边栏推荐
- Key features and application trends of next generation terminal security management
- Iterator pattern of behavioral pattern
- How to use yolov5 as an intelligent transportation system for red light running monitoring (1)
- The expression of flag=false if (flag) {return} timer=null if (timer) {return} in the throttle valve has been unclear
- 你还在用浏览器自带书签?这款书签插件超赞
- arcgis根据矢量范围裁取tif影像(栅格数据)、批量合并shp文件、根据矢量范围裁取区域内的矢量,输出地理坐标系、转换16位TIF影像的像素深度至8位、shp文件创建和矢量框标绘设置
- ShardingSphere数据分片
- 注解@Autowired源码解析
- 调用钉钉api报错:机器人发送签名过期;solution:签名生成时间和发送时间请保持在 timestampms 以内
- 栈与队列——150. 逆波兰表达式求值
猜你喜欢

Loading process such as reflection

抽丝剥茧C语言(高阶)程序环境和预处理

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

二叉树——101. 对称二叉树

BOM 浏览器对象模型

二叉树——404. 左叶子之和

二叉树——226. 翻转二叉树

GUI interface of yolov3 (2) -- beautify the page + output the name and quantity of the identified object

The process of finding free screen recording software - I didn't expect win10 to come with this function

C - readonly and const keywords
随机推荐
二叉树——654. 最大二叉树
GUI interface of yolov3 (2) -- beautify the page + output the name and quantity of the identified object
[learning notes] unreal 4 engine introduction (III)
Problem set
Taobao flexible.js file realizes flexible layout
After entering www.baidu.com in the address bar
Kubernetes网络插件详解 - Calico篇 - 概述
程序环境和预处理
The mobile version of Duoyu security browser will add new functions to make users browse more personalized
如何用yolov5 做个闯红灯监控的智能交通系统(1)
开放API生态系统面临的十个威胁
Redis basic data type (string/list/set/hash/zset)
How to solve cross domain problems
Ratio of learning_ add,ratio_ subtract,ratio_ multiply,ratio_ Use of divide
The GUI interface of yolov3 (3) -- solve the out of memory problem and add camera detection function
Promise resolve callback hell, async await modifier
指针函数的demo
调用钉钉api报错:机器人发送签名过期;solution:签名生成时间和发送时间请保持在 timestampms 以内
Annotation @autowired source code analysis
What is multithreading