• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-19
  • 语言: 其他
  • 标签: DS18B20  MSP430  

资源简介

msp430单片机通过Proteus仿真DS18B20程序,刚刚调试通过,只要读写的时序按照文件里面的处理就行,显示部分就自己做吧

资源截图

代码片段和文件信息

#include “msp430f2491.h“
#include “DS18B20.h“
#include “define.h“
unsigned char  GetScratchpad[9];
//unsigned char GetScratchpad[9];
unsigned char ResultTemperatureH;  //温度的整数部分
unsigned char ResultTemperatureLH;  //温度的小数部分(高位)
unsigned char ResultTemperatureLL;  //温度的小数部分(低位)
 unsigned char decimalH[16]={00061218253137435056626875818793};
unsigned char decimalL[16]={00255075002550750025507500255075};
unsigned char dispcode[]={0x3f0x060x5b0x4f 
0x660x6d0x7d0x07 
0x7f0x6f0x770x7c 
0x390x5e0x790x710x000x40};    //0x40  负
unsigned char dispbitcode[]={0xfe0xfd0xfb0xf7 
0xef0xdf0xbf0x7f};   // 数码管为共阳极数码管,此数组存储的是阴极的管脚数据,依次可以点亮一个数码管对应P2口
unsigned char dispbuf[8]={00000000}; 
unsigned char DS18B20_Init_old(void){
  INT8U result;
   DS18B20_DIR |= DS18B20_DQ;       // ow output
 DS18B20_OUT |=DS18B20_DQ;
 _NOP();
  DS18B20_OUT &= ~DS18B20_DQ;      // DS18B20_DQ=0;
  Delay(90);
                                  // Bus master pulling low 480us minimum;
DS18B20_OUT |= DS18B20_DQ;      // DS18B20_DQ=1;
DS18B20_DIR &= ~DS18B20_DQ;
//Delay(8);                         // Resister pull up 15-60us;
        // ow input
  result = DS18B20_IN & DS18B20_DQ;
while(DS18B20_IN & DS18B20_DQ)
{
_NOP();
 
}
 
  DS18B20_DIR |= DS18B20_DQ;       // ow output
    Delay(19);                     // End of timeslot total 480us;
  DS18B20_OUT |=DS18B20_DQ;
    return(result);                  // any 1 wire device ?result:=1 no devide; ?result:=0 have device;
}


unsigned char DS18B20_ReadByte(void){
  INT8U i;
  INT8U result=0;
    DS18B20_DIR |= DS18B20_DQ;
   
  for(i = 8; i >0; i--)
  {
    DS18B20_OUT |= DS18B20_DQ;
    _NOP();
  //  result>>1;
    DS18B20_OUT &= ~DS18B20_DQ;
    
    _NOP();
    
    DS18B20_OUT |= DS18B20_DQ;
    _NOP();
    _NOP();
     _NOP();
    _NOP();
    DS18B20_DIR &=~DS18B20_DQ;
 
    if(P4IN&BIT3)
      result |=(1<    else
      result &=~(1<     Delay(3);
    DS18B20_DIR |= DS18B20_DQ;
  }
  
  return(result);       // return the result of the 1-wire device;
}//Read a byte from the 1-wire bus;
void DS18B20_WriteByte(INT8U oww_dat)
{
  INT8U i;
 DS18B20_DIR |= DS18B20_DQ;
  for(i = 0; i < 8; i++)
  {
       
       
    if(oww_dat & 0X01)
    {
      DS18B20_OUT |= DS18B20_DQ;
        _NOP();
     DS18B20_OUT  &=~DS18B20_DQ;
     _NOP();
     
     DS18B20_OUT |=DS18B20_DQ;
     Delay(8);
    } 
    else
    { 
       DS18B20_OUT |= DS18B20_DQ;
        _NOP();
      DS18B20_OUT  &=~DS18B20_DQ;
       Delay(8);
      _NOP();
      _NOP();
       
    }
     // Delay(8);
      DS18B20_OUT |=DS18B20_DQ;
      _NOP();
      oww_dat>>=1;
  }
   
}//Write a byte to the 1-wire bus;

unsigned char DS18B20_ReadTemp(void)
{ INT8U  tempHtempL;
  INT8U X=0;
 DS18B20_Init_old();
 DS18B20_WriteByte(SkipRom);
 _NOP();
 //_NOP();
 //_NOP();
  //There is

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5722  2011-04-26 22:34  DS18B20.c

     文件        988  2011-04-26 22:35  DS18B20.h

----------- ---------  ---------- -----  ----

                 6710                    2


评论

共有 条评论