加热和开水解耦代码索引:
heat.c
heat.c
#include "heat.h"
HEAT_water_INFO heat_water_info = {0};
void HEAT_water_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA, GPIO_Pin_6);
}
void HEAT_water_Set(_Bool status)
{
if(status == heat_water_ON && heat_water_info.Status != heat_water_ON)
{
GPIO_SetBits(GPIOA, GPIO_Pin_6);
heat_water_info.Status = heat_water_ON;
}
else if(status == heat_water_OFF && heat_water_info.Status != heat_water_OFF)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_6);
heat_water_info.Status = heat_water_OFF;
}
}
heat.h
#ifndef _HEAT_H_
#define _HEAT_H_
#define heat_water_ON 1
#define heat_water_OFF 0
#include "stm32f10x.h"
typedef struct
{
_Bool Status;
} HEAT_water_INFO;
extern HEAT_water_INFO heat_water_info;
void HEAT_water_Init(void);
void HEAT_water_Set(_Bool status);
#endif
out_water.c
#include "out_water.h"
OUT_water_INFO out_water_info = {0};
void OUT_water_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA, GPIO_Pin_7);
}
void OUT_water_Set(_Bool status)
{
if(status == out_water_ON && out_water_info.Status != out_water_ON)
{
GPIO_SetBits(GPIOA, GPIO_Pin_7);
out_water_info.Status = out_water_ON;
}
else
if(status == out_water_OFF && out_water_info.Status != out_water_OFF)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_7);
out_water_info.Status = out_water_OFF;
}
}
out_water.h
#ifndef _OUT_WATER_H_
#define _OUT_WATER_H_
#define out_water_ON 1
#define out_water_OFF 0
#include "stm32f10x.h"
typedef struct
{
_Bool Status;
} OUT_water_INFO;
extern OUT_water_INFO out_water_info;
void OUT_water_Init(void);
void OUT_water_Set(_Bool status);
#endif
main.c
#include "stm32f10x.h"
#include "heat.h"
#include "out_water.h"
int main(void)
{
HEAT_water_Init();
OUT_water_Init();
HEAT_water_Set(heat_water_ON);
OUT_water_Set(out_water_ON);
while(1)
{
}
}