在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > AVR128的程序——DS18B20

            AVR128的程序——DS18B20

            作者: 時間:2016-11-22 來源:網(wǎng)絡 收藏
            #include
            #include
            #define uchar unsigned char
            #define uint unsigned int
            #define DQ_IN DDRE &= ~(1 << PE6)
            #define DQ_OUT DDRE |= (1 << PE6)
            #define DQ_CLR PORTE &= ~(1 << PE6)
            #define DQ_SET PORTE |= (1 << PE6)
            #define DQ_R PINE & (1 << PE6)
            uchar TempData[8];
            uchar WeiMa[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
            uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,
            0x92,0x82,0xf8,0x80,0x90,0xff};
            void Delayms(uint MS)
            {
            uint i,j;
            for( i=0;i
            for(j=0;j<1141;j++);
            }
            void Delayus(uint US)
            {
            uint i;
            US=US*5/4;
            for( i=0;i
            }
            void smg_init(void)
            {
            DDRA=0XFF;
            PORTA=0XFF;
            DDRC=0XFF;
            PORTC=0XFF;
            DDRF|=0X0E;
            PORTF|=0X0E;
            PORTF&=0xF7;
            DDRB |=0X10;
            PORTB|=0X10;
            }
            unsigned char ds1820_reset(void)
            {
            unsigned char i;
            DQ_OUT;
            DQ_CLR;
            Delayus(500);
            DQ_SET;
            DQ_IN;
            Delayus(100);
            i = DQ_R;
            Delayus(500);
            return i;
            }
            unsigned char ds1820_read_byte(void)
            {
            unsigned char i;
            unsigned char value = 0;
            for (i = 0; i < 8; i++)
            {
            value >>= 1;
            DQ_OUT;
            DQ_CLR;
            Delayus(10);
            DQ_SET;
            DQ_IN;
            if (DQ_R) value|=0x80;
            Delayus(60);
            }
            return value;
            }
            void ds1820_write_byte(unsigned char value)
            {
            unsigned char i;
            for (i = 0; i < 8; i++)
            {
            DQ_OUT;
            DQ_CLR;
            Delayus(10);
            if (value & 0x01) DQ_SET;
            Delayus(100);
            DQ_SET;
            value >>= 1;
            }
            }
            void data_pro(uchar data)
            {
            TempData[2] = led_discode[data0];
            TempData[1] = led_discode[data0/10];
            TempData[0] = led_discode[data/100];
            }
            void display(uchar FirstBit,uchar Num)
            {
            unsigned char i;
            for(i=0;i
            {
            PORTC=led_discode[10];
            PORTA=WeiMa[i+FirstBit];
            PORTC=TempData[i];
            Delayms(2);
            }
            }
            void display1(uchar FirstBit,uchar Num)
            {
            unsigned char i;
            for(i=0;i
            {
            PORTC=led_discode[10];
            PORTA=WeiMa[i+FirstBit];
            PORTC=0X7F;
            Delayms(2);
            }
            }
            void main(void)
            {
            uchar i,j;
            uint temp;
            smg_init();
            while (1)
            {
            ds1820_reset();
            ds1820_write_byte(0xCC);
            ds1820_write_byte(0x44);
            Delayms(2);
            ds1820_reset();
            ds1820_write_byte(0xCC);
            ds1820_write_byte(0xbe);
            i=ds1820_read_byte();
            j=ds1820_read_byte();
            temp=j*256+i;
            temp=temp*0.625;
            data_pro(temp);
            display(5,3);
            display1(6,1);
            }
            }


            關(guān)鍵詞: AVR128DS18B2

            評論


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

            關(guān)閉