MSP430的温湿度、光照的测量和显示

[复制链接]
935|3
 楼主| dirtwillfly 发表于 2017-8-23 21:02 | 显示全部楼层 |阅读模式
温湿度传感器采用DHT11
光照传感器采用BH1750



  1. #include "msp430x26x.h"
  2. #include "UART1.h"
  3. #include "sht10.h"
  4. #include "XT2_Start.h"
  5. #include "BH1750.h"
  6. #include"stdio.h"

  7. void main( void )
  8. {
  9.   // Stop watchdog timer to prevent time out reset
  10.   WDTCTL = WDTPW + WDTHOLD;
  11.   unsigned int i,a0,a1,a2,a3,a,b,c,d,e,f;
  12.   int Light_Data[4];
  13.   unsigned int Sample_Data[6];
  14.   unsigned char m;
  15.   WDTCTL=WDTPW+WDTHOLD;
  16.   XT2_Start();
  17.   UART1_Initial();
  18.   SHT_Init();
  19.   SHT_ConnectionReset();
  20.   
  21.   while(1)
  22.   {
  23.     SHT_Function();
  24.     a=(int)(Temp_Val.f/10);
  25.   Sample_Data[0]=a;
  26.   b=(int)(Temp_Val.f-a*10);
  27.   Sample_Data[1]=b;
  28.   c=(int)((Temp_Val.f-a*10-b)*10);
  29.   Sample_Data[2]=c;
  30.   d=(int)(Humi_Val.f/10);
  31.   Sample_Data[3]=d;
  32.   e=(int)(Humi_Val.f-d*10);
  33.   Sample_Data[4]=e;
  34.   f=(int)((Humi_Val.f-d*10-e)*10);
  35.   Sample_Data[5]=f;
  36.   for(i=0;i<6;i++)
  37.   {
  38.     UCA0TXBUF=Sample_Data[i];
  39.     while((IFG2&UCA0TXIFG)==0);//等待一字节的数据发送完毕
  40.   }
  41.     //send final data to serial interface (UART)
  42.     printf("temp:%5.1fC humi:%5.1f%% ",Temp_Val.f,Humi_Val.f);
  43.     //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------
  44.     for (i=0;i<40000;i++); //(be sure that the compiler doesn't eliminate this line!)
  45.    //----------------------------------------------------------------------------------
  46.     m=get_light();
  47.     a0=(int)(m/1000);
  48.     Light_Data[0]=a0;
  49.     a1=(int)((m-a0*1000)/100);
  50.     Light_Data[1]=a1;
  51.     a2=(int)((m-a0*1000-a1*100)/10);
  52.     Light_Data[2]=a2;
  53.     a3=(int)(m-a0*1000-a1*100-a2*10);
  54.     Light_Data[3]=a3;
  55.     for(i=0;i<4;i++)
  56.     {
  57.       UCA0TXBUF=Light_Data[i];
  58.       while((IFG2&UCA0TXIFG)==0);
  59.     }

  60.     for (i=0;i<40000;i++);
  61.   }
  62. }



 楼主| dirtwillfly 发表于 2017-8-23 21:02 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
tongbu2015 发表于 2017-8-26 23:25 | 显示全部楼层
谢谢分享,看来diamante的还不特复杂的
tongbu2015 发表于 2017-8-26 23:26 | 显示全部楼层
是说这代码的,,资料我下载了的,谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:欢迎进入TI MCU论坛      21ic TI技术交流1群:61549143(已满),  21ic TI技术交流2群:311421422 我的博客:http://blog.timcu.com/

1199

主题

35121

帖子

1122

粉丝
快速回复 在线客服 返回列表 返回顶部