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;
}