中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于ATMEGA16的DS18B20測(cè)溫程序

        基于ATMEGA16的DS18B20測(cè)溫程序

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

        //讀取溫度值先讀取暫存器的值在進(jìn)行溫度轉(zhuǎn)換否則會(huì)意外出錯(cuò)
        unsigned int readTemp(void)
        {
        unsigned char tempL,tempH;
        unsigned int temp;
        //開始讀取溫度
        ds18b20_reset();//18B20復(fù)位
        ds18b20_write_byte(0xcc);//跳過ROM
        ds18b20_write_byte(0xbe);//命令讀取暫存器
        tempL=ds18b20_read_byte();//從暫存器中讀取數(shù)據(jù)
        tempH=ds18b20_read_byte();//從暫存器中讀取數(shù)據(jù)
        temp=(tempH8)|tempL;//總值為高位*256+低位
        temp=temp*0.625;//為了保留1位小數(shù),最小單位為0.0625
        ds18b20_reset();//18B20初始化
        ds18b20_write_byte(0xcc);//對(duì)ROM進(jìn)行操作,因?yàn)橹唤恿?個(gè)器件所以寫跳過指令
        ds18b20_write_byte(0x44);//啟動(dòng)溫度轉(zhuǎn)換
        Delay_ms(1);//給硬件一點(diǎn)時(shí)間讓其進(jìn)行轉(zhuǎn)換
        return(temp);
        }

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


        display.c:
        #include iom16v.h>
        #include macros.h>
        #include"display.h"
        #define uchar unsigned char
        #define uint unsigned int

        uchar table1[]="0123456789";
        uchar table2[]="design:zhubo";
        uchar table3[]="temperature:";
        uchar table4[]=".";

        extern int temperture;
        void delay(unsigned int ms)
        {
        unsigned int i,j;
        for(i=0;ims;i++)
        {
        for(j=0;j1141;j++);
        }
        }

        void write_com(uchar com)
        {
        PORTD=~BIT(4);
        PORTD=~BIT(5);
        PORTB=com;
        PORTD|=BIT(6);
        delay(1);
        PORTD=~BIT(6);
        }

        void write_dat(uchar dat)
        {
        PORTD|=BIT(4);
        PORTD=~BIT(5);
        PORTB=dat;
        PORTD|=BIT(6);
        delay(1);
        PORTD=~BIT(6);
        }
        void LCD_init()
        {
        DDRB=0XFF;
        DDRD|=BIT(4)|BIT(5)|BIT(6);
        PORTD=~BIT(6);

        write_com(0X38);
        delay(5);
        write_com(0X01);
        delay(5);
        write_com(0X0C);
        delay(5);
        write_com(0X06);
        delay(5);

        }
        void display()
        {
        uint i;

        write_com(0X80+0);
        delay(5);
        for(i=0;i12;i++)
        {
        write_dat(table3[i]);
        delay(5);
        }

        write_com(0X80+12);
        delay(5);
        write_dat(table1[temperture/100%10]);
        delay(5);
        write_com(0X80+13);
        delay(5);
        write_dat(table1[temperture/10%10]);
        delay(5);
        write_com(0X80+14);
        delay(5);
        write_dat(table4[0]);
        delay(5);
        write_com(0X80+15);
        delay(5);
        write_dat(table1[temperture%10]);
        delay(5);

        write_com(0X80+0X40);
        delay(5);
        for(i=0;i12;i++)
        {
        write_dat(table2[i]);
        delay(5);
        }
        }


        --------------------------------------------------------
        接口函數(shù):
        18B20.h:
        #define uchar unsigned char
        #define uint unsigned int

        extern uchar ds18b20_reset();
        extern void ds18b20_write_byte(uchar value);
        extern uint ds18b20_read_byte(void);
        extern uint readTemp(void);
        display.h:
        #define uchar unsigned char
        #define uint unsigned int
        #ifndef display_h
        #define display_h
        extern void write_com(uchar com);
        extern void write_dat(uchar dat);
        extern void LCD_init();
        extern void display();
        extern uchar table[];
        #endif
        delay.h:

        /**************************************************************
        **函數(shù)功能:延時(shí)1us
        **輸入?yún)?shù):無(wú)
        **返回值:無(wú)
        **在本函數(shù)外定義變量:無(wú)
        **調(diào)用的函數(shù):NOP()
        **************************************************************/
        void Delay_1us(void);

        /**************************************************************
        **函數(shù)功能:us級(jí)延時(shí)
        **輸入?yún)?shù):xus:延時(shí)us數(shù)
        **返回值:無(wú)
        **在本函數(shù)外定義變量:無(wú)
        **調(diào)用的函數(shù):Delay_1us()
        **************************************************************/
        void Delay_Us(unsigned int xus);

        /**************************************************************
        **函數(shù)功能:延時(shí)1ms
        **輸入?yún)?shù):無(wú)
        **返回值:無(wú)
        **在本函數(shù)外定義變量:無(wú)
        **調(diào)用的函數(shù):NOP()
        **************************************************************/
        void Delay_1ms(void);

        /**************************************************************
        **函數(shù)功能:ms級(jí)延時(shí)
        **輸入?yún)?shù):xms:延時(shí)ms數(shù)
        **返回值:無(wú)
        **在本函數(shù)外定義變量:無(wú)
        **調(diào)用的函數(shù):Delay_1ms()
        **************************************************************/
        void Delay_ms(unsigned int xms);

        /**************************************************************
        **函數(shù)功能:10us級(jí)延時(shí)
        **輸入?yún)?shù):x10us:延時(shí)x10us數(shù)
        **返回值:無(wú)
        **在本函數(shù)外定義變量:無(wú)
        **調(diào)用的函數(shù):無(wú)
        **************************************************************/
        void Delay10us(int x10us);


        void Delay_1us()
        {
        unsigned char t=2;
        t--;
        }

        void Delay_Us(unsigned int xus)
        {
        while (xus--)
        Delay_1us();
        }

        void Delay_1ms(void)
        {
        unsigned int i;
        for(i=0;i1142;i++)
        ;
        }

        void Delay_ms(unsigned int x)
        {
        int i,j; //variable:declare int
        for(i=0; ix; i++)
        for(j=0; j498;j++)
        {
        NOP();
        NOP();
        NOP();
        NOP();
        NOP();
        NOP();
        NOP();
        NOP();
        NOP();
        }
        }

        void Delay10us(int x10us)//crystal=8MHz
        {
        int i;int j; //variable:declare int
        for(i=0; ix10us; i++)
        {
        for(j=0;j2;j++)
        {
        NOP();
        NOP();
        NOP();
        }
        }
        }


        上一頁(yè) 1 2 下一頁(yè)

        關(guān)鍵詞: ATMEGA16 DS18B20 測(cè)溫程序

        評(píng)論


        相關(guān)推薦

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

        關(guān)閉