IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> 基于STM32 GPRS的智能家居系统毕设论文 -> 正文阅读

[嵌入式]基于STM32 GPRS的智能家居系统毕设论文

在这里插入图片描述
在这里插入图片描述

//头文件调用
#include "usually.h"
#include "usart.h"
#include "oled.h"
#include "dht11.h"
#include "rtc.h"
#include "delay.h"
#include "stm32f10x_adc.h"
#include <string.h>
#include "BSP_Config.h"
#include "gpio.h"
#include "gsm.h"


//宏定义
#define ADC_CH0  0 //通道0
#define ADC_CH1  1 //通道1
#define ADC_CH2  2 //通道2
#define ADC_CH3  3 //通道3	


#define SEC 0
#define MIN 1
#define HOUR 2
#define DATE 3
#define MON 4
#define YEAR 6

#define MODE_NORMAL 0
#define MODE_SET_HOUR 1
#define MODE_SET_MIN 2
#define MODE_SET_SEC 3
#define MODE_SET_YEAR 4
#define MODE_SET_MON 5
#define MODE_SET_DATE 6
#define MODE_SET_HUMI_HIGH 8
#define MODE_SET_TEMP_HIGH 7
#define MODE_SET_LIGHT 9


#define KEY_MENU_IN PBin(0)
#define KEY_ADD_IN PBin(1)
#define KEY_SUB_IN PBin(2)

//步进控制 A-AB-B-BC-C-CD-D-DA
#define Motor1_A_run  { GPIO_SetBits(GPIOB,GPIO_Pin_8);  GPIO_ResetBits(GPIOB,GPIO_Pin_9);GPIO_ResetBits(GPIOB,GPIO_Pin_10);GPIO_ResetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_AB_run { GPIO_SetBits(GPIOB,GPIO_Pin_8);  GPIO_SetBits(GPIOB,GPIO_Pin_9);  GPIO_ResetBits(GPIOB,GPIO_Pin_10);GPIO_ResetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_B_run  { GPIO_ResetBits(GPIOB,GPIO_Pin_8);GPIO_SetBits(GPIOB,GPIO_Pin_9);  GPIO_ResetBits(GPIOB,GPIO_Pin_10);GPIO_ResetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_BC_run { GPIO_ResetBits(GPIOB,GPIO_Pin_8);GPIO_SetBits(GPIOB,GPIO_Pin_9);  GPIO_SetBits(GPIOB,GPIO_Pin_10);  GPIO_ResetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_C_run  { GPIO_ResetBits(GPIOB,GPIO_Pin_8);GPIO_ResetBits(GPIOB,GPIO_Pin_9);GPIO_SetBits(GPIOB,GPIO_Pin_10);  GPIO_ResetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_CD_run { GPIO_ResetBits(GPIOB,GPIO_Pin_8);GPIO_ResetBits(GPIOB,GPIO_Pin_9);GPIO_SetBits(GPIOB,GPIO_Pin_10);  GPIO_SetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_D_run  { GPIO_ResetBits(GPIOB,GPIO_Pin_8);GPIO_ResetBits(GPIOB,GPIO_Pin_9);GPIO_ResetBits(GPIOB,GPIO_Pin_10);GPIO_SetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_DA_run { GPIO_SetBits(GPIOB,GPIO_Pin_8);  GPIO_ResetBits(GPIOB,GPIO_Pin_9);GPIO_ResetBits(GPIOB,GPIO_Pin_10);GPIO_SetBits(GPIOB,GPIO_Pin_11);}
#define Motor1_STOP_run { GPIO_ResetBits(GPIOB,GPIO_Pin_8);  GPIO_ResetBits(GPIOB,GPIO_Pin_9);GPIO_ResetBits(GPIOB,GPIO_Pin_10);GPIO_ResetBits(GPIOB,GPIO_Pin_11);}


#define motorSpdDelayUs  1100
//声明变量
extern struct Data_Time  timer;
unsigned char *pUart1_Rxd;//接收数据指针
unsigned int  uart1_RxNum=0;//串口1接收字数
unsigned char Num_TXD=0;//串口1发送缓冲区的字节数
unsigned char Uart1_TxBuf[256]={0,2,3,};//串口1发送缓冲区
unsigned char Uart1_RxBuf[256]; //串口1接收缓冲区

unsigned char *pUart2_Rxd;			//串口2接收数据指针
unsigned int  uart2_RxNum=0;	 //串口2接收字数
unsigned char uart2_TxNum=0;	 //串口2发送缓冲区的字节数
unsigned char Uart2_TxBuf[256]={0,2,3,};//串口2发送缓冲区
unsigned char Uart2_RxBuf[256]; //串口2接收缓冲区

//变量声明
//extern struct tm  timer;
char line1str[17]="Welcome to use!";
char line2str[17]="Wating gsm... ";
char line3str[17]="              ";
char line4str[17]="              ";
uint8_t dht11_buf[5];
uint8_t nowtemp,nowhumi;//当前温湿度值
uint8_t thalmflg;  //温湿度过高报警
uint16_t adtemp[12]={0};  //连续采集12点算平均值
uint16_t light_adc,set_lit_high,lit_high;
uint8_t almtmp_high,almhumi_high;
uint8_t mode_status; //模式
uint8_t flashflg; //模式
uint8_t settimeflg;	//时间被设置标志位
uint8_t solid1flg,solid2flg,winflg;
unsigned char settime[8]={0x00,30,12,0x6,10,0x01,15};//??sec,min,hour,date,month,week,year
char recephonenum[12]="13538510586";
char phonenum_flash;
uint8_t adci=0;
char strLs[32];
//按键输入初始化
void Key_init(void){
	
  GPIO_InitTypeDef  GPIO_InitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);	 //使能PB端口时钟
	//Configure pin Pb1 as output 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;		//PA13,PA14,PA15按键输入
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 	//上拉输入	
	GPIO_Init(GPIOB,&GPIO_InitStructure);	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 	//上拉输入
	GPIO_Init(GPIOB,&GPIO_InitStructure);	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 	//上拉输入
	GPIO_Init(GPIOB,&GPIO_InitStructure);	

}

//继电器输出IO初始化
void Solid_Init(){
	
  GPIO_InitTypeDef  GPIO_InitStructure;
	//Configure pin Pb0 as output 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	//推挽输出
	GPIO_Init(GPIOB,&GPIO_InitStructure);

	//Configure pin Pb1 as output 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	//推挽输出
	GPIO_Init(GPIOB,&GPIO_InitStructure);
/*	GPIO_SetBits(GPIOB,GPIO_Pin_5);
	GPIO_SetBits(GPIOB,GPIO_Pin_6);	
	GPIO_ResetBits(GPIOB,GPIO_Pin_5);
	GPIO_ResetBits(GPIOB,GPIO_Pin_6);	*/
}

//步进输出IO初始化
void Motor_Init(){
	
  GPIO_InitTypeDef  GPIO_InitStructure;
	//Configure pin Pb0 as output 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	//推挽输出
	GPIO_Init(GPIOB,&GPIO_InitStructure);

	//Configure pin Pb1 as output 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	//推挽输出
	GPIO_Init(GPIOB,&GPIO_InitStructure);
		//Configure pin Pb0 as output 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	//推挽输出
	GPIO_Init(GPIOB,&GPIO_InitStructure);

	//Configure pin Pb1 as output 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	//推挽输出
	GPIO_Init(GPIOB,&GPIO_InitStructure);
	
	
/*	GPIO_SetBits(GPIOB,GPIO_Pin_5);
	GPIO_SetBits(GPIOB,GPIO_Pin_6);	
	GPIO_ResetBits(GPIOB,GPIO_Pin_5);
	GPIO_ResetBits(GPIOB,GPIO_Pin_6);	*/
}

//初始化ADC
//这里我们仅以规则通道为例
//我们默认将开启通道0~3																	   
void  Adc_Init(void)
{    
	//先初始化IO口
 	RCC->APB2ENR|=1<<2;    //使能PORTA口时钟 
	GPIOA->CRL&=0XFFFF0000;//PA0 1 2 3 anolog输入
	//通道10/11设置			 
	RCC->APB2ENR|=1<<9;    //ADC1时钟使能	  
	RCC->APB2RSTR|=1<<9;   //ADC1复位
	RCC->APB2RSTR&=~(1<<9);//复位结束	    
	RCC->CFGR&=~(3<<14);   //分频因子清零	
	//SYSCLK/DIV2=12M ADC时钟设置为12M,ADC最大时钟不能超过14M!
	//否则将导致ADC准确度下降! 
	RCC->CFGR|=2<<14;      	 

	ADC1->CR1&=0XF0FFFF;   //工作模式清零
	ADC1->CR1|=0<<16;      //独立工作模式  
	ADC1->CR1&=~(1<<8);    //非扫描模式	  
	ADC1->CR2&=~(1<<1);    //单次转换模式
	ADC1->CR2&=~(7<<17);	   
	ADC1->CR2|=7<<17;	   //软件控制转换  
	ADC1->CR2|=1<<20;      //使用用外部触发(SWSTART)!!!	必须使用一个事件来触发
	ADC1->CR2&=~(1<<11);   //右对齐	 
	ADC1->SQR1&=~(0XF<<20);
	ADC1->SQR1&=0<<20;     //1个转换在规则序列中 也就是只转换规则序列1 			   
	//设置通道0~3的采样时间
	ADC1->SMPR2&=0XFFFFF000;//通道0,1,2,3采样时间清空	  
	ADC1->SMPR2|=7<<9;      //通道3  239.5周期,提高采样时间可以提高精确度	 
	ADC1->SMPR2|=7<<6;      //通道2  239.5周期,提高采样时间可以提高精确度	 
	ADC1->SMPR2|=7<<3;      //通道1  239.5周期,提高采样时间可以提高精确度	 
	ADC1->SMPR2|=7<<0;      //通道0  239.5周期,提高采样时间可以提高精确度	 

	ADC1->CR2|=1<<0;	    //开启AD转换器	 
	ADC1->CR2|=1<<3;        //使能复位校准  
	while(ADC1->CR2&1<<3);  //等待校准结束 			 
    //该位由软件设置并由硬件清除。在校准寄存器被初始化后该位将被清除。 		 
	ADC1->CR2|=1<<2;        //开启AD校准	   
	while(ADC1->CR2&1<<2);  //等待校准结束
	//该位由软件设置以开始校准,并在校准结束时由硬件清除  
}				  
//获得ADC值
//ch:通道值 0~3
u16 Get_Adc(u8 ch)   
{
	//设置转换序列	  		 
	ADC1->SQR3&=0XFFFFFFE0;//规则序列1 通道ch
	ADC1->SQR3|=ch;		  			    
	ADC1->CR2|=1<<22;       //启动规则转换通道 
	while(!(ADC1->SR&1<<1));//等待转换结束	 	   
	return ADC1->DR;		//返回adc值	
}


//
uint16_t adc_avg(void)
{
  uint8_t i;
	uint32_t sum=0;
	uint16_t ret=0;
	for(i=0;i<12;i++)  sum+=adtemp[i];
	ret= sum/12;
	
	return ret;  
}
//马达正转开窗帘
void motor_Foreward(void)
{
    Motor1_A_run;
    delay_us(motorSpdDelayUs);
    Motor1_AB_run;
    delay_us(motorSpdDelayUs);
    Motor1_B_run;
    delay_us(motorSpdDelayUs);
    Motor1_BC_run;
    delay_us(motorSpdDelayUs);
    Motor1_C_run;
    delay_us(motorSpdDelayUs);
    Motor1_CD_run;
    delay_us(motorSpdDelayUs);
    Motor1_D_run;
    delay_us(motorSpdDelayUs);
    Motor1_DA_run;
    delay_us(motorSpdDelayUs);
}


//马达反转关窗帘
void motor_Backward(void)
{
    Motor1_DA_run;
    delay_us(motorSpdDelayUs);   
    Motor1_D_run; 
    delay_us(motorSpdDelayUs);
    Motor1_CD_run;
    delay_us(motorSpdDelayUs);
    Motor1_C_run; 
    delay_us(motorSpdDelayUs);
    Motor1_BC_run;
    delay_us(motorSpdDelayUs);
    Motor1_B_run;
    delay_us(motorSpdDelayUs);
    Motor1_AB_run;
    delay_us(motorSpdDelayUs);
    Motor1_A_run;
    delay_us(motorSpdDelayUs);   
}



//显示设置页面
void Show_Normal(void){
	//显示温湿度
	strncpy(line1str,"tmp:99C/hm:99%RH",16);
	line1str[4]=0x30+nowtemp/10;
	line1str[5]=0x30+nowtemp%10;
	line1str[11]=0x30+nowhumi/10;
	line1str[12]=0x30+nowhumi%10;
	OLED_8x16Str(0,0,line1str);	
	//显示光照强度及窗帘状态
	if(winflg){
	  strncpy(line2str,"lit:99 /wn:open ",16);
	}else{
		strncpy(line2str,"lit:99 /wn:close",16);
  }
	line2str[4]=0x30+light_adc/41/10; //100%显示
	line2str[5]=0x30+light_adc/41%10;
	OLED_8x16Str(0,2,line2str);	
	
	//显示继电器输出状态
	strncpy(line3str, "s1:open s2:open ",16);
	if(solid1flg) {
	  line3str[3]='o';line3str[4]='p';line3str[5]='e';line3str[6]='n';line3str[7]=' ';
  }else{
	  line3str[3]='c';line3str[4]='l';line3str[5]='o';line3str[6]='s';line3str[7]='e';
  }
	if(solid2flg) {
	  line3str[11]='o';line3str[12]='p';line3str[13]='e';line3str[14]='n';line3str[15]=' ';
  }else{
	  line3str[11]='c';line3str[12]='l';line3str[13]='o';line3str[14]='s';line3str[15]='e';
  }	
	
	OLED_8x16Str(0,4,line3str);
	
	//显示时间
	//line4str[0]= 0x30+ timer.w_year%1000%100/10;	
	line4str[0]= 0x30+ timer.w_year%1000%100%10;	
	line4str[1]= '/';
	line4str[2]= 0x30+timer.w_month/10;	
	line4str[3]= 0x30+ timer.w_month%10;	
	line4str[4]= '/';	
	line4str[5]= 0x30+timer.w_date/10;	
	line4str[6]= 0x30+ timer.w_date%10;	
	line4str[7]= ' ';		
	line4str[8]= 0x30+ timer.hour/10;	
	line4str[9]= 0x30+ timer.hour%10;	
	line4str[10]= ':';
	line4str[11]= 0x30+timer.min/10;	
	line4str[12]= 0x30+ timer.min%10;	
	line4str[13]= ':';	
	line4str[14]= 0x30+timer.sec/10;	
	line4str[15]= 0x30+timer.sec%10;	
	OLED_8x16Str(0,6,line4str);

}
/*
   显示设置页面

*/

链接:https://pan.baidu.com/s/1AXIBoaKfDw_ITSXsO0ucUQ
提取码:aeue

  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2021-07-22 14:21:29  更:2021-07-22 14:22:18 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/7 17:41:11-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码