標(biāo)題: 51單片機(jī)SHT25溫濕度測(cè)量 proteus仿真工程(8.9SP2) [打印本頁(yè)]

作者: liaoxj    時(shí)間: 2020-7-20 11:38
標(biāo)題: 51單片機(jī)SHT25溫濕度測(cè)量 proteus仿真工程(8.9SP2)
SHT25溫濕度測(cè)量仿真原理圖如下(proteus 8.9SP2 仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. //vender:liaoxj
  2. //version:v1

  3. #include "reg8051.h"
  4. #include <stdio.h>
  5. #include "drv.h"
  6. #include "common.h"
  7. #include "delay.h"
  8. #include "iic.h"
  9. #include "SHT20.h"



  10. int ReadTempFlag;//定義讀時(shí)間標(biāo)志

  11. char temp_H,temp_L;

  12. unsigned int temp;
  13. unsigned int num;

  14. int a=0;
  15. int timer0_count=0;
  16. int v=0;
  17. char v_h,v_l;

  18. int uart_flag=0;
  19. unsigned char receive[4];

  20. void main()
  21. {
  22.         uart_init();
  23.         timer0_init();
  24.    SHT20_Init();
  25.         EA=1;
  26.         SHT20_setResolution();                        
  27.         while(1)
  28.                 {
  29.                         if(ReadTempFlag==1)
  30.                         {
  31.             
  32.             ReadTempFlag=0;
  33.             //SHT25,IIC接口
  34.             temp=SHT20_readTem();
  35. //            temp>>=5;//數(shù)據(jù)是11位的,高位對(duì)齊,所以數(shù)據(jù)右移5位,變低位對(duì)齊
  36.             temp=temp&0xfffc;
  37.                                 temp_L=temp;//拆分為低8位和高3位,用串口傳輸
  38.                                 temp_H=temp>>8;
  39.             send(temp_H);
  40.             send(temp_L);
  41.             
  42.             temp=SHT20_readHum();
  43. //            temp>>=5;
  44.             temp=temp&0xfffc;
  45.                                 temp_L=temp;
  46.                                 temp_H=temp>>8;
  47.             send(temp_H);
  48.             send(temp_L);
  49.                         }
  50.                
  51.                 }        

  52. }

  53. void timer0_isr() interrupt 1
  54. {
  55.         
  56.                 TH0=0xF8;
  57.                 TL0=0xCC;

  58.                 timer0_count++;
  59.                 if(timer0_count==1000)
  60.                 {
  61.                         P10=~P10;
  62.                         timer0_count=0;
  63.          ReadTempFlag=1; //讀標(biāo)志位置1

  64.                 }


  65. }



  66. void uart_isr() interrupt 4
  67. {  

  68.    static unsigned char count;//串口接收計(jì)數(shù)的變量  
  69.   RI=0;//手動(dòng)清某個(gè)寄存器,大家都懂的  
  70.   receive[count]=SBUF;  
  71.   count++;
  72.         if(count==4)
  73.         {        
  74.                 ES=0;  
  75.     count=0;  
  76.     uart_flag =1;//串口接收成功標(biāo)志,為1時(shí)在主程序中回復(fù),然后清零  
  77.                     //關(guān)中斷,回復(fù)完了再ES=1;  
  78.   }  
  79.   
  80. }
復(fù)制代碼

所有資料51hei提供下載:
IIC-SHT25溫濕度傳感器.zip (183.75 KB, 下載次數(shù): 77)






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1