找回密码
 立即注册

QQ登录

只需一步,快速开始

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

请问温度控制系统DS18B20显示器上没有温度数据要如何修改调试,求方向

[复制链接]
ID:939630 发表于 2021-6-19 13:56 | 显示全部楼层 |阅读模式
51hei图片20210619135527.png 51hei图片20210619135539.png
  1. #include<reg51.h>
  2. #include<intrins.h>
  3. #include<absacc.h>
  4. #define uchar unsigned char
  5. #define uint  unsigned int
  6. #define BUSY 0x80
  7. sbit RS=P2^0;
  8. sbit RW=P2^1;
  9. sbit E=P2^2;
  10. sbit DQ=P2^7;
  11. sbit LED=P3^7;
  12. uchar  temp_data_L,temp_data_H;
  13. uchar code look_ASCII[10]=
  14. {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
  15. uchar code TABLE_DECIMAL[16]=
  16. {0X30,0X31,0X31,0X32,0X33,0X33,0X34,0X34,0X35,0X36,0X36,0X37,0X38,0X38,0X39,0X39};
  17. uchar display1[16]=
  18. {0x53,0x45,0x54,0x5F,0x54,0x45,0x4D,0x50,0x3A,0x00,0x00,0x00,0x2E,0x30,0xDF,0x43};
  19. uchar display2[16]=
  20. {0x43,0x55,0x52,0x5F,0x54,0x45,0x4D,0x50,0x3A,0x00,0x00,0x00,0x2E,0x00,0xDF,0x43};
  21. uint temp_current,temp_set=40;
  22. void delay(uint m)
  23. {
  24.   uint i;
  25.   for(i=0;i<m;i++);
  26. }
  27. bit resetpulse(void)
  28. {
  29.   DQ=0;
  30.   delay(40);
  31.   DQ=1;
  32.   delay(4);
  33.   return(DQ);
  34. }
  35. void DS18B20_init(void)
  36. {
  37.   while(1)
  38.   {
  39.    if(!resetpulse())
  40.    {
  41.      DQ=1;
  42.          delay(40);
  43.          break;
  44.    }
  45.    else
  46.           resetpulse();
  47.   }
  48. }
  49. uchar read_bit(void)
  50. {
  51.   DQ=0;
  52.   _nop_();
  53.   _nop_();
  54.   DQ=1;
  55.   delay(2);
  56.   return(DQ);
  57. }
  58. uchar read_byte(void)
  59. {
  60.   uchar i,shift,temp;
  61.   shift=1;
  62.   temp=0;
  63.   for(i=0;i<8;i++)
  64.   {
  65.     if(read_bit())
  66.         {
  67.           temp=temp+(shift<<i);
  68.         }
  69.         delay(7);
  70.   }
  71.     return(temp);
  72. }
  73. void write_bit(uchar temp)
  74. {
  75.   DQ=0;
  76.   if(temp==1)
  77.   DQ=1;
  78.   delay(5);
  79.   DQ=1;
  80. }
  81. void write_byte(uchar value)
  82. {
  83.   uchar i,temp;
  84.   for(i=0;i<8;i++)
  85.   {
  86.     temp=value>>i;
  87.         temp=temp&0x01;
  88.         write_bit(temp);
  89.         delay(5);
  90.   }
  91. }
  92. void read_temp()
  93. {
  94.   DS18B20_init();
  95.   write_byte(0xCC);
  96.   write_byte(0x44);
  97.   delay(500);
  98.   DS18B20_init();
  99.   write_byte(0xCC);
  100.   write_byte(0xBE);
  101.   temp_data_L=read_byte();
  102.   temp_data_H=read_byte();
  103. }
  104. void test_LCDbusy()
  105. {
  106.   P0=0xFF;
  107.   E=1;
  108.   RS=0;
  109.   RW=1;
  110.   _nop_();
  111.   while(P0&BUSY)
  112.   {
  113.     E=0;
  114.         _nop_();
  115.         E=1;
  116.         _nop_();
  117.   }
  118.   E=0;
  119. }
  120. void write_LCDcomm(uchar Comm)
  121. {
  122.   test_LCDbusy();
  123.   RS=0;
  124.   RW=0;
  125.   E=0;
  126.   _nop_();
  127.   P0=Comm;
  128.   _nop_();
  129.   E=1;
  130.   _nop_();
  131.   E=0;
  132.   }
  133.   void write_LCDdata(uchar Data)
  134.   {
  135.     test_LCDbusy();
  136.         P0=Data;
  137.         RS=1;
  138.         RW=1;
  139.         E=1;
  140.         _nop_();
  141.         E=0;
  142.   }
  143. void convert_temp()
  144. {
  145.   if((temp_data_H&0xF0)==0xF0)
  146.   {
  147.     temp_data_L=~temp_data_L;
  148.         if(temp_data_L==0xFF)
  149.         {
  150.           temp_data_L=temp_data_L+0x01;
  151.           temp_data_H=~temp_data_H;
  152.           temp_data_H=~temp_data_H+0x01;
  153.         }
  154.     else
  155.     {
  156.           temp_data_L=temp_data_L+0x01;
  157.           temp_data_H=~temp_data_H;
  158.         }
  159.     display2[13]=TABLE_DECIMAL[temp_data_L&0x0F];
  160.         temp_current=((temp_data_L&0xF0)>>4)|((temp_data_H&0x0F)<<4);
  161.         display2[9]=0x2D;
  162.         display2[10]=look_ASCII[(temp_current%100)/10];
  163.         display2[11]=look_ASCII[(temp_current%100)%10];
  164.         if((temp_current%100)/10==0)
  165.         {
  166.           display2[9]=0;
  167.           display2[10]=0x2D;
  168.         }
  169.         else
  170.         {
  171.           display2[13]=TABLE_DECIMAL[temp_data_L&0x0F];
  172.           temp_current=((temp_data_L&0xF0)>>4)|((temp_data_H&0x0F)<<4);
  173.           display2[9]=look_ASCII[temp_current/100];
  174.           display2[10]=look_ASCII[(temp_current%100)/10];
  175.           display2[11]=look_ASCII[(temp_current%100)%10];
  176.           if(temp_current/100==0)
  177.           {
  178.             display2[9]=0;
  179.             if((temp_current%100)/10==0)display2[10]=0;
  180.           }
  181.         }
  182.   }
  183. }
  184. void set_temp()
  185. {
  186.   display1[9]=look_ASCII[temp_set/100];
  187.   display1[10]=look_ASCII[(temp_set%100)/10];
  188.   display1[11]=look_ASCII[(temp_set%100)%100];
  189.   if(temp_set/100==0)
  190.   {
  191.     display1[9]=0;
  192.         if((temp_set%100)/10==0)display1[10]=0;
  193.   }
  194. }
  195. void init_LCD(void)
  196. {
  197.   write_LCDcomm(0x01);
  198.   write_LCDcomm(0x38);
  199.   write_LCDcomm(0x0C);
  200.   write_LCDcomm(0x06);
  201. }
  202. void display_temp()
  203. {
  204.   uchar i;
  205.   write_LCDcomm(0x80);
  206.   for(i=0;i<16;i++)
  207.   {
  208.     write_LCDdata(display1[i]);
  209.   }
  210.   write_LCDcomm(0xC0);
  211.   for(i=0;i<16;i++)
  212.   {
  213.     write_LCDdata(display2[i]);
  214.   }
  215. }
  216. void main()
  217. {
  218.   IE=0x85;
  219.   IT0=1;
  220.   IT1=1;
  221.   init_LCD();
  222.   LED=0;
  223.   while(1)
  224.   {
  225.     read_temp();
  226.         convert_temp();
  227.         set_temp();
  228.         display_temp();
  229.         if(temp_current>=temp_set){LED=~LED;delay(20);}
  230.         else LED=0;
  231.         delay(20);
  232.   }
  233. }
  234. void EX_INT0()interrupt 0
  235. {
  236.   temp_set++;
  237. }
  238. void EX_INT1()interrupt 2
  239. {
  240.   temp_set--;

复制代码



回复

使用道具 举报

ID:939630 发表于 2021-6-19 13:58 | 显示全部楼层
用keil写程序检查是正确的,但是显示器上始终没有温度显示,请问是什么原因,该如何显示?拜托各位论坛大神捞捞孩子!!球球了QAQ
回复

使用道具 举报

ID:123289 发表于 2021-6-21 13:58 | 显示全部楼层
走单路,看看每一步有没有达成目的。
回复

使用道具 举报

ID:939710 发表于 2021-6-22 00:32 | 显示全部楼层
先查看是1602的问题还是18b20的问题。在测温前随便显示点啥。如果不能显示就找1602的问题。如果能显示有可能是18b20程序卡死
回复

使用道具 举报

ID:413530 发表于 2021-6-22 08:28 | 显示全部楼层
教你一个实用的调试方法:
1.编写一个串口发送的程序,在主程序中发送字符串给调试助手,确保程序通畅
2.如果主程序通畅无阻,在各个模块内进行相同调试,例如,在DS18B20子函数中发送串口数据,确保DS18B20顺利的进行了数据的采集、数据的转换(最后将温度数据发送至串口调试助手);同样的,若DS18B20没有问题,则问题肯定出现在1602显示,跳过温度首先在1602上显示一些无关数据检查是否是程序编写问题,最后检车硬件。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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