1 简介
Hi,大家好,今天向大家介绍一个学长做的单片机项目,不过这个项目是帮助企业研发的
基于单片机的智能饮水控制系统
大家可用于 毕业设计
选题指导,项目分享:
https://gitee.com/yaa-dc/warehouse-1/blob/master/iot/README.md
2 功能要求
-
出水量达到设定值自动关水
-
温度、湿度测量
-
光照强度测量
-
用水总量统计
-
NTP时间
-
物联网,可在手机APP上远程查看室内温度、湿度、上电总次数等信息
-
简洁易懂的UI界面
3 相关器件
4 实现效果
自己开发的APP
5 部分实现代码
仅部分代码
void TIM_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// ¿ªÆô¶¨Ê±Æ÷ʱÖÓ,¼´ÄÚ²¿Ê±ÖÓCK_INT=72M
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_TIM1, ENABLE);
// Êä³ö±È½ÏͨµÀ1 GPIO ³õʼ»¯
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_13);
GPIO_ResetBits(GPIOB, GPIO_Pin_14);
TIM_DeInit(TIM1); //½«ÍâÉèTIM1¼Ä´æÆ÷ÖØÉèΪȱʡֵ
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1 ; //ÉèÖÃÁËʱÖÓ·Ö¸î(Tck_tim)
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up ; //Ñ¡ÔñÁ˼ÆÊýÆ÷ģʽ(TIMÏòÉϼÆÊýģʽ)
TIM_TimeBaseInitStruct.TIM_Period = 6005 ; //É趨¼ÆÊýÆ÷×Ô¶¯ÖØ×°Öµ,È¡Öµ·¶Î§0x0000~0xFFFF
TIM_TimeBaseInitStruct.TIM_Prescaler = 71 ; //ÉèÖÃÓÃÀ´×÷ΪTIM3ʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵΪ(79+1),È¡Öµ·¶Î§0x0000~0xFFFF
TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStruct ) ;
/* ¶¨Ê±Æ÷Êä³öͨµÀ1ģʽÅäÖà */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;/* ģʽÅäÖãºPWMģʽ1 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; /* Êä³ö״̬ÉèÖãºÊ¹ÄÜÊä³ö */
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; /* »¥²¹Í¨µÀÊä³ö״̬ÉèÖãºÊ¹ÄÜÊä³ö */
TIM_OCInitStructure.TIM_Pulse = 3000;/* ÉèÖÃÌø±äÖµ£¬µ±¼ÆÊýÆ÷¼ÆÊýµ½Õâ¸öֵʱ£¬µçƽ·¢ÉúÌø±ä */
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;/* µ±¶¨Ê±Æ÷¼ÆÊýֵСÓÚCCR1_ValʱΪ¸ßµçƽ */
TIM_OCInitStructure.TIM_OCNPolarity= TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCNIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;/* ģʽÅäÖãºPWMģʽ1 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; /* Êä³ö״̬ÉèÖãºÊ¹ÄÜÊä³ö */
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; /* »¥²¹Í¨µÀÊä³ö״̬ÉèÖãºÊ¹ÄÜÊä³ö */
TIM_OCInitStructure.TIM_Pulse = 3000;/* ÉèÖÃÌø±äÖµ£¬µ±¼ÆÊýÆ÷¼ÆÊýµ½Õâ¸öֵʱ£¬µçƽ·¢ÉúÌø±ä */
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;/* µ±¶¨Ê±Æ÷¼ÆÊýֵСÓÚCCR1_ValʱΪ¸ßµçƽ */
TIM_OCInitStructure.TIM_OCNPolarity= TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCNIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime = 5;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE);/* ʹÄܶ¨Ê±Æ÷ÖØÔؼĴæÆ÷ARR */
TIM_Cmd(TIM1, ENABLE);/* ʹÄܶ¨Ê±Æ÷ */
TIM_CtrlPWMOutputs(TIM1, ENABLE); /* TIMÖ÷Êä³öʹÄÜ */
TIM_CCxCmd(TIM1,TIM_Channel_1,TIM_CCx_Enable);
TIM_CCxNCmd(TIM1,TIM_Channel_1,TIM_CCxN_Enable);
TIM_CCxCmd(TIM1,TIM_Channel_2,TIM_CCx_Enable);
TIM_CCxNCmd(TIM1,TIM_Channel_2,TIM_CCxN_Enable);
}
选题指导,项目分享:
https://gitee.com/yaa-dc/warehouse-1/blob/master/iot/README.md