欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

    標題: 請問溫度控制系統(tǒng)DS18B20顯示器上沒有溫度數(shù)據(jù)要如何修改調(diào)試,求方向 [打印本頁]

    作者: Maggie0517    時間: 2021-6-19 13:56
    標題: 請問溫度控制系統(tǒng)DS18B20顯示器上沒有溫度數(shù)據(jù)要如何修改調(diào)試,求方向

    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--;

    復(fù)制代碼




    作者: Maggie0517    時間: 2021-6-19 13:58
    用keil寫程序檢查是正確的,但是顯示器上始終沒有溫度顯示,請問是什么原因,該如何顯示?拜托各位論壇大神撈撈孩子!!球球了QAQ
    作者: yzwzfyz    時間: 2021-6-21 13:58
    走單路,看看每一步有沒有達成目的。
    作者: lishengaha    時間: 2021-6-22 00:32
    先查看是1602的問題還是18b20的問題。在測溫前隨便顯示點啥。如果不能顯示就找1602的問題。如果能顯示有可能是18b20程序卡死
    作者: 1986654946    時間: 2021-6-22 08:28
    教你一個實用的調(diào)試方法:
    1.編寫一個串口發(fā)送的程序,在主程序中發(fā)送字符串給調(diào)試助手,確保程序通暢
    2.如果主程序通暢無阻,在各個模塊內(nèi)進行相同調(diào)試,例如,在DS18B20子函數(shù)中發(fā)送串口數(shù)據(jù),確保DS18B20順利的進行了數(shù)據(jù)的采集、數(shù)據(jù)的轉(zhuǎn)換(最后將溫度數(shù)據(jù)發(fā)送至串口調(diào)試助手);同樣的,若DS18B20沒有問題,則問題肯定出現(xiàn)在1602顯示,跳過溫度首先在1602上顯示一些無關(guān)數(shù)據(jù)檢查是否是程序編寫問題,最后檢車硬件。




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