加热和开水解耦代码索引:

加热和开水解耦代码索引:

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"                  // Device header
#include "heat.h"
#include "out_water.h"


int main(void)
{
	//加热初始化
	HEAT_water_Init();
	//开水初始化
	OUT_water_Init();
	//加热
//	GPIO_SetBits(GPIOA, GPIO_Pin_6);	
	HEAT_water_Set(heat_water_ON);
	//开水龙头
//	GPIO_SetBits(GPIOA, GPIO_Pin_7);
	OUT_water_Set(out_water_ON);
	
	while(1)
	{
		
	}
}	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值