<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        mega16驅動ds12c887顯示于lcd1602

        作者:佚名   來源:不詳   點擊數:  更新時間:2014年09月18日   【字體:

        #include<iom16v.h>
        #include<macros.h>
        #define uchar unsigned char
        #define uint unsigned int
        #define DS_ PORTC&=~BIT(6)
        #define DS PORTC|=BIT(6)
        #define RW_ PORTC&=~BIT(5)
        #define RW PORTC|=BIT(5)
        #define AS_ PORTC&=~BIT(4)
        #define AS PORTC|=BIT(4)
        #define CS_ PORTC&=~BIT(3)
        #define CS PORTC|=BIT(3)
        uchar tab1[]={"DAT:"};
        uchar tab2[]={"TIME:"};
        const uchar tab[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x20};
        extern uchar dat[]={0x32,0x30,0x31,0x31,0x2d,0x39,0x39,0x2d,0x30,0x36};
        extern uchar time[8]={0x30,0x30,0x2d,0x30,0x30,0x2d,0x30,0x30};
        uchar sec=0,min=0,hou=0,day=0,mon=0,yea=0,week=0;
        void delay(uint z)
        {
        while(z--);
        }
        void disan()
        {
        uchar hlb;
        hlb=hou;
          dat[0x00]=2+0x30;
          dat[0x01]=0+0x30;
          dat[0x02]=yea%100/10+0x30;
          dat[0x03]=yea%16+0x30;
          dat[0x05]=mon/16+0x30;
          dat[0x06]=mon%16+0x30;
          dat[0x08]=day/16+0x30;
          dat[0x09]=day%16+0x30;
          time[0x00]=hou/16+0x30;
          time[0x01]=hou%16+0x30;
          time[0x03]=min/16+0x30;
          time[0x04]=min%16+0x30;
          time[0x06]=sec/16+0x30;
          time[0x07]=sec%16+0x30;

        }
        void write_com(uchar com)
        {
        PORTC&=~BIT(2);
        PORTC&=~BIT(1);
        PORTB=com;
        PORTC|=BIT(0);
        delay(1);
        PORTC&=~BIT(0);
        delay(3);
        }

        void write_dat(uchar dat)
        {
        PORTC|=BIT(2);
        PORTC&=~BIT(1);
        PORTB=dat;
        PORTC|=BIT(0);
        delay(1);
        PORTC&=~BIT(0);
        delay(3);

        }
        void init()
        {
          write_com(0X38);
        delay(5);
          write_com(0X0c);
        delay(5);
          write_com(0X06);
        delay(5);
        }

        void write_ds(uchar add,uchar date)
        {
        CS_;
        RW;
        DS;
        AS;
        PORTA=add;
        AS_;
        RW_;
        PORTA=date;
        delay(1);
        RW;
        AS;
        CS;
        }
        uchar read_ds(uchar add)
        {
        uchar ds_date;
        CS_;
        DS;
        RW;
        AS;
        PORTA=add;
        AS_;
        DS_;
        DDRA=0X00;
        delay(1);
        ds_date=PINA;
        DDRA=0XFF;
        DS;
        AS;
        CS;
        return ds_date;
        }

        void ds12887()
        {
        sec=read_ds(0);
        min=read_ds(2);
        hou=read_ds(4);
        day=read_ds(7);
        mon=read_ds(8);
        week=read_ds(6);
        yea=read_ds(9);
        }
        void display()
        {
        uchar i;
        init();
        write_com(0X80);
        delay(5);
        for(i=0;i<4;i++)
        {
        write_dat(tab1[i]);
        delay(5);
        }
        for(i=0;i<10;i++)
        {
        write_dat(dat[i]);
        delay(5);
        }
        write_com(0X80+0X40);
        delay(5);
        for(i=0;i<5;i++)
        {
        write_dat(tab2[i]);
        delay(5);
        }
        for(i=0;i<8;i++)
        {
        write_dat(time[i]);
        delay(5);
        }
        write_dat(0x20);
        delay(5);
        write_dat(0x20);
        delay(5);
        write_dat(0x30+week);
        delay(5);
        }
        void key_set()
        {
          write_ds(9,0x11);
          write_ds(8,0x11);
          write_ds(7,0x03);
          write_ds(6,0x06);
          write_ds(4,0x18);
          write_ds(2,0x45);
          write_ds(0,0x50);
        }
        void main()
        {
          MCUCSR |= 1<<JTD;
          MCUCSR |= 1<<JTD; 
        DDRA=0XFF;
        DDRB=0XFF;
        DDRC=0XFF;
          write_com(0X01);
          write_com(0X03);
        /////////////////
        write_ds(0x0b,0x02);
        //key_set();
        while(1)
        {
        ds12887();
        disan();
        display();
        delay(1000);
        }
        }

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮