深圳市炜烨兴电子有限公司|LCD在线|智能串口液晶
注册| 登录| 通行证 生产液晶显示模块哪家强?Wayeah LCM!专业的液晶显示模块研发、生产厂家!

首页 新闻 字符型| 图形型| 定制型| 智能型| 技术应用 留言反馈 联系方式 |

当前位置液晶应用技术 >> KM1604A之C51驱动程序

KM1604A之C51驱动程序

  //Character display Module Built-in ST7066:16 x 4 
  //单位:深圳市炜烨兴电子有限公司
  //编程:yesever
  //时间:2008-12-09
  //KM1604演示用
  //欢迎使用,网上转载请注明出处"LCD在线"或"深圳炜烨电子""
  //硬件:AT89S51@12MHz
  #include <reg51.h>  /* 8051 寄存器定义 */
  typedef  unsigned char uchar;
  typedef  unsigned int  uint;
  //以下为自定义的字符
  uchar code data0[] ={0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff};       //测试数据
  uchar code data1[] ={0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00};
  uchar code data2[] ={0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55};
  uchar code data3[] ={0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa};
  uchar code data4[] ={0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
  uchar code data5[] ={0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55};
  uchar code data6[] ={0x1f,0x11,0x11,0x11,0x11,0x11,0x11,0x1f};
  uchar code data7[] ={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  uchar code data8[] ={"WAYEAH ELECT.CO."};                     //显示的字符
  uchar code data9[] ={"Tel:755-26158257"};
  uchar code data10[]={" 5*8Dots Matrix "};
  uchar code data11[]={" Character LCDM "};
  uchar code data12[]={" Welcome to use "};
  uchar code data13[]={"WAYEAH LCD & LCM"};
  uchar code data15[]={"The controler is"};
  uchar code data16[]={"ST7066 / S6A0069"};
  uchar code load[]  ={" Please wait... "};
  uchar code bmp1[]  ={0x1f,0x1f,0x0e,0x04,0x0e,0x1f,0x1f,0x00};    //漏斗1
  uchar code bmp2[]  ={0x11,0x11,0x1b,0x1f,0x1b,0x11,0x11,0x00}; //漏斗2
  //接口IO定义
  sbit  _rs =P3^3;
  sbit  _rw =P3^1;
  sbit  _e1 =P3^0;
  sbit  key =P3^2;
  sfr  dbus =0x90;
 
  /*-----------------*/
  DELAY(int t)   //用于延时
  {
        int i,j;
           for (i=0;i<t;i++)
             for (j=0;j<t;j++)
               while(!key);
   }

DELAY10(void)   //用于延时
  {
        unsigned char  i;
        for (i=10;i>0;i--);
  }

  /*-----------------*/
  WRITE_COM(uchar com)  /*Write a command to LCD*/
  {
   DELAY10();
   _rs = 0;
   _rw = 0;
   _e1 = 1;
   dbus=com;  
   _e1 = 0;
  }
  /*------------------*/ 
  WRITE_DAT(uchar dat)  /*Write display data to LCD*/
  {
   DELAY10();
   _rs = 1;
   _rw = 0;
   _e1 = 1;
   dbus=dat;  
   _e1 = 0;
  }
  SET_ADDR(uchar addr) //显示地址设置
  {
    switch (addr)
    {
      case 1:WRITE_COM(0x80);break;              //第一行地址
      case 2:WRITE_COM(0xc0);break;              //第二行地址
      case 3:WRITE_COM(0x80+16);break;       //第三行地址
      case 4:WRITE_COM(0xc0+16);break;       //第四行地址
    }
  }
  WRITE_CGRAM(uchar row,uchar code *DEFDAT) //Write a typedef char
  {
    uchar counter;
    if (row>8)
       row=row-8;
    WRITE_COM(0x40+row*8);
    for (counter=0;counter<8;counter++)
    {
       WRITE_DAT(*DEFDAT++);
     } 
  }
  SETUP_LCD(void)   //初始化液晶
  {
    DELAY(20);
    WRITE_COM(0x38);
    DELAY(100);
    WRITE_COM(0x38); /*Function set*/
    WRITE_COM(0x06); /*Entry mode set*/
    WRITE_COM(0x14); /*Shift*/
    WRITE_COM(0x0c); /*Display control*/
    WRITE_COM(0x01); /*Clear dislpay*/
    DELAY(20);
    WRITE_COM(0x02);
    DELAY(20);
  }
  main()
  {
      uchar code *p;
      uchar data i,temp;
      DELAY(100);
      P3=0xff;
  while(1) ///死循环,演示用的目的:不停反复显示
    {
      SETUP_LCD();
      SET_ADDR(1);
      p=data12;
      for (i=0;i<16;i++) { WRITE_DAT(*p++);} /* Welcome to use */
      SET_ADDR(2);
      p=data13;
      for (i=0;i<16;i++) { WRITE_DAT(*p++);} /*WAYEAH LCD & LCM*/
      SET_ADDR(3);
      p=load;
      for (i=0;i<16;i++) { WRITE_DAT(*p++);} /* Please Wait... */
      WRITE_COM(0xde);
      WRITE_DAT(0x00);
      for(i=0;i<4;i++)
      {
         WRITE_CGRAM(0,bmp1);
         DELAY(150);
         WRITE_COM(0xa1);
         WRITE_DAT(0x20);
         WRITE_CGRAM(0,bmp2);
         DELAY(150);
         WRITE_COM(0xa2);
         WRITE_DAT(0x20);
         WRITE_CGRAM(0,bmp1);
         DELAY(150);
         WRITE_COM(0xa1);
         WRITE_DAT(0x2e);
         WRITE_CGRAM(0,bmp2);
         DELAY(150);
         WRITE_COM(0xa2);
         WRITE_DAT(0x2e);
      }

      p = data7;
      WRITE_CGRAM(7,p);
      DELAY(10);
     
      DELAY(200);
      SET_ADDR(1);
      temp=0x41;
      for (i=0;i<16;i++) { WRITE_DAT(temp++);DELAY(50);}
      SET_ADDR(2);
      for (i=0;i<16;i++) { WRITE_DAT(temp++);DELAY(50);}
      SET_ADDR(3);
      temp=0x30;
      for (i=0;i<16;i++) { WRITE_DAT(temp++);DELAY(50);}
      SET_ADDR(4);
      for (i=0;i<16;i++) { WRITE_DAT(temp++);DELAY(50);}
      DELAY(200);
      SET_ADDR(1);
      for (i=0;i<16;i++) { WRITE_DAT(0x07);DELAY(50);}
      SET_ADDR(2);
      for (i=0;i<16;i++) { WRITE_DAT(0x07);DELAY(50);}
      SET_ADDR(3);
      for (i=0;i<16;i++) { WRITE_DAT(0x07);DELAY(50);}
      SET_ADDR(4);
      for (i=0;i<16;i++) { WRITE_DAT(0x07);DELAY(50);}
      /*Test data start*/
      DELAY(200);
      p = data4;
      WRITE_CGRAM(7,p);
      DELAY(200);
      p = data1;
      WRITE_CGRAM(7,p);
      DELAY(200);
      p = data3;
      WRITE_CGRAM(7,p);
      DELAY(200);
      p = data6;
      WRITE_CGRAM(7,p);
      DELAY(200);
      /*Test data end*/
      SET_ADDR(1);
      p=data8;
      for (i=0;i<16;i++) { WRITE_DAT(*p++);DELAY(50);}
      SET_ADDR(2);
      p=data9;
      for (i=0;i<16;i++) { WRITE_DAT(*p++);DELAY(50);}
     
      SET_ADDR(3);
      p=data10;
      for (i=0;i<16;i++) { WRITE_DAT(*p++);DELAY(50);}
      SET_ADDR(4);
      p=data11;
      for (i=0;i<16;i++) { WRITE_DAT(*p++);DELAY(50);}
      DELAY(400);
    }
  }

[来源:深圳市炜烨兴电子有限公司] [作者:yesever] [日期:09-03-29] [热度:]

评论

© 2004-2015 Wayeah LCM All rights reserved.

Powered by: KingCMS 5.1.0.0812

|2009旧版 | 联系方式 | 付款方式 | 淘宝店|