新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 12232F用串口的顯示程序

        12232F用串口的顯示程序

        作者: 時間:2016-11-18 來源:網(wǎng)絡 收藏
        這是12232F串口顯示程序,該程序可以通過調(diào)用函數(shù)可在任意位置顯示任意字符,供大家參考。


        /* 第一行起始地址為0x80
        第二行起始地址為0x90 */
        #include
        #include "INTRINS.H"

        本文引用地址:http://www.104case.com/article/201611/315571.htm

        #define comm 1
        #define dat 0
        #define uint unsigned int
        #define uchar unsigned char

        sbit CS = P0^2;
        sbit CLK = P0^0;
        sbit STD = P0^1;


        unsigned char code Chinese [] = {"歡迎使用"};

        void delay ()
        {
        unsigned int i;
        for (i=0;i<1500;i++);
        }

        void Write_Byte (unsigned char Data)
        {
        unsigned char i;
        CLK = 0;
        _nop_();
        _nop_();
        for (i=8;i>0;i--)
        {
        Data <<= 1;
        STD = CY;
        CLK = 0;
        _nop_();
        _nop_();
        _nop_();
        CLK = 1;
        _nop_();
        _nop_();
        }
        }

        void Write_12232 (unsigned char Derect,unsigned char Hight)
        {
        CS = 0;
        _nop_();
        _nop_();
        _nop_();
        CS = 1;
        if(Derect==1)
        Write_Byte (0xf8); //命令字
        else
        Write_Byte (0xfa);
        Write_Byte (Hight&0xf0); //數(shù)據(jù)字
        Hight &= 0x0f;
        Write_Byte (Hight<<=4);
        CS = 0;
        }
        //該函數(shù)用于在指定位置顯示字符串,x為行數(shù),y為列,k為字符個數(shù)
        void lcd_char(uchar x,uchar y,uchar k,uchar *datt)
        {
        uchar addr,i;
        if(x==0)
        addr=0x80+y;
        else
        addr=0x90+y;
        Write_12232 (comm,addr);
        for(i=0;i Write_12232 (dat,datt[i]);
        }
        //在指定位置顯示漢字串,其中x為行坐標,y為列坐標,k為所要顯示的漢字個數(shù)
        void Write_Chinese (uchar x,uchar y,uchar k,uchar *p)
        {
        uchar addr,i;
        if(x==0)
        addr=0x80+y;
        else
        addr=0x90+y;
        Write_12232 (comm,addr);
        for (i=0;i<2*k;i++)
        Write_12232 (dat,p [i]);

        }

        void init_lcd()
        {
        CS = 0;
        Write_12232 (comm,0x08);//關顯示
        delay ();
        Write_12232 (comm,0x10);//設置光標為右移
        delay ();
        Write_12232 (comm,0x06);//設置光標整體右移時AC加1
        delay ();
        Write_12232 (comm,0x02);//地址歸位
        delay ();
        Write_12232 (comm,0x01);//清除顯示
        delay ();
        Write_12232 (comm,0x0c);//開顯示,不顯示光標,光標不反白顯示
        }

        void main ()
        { uchar b[4];
        P0M1=0X00;
        P0M0=0X00;
        b[0]=5+0x30;
        b[1]=6+0x30;
        b[2]=0x37;
        b[3]=0x38;
        init_lcd();
        lcd_char(0,2,4,b);
        Write_Chinese (1,0,4,Chinese);
        delay ();
        while (1)
        {
        }
        }



        關鍵詞: 12232F串口顯示程

        評論


        技術專區(qū)

        關閉
        主站蜘蛛池模板: 卓尼县| 徐水县| 桐庐县| 武威市| 岳西县| 百色市| 合山市| 阜南县| 清徐县| 水富县| 涿州市| 赣榆县| 拉孜县| 华宁县| 班玛县| 安国市| 义马市| 宁远县| 神木县| 安多县| 丹巴县| 高唐县| 江源县| 台东市| 肃北| 蓬溪县| 海门市| 商洛市| 日照市| 卓尼县| 西平县| 旬阳县| 苏尼特左旗| 墨玉县| 永丰县| 富源县| 游戏| 苍南县| 郯城县| 中山市| 石嘴山市|