找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1309|回复: 1
收起左侧

51单片机非接触人体测温安装图+原理图+C语言程序

[复制链接]
ID:981841 发表于 2021-12-13 09:56 | 显示全部楼层 |阅读模式
51hei图片20211213095124.jpg 51hei图片20211213095132.jpg

电路原理图如下:
51hei.png

02.jpg 04.jpg 05.jpg 01.jpg 07.jpg

单片机源程序如下:
  1. #include"reg52.h"
  2. #include"intrins.h"
  3. #include"common.h"
  4. #include"Key.h"
  5. #include"lcd1602.h"

  6. //************************************
  7. #define Nack_counter 10

  8. //mlx90614 端口定义
  9. sbit SCL=P3^6;//时钟线
  10. sbit SDA=P3^7;//数据线
  11. //************数据定义****************
  12. bdata uchar flag;//可位寻址数据
  13. sbit bit_out=flag^7;
  14. sbit bit_in=flag^0;

  15. bit start_flag;
  16. uchar DataH,DataL,Pecreg;
  17. uchar flag1;

  18. uchar dis0[] = "Life Is Movement";
  19. uchar dis1[] = "  T: 000.00 C   ";
  20. uchar dis2[] = " X:     S:      ";
  21. uint Max_Tem = 3800;//最大温度,100倍
  22. uint Min_Tem = 2000;//最小温度
  23. uint Tem;
  24. uchar status = 0;




  25. //************函数声明*****************************************
  26. void start_bit(); //MLX90614 发起始位子程序
  27. void stop_bit(); //MLX90614 发结束位子程序
  28. uchar rx_byte(void); //MLX90614 接收字节子程序
  29. void send_bit(void); //MLX90614 发送位子程序
  30. void tx_byte(uchar dat_byte); //MLX90614 接收字节子程序
  31. void receive_bit(void); //MLX90614 接收位子程序
  32. void delay(uint);
  33. uint memread(void); //读温度数据
  34. void display(uint Tem); //显示子程序
  35. //*************主函数*******************************************
  36. void main()
  37. {
  38.     uint i,count;
  39. //函数部分
  40.     SCL=1;
  41.     SDA=1;
  42.     _nop_();
  43.     _nop_();
  44.     _nop_();
  45.     _nop_();
  46.     SCL=0;
  47.     delay(1000);
  48.     SCL=1;

  49.         dis1[11] =0xdf;
  50.         
  51.         LCD_init();                  //lcd初始化
  52.     start_flag = 0;
  53.         delay_ms(2000);
  54.     while(1)
  55.     {
  56.             count++;
  57.                 if(count<500)
  58.                 {
  59.           Tem=memread();         //读取温度
  60.                   delay_ms(5000);
  61.                   key_det();                 //按键扫描
  62.           display(Tem);                  //显示温度
  63.                   delay_ms(5000);
  64.               for(i=0;i<16;i++)
  65.           {
  66.                         LCD_write_char(i,0,dis1[i]);
  67.                         LCD_write_char(i,1,dis2[i]);
  68.           }
  69.                   delay_ms(500);
  70.                   count=0;
  71.                 }
  72.     }
  73. }




  74. //*********输入转换并装载*********
  75. void display(uint Tem)
  76. {
  77.     uint T,a,b,min,max;
  78.     T=Tem*2;
  79.     if(T>=27315)
  80.     {
  81.         T=T-27315;
  82.                 dis1[5]=' ';             // 符号位
  83.     }
  84.     else
  85.     {
  86.         T=27315-T;   
  87.                 dis1[5]='-';             // 符号位

  88.     }
  89.     a=T/100;
  90.         b=T-a*100;
  91.         dis1[5]=a/100+0x30;      // 百位
  92.         dis1[6]=(a%100)/10+0x30; // 十位
  93.         dis1[7]=a%10+0x30;       // 个位
  94.         dis1[9]=b/10+0x30;      //十分位
  95.         dis1[10]=b%10+0x30;      //百分位        

  96.         if(Min_Tem<0)
  97.         {
  98.            dis2[3]='-';
  99.            min=-Min_Tem/100;
  100.         }
  101.         else
  102.         {
  103.            dis2[3]=' ';
  104.            min=Min_Tem/100;
  105.         }        
  106.         if(Max_Tem<0)
  107.         {
  108.            dis2[10]='-';
  109.            max=-Max_Tem/100;
  110.         }
  111.         else
  112.         {
  113.            dis2[10]=' ';
  114.            max=Max_Tem/100;
  115.         }        
  116.         
  117.         dis2[4] = min/100+0x30;                                //Min
  118.         dis2[5] = (min%100)/10+0x30;
  119.         dis2[6] = min%10+0x30;

  120.         dis2[11]= max/100+0x30;                           //Max
  121.         dis2[12]= (max%100)/10+0x30;
  122.         dis2[13]= max%10+0x30;

  123.         if(status==0)
  124.         {
  125.                 dis2[0] = ' ';
  126.                 dis2[7] = ' ';
  127.         }               

  128.         if(status==1)
  129.         {
  130.                 dis2[0] = '>';
  131.                 dis2[7] = ' ';
  132.         }
  133.                
  134.         if(status==2)
  135.         {
  136.                 dis2[0] = ' ';
  137.                 dis2[7] = '>';
  138.         }
  139.         
  140. }


  141. void start_bit(void)
  142. {
  143.     SDA=1;
  144.     _nop_();
  145.     _nop_();
  146.     _nop_();
  147.     _nop_();
  148.     _nop_();
  149.     SCL=1;
  150.     _nop_();
  151.     _nop_();
  152.     _nop_();
  153.     _nop_();
  154.     _nop_();
  155.     SDA=0;
  156.     _nop_();
  157.     _nop_();
  158.     _nop_();
  159.     _nop_();
  160.     _nop_();
  161.     SCL=0;
  162.     _nop_();
  163.     _nop_();
  164.     _nop_();
  165.     _nop_();
  166.     _nop_();
  167. }
  168. //------------------------------
  169. void stop_bit(void)
  170. {
  171.     SCL=0;
  172.     _nop_();
  173.     _nop_();
  174.     _nop_();
  175.     _nop_();
  176.     _nop_();
  177.     SDA=0;
  178.     _nop_();
  179.     _nop_();
  180.     _nop_();
  181.     _nop_();
  182.     _nop_();
  183.     SCL=1;
  184.     _nop_();
  185.     _nop_();
  186.     _nop_();
  187.     _nop_();
  188.     _nop_();
  189.     SDA=1;
  190. }
  191. //---------发送一个字节---------
  192. void tx_byte(uchar dat_byte)
  193. {
  194.     char i,n,dat;
  195.     n=Nack_counter;
  196. TX_again:
  197.     dat=dat_byte;
  198.     for(i=0; i<8; i++)
  199.     {
  200.         if(dat&0x80)
  201.             bit_out=1;
  202.         else
  203.             bit_out=0;
  204.         send_bit();
  205.         dat=dat<<1;
  206.     }
  207.     receive_bit();
  208.     if(bit_in==1)
  209.     {
  210.         stop_bit();
  211.         if(n!=0)
  212.         {
  213.             n--;
  214.             goto Repeat;
  215.         }
  216.         else
  217.             goto exit;
  218.     }
  219.     else
  220.         goto exit;
  221. Repeat:
  222.     start_bit();
  223.     goto TX_again;
  224. exit:
  225.     ;
  226. }
  227. //-----------发送一个位---------
  228. void send_bit(void)
  229. {
  230.     if(bit_out==0)
  231.         SDA=0;
  232.     else
  233.         SDA=1;
  234.     _nop_();
  235.     SCL=1;
  236.     _nop_();
  237.     _nop_();
  238.     _nop_();
  239.     _nop_();
  240.     _nop_();
  241.     _nop_();
  242.     _nop_();
  243.     _nop_();
  244.     SCL=0;
  245.     _nop_();
  246.     _nop_();
  247.     _nop_();
  248.     _nop_();
  249.     _nop_();
  250.     _nop_();
  251.     _nop_();
  252.     _nop_();
  253. }
  254. //----------接收一个字节--------
  255. uchar rx_byte(void)
  256. {
  257.     uchar i,dat;
  258.     dat=0;
  259.     for(i=0; i<8; i++)
  260.     {
  261.         dat=dat<<1;
  262.         receive_bit();
  263.         if(bit_in==1)
  264.             dat=dat+1;
  265.     }
  266.     send_bit();
  267.     return dat;
  268. }
  269. //----------接收一个位----------
  270. void receive_bit(void)
  271. {
  272.     SDA=1;
  273.     bit_in=1;
  274.     SCL=1;
  275.     _nop_();
  276.     _nop_();
  277.     _nop_();
  278.     _nop_();
  279.     _nop_();
  280.     _nop_();
  281.     _nop_();
  282.     _nop_();
  283.     bit_in=SDA;
  284. ……………………

  285. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei附件下载:
程序与原理图.7z (583.09 KB, 下载次数: 27)
03.jpg
IMG_20200830_175948_副本.jpg

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:981841 发表于 2021-12-13 09:56 | 显示全部楼层
第二次的发帖
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表