|
@@ -14,8 +14,11 @@
|
|
#define HwInput3 PBin(6) //红外传感器输入
|
|
#define HwInput3 PBin(6) //红外传感器输入
|
|
#define HwInput4 PBin(5) //红外传感器输入
|
|
#define HwInput4 PBin(5) //红外传感器输入
|
|
|
|
|
|
|
|
+#define DY_Input PBin(14)
|
|
#define KEY1 PAin(0) // 手动取消报警按钮
|
|
#define KEY1 PAin(0) // 手动取消报警按钮
|
|
-
|
|
|
|
|
|
+char showbuff[16]={0};
|
|
|
|
+u8 warning_sta=0;//异常状态
|
|
|
|
+u8 warning_flag=0;//警告标志位
|
|
int temp_val=0;
|
|
int temp_val=0;
|
|
u16 get_cnt=0;
|
|
u16 get_cnt=0;
|
|
u16 ds_val=0;//滴速
|
|
u16 ds_val=0;//滴速
|
|
@@ -26,12 +29,12 @@ void KEY_Init(void)
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE); //使能端口时钟
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE); //使能端口时钟
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // 端口配置
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // 端口配置
|
|
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //上拉输入
|
|
|
|
|
|
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化
|
|
|
|
|
|
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_7|GPIO_Pin_6; // 端口配置
|
|
|
|
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //上拉输入
|
|
|
|
|
|
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_7|GPIO_Pin_6|GPIO_Pin_5|GPIO_Pin_14; // 端口配置
|
|
|
|
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化
|
|
}
|
|
}
|
|
@@ -45,17 +48,17 @@ void exti_Init(void)
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
// KEY_Init();//IO初始化
|
|
// KEY_Init();//IO初始化
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//配置外部中断时钟
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//配置外部中断时钟
|
|
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//使能GPIOA时钟
|
|
|
|
|
|
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//使能GPIOA时钟
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//
|
|
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成输入
|
|
|
|
|
|
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置成输入
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOA8
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOA8
|
|
//io口与中断线映射
|
|
//io口与中断线映射
|
|
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource9);//链接到中断线8 GPIO8只能映射到中断线4上面
|
|
|
|
- EXTI_InitStruct.EXTI_Line=EXTI_Line8;//确定中断线
|
|
|
|
|
|
+ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource9);//链接到中断线8 GPIO8只能映射到中断线4上面
|
|
|
|
+ EXTI_InitStruct.EXTI_Line=EXTI_Line9;//确定中断线
|
|
EXTI_InitStruct.EXTI_LineCmd=ENABLE;//使能
|
|
EXTI_InitStruct.EXTI_LineCmd=ENABLE;//使能
|
|
EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt;//中断模式
|
|
EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt;//中断模式
|
|
- EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Falling;//上降沿触发
|
|
|
|
|
|
+ EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Rising;//上降沿触发
|
|
EXTI_Init(&EXTI_InitStruct);//初始化
|
|
EXTI_Init(&EXTI_InitStruct);//初始化
|
|
|
|
|
|
NVIC_InitStruct.NVIC_IRQChannel=EXTI9_5_IRQn;
|
|
NVIC_InitStruct.NVIC_IRQChannel=EXTI9_5_IRQn;
|
|
@@ -75,9 +78,15 @@ void EXTI9_5_IRQHandler(void)
|
|
|
|
|
|
if(EXTI_GetITStatus(EXTI_Line9)!=RESET)
|
|
if(EXTI_GetITStatus(EXTI_Line9)!=RESET)
|
|
{
|
|
{
|
|
- count++;
|
|
|
|
|
|
+ delay_ms(2);
|
|
|
|
+ if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1)
|
|
|
|
+ {
|
|
|
|
+ count++;
|
|
|
|
+ // ds_val=count;//获取滴速
|
|
|
|
+ //OLED_ShowString(0,6,"324",16);
|
|
|
|
+ }
|
|
|
|
+ EXTI_ClearITPendingBit(EXTI_Line9);//清除中断 标志
|
|
}
|
|
}
|
|
- EXTI_ClearITPendingBit(EXTI_Line9);//清除中断 标志
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -122,25 +131,33 @@ void TIM2_IRQHandler()
|
|
if(st!=0)
|
|
if(st!=0)
|
|
{
|
|
{
|
|
TIM_ClearFlag(TIM2, TIM_IT_Update);
|
|
TIM_ClearFlag(TIM2, TIM_IT_Update);
|
|
- if(++pw>=100*60)//10s时间到
|
|
|
|
|
|
+ if(DY_Input==1)
|
|
|
|
+ {
|
|
|
|
+ if(++pw>=100*10)//10s时间到
|
|
{
|
|
{
|
|
- pw=0;
|
|
|
|
- ds_val=count;//获取滴速
|
|
|
|
- count=0;
|
|
|
|
|
|
+ pw=0;
|
|
|
|
+ ds_val=count*6;//获取滴速
|
|
|
|
+ count=0;
|
|
|
|
+ if(ds_val>70||ds_val<10)
|
|
|
|
+ {
|
|
|
|
+ warning_flag=1;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if(HwInput1==0)
|
|
|
|
|
|
+ }
|
|
|
|
+ if(HwInput1==1)
|
|
{
|
|
{
|
|
sy_val=100;
|
|
sy_val=100;
|
|
|
|
+
|
|
}
|
|
}
|
|
- else if(HwInput2==0)
|
|
|
|
|
|
+ else if(HwInput2==1)
|
|
{
|
|
{
|
|
sy_val=50;
|
|
sy_val=50;
|
|
}
|
|
}
|
|
- else if(HwInput3==0)
|
|
|
|
|
|
+ if(HwInput3==1)
|
|
{
|
|
{
|
|
sy_val=10;
|
|
sy_val=10;
|
|
}
|
|
}
|
|
- else if(HwInput4==0)
|
|
|
|
|
|
+ if(HwInput4==1)
|
|
{
|
|
{
|
|
sy_val=0;
|
|
sy_val=0;
|
|
}
|
|
}
|
|
@@ -150,9 +167,7 @@ void TIM2_IRQHandler()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-char showbuff[16]={0};
|
|
|
|
-u8 warning_sta=0;//异常状态
|
|
|
|
-u8 warning_flag=0;//警告标志位
|
|
|
|
|
|
+
|
|
|
|
|
|
int main(void)
|
|
int main(void)
|
|
{
|
|
{
|
|
@@ -177,12 +192,15 @@ int main(void)
|
|
|
|
|
|
TIM2_Int_Init(71,10000) ; // 开启定时器4 10ms
|
|
TIM2_Int_Init(71,10000) ; // 开启定时器4 10ms
|
|
buzz=1;
|
|
buzz=1;
|
|
|
|
+ exti_Init();
|
|
|
|
+ KEY_Init();
|
|
while(1)
|
|
while(1)
|
|
{
|
|
{
|
|
|
|
|
|
if(get_cnt>100) //采集时间计数器
|
|
if(get_cnt>100) //采集时间计数器
|
|
{
|
|
{
|
|
get_cnt=0;
|
|
get_cnt=0;
|
|
|
|
+ temp_val=DS18B20_Get_Temp();
|
|
sprintf(showbuff,"温度:%2d.%1d",temp_val/10,temp_val%10); //打印成字符串
|
|
sprintf(showbuff,"温度:%2d.%1d",temp_val/10,temp_val%10); //打印成字符串
|
|
OLED_ShowText(0,0,showbuff,0); //显示
|
|
OLED_ShowText(0,0,showbuff,0); //显示
|
|
|
|
|
|
@@ -192,7 +210,7 @@ int main(void)
|
|
sprintf(showbuff,"剩余量:%3d/ml",sy_val); //打印成字符串
|
|
sprintf(showbuff,"剩余量:%3d/ml",sy_val); //打印成字符串
|
|
OLED_ShowText(0,4,showbuff,0); //显示 0); //打印成字符串
|
|
OLED_ShowText(0,4,showbuff,0); //显示 0); //打印成字符串
|
|
|
|
|
|
- if(ds_val>70||ds_val<10||sy_val==10||sy_val==0)//滴速 通常成人每分钟40-60滴,儿童每分钟20-40滴。
|
|
|
|
|
|
+ if(sy_val==10||sy_val==0)//滴速 通常成人每分钟40-60滴,儿童每分钟20-40滴。
|
|
{
|
|
{
|
|
warning_flag=1;
|
|
warning_flag=1;
|
|
}
|
|
}
|