在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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) > 設(shè)計應(yīng)用 > AVR128的程序——DS18B20與12864液晶時鐘綜合運用

            AVR128的程序——DS18B20與12864液晶時鐘綜合運用

            作者: 時間:2016-11-22 來源:網(wǎng)絡(luò) 收藏
            #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)
            #define psbset DDRB |= (1<<4)
            #define psbset PORTB |= (1<<4)
            #define psbclr PORTB &=~(1<<4)
            #define rsout DDRB |= (1<<5)
            #define rsset PORTB |=(1<<5)
            #define rsclr PORTB &=~(1<<5)
            #define rwout DDRB |= (1<<6)
            #define rwset PORTB |= (1<<6)
            #define rwclr PORTB &= ~(1<<6)
            #define enout DDRB |= (1<<7)
            #define enset PORTB |= (1<<7)
            #define enclr PORTB &= ~(1<<7)
            unsigned char table1[]=" 2012年02月06日";
            unsigned char table2[]="星期六 溫度 8℃";
            unsigned char table3[]=" 00: 00: 00";
            unsigned char table4[]=" 科嵌電子創(chuàng)作";
            uint num=10,fen=07,shi=14,ri=06,yue=02;;
            void mcu_init(void);
            void timer1_init(void)
            {
            TCNT1H = 0xE1;
            TCNT1L = 0x7C;
            TCCR1A = 0x00;
            TCCR1B = 0x05;
            TIMSK = 0x04;
            }
            void Delayus(uint US)
            {
            uint i;
            US=US*5/4;
            for( i=0;i
            }
            void Delayms(uint MS)
            {
            uint i,j;
            for( i=0;i
            for(j=0;j<1141;j++);
            }
            void write_12864com(uchar com)
            {
            rwclr;
            rsclr;
            Delayus(500);
            PORTA=com;
            enset;
            Delayus(1000);
            enclr;
            Delayus(1000);
            }
            void write_12864dat(uchar dat)
            {
            rwclr;
            rsset;
            Delayus(500);
            PORTA=dat;
            enset;
            Delayus(1000);
            enclr;
            Delayus(1000);
            }
            void init12864lcd(void)
            {
            Delayms(500);
            write_12864com(0x30);
            Delayus(500);
            write_12864com(0x30);
            Delayus(500);
            write_12864com(0x0f);
            Delayus(500);
            write_12864com(0x01);
            Delayms(25);
            write_12864com(0x06);
            Delayus(2500);
            write_12864com(0x0c);
            Delayus(500);
            }
            void display(void)
            {
            uchar i;
            write_12864com(0x80);
            for(i=0;i<16;i++)
            {
            write_12864dat(table1[i]);
            Delayms(10);
            }
            }
            void display1(void)
            {
            uchar i;
            write_12864com(0x90);
            for(i=0;i<16;i++)
            {
            write_12864dat(table2[i]);
            Delayms(10);
            }
            }
            void display2(void)
            {
            uchar i;
            write_12864com(0x88);
            for(i=0;i<12;i++)
            {
            write_12864dat(table3[i]);
            Delayms(10);
            }
            }
            void display3(void)
            {
            uchar i;
            write_12864com(0x98);
            for(i=0;i<14;i++)
            {
            write_12864dat(table4[i]);
            Delayms(10);
            }
            }
            void write_sfm(uchar add,uchar date)
            {
            uchar shi,ge;
            shi=date/10;
            ge=date;
            write_12864com(add);
            write_12864dat(0x30+shi);
            write_12864dat(0x30+ge);
            }
            void write_wendu(uchar add,uchar date)
            {
            uchar shi,ge;
            shi=date/10;
            ge=date;
            write_12864com(add);
            write_12864dat(0x30+shi);
            write_12864dat(0x30+ge);
            }
            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 main(void)
            {
            uchar i,j;
            uint temp;
            mcu_init();
            init12864lcd();
            timer1_init();
            SEI();
            display();
            display1();
            display2();
            display3();
            while(1)
            {
            write_sfm(0x8D,num);
            write_sfm(0x8B,fen);
            write_sfm(0x89,shi);
            write_sfm(0x86,ri);
            write_sfm(0x84,yue);
            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.0625;
            write_wendu(0x96,temp);
            }
            }
            void mcu_init(void)
            {
            DDRA = 0XFF;
            PORTA = 0XFF;
            DDRC = 0XFF;
            PORTC = 0XFF;
            DDRF |= 0X0E;
            PORTF |= 0X0E;
            PORTF &= 0xF0;
            DDRB |= 0X10;
            PORTB |= 0X10;
            psbset;
            rsout;
            rwout;
            enout;
            }
            #pragma interrupt_handler timer1_ovf_isr:15
            void timer1_ovf_isr(void)
            {
            TCNT1H = 0xE1;
            TCNT1L = 0x7C;
            num++;
            if(num==60)
            {
            num=0;
            fen++;
            if(fen==60)
            {
            fen=0;
            shi++;
            if(shi==24)
            {
            shi=0;
            ri++;
            if(ri==32)
            {
            ri=1;
            yue++;
            }
            }
            }
            }
            }



            關(guān)鍵詞: AVR128DS18B2012864液晶時

            評論


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

            關(guān)閉