新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > AVR 1602液晶字符移動

        AVR 1602液晶字符移動

        作者: 時間:2016-11-30 來源:網絡 收藏
        #include
        #include
        #define uchar unsigned char
        #define uint unsigned int
        uchar str1[16]="This is a ASCII";
        uchar str2[16]=" Test ";
        #include "1602.h"
        void port_init()
        {
        PORTA=0xff;
        DDRA=0xff;
        PORTB=0xff;
        DDRB=0xff;
        PORTD=0xff;
        DDRD=0xff;
        }
        void init()
        {
        MCUCR=0x0a;
        GICR=0xc0;
        SREG=0x80;
        }
        void disline(uchar w) //字符移動函數
        {
        uchar i;
        for(i=0;i<16;i++)
        {
        displayonechar(i,1,w); //字符顯示在第二行 即字母A--Z
        w++;
        if(w>90)w=65; //字符顯示限定范圍A--Z

        }
        delay(500);
        }
        void main()
        {
        uchar w=65;
        port_init();
        init();
        //1602設備初始化
        delay(15);
        writecmd(0x38);
        delay(5);
        writecmd(0x38);
        delay(5);
        writecmd(0x38);
        writecmd(0x80);
        writecmd(0x01);
        writecmd(0x06);
        writecmd(0x0c);
        delay(500);
        //初始化結束
        writecmd(0x01);
        writecmd(0x0c);
        displaychar(0,0,str1);
        delay(1000);
        writecmd(0x01);
        writecmd(0x0c);
        displaychar(0,1,str2);
        delay(1000);
        writecmd(0x01);
        writecmd(0x0c);
        while(1)
        {
        disline(w++); //字符移動模式
        if(w>90)w=65;
        }
        }

        //-----------------1602庫函數-----------------------
        #define RS PORTB_Bit0
        #define RW PORTB_Bit1
        #define EN PORTB_Bit2
        #define DATA PORTA
        #define busy 0x80

        上一頁 1 2 下一頁

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 含山县| 虞城县| 江油市| 苗栗市| 清原| 仙居县| 夏邑县| 奇台县| 房山区| 虎林市| 福州市| 黑山县| 诸暨市| 宁化县| 南岸区| 韶山市| 无为县| 忻州市| 平遥县| 会宁县| 家居| 澄迈县| 福安市| 武定县| 宜城市| 延边| 光山县| 布尔津县| 罗定市| 迭部县| 五河县| 资兴市| 五家渠市| 增城市| 禄丰县| 仁寿县| 红河县| 绥阳县| 乌恰县| 湘西| 九龙城区|