找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6712|回复: 4
收起左侧

DS18B20的8路温度检测程序和AD格式原理图

[复制链接]
ID:205862 发表于 2017-5-30 10:48 | 显示全部楼层 |阅读模式
基于DS18B20的8路温度检测程序

原理图altium格式.SchDoc:
0.png

0.png

0.png



单片机源程序如下:
  1. #include "lcd1602.h"
  2. #include "18b20.h"
  3. #include "key_contrl.h"
  4. #include <reg52.h>
  5. #include <usart.c>
  6. sbit beep = P2^0; //beep = 0时候发声
  7. sbit K1=P1^4;
  8. sbit K2=P1^5;
  9. sbit K3=P1^6;
  10. unsigned char Mode;

  11. int TempH = 380;                    //初始上限值
  12. int TempL = 100;                                          //初始下限值

  13. unsigned char  SN[8][8]={
  14. {0x28,0xEE,0xc8,0x47,0x1b,0x16,0x02,0x2f},

  15. {0x28,0xee,0x97,0xf6,0x1c,0x16,0x02,0xb1},

  16. {0x28,0xee,0x6c,0x48,0x1b,0x16,0x02,0x99},

  17. {0x28,0xee,0xcf,0x46,0x1b,0x16,0x02,0xf1},

  18. {0x28,0xee,0x1e,0x49,0x1b,0x16,0x02,0xf8},

  19. {0x28,0xee,0x55,0x67,0x1b,0x16,0x02,0x04},

  20. {0x28,0xee,0x4c,0x4b,0x1b,0x16,0x02,0xe9},

  21. {0x28,0xee,0x30,0x6a,0x1b,0x16,0x02,0x5a},
  22. };//二维数组存取序列号

  23. void KEY()
  24. {
  25.         if(K1==0)
  26.         {
  27.                 delay_ms(10);
  28.                 if(K1==0);
  29.                 {
  30.                         Mode++;
  31.                         if(Mode==4)
  32.                                 Mode=0;
  33.                         while(!K1);
  34.                 }
  35.         }
  36. }

  37. void main(void)
  38. {        u8 num;
  39.         u16 temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8;
  40.         LCD_Init();
  41.         UartInit();
  42.         while(1)
  43.         {
  44.                 temp1=ReadTemperature(0);Send_string("第1路温度:");SendData(temp1/100%10+48);SendData(temp1/10%10+48);SendData('.');SendData(temp1/1%10+48);Send_string("度:");SendData('\r');SendData('\n');
  45.                 temp2=ReadTemperature(1);Send_string("第2路温度:");SendData(temp2/100%10+48);SendData(temp2/10%10+48);SendData('.');SendData(temp2/1%10+48);Send_string("度:");SendData('\r');SendData('\n');
  46.                 temp3=ReadTemperature(2);Send_string("第3路温度:");SendData(temp3/100%10+48);SendData(temp3/10%10+48);SendData('.');SendData(temp3/1%10+48);Send_string("度:");SendData('\r');SendData('\n');
  47.                 temp4=ReadTemperature(3);Send_string("第4路温度:");SendData(temp4/100%10+48);SendData(temp4/10%10+48);SendData('.');SendData(temp4/1%10+48);Send_string("度:");SendData('\r');SendData('\n');
  48.                 temp5=ReadTemperature(4);Send_string("第5路温度:");SendData(temp5/100%10+48);SendData(temp5/10%10+48);SendData('.');SendData(temp5/1%10+48);Send_string("度:");SendData('\r');SendData('\n');
  49.                 temp6=ReadTemperature(5);Send_string("第6路温度:");SendData(temp6/100%10+48);SendData(temp6/10%10+48);SendData('.');SendData(temp6/1%10+48);Send_string("度:");SendData('\r');SendData('\n');
  50.                 temp7=ReadTemperature(6);Send_string("第7路温度:");SendData(temp7/100%10+48);SendData(temp7/10%10+48);SendData('.');SendData(temp7/1%10+48);Send_string("度:");SendData('\r');SendData('\n');
  51.                 temp8=ReadTemperature(7);Send_string("第8路温度:");SendData(temp8/100%10+48);SendData(temp8/10%10+48);SendData('.');SendData(temp8/1%10+48);Send_string("度:");SendData('\r');SendData('\n');SendData('\r');SendData('\n');
  52.                 delay_ms(1000);
  53.                 KEY();
  54.                 switch(Mode)
  55.                 {        
  56.                         
  57.                         case 0:
  58.                         {        
  59.                                 num++;
  60.                                 if(num<3)
  61.                                 {        LCD_Display_String(0x00,"1:");
  62.                                         LCD_Write_Cmd(0x82);
  63.                                         LCD_Write_Data(temp1/100%10+48);
  64.                                         LCD_Write_Data(temp1/10%10+48);
  65.                                         LCD_Write_Data('.');
  66.                                         LCD_Write_Data(temp1%10+48);
  67.                                         LCD_Write_Data(0xdf);
  68.                                         LCD_Write_Data(' ');

  69.                                         LCD_Display_String(0x08,"2:");
  70.                                         LCD_Write_Cmd(0x8a);
  71.                                         LCD_Write_Data(temp2/100%10+48);
  72.                                         LCD_Write_Data(temp2/10%10+48);
  73.                                         LCD_Write_Data('.');
  74.                                         LCD_Write_Data(temp2%10+48);
  75.                                         LCD_Write_Data(0xdf);
  76.                                         LCD_Write_Data(' ');

  77.                                         LCD_Display_String(0x40,"3:");
  78.                                         LCD_Write_Cmd(0xc2);
  79.                                         LCD_Write_Data(temp3/100%10+48);
  80.                                         LCD_Write_Data(temp3/10%10+48);
  81.                                         LCD_Write_Data('.');
  82.                                         LCD_Write_Data(temp3%10+48);
  83.                                         LCD_Write_Data(0xdf);
  84.                                         LCD_Write_Data(' ');

  85.                                         LCD_Display_String(0x48,"4:");
  86.                                         LCD_Write_Cmd(0xca);
  87.                                         LCD_Write_Data(temp4/100%10+48);
  88.                                         LCD_Write_Data(temp4/10%10+48);
  89.                                         LCD_Write_Data('.');
  90.                                         LCD_Write_Data(temp4%10+48);
  91.                                         LCD_Write_Data(0xdf);
  92.                                         LCD_Write_Data(' ');
  93.                                 }
  94.                                 else if(num<6)
  95.                                 {
  96.                                         LCD_Display_String(0x00,"5:");
  97.                                         LCD_Write_Cmd(0x82);
  98.                                         LCD_Write_Data(temp5/100%10+48);
  99.                                         LCD_Write_Data(temp5/10%10+48);
  100.                                         LCD_Write_Data('.');
  101.                                         LCD_Write_Data(temp5%10+48);
  102.                                         LCD_Write_Data(0xdf);
  103.                                         LCD_Write_Data(' ');

  104.                                         LCD_Display_String(0x08,"6:");
  105.                                         LCD_Write_Cmd(0x8a);
  106.                                         LCD_Write_Data(temp6/100%10+48);
  107.                                         LCD_Write_Data(temp6/10%10+48);
  108.                                         LCD_Write_Data('.');
  109.                                         LCD_Write_Data(temp6%10+48);
  110.                                         LCD_Write_Data(0xdf);
  111.                                         LCD_Write_Data(' ');

  112.                                         LCD_Display_String(0x40,"7:");
  113.                                         LCD_Write_Cmd(0xc2);
  114.                                         LCD_Write_Data(temp7/100%10+48);
  115.                                         LCD_Write_Data(temp7/10%10+48);
  116.                                         LCD_Write_Data('.');
  117.                                         LCD_Write_Data(temp7%10+48);
  118.                                         LCD_Write_Data(0xdf);
  119.                                         LCD_Write_Data(' ');

  120.                                         LCD_Display_String(0x48,"8:");
  121.                                         LCD_Write_Cmd(0xca);
  122.                                         LCD_Write_Data(temp8/100%10+48);
  123.                                         LCD_Write_Data(temp8/10%10+48);
  124.                                         LCD_Write_Data('.');
  125.                                         LCD_Write_Data(temp8%10+48);
  126.                                         LCD_Write_Data(0xdf);
  127.                                         LCD_Write_Data(' ');

  128.                                 }
  129.                                 else num=0;
  130.                         }
  131.                                         break;
  132.                         case 1:
  133.                                         LCD_Display_String(0x00,"High Limit:");
  134.                                         LCD_Write_Cmd(0x8b);
  135.                                         LCD_Write_Data(TempH/100%10+48);
  136.                                         LCD_Write_Data(TempH/10%10+48);
  137.                                         LCD_Write_Data('.');
  138.                                         LCD_Write_Data(TempH%10+48);
  139.                                         LCD_Write_Data(0xdf);
  140.                                         LCD_Display_String(0x40,"Low  Limit:");
  141.                                         LCD_Write_Cmd(0xcb);
  142.                                         LCD_Write_Data(TempL/100%10+48);
  143.                                         LCD_Write_Data(TempL/10%10+48);
  144.                                         LCD_Write_Data('.');
  145.                                         LCD_Write_Data(TempL%10+48);
  146.                                         LCD_Write_Data(0xdf);
  147.                                         break;
  148.                         case 2:
  149.                                         if(K2==0)
  150.                                         {
  151.                                                 delay_ms(10);
  152.                                                 if(K2==0)
  153.                                                 {
  154.                                                         TempH+=10;
  155.                                                         if(TempH>=990)
  156.                                                                 TempH=990;
  157.                                                 }
  158.                                         }
  159.                                         if(K3==0)
  160.                                         {
  161.                                                 delay_ms(10);
  162.                                                 if(K3==0)
  163.                                                 {
  164.                                                         TempH-=10;
  165.                                                         if(TempH<=TempL)
  166.                                                                 TempH=TempL;
  167.                                                 }
  168.                                         }
  169.                                         LCD_Write_Cmd(0x8b);
  170.                                         LCD_Write_Data(TempH/100%10+48);
  171.                                         LCD_Write_Data(TempH/10%10+48);
  172.                                         LCD_Write_Data('.');
  173.                                         LCD_Write_Data(TempH%10+48);
  174.                                         LCD_Write_Data(0xdf);
  175.                                         LCD_Write_Cmd(0x8d);
  176.                                         LCD_Write_Cmd(0x0f); //开光标
  177.                                         break;
  178.                         case 3:
  179.                                         if(K2==0)
  180.                                         {
  181.                                                 delay_ms(10);
  182.                                                 if(K2==0)
  183.                                                 {
  184.                                                         TempL+=10;
  185.                                                         if(TempL>=TempH)
  186.                                                                 TempL=TempH;
  187.                                                 }
  188.                                         }
  189.                                         if(K3==0)
  190.                                         {
  191.                                                 delay_ms(10);
  192.                                                 if(K3==0)
  193.                                                 {
  194.                                                         TempL-=10;
  195.                                                         if(TempL<=0)
  196. ……………………

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

所有资料51hei提供下载:
资料2.zip (197.09 KB, 下载次数: 108)
回复

使用道具 举报

ID:317036 发表于 2018-4-26 15:12 | 显示全部楼层
非常有用对于我们初学者
回复

使用道具 举报

ID:324052 发表于 2018-5-7 14:07 | 显示全部楼层
感谢分享                  
回复

使用道具 举报

ID:633417 发表于 2019-11-5 09:57 | 显示全部楼层
我想知道里面的封装是自己画的还是在库里找的??
回复

使用道具 举报

ID:688089 发表于 2020-5-16 17:06 | 显示全部楼层
万分感谢楼主,很有帮助!
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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