新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > AVR單片機IIC實驗

        AVR單片機IIC實驗

        作者: 時間:2016-11-30 來源:網絡 收藏

        //-------------------1602.h--------------------
        //------------1602.h-------------
        #define RS1 PORTB_Bit0=1
        #define RS0 PORTB_Bit0=0
        #define RW1 PORTB_Bit1=1
        #define RW0 PORTB_Bit1=0
        #define EN1 PORTB_Bit2=1
        #define EN0 PORTB_Bit2=0
        #define DATAPORT PORTA
        #define busy 0x80
        void wait()
        {
        uchar val;
        DATAPORT=0xff;
        RS0;
        RW1;
        __no_operation();
        EN1;
        __no_operation();
        __no_operation();
        DDRA=0x00;
        val=PINA;
        while(val&busy)val=PINA;
        EN0;
        DDRA=0xff;
        }

        void writecmd(uchar w)
        {
        wait();
        RS0;
        RW0;
        __no_operation();
        DATAPORT=w;
        __no_operation();
        EN1;
        __no_operation();
        __no_operation();
        EN0;
        }

        void writedata(uchar data)
        {
        wait();
        RS1;
        RW0;
        __no_operation();
        DATAPORT=data;
        __no_operation();
        EN1;
        __no_operation();
        __no_operation();
        EN0;
        }

        void delay_nms(uint k)
        {
        uint i,j;
        for(i=0;i
        for(j=0;j<1140;j++);
        }

        void init()
        {
        delay_nms(15);
        writecmd(0x38);
        delay_nms(5);
        writecmd(0x38);
        delay_nms(5);
        writecmd(0x38);
        writecmd(0x80);
        writecmd(0x01);
        writecmd(0x06);
        writecmd(0x0c);
        }

        void display(uchar x,uchar y,uchar *p)
        {

        uchar add=0x80;
        y=y&0x01;
        x=x&0x0f;
        if(y)add=add+0x40;
        writecmd(add+x);
        while(*p!= 主站蜘蛛池模板: 深泽县| 保定市| 长汀县| 永胜县| 大足县| 鸡西市| 崇左市| 交口县| 加查县| 哈巴河县| 志丹县| 台安县| 南乐县| 韶关市| 神木县| 洛南县| 合阳县| 竹山县| 佳木斯市| 阳高县| 历史| 华宁县| 遂溪县| 昌黎县| 崇左市| 宝清县| 泾源县| 桃江县| 榆林市| 靖江市| 凭祥市| 榆社县| 金门县| 攀枝花市| 五大连池市| 合阳县| 桐乡市| 金溪县| 南丰县| 武义县| 桐柏县|