标题: 51单片机SHT25温湿度测量 proteus仿真工程(8.9SP2) [打印本页]

作者: liaoxj    时间: 2020-7-20 11:38
标题: 51单片机SHT25温湿度测量 proteus仿真工程(8.9SP2)
SHT25温湿度测量仿真原理图如下(proteus 8.9SP2 仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  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;//定义读时间标志

  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;//数据是11位的,高位对齐,所以数据右移5位,变低位对齐
  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; //读标志位置1

  64.                 }


  65. }



  66. void uart_isr() interrupt 4
  67. {  

  68.    static unsigned char count;//串口接收计数的变量  
  69.   RI=0;//手动清某个寄存器,大家都懂的  
  70.   receive[count]=SBUF;  
  71.   count++;
  72.         if(count==4)
  73.         {        
  74.                 ES=0;  
  75.     count=0;  
  76.     uart_flag =1;//串口接收成功标志,为1时在主程序中回复,然后清零  
  77.                     //关中断,回复完了再ES=1;  
  78.   }  
  79.   
  80. }
复制代码

所有资料51hei提供下载:
IIC-SHT25温湿度传感器.zip (183.75 KB, 下载次数: 77)






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1