<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          PIC16F877A例程---DS18B20

          作者: 時間:2016-11-24 來源:網(wǎng)絡(luò) 收藏

          本文引用地址:http://www.ex-cimer.com/article/201611/321024.htm

          void WRITE_LCD_CMD(char cmd)

          {

          LCD1602_BUSY();

          TRISB & =0XF8;

          TRISD=0;

          LCDDATA=cmd;

          LCDRS=0;

          LCDRW=0;

          LCDE=0;

          asm("NOP");

          asm("NOP");

          LCDE=1;

          }

          void LCD1602_INIT(void)

          {

          LCD1602_BUSY();

          TRISB &= 0XF8;

          TRISD=0;

          WRITE_LCD_CMD(CLRLCD);

          WRITE_LCD_CMD(LCDMOD);

          WRITE_LCD_CMD(TURNON);

          WRITE_LCD_CMD(CURMODE);

          LCD_Display_location (0,0);

          }

          void DS18B20_INIT()

          {

          TRIS_B20=0;

          DS18B20=0;

          US_delay(20);

          TRIS_B20=1;

          US_delay(10);

          }

          void WRITE_DS18B20_CMD(char cmd)

          {

          char tmp;

          char i;

          TRIS_B20=0;

          for(tmp=8;tmp>0;tmp--)

          {

          TRIS_B20=0;

          DS18B20= 0;

          asm ("NOP");

          asm ("NOP");

          asm ("NOP");

          asm ("NOP");

          asm ("NOP");

          if (cmd & 0x01)

          {

          TRIS_B20=1;

          US_delay(1);

          for (i=5;i>0;i--);

          }

          else

          {

          DS18B20=0 ;

          US_delay(1);

          for (i=5;i>0;i--);

          TRIS_B20=1;

          }

          cmd=cmd/2;

          }

          }

          float READ_DS18B20 ()

          {

          char tmp=0x01;

          float t;

          union

          {

          char c[2];

          int x;

          }temp;

          temp.x=0;

          while (tmp)

          { // read first 8 bits

          TRIS_B20=0;

          DS18B20=0;

          asm("NOP");

          TRIS_B20=1;

          if (DS18B20)

          temp.c[0] |= tmp;

          tmp=tmp<<1;

          US_delay(2);

          }

          tmp=1;

          while (tmp)

          { // read first 8 bits

          TRIS_B20=0;

          DS18B20=0;

          asm("NOP");

          TRIS_B20=1; // release the bus

          asm("NOP");

          if (DS18B20) // "1" presented

          temp.c[1] |= tmp;

          tmp=tmp<<1;

          US_delay(2);

          }

          t=((float) temp.x)/16.0 ;

          return t;

          }

          void itoa10(unsigned char *buf, int i)

          {

          unsigned int rem;

          unsigned char *s,length=0;

          s = buf;

          if (i == 0)

          *s++ = 0;

          else

          {

          if (i < 0)

          {

          *buf++ = -;

          s = buf;

          i = -i;

          }

          while (i)

          {

          ++length;

          rem = i % 10;

          *s++ = rem + 0;

          i /= 10;

          }

          for(rem=0; ((unsigned char)rem)

          {

          *(buf+length) = *(buf+((unsigned char)rem));

          *(buf+((unsigned char)rem)) = *(buf+(length-((unsigned char)rem)-1));

          *(buf+(length-((unsigned char)rem)-1)) = *(buf+length);

          }

          }

          *s=0;

          }

          void US_delay( int i)

          {

          unsigned char j;

          while(i--)

          {

          j=3;

          while(j--);

          }

          }


          上一頁 1 2 下一頁

          關(guān)鍵詞: PIC16F877ADS18B2

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();