本文主要是介绍蓝桥杯物联网_STM32L071_2_继电器控制,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
CubeMX配置:
Function.c及Function.h:
#include "Function.h"
#include "gpio.h"
void Function_LD5_ON(void){HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_RESET);
}void Function_LD5_OFF(void){HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_SET);
}void Function_LD5_Toggle(void){HAL_GPIO_TogglePin(LD5_GPIO_Port, LD5_Pin);
}void Function_K1_ON(void){HAL_GPIO_WritePin(K1_GPIO_Port, K1_Pin, GPIO_PIN_RESET);
}void Function_K1_OFF(void){HAL_GPIO_WritePin(K1_GPIO_Port, K1_Pin, GPIO_PIN_SET);
}void Function_K1_Toggle(void){HAL_GPIO_TogglePin(K1_GPIO_Port, K1_Pin);
}void Function_K2_ON(void){HAL_GPIO_WritePin(K2_GPIO_Port, K2_Pin, GPIO_PIN_RESET);
}void Function_K2_OFF(void){HAL_GPIO_WritePin(K2_GPIO_Port, K2_Pin, GPIO_PIN_SET);
}void Function_K2_Toggle(void){HAL_GPIO_TogglePin(K2_GPIO_Port, K2_Pin);
}
#ifndef __FUNCTION__
#define __FUNCTION__
void Function_LD5_ON(void);void Function_LD5_OFF(void);void Function_LD5_Toggle(void);void Function_K1_ON(void);void Function_K1_OFF(void);void Function_K1_Toggle(void);void Function_K2_ON(void);void Function_K2_OFF(void);void Function_K2_Toggle(void);#endif
main函数:
while (1){Function_K1_Toggle();Function_LD5_Toggle();Function_K2_Toggle();HAL_Delay(300);}
效果:
K1-LED、K2-LED、LD5持续亮灭
这篇关于蓝桥杯物联网_STM32L071_2_继电器控制的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!