1559 views|1 replies

3836

Posts

19

Resources
The OP
 

Programming: MSP430 temperature, humidity and light measurement and display [Copy link]

温湿度传感器采用DHT11
光照传感器采用BH1750

#include "msp430x26x.h"
#include "UART1.h"
#include "sht10.h"
#include "XT2_Start.h"
#include "BH1750.h"
#include"stdio.h"


void main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  unsigned int i,a0,a1,a2,a3,a,b,c,d,e,f;
  int Light_Data[4];
  unsigned int Sample_Data[6];
  unsigned char m;
  WDTCTL=WDTPW+WDTHOLD;
  XT2_Start();
  UART1_Initial();
  SHT_Init();
  SHT_ConnectionReset();
  
  while(1)
  {
    SHT_Function();
    a=(int)(Temp_Val.f/10);
  Sample_Data[0]=a;
  b=(int)(Temp_Val.f-a*10);
  Sample_Data[1]=b;
  c=(int)((Temp_Val.f-a*10-b)*10);
  Sample_Data[2]=c;
  d=(int)(Humi_Val.f/10);
  Sample_Data[3]=d;
  e=(int)(Humi_Val.f-d*10);
  Sample_Data[4]=e;
  f=(int)((Humi_Val.f-d*10-e)*10);
  Sample_Data[5]=f;
  for(i=0;i<6;i++)
  {
    UCA0TXBUF=Sample_Data;
    while((IFG2&UCA0TXIFG)==0);//等待一字节的数据发送完毕
  }
    //send final data to serial interface (UART)
    printf("temp:%5.1fC humi:%5.1f%% ",Temp_Val.f,Humi_Val.f);
    //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------
    for (i=0;i<40000;i++); //(be sure that the compiler doesn't eliminate this line!)
   //----------------------------------------------------------------------------------
    m=get_light();
    a0=(int)(m/1000);
    Light_Data[0]=a0;
    a1=(int)((m-a0*1000)/100);
    Light_Data[1]=a1;
    a2=(int)((m-a0*1000-a1*100)/10);
    Light_Data[2]=a2;
    a3=(int)(m-a0*1000-a1*100-a2*10);
    Light_Data[3]=a3;
    for(i=0;i<4;i++)
    {
      UCA0TXBUF=Light_Data;
      while((IFG2&UCA0TXIFG)==0);
    }


    for (i=0;i<40000;i++);
  }
}


This post is from Microcontroller MCU

Latest reply

After searching for a long time, I finally found a comment. It was not easy.  Details Published on 2018-12-25 17:57
 

6366

Posts

4936

Resources
2
 
After searching for a long time, I finally found a comment. It was not easy.
This post is from Microcontroller MCU
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list