lzh电子论坛

欢迎来到lzh电子论坛:
如果您对电子技术感兴趣就加入我们吧!在这里互相交流互相学习!主要讨论的方向有:单片机,ARM,PCB板设计,FPGA,汇编,C/C++等方面。
-----lzh电子论坛
lzhbbs.forumotion.com
lzh电子论坛

电子的道路是孤独的,要懂得左手温暖右手,要懂得把debug当作快乐去欣赏,去享受,那样你才会成功...

欢迎访问lzh电子论坛。可通过【谷歌,SOSO,搜狗】搜索“lzh电子论坛”直接进入论坛。点击了解论坛详细制度


    关于12864整屏画图的程序源代码

    分享
    avatar
    PZ
    初级会员
    初级会员

    帖子数 : 4
    威望 : 0
    注册日期 : 13-01-15

    关于12864整屏画图的程序源代码

    帖子 由 PZ 于 2013-05-01, 3:59 pm

    发给像我一样还在51世界撞墙的菜鸟,希望能对你们学习有点用!

    代码:

    #include<reg52.h>
    #include<intrins.h>
    #define uchar unsigned char
    #define uint unsigned int
    #define lcd P0



    sbit RW=P2^5;
    sbit E=P2^6;
    sbit PSB=P2^1;
    sbit RS=P2^4;
    sbit RES=P2^3;
    uint code tab[]={
    0xF7,0xE8,0x9F,0x81,0x80,0x0F,0x78,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,
    0x90,0x45,0x12,0x9E,0x3E,0x09,0x48,0x00,0x00,0x00,0x0F,0xF0,0x00,0x00,0x00,0x00,
    0xA0,0x42,0x1F,0x82,0x22,0x09,0x48,0x00,0x01,0xE0,0x1C,0x38,0x00,0x00,0x00,0x00,
    0xC3,0xC7,0x12,0x9F,0xA2,0x0F,0x78,0x00,0x07,0xF8,0x78,0x38,0x00,0x00,0x00,0x00,
    0xA2,0xC8,0x92,0x82,0x22,0x09,0x48,0x00,0x07,0xFF,0xF0,0x1C,0x00,0x00,0x00,0x00,
    0x93,0xC2,0x9F,0x83,0x22,0x09,0x48,0x00,0x06,0x1F,0xFE,0x1C,0x00,0x00,0x00,0x00,
    0xF0,0x44,0x82,0x06,0xA2,0x0F,0x78,0x00,0x06,0x1F,0xFF,0x9C,0x00,0x00,0x00,0x00,
    0x80,0x48,0x9F,0x8A,0x3E,0x09,0x48,0x00,0x06,0x3F,0xFF,0xCC,0x00,0x00,0x00,0x00,
    0x80,0x40,0x82,0x12,0x22,0x09,0x48,0x00,0x06,0x7F,0xFF,0xFC,0x00,0x00,0x00,0x00,
    0x80,0x40,0x82,0x02,0x00,0x11,0x88,0x00,0x06,0x7F,0xC7,0xFC,0x00,0x00,0x00,0x00,
    0x81,0xC3,0x9F,0xC2,0x00,0x23,0x38,0x00,0x06,0xFF,0xC1,0xFC,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xE7,0x01,0xFC,0x00,0x00,0x00,0x00,
    0x08,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0xFC,0x00,0x00,0x00,0x00,
    0x08,0x40,0x4F,0xC0,0x20,0x00,0x00,0x00,0x01,0xC0,0x00,0x7C,0x00,0x00,0x00,0x00,
    0xFF,0xE3,0xE8,0x40,0x20,0x00,0x00,0x00,0x01,0x80,0x00,0x7E,0x00,0x00,0x00,0x00,
    0x08,0x00,0x28,0x47,0xFF,0x00,0x00,0x00,0x01,0x80,0x00,0x7E,0x00,0x00,0x00,0x00,
    0x0F,0x80,0x48,0x40,0x20,0x00,0x00,0x00,0x01,0x80,0x00,0x7F,0x00,0x00,0x00,0x00,
    0x08,0x80,0x8F,0xC0,0x20,0x00,0x00,0x00,0x01,0x80,0x00,0x7F,0x00,0x00,0x00,0x00,
    0x14,0x81,0x82,0x80,0x50,0x00,0x00,0x00,0x01,0x80,0x01,0xBE,0x00,0x00,0x00,0x00,
    0x14,0x82,0xE2,0x80,0x88,0x00,0x00,0x00,0x01,0x84,0x0E,0x7F,0x00,0x00,0x00,0x00,
    0x25,0x00,0x82,0x81,0x04,0x00,0x1F,0xE0,0x00,0xFD,0xC0,0xFE,0x00,0x00,0x00,0x00,
    0x42,0x00,0x84,0x92,0x02,0x00,0xE0,0x60,0x00,0xC1,0xC0,0xFC,0x00,0x00,0x00,0x00,
    0x85,0x00,0x88,0x94,0x01,0xC0,0x7F,0xC0,0x03,0xE1,0x0F,0xFF,0x00,0x00,0x00,0x00,
    0x08,0xE0,0xB0,0xF0,0x00,0x00,0x3F,0xC0,0x03,0xFF,0xFF,0x67,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x03,0xB3,0xFF,0xE3,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x80,0x01,0x33,0xFF,0x73,0x00,0x00,0x00,0x00,
    0x04,0x00,0x00,0x00,0x00,0x00,0x1F,0xE0,0x01,0xF7,0xFF,0x7E,0x00,0x00,0x00,0x00,
    0x7F,0xE1,0xFC,0x0C,0x00,0x00,0xFF,0xFF,0x00,0xF3,0xFF,0xFE,0x00,0x00,0x00,0x00,
    0xC0,0x21,0x00,0x14,0x00,0x00,0x9F,0xB5,0x80,0xF7,0xFF,0xDC,0x00,0x00,0x00,0x00,
    0x3F,0x81,0x00,0x24,0x00,0x03,0xE0,0x6D,0x80,0x6F,0xFF,0xAC,0x00,0x00,0x00,0x00,
    0x14,0x41,0xF0,0x04,0x00,0x06,0x7F,0xC9,0x80,0x67,0xFF,0xFC,0x00,0x7C,0x00,0x00,
    0x24,0x80,0x08,0x04,0x00,0x0D,0xA0,0x9D,0x80,0x4F,0xA7,0xCC,0x01,0xDE,0x00,0x00,
    0xCB,0x00,0x04,0x04,0x00,0x1F,0xFF,0xF5,0x80,0x4F,0x83,0xF8,0x03,0x7A,0x00,0x00,
    0x16,0x80,0x04,0x04,0x00,0x3B,0xFF,0x6D,0xC0,0x6F,0xE0,0xF8,0x03,0xEF,0x00,0x00,
    0x6A,0x40,0x04,0x04,0x00,0x27,0xFF,0xF8,0x40,0x3F,0x20,0xF0,0x02,0x86,0x00,0x00,
    0x32,0x20,0x04,0x04,0x00,0x6F,0xFF,0xF6,0x60,0x1E,0x11,0x90,0x03,0xB6,0x00,0x00,
    0xC2,0x01,0x04,0x04,0x00,0x7F,0xFF,0xFD,0xE0,0x1E,0x4E,0xF0,0xE3,0xBE,0x00,0x00,
    0x0E,0x00,0x88,0x04,0x00,0x57,0xFF,0xE9,0xF0,0x1C,0x7E,0x21,0xFF,0x98,0x00,0x00,
    0x00,0x00,0x70,0x3F,0x80,0x5F,0xFF,0xFB,0xF8,0x1C,0x7C,0xE1,0x3F,0x80,0xFC,0x00,
    0x00,0x00,0x00,0x00,0x00,0xDD,0xFF,0xFB,0xF8,0x0C,0x7F,0xE3,0x0F,0x87,0xFE,0x00,
    0x00,0x00,0x00,0x00,0x00,0xDB,0xFF,0x2B,0xF0,0x08,0x7F,0xE3,0x07,0xFF,0xFE,0x00,
    0x00,0x00,0x00,0x00,0x00,0xDF,0xFF,0xFB,0xF0,0xDC,0x30,0x23,0x1F,0xFC,0x0E,0x00,
    0x41,0x00,0x00,0x00,0x00,0xDD,0xFF,0x57,0xDC,0x47,0xF0,0xE2,0x7F,0xFC,0x0E,0x00,
    0x41,0x00,0x1C,0x06,0x00,0x55,0xFF,0xF6,0xD6,0xF1,0x8D,0xE2,0x7F,0xFF,0x0E,0x00,
    0x47,0xE0,0xE0,0x0F,0x00,0x5E,0xFF,0x7C,0xA7,0xFC,0x7F,0xE3,0xFF,0xFF,0x8E,0x00,
    0xE1,0x20,0x90,0x0F,0x00,0x4E,0xFF,0xFB,0xA7,0xFF,0xFF,0xA3,0xC7,0xFF,0xCE,0x00,
    0xD1,0x20,0x90,0x0F,0x00,0x7E,0xFF,0xAF,0xE7,0xFF,0xFF,0xA3,0x83,0x0F,0xCE,0x00,
    0x4F,0xF9,0x12,0x06,0x00,0xCF,0xDF,0xFE,0x6F,0x87,0x83,0xE3,0x00,0x03,0xEE,0x00,
    0x41,0x01,0xFF,0x06,0x00,0xC0,0xBF,0xD6,0x6F,0x01,0x01,0xE7,0x00,0x01,0xEC,0x00,
    0x42,0x80,0x58,0x00,0x00,0x41,0xED,0x3F,0xEE,0x00,0x00,0xE6,0x00,0x01,0xFC,0x00,
    0x44,0x40,0x94,0x06,0x00,0x40,0xC0,0x6B,0x6E,0x00,0x00,0xE6,0x00,0x01,0xFC,0x00,
    0x48,0x41,0x12,0x06,0x00,0x30,0xFF,0xE7,0x5F,0xC0,0x1F,0xE4,0x00,0x01,0xF8,0x00,
    0x50,0x38,0x71,0x00,0x00,0x0F,0xBF,0xB7,0xDC,0x20,0x10,0xEC,0x00,0x01,0xF8,0x00,
    0x00,0x00,0x00,0x00,0x00,0x0D,0x91,0x34,0xD8,0x10,0x20,0x6F,0x80,0x01,0xF8,0x00,
    0x00,0x00,0x00,0x00,0x00,0x1A,0xDB,0x1C,0x98,0xD0,0x2C,0x79,0x80,0x21,0xF8,0x00,
    0x00,0x00,0x00,0x00,0x00,0x13,0xFF,0x98,0x89,0xD0,0x3E,0x7D,0x80,0x79,0xF8,0x00,
    0x00,0x00,0x00,0x00,0x00,0x1B,0xE1,0x00,0xFC,0xA0,0x34,0xFE,0x38,0x79,0xF8,0x00,
    0x00,0x00,0x00,0x00,0x00,0x1F,0xF9,0xEB,0x8E,0x63,0x19,0xFE,0x3C,0x31,0xF8,0x00,
    0x00,0x00,0x00,0x00,0x00,0x0E,0xFF,0xF3,0x83,0x03,0x03,0x06,0x08,0x03,0xF8,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x9B,0xFF,0x81,0x80,0x06,0x02,0x00,0x0F,0xF0,0x00,
    0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x1F,0x1C,0x7A,0x70,0x03,0x80,0x0F,0x70,0x00,
    0x00,0x00,0x00,0x00,0x00,0x01,0x23,0x81,0x01,0x3F,0xF3,0xF0,0x60,0x0F,0xC0,0x00,
    0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x49,0x01,0x7C,0xF0,0x20,0x9F,0xFF,0xC0,0x00,
    0x00,0x00,0x00,0x00,0x00,0x01,0xC4,0x61,0x82,0x23,0x07,0x21,0x37,0xFF,0xC0,0x00};









    void delayms(uchar);
    void delayus(uchar);
    void init_12864();
    void write_pos(uint code *p);
    void clear_up();
    void write_com(uchar);
    void write_data(uchar);





    void main()
    {
       init_12864();
       clear_up();
       write_pos(tab);
       while(1);   
    }



    void delayus(uchar xus)
    {
       uchar uscnt;                
       uscnt=xus>>1;
       while(--uscnt);
    }



    void delayms(uchar xms)
    {
       while(--xms)
       {
          delayus(250);
          delayus(250);
          delayus(250);
          delayus(250);   
       }
    }



    void init_12864()                    //该初始化方式为画图方式的初始化
    {
       delayms(40);                    //大于40MS的延时程序
       PSB=1;                          //设置为8BIT并口工作模式
       delayus(5);                       //延时
       RES=0;                          //复位
       delayus(1);                       //延时
        RES=1;                              //复位置高
        delayus(10);
          
       write_com(0x36);                 //
       delayms(1);
       write_com(0x36);
       delayms(1);
       write_com(0x3e);
       delayms(1);
       write_com(0x01);
       delayms(1);
    }


    void write_com(uchar com)              //定义写指令函数
    {
       delayms(15);                    //延时15MS让数据稳定一下
       RS=0;                          //以下源代码参考时序图
       RW=0;
       E=0;
       delayus(40);
       E=1;
       lcd=com;
       delayus(400);
       E=0;
    //   RS=1;
    }



    void write_data(uchar dat)              //定义写数据函数
    {
       delayms(15);                    //延时让数据稳定
       RS=1;                          //参考时序图
       RW=0;
       E=0;
       delayus(40);
       E=1;
       lcd=dat;
       delayus(400);
       E=0;
       //RS=0;   
    }



    void clear_up()                        //定义清屏函数
    {
       uchar a,b,c,x,y;
       x=0x80;                           //x是数据在液晶中的水平字节地址
       y=0x80;                           //y是数据在竖直方向的位地址
       
       for(a=0;a<2;a++)                  //循环两次,使上下屏幕的数据写入液晶
       {
          for(b=0;b<32;b++)               //循环32次,把上半个屏幕数据写入液晶
          {
             write_com(y+b);                //每给完每一行的数据,竖直方向的位就加一,继续下一行,一共有32行
             write_com(x);               //写入水平方向的此时的字节地址
             for(c=0;c<16;c++)            //循环16次,当给完2个字节数值,X自动加一,继续写下一个“字节”,注意这里的“字节是16位而不是传统的8位”,直到给完8个“字节”
             {
                write_data(0x00);         //每个字节都00清屏
             }
          }
          x=0x88;                        //水平地址换到屏幕的下半部分
       }
    }



    void write_pos(uint code *p)            //定义画图函数
    {
       uchar a,b,c,x,y;
       x=0x80;                           //x是数据在液晶中的水平字节地址
       y=0x80;                           //y是数据在竖直方向的位地址
       
       for(a=0;a<2;a++)                  //循环两次,使上下屏幕的数据写入液晶
       {
          for(b=0;b<32;b++)               //循环32次,把上半个屏幕数据写入液晶
          {
             write_com(y+b);               //每给完每一行的数据,竖直方向的位就加一,继续下一行,一共有32行
             write_com(x);               //写入水平方向的此时的字节地址
             for(c=0;c<16;c++)            //循环16次,当给完2个字节数值,X自动加一,继续写下一个“字节”,注意这里的“字节是16位而不是传统的8位”,直到给完8个“字节”
             {
                write_data(*p++);         //给入你在此时8位要写入的数据
             }
          }
          x=0x88;                       //水平地址换到了屏幕下半部分
       }
       
    }
    附件
    12864.zip
    您无权下载这里的附件。
    (36 Kb) 下载5次
    avatar
    Admin
    管理员
    管理员

    帖子数 : 869
    威望 : 15
    注册日期 : 12-11-23
    年龄 : 25

    回复: 关于12864整屏画图的程序源代码

    帖子 由 Admin 于 2013-05-01, 4:11 pm

    给你上了一个图,感觉不错!!!呵呵 Crying or Very sad
    avatar
    寒夜
    中级会员
    中级会员

    帖子数 : 34
    威望 : 0
    注册日期 : 13-04-22

    回复: 关于12864整屏画图的程序源代码

    帖子 由 寒夜 于 2013-05-01, 4:34 pm

    楼主不错额,多谢分享咯,下载下来看看!!!
    avatar
    Admin
    管理员
    管理员

    帖子数 : 869
    威望 : 15
    注册日期 : 12-11-23
    年龄 : 25

    回复: 关于12864整屏画图的程序源代码

    帖子 由 Admin 于 2013-05-01, 4:45 pm

    寒夜 写道::楼主不错额,多谢分享咯,下载下来看看!!!
    都支持代码开源共享嘛,互相学习撒,呵呵!回帖是好习惯,赞一个……


    _________________
    电子的道路是孤独的,要懂得左手温暖右手,要懂得把debug当作快乐去欣赏,去享受,那样你才会成功...

      目前的日期/时间是2018-09-21, 8:09 pm