stm32水培检测(3完结)

JDQ.c、Key.c 

要求:
1、采集装置水温,联网上传到巴法云。
2、获取装置水位高度(AD采集),上传到巴法云。
3、采集环境光照(iic),上传到巴法云。
4、按键控制水泵开关(这里用继电器代替),按键1按下打开,按键2关闭。
5、水位高于某个值时,打开水泵(继电器),低于时不会自动关闭,需要按键来关闭。 

JDQ.c 

#include "stm32f10x.h"                  // Device header

void JDQ_Init(void)
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	
	GPIO_InitTypeDef GPIO_InitStruct;
	
	GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
	GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0;
	GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
	
	GPIO_Init(GPIOA,&GPIO_InitStruct);
	GPIO_ResetBits(GPIOA,GPIO_Pin_0);
}

void JDQ_OFF(void)
{
	GPIO_ResetBits(GPIOA,GPIO_Pin_0);
}

void JDQ_ON(void)
{
	GPIO_SetBits(GPIOA,GPIO_Pin_0);
}

 Key.c

#include "stm32f10x.h"                  // Device header
#include "delay.h"


GPIO_InitTypeDef GPIO_InitStructure;


void Key_Init(void)
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
	
	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
}

uint8_t Get_Key_1(void)
{
	uint8_t KeyNum = 0;
	if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_15) == 0)
	{
		Delay_ms(20);
		while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_15) == 0);
		Delay_ms(20);
		KeyNum = 1;
	}
	
	return KeyNum;
}
uint8_t Get_Key_2(void)
{
    uint8_t KeyNum = 0;
    if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_14) == 0)
	{
		Delay_ms(20);
		while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_14) == 0);
		Delay_ms(20);
		KeyNum = 2;
	}
    return KeyNum;
}

uint8_t Get_Key_3(void)
{
    uint8_t KeyNum = 0;
    if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == 0)
	{
		Delay_ms(20);
		while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == 0);
		Delay_ms(20);
		KeyNum = 3;
	}
    return KeyNum;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值