新手上路
- 积分
- 33
- 金钱
- 33
- 注册时间
- 2016-1-20
- 在线时间
- 3 小时
|
1金钱
#include "stm32f10x.h"
#include "string.h"
#include "delay.h"
#include "GUI.h"
#include "usart.h"
#include "mq2.h"
#include "stdarg.h"
#include "stdio.h"
#include "beep.h"
#include "ds18b20.h"
#include "led.h"
#include "remote.h"
#define FONT_SIZE 24 //ÑìÎí′«¸DÆ÷
#define MQ2_ADC_POS (0*FONT_SIZE)
#define DS18B20_ADC_POS (1*FONT_SIZE)
//#define DS18B20_ADC_POS2 (2*FONT_SIZE)
#define MQ2_HANDLER_TIME_MSECS 2000
float MQ2_Adc;
short temperature;
float temp;
void MQ2_Handler(void);
void LCD_Printf(int y,char *format, ...);
void DS18B20_Handler(void);
void Sensor_Periodic_Handle(u32 localtime);
int main()
{
u32 time;
SysTick_Config(SystemCoreClock / 1000);
delay_ms(200); //éÏμçÎ趨oó
NVIC_Configuration(); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
uart_init(9600); //USART3õê¼»ˉ
GUI_Init();
GUI_SetBkColor(GUI_WHITE);
GUI_SetColor(GUI_RED);
GUI_Clear();
GUI_SetFont(&GUI_Font24_1);
MQ2_Init(); //ÑìÎíÄ£¿é3õê¼»ˉ
DS18B20_Init(); //DS18b203õê¼»ˉ
LED_Init(); //LED3õê¼»ˉ
time = 0;
delay_ms(3000);//Ñóê±3Ãë
printf("AT+CSCS=\"GSM\"\r\n");
delay_ms(3000);//Ñóê±3Ãë
printf("AT+CMGF=1\r\n");
delay_ms(3000);//Ñóê±3Ãë
printf("AT+CMGS=\"18060614154\"\r\n");//′Ë′|DT¸ÄÎa¶Ô·½μÄμç»°oÅ
delay_ms(5000);//Ñóê±3Ãë
printf("THIS IS GSM SIM900A TEST!\r\n");//DT¸Ä¶ìDÅÄúèY
delay_ms(3000);//Ñóê±3Ãë
USART_SendData(USART1,0x1a);
delay_ms(3000);//Ñóê±20Ãë
while(1)
{
time = GetCurTime();
Sensor_Periodic_Handle(time);
}
}
//................................................
void Sensor_Periodic_Handle(u32 localtime)
{
static u32 SensorTimer = 0;
static u32 time = 0;
if (localtime - SensorTimer >= 1)
{
SensorTimer =localtime;
if(time%MQ2_HANDLER_TIME_MSECS == 0)
{
MQ2_Handler();
DS18B20_Handler();
}
time ++;
}
}
//.................ÑìÎí′«¸DÆ÷′úÂë............................
void MQ2_Handler()
{
float res_adc;
MQ2_Adc = MQ2_ReadADC();
res_adc = RES_ReadADC();
if(MQ2_Adc > 1.9)
{
LCD_Printf(MQ2_ADC_POS, "ADC:MQ2 Alarm RES:%.3fV",res_adc);
//BEEP_Init( );
LED0=0;//»Æé«μÆ
//Uart1Sends("DF70FE9635758B533C50C78FD89A0CFFF78BE86C0F61");//¶ìDÅÄúèYunicon±àÂë ÑìÎíμçÑ1Öμ1y¸ß£¬Çë×¢òa
}
else
{
LCD_Printf(MQ2_ADC_POS, "ADC:MQ2:%.3fV RES:%.3fV", MQ2_Adc,res_adc);
}
}
//...................DS18B20′úÂë.......................
void DS18B20_Handler()
{
// u8 t=0;
//NVIC_Configuration(); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
while(DS18B20_Init()==1) //DS18B203õê¼»ˉerror
{
LCD_Printf(DS18B20_ADC_POS, "DS18B20 Alarm T ");
delay_ms(200);
}
// delay_ms(2);
temperature=DS18B20_Get_Temp();
temp=temperature/10;
//delay_ms(200);
if(temp<19.0) //3¬1y30éãê϶èÔò±¨¾ˉ
{
LCD_Printf(DS18B20_ADC_POS, "DS18B20 %3.1f",temp);//
delay_ms(200);
}
else
{
LCD_Printf(DS18B20_ADC_POS, "DS18B20 Alarm %3.1f",temp);
//BEEP_Init( );
LED1=0;//oìé«μÆ
delay_ms(200);
//Uart1Sends("296EA65EF25DC78FD89A0CFFF78BE86C0F61");//¶ìDÅÄúèYunicon±àÂë¡£¡£¡£ζèòÑ1y¸ß£¬Çë×¢òa
//Uart1Sends("A");
}
LED1=1;//oìé«μÆ
}
//...................LCDÏÔê¾oˉêy.....................
char buf_str[201u];
void LCD_Printf(int y,char *format, ...)
{
va_list v_args;
va_start(v_args, format);
(void)vsnprintf((char *)&buf_str[0],
(size_t ) sizeof(buf_str),
(char const *) format,
v_args);
va_end(v_args);
memset(&buf_str[strlen(buf_str)], ' ', 60 > strlen(buf_str)?60 - strlen(buf_str):0);
buf_str[60] = 0;
GUI_DispStringAt(buf_str, 0,y);
}
|
|