Temperature and humidity program based on msp430f5529
[Copy link]
The experimental project uses MSP430F5529 as the main control, WiFi module to transmit data, DHT11 module to detect temperature and humidity, and also detects light conditions and toxic gas detection functions. The
microcontroller source program is as follows:
- /*
- * light.c
- *
- * Created on: September 27, 2018
- * 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(); //Clear screen
- Dogs102x6_init(); //Initialize LCD
- Dogs102x6_backlightInit();
- Dogs102x6_setContrast(15); //Set contrast
- Dogs102x6_setBacklight(11); //Set backlight
- WifiConfig(); //wifi initialization (including serial port)
- while (1)
- {
- Dogs102x6_clearScreen();//Clear screen
- Menu(); //Redraw the menu interface
- DHT11(); //Measure temperature and humidity data and display them on LCD
- light(); //Measure the lighting conditions and display the results on the LCD
- gas(); //Measure the smoke condition and display the result on LCD
- led(); //Detect LED status and display the result on LCD
- delay_ms(2000); //Delay 2s to ensure the time interval of temperature and humidity measurement
- }
- }
- // 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; //Turn on the LED
- LedStatus = 1; //LED FLAG, used as the basis for displaying the status on the LCD
- }
- else if('0' == UCA1RXBUF)
- {
- P1DIR |= 0x01;
- P1OUT &= 0xFE; //Turn off the LED light
- LedStatus = 0; //LED FLAG, as the basis for displaying the status on the LCD
- }
- else if('2' == UCA1RXBUF)
- {
- WifiSendMessage(); //WiFi sends the measured data to the client
- }
- break;
- case 4:break; // Vector 4 - TXIFG
- default: break;
- }
- }
|