芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

飞芯科技-芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

芯片解密PIC单片机DS18B20读取温度程序

芯片解密DS18B20温度的读取
//环 境 :PIC单片机
//时 序 :4.00 晶振
/////////////////////////////////////////////
#include<pic.h>
/////////////////////////////////////////////
#define uchar unsigned char
#define uint  unsigned int
/////////////////////////////////////////////
#define DQ  RC3
#define DQ_HIGH()  TRISC3=1
#define DQ_LOW()  TRISC3=0;DQ=0
/////////////////////////////////////////////
void reset(void);
void write_byte(uchar date);
uchar read_byte(void);
void yanshius(uint t);
void start_t(void);
signed int read_t(void);
/////////////////////////////////////////////
void yanshius(uint t)
{
        uint i;
        for(i=0;i<t;i++)
        {        NOP();        }
}
void reset(void)
{
        uchar st=1;
        while(st)
        {
                DQ_LOW();
                yanshius(29);//510uS
                DQ_HIGH();
                yanshius(2);//60uS
                if(DQ==1)
                        st=1;
                else
                {        st=0;
                         yanshius(25);//480uS
                }
        }
}
void write_byte(uchar date)
{
        uchar i,temp;
        for(i=8;i>0;i--)
        {
                temp=date & 0x01;//01010101
                DQ_LOW();
                if(temp == 1)
                {        NOP();NOP();
                        DQ_HIGH();
                        yanshius(2);       
                }
                else
                {
                        yanshius(2);//60uS
                        DQ_HIGH();       
                }       
                NOP();NOP();
                date = date>>1;//00101010yanshius(0);
        }
}
uchar read_byte(void)
{
        uchar i,date;
        static bit j;
        for(i=8;i>0;i--)
        {
                date = date>>1;
                DQ_LOW();
                NOP();NOP();
                DQ_HIGH();
                NOP();NOP();NOP();NOP();NOP();NOP();NOP();
                j = DQ;
                if(j == 1)
                {
                        date=date|0x80;//1000 0000                       
                }       
                yanshius(1);//47uS
        }
        return date;
}

void start_t(void)
{
        reset();  //复位
        write_byte(0xCC);//跳过ROM
        write_byte(0x44);//温度转换
}
//////读取的温度数值是放大10倍
signed int read_t(void)
{
        uchar tem1,tem2;
        uint tt,mm=0;
        double aaa;
        signed int temper;
        reset();
        write_byte(0xCC);
        write_byte(0xBE);
        tem1=read_byte();
        tem2=read_byte();
        tt = tem2;
        tt = tt<<8|tem1;
        if(tt&0x8000)
        {
                mm = ~tt + 1;
                aaa = mm * (-0.625);
        }
        else
        {
                aaa = tt*0.625;
        }
        temper=(signed int)aaa;
        return temper;       
}


联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.feixindz.com
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信