新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 用DS18B20構(gòu)成測(cè)溫系統(tǒng)

        用DS18B20構(gòu)成測(cè)溫系統(tǒng)

        作者: 時(shí)間:2012-10-12 來(lái)源:網(wǎng)絡(luò) 收藏

        用DS18B20構(gòu)成測(cè)溫系統(tǒng)
        3、電路圖

        4、源程序

        #include AT89X52.H>

        #include INTRINS.h>

        unsigned char code displaybit[]={0xfe,0xfd,0xfb,0xf7,

        0xef,0xdf,0xbf,0x7f};

        unsigned char code displaycode[]={0x3f,0x06,0x5b,0x4f,

        0x66,0x6d,0x7d,0x07,

        0x7f,0x6f,0x77,0x7c,

        0x39,0x5e,0x79,0x71,0x00,0x40};

        unsigned char code dotcode[32]={0,3,6,9,12,16,19,22,

        25,28,31,34,38,41,44,48,

        50,53,56,59,63,66,69,72,

        75,78,81,84,88,91,94,97};

        unsigned char displaycount;

        unsigned char displaybuf[8]={16,16,16,16,16,16,16,16};

        unsigned char timecount;

        unsigned char readdata[8];

        sbit DQ=P3^7;

        bit sflag;

        bit resetpulse(void)

        {

        unsigned char i;

        DQ=0;

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

        DQ=1;

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

        return(DQ);

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

        }

        void writecommandtods18b20(unsigned char command)

        {

        unsigned char i;

        unsigned char j;

        for(i=0;i8;i++)

        {

        if((command 0x01)==0)

        {

        DQ=0;

        for(j=35;j>0;j--);

        DQ=1;

        }

        else

        {

        DQ=0;

        for(j=2;j>0;j--);

        DQ=1;

        for(j=33;j>0;j--);

        }

        command=_cror_(command,1);

        }

        }

        unsigned char readdatafromds18b20(void)

        {

        unsigned char i;

        unsigned char j;

        unsigned char temp;

        temp=0;

        for(i=0;i8;i++)

        {

        temp=_cror_(temp,1);

        DQ=0;

        _nop_();

        _nop_();

        DQ=1;

        for(j=10;j>0;j--);

        if(DQ==1)

        {

        temp=temp | 0x80;

        }

        else

        {

        temp=temp | 0x00;

        }

        for(j=200;j>0;j--);

        }

        return(temp);

        }



        評(píng)論


        相關(guān)推薦

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

        關(guān)閉
        主站蜘蛛池模板: 五莲县| 新和县| 深水埗区| 南丹县| 许昌市| 岳普湖县| 西城区| 高碑店市| 万载县| 霍山县| 永济市| 沧州市| 临潭县| 常宁市| 平山县| 林周县| 宁安市| 榕江县| 贵州省| 迁安市| 栾川县| 依兰县| 宁明县| 高雄市| 平潭县| 浦县| 普定县| 清苑县| 桐乡市| 江源县| 安徽省| 孝感市| 沙坪坝区| 温宿县| 织金县| 汶上县| 上栗县| 图片| 澄江县| 余江县| 辽宁省|