一次实验项目做的工程,用MSP430F5529为主控,用WiFi模块传输数据,用DHT11模块检测温湿度,同时还检测光照情况和毒气检测功能。
单片机源程序如下:
- /*
- * light.c
- *
- * Created on: 2018年9月27日
- * Author: Wade
- * call:13594729060
- */
- #include <msp430f5529.h>
- #include "HAL_Dogs102x6.h"
- #include "NumberShow.h"
- #include "delay.h"
- #include "DHT11.h"
- #include "light.h"
- #include "gas.h"
- #include "led.h"
- #include "wifi.h"
- int LedStatus;
- void Menu(){
- Dogs102x6_stringDraw(0, 0, "Smart Home System", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(2, 0, "Tem:", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(2, 46, "C", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 0, "Hum:", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 46, "%", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(4, 0, "Lig:", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 0, "Gas:", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(6, 0, "LED:", DOGS102x6_DRAW_NORMAL);
- }
- void main( void )
- {
- WDTCTL=WDTPW+WDTHOLD;
- UCSCTL4 |= SELS__DCOCLK ;
- Dogs102x6_init();
- Dogs102x6_clearScreen(); //清屏
- Dogs102x6_init();//初始化LCD
- Dogs102x6_backlightInit();
- Dogs102x6_setContrast(15); //设置对比度
- Dogs102x6_setBacklight(11);//设置背光度
- WifiConfig(); //wifi初始化(含串口)
- while (1)
- {
- Dogs102x6_clearScreen();//清屏
- Menu(); //重画菜单界面
- DHT11( ); //测量温湿度数据,并显示在LCD上
- light(); //测量光照情况,并把结果显示在LCD上
- gas(); //测量烟雾情况,并把结果显示在LCD上
- led(); //检测LED状态,并把结果显示在LCD上
- delay_ms(2000); //延时2s,确保温湿度测量时间间隔
- }
- }
- // Echo back RXed character, confirm TX buffer is ready first
- #pragma vector=USCI_A1_VECTOR
- __interrupt void USCI_A1_ISR(void)
- {
- switch(__even_in_range(UCA1IV,4))
- {
- case 0:break; // Vector 0 - no interrupt
- case 2: // Vector 2 - RXIFG
- if('1' == UCA1RXBUF)
- {
- P1DIR |= 0x01;
- P1OUT |= 0x01; //点亮LED灯
- LedStatus = 1; //LED的FLAG,作为在LCD上显示状态的依据
- }
- else if('0' == UCA1RXBUF)
- {
- P1DIR |= 0x01;
- P1OUT &= 0xFE; //熄灭LED灯
- LedStatus = 0; //LED的FLAG,作为在LCD上显示状态的依据
- }
- else if('2' == UCA1RXBUF)
- {
- WifiSendMessage(); //WiFi将测量的数据发送到客户端
- }
- break;
- case 4:break; // Vector 4 - TXIFG
- default: break;
- }
- }
复制代码
所有资料51hei提供下载:
基于msp430f5529的温湿度测量程序.rar
(1.24 MB, 下载次数: 83)
|