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持续亮灭