温湿度传感器采用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[i];
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[i];
while((IFG2&UCA0TXIFG)==0);
}
for (i=0;i<40000;i++);
}
}
|