论坛风格切换切换到宽版
  • 4421阅读
  • 2回复

求个24064LCD的驱动程序. [复制链接]

上一主题 下一主题
离线顺义火腿
 
只看楼主 倒序阅读 0楼 发表于: 2008-03-08
我有个24064的液晶屏, 求个驱动程序.

我找了个程序, 但显示的都是格子, 想显示文字, 但不会修改, 请高手帮助.
/****      test program for 24064   *****/
#include <stc89c51rc_rd_plus.h>      
#include <intrins.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit      cd = p2^0;      /*通道选择,=1为指令通道,=0为数据通道*/
sbit      ce = p2^7;      /*低电平有效,t6963c片选信号*/
sbit      fs = p3^5;      /*字体选择*/
sbit      rst = p2^3;      /*复位信号,低电平有效*/
sbit      rd = p3^7;      /*读操作,低电平有效*/
sbit      wr = p3^6;      /*写操作,低电平有效*/
sbit   test2 = p3^2;
sbit   test3 = p3^3;
sbit   test4 = p3^4;
sbit      sta0 = p0^0;
sbit      sta1 = p0^1;
sbit      sta2 = p0^2;
sbit      sta3 = p0^3;
sbit      sta4 = p0^4;
sbit      sta5 = p0^5;
sbit      sta6 = p0^6;
sbit      sta7 = p0^7;
sfr lcdbus=0x80;      /*数据总线,p0口,db0-db7*/
bit d1500ms_flag = 0;
uint data i;
uchar data time0_number;
uchar code han0[] = {0x80,0x81,0x82,0x83};
uchar code han1[] = {0x84,0x85,0x86,0x87};
uchar code han2[] = {0x88,0x89,0x8a,0x8b};
uchar code han3[] = {0x8c,0x8d,0x8e,0x8f};
uchar code han4[] = {0x90,0x91,0x92,0x93};
uchar code han5[] = {0x94,0x95,0x96,0x97};
uchar code han6[] = {0x98,0x99,0x9a,0x9b};
uchar code han7[] = {0x9c,0x9d,0x9e,0x9f};
uchar code han8[] = {0xa0,0xa1,0xa2,0xa3};
uchar code han9[] = {0xa4,0xa5,0xa6,0xa7};
uchar code han10[] = {0xa8,0xa9,0xaa,0xab};
uchar code han11[] = {0xac,0xad,0xae,0xaf};
uchar code han12[] = {0xb0,0xb1,0xb2,0xb3};
uchar code han13[] = {0xb4,0xb5,0xb6,0xb7};
uchar code han14[] = {0xb8,0xb9,0xba,0xbb};
uchar code han15[] = {0xbc,0xbd,0xbe,0xbf};
uchar code han16[] = {0xc0,0xc1,0xc2,0xc3};
uchar code han17[] = {0xc4,0xc5,0xc6,0xc7};
uchar code han18[] = {0xc8,0xc9,0xca,0xcb};
uchar code han19[] = {0xcc,0xcd,0xce,0xcf};
uchar code han20[] = {0xd0,0xd1,0xd2,0xd3};
uchar code han21[] = {0xd4,0xd5,0xd6,0xd7};
uchar code tab[] =
     {
/*80*/      0x00,0x00,0x00,0x00,0xfc,0x8d,0x69,0x3a,
     0x00,0x00,0x80,0xc0,0x8c,0xf4,0x4c,0x58,
     0x38,0x6c,0xc1,0x03,0x1e,0x00,0x00,0x00,
     0xe0,0xb0,0x9c,0x0f,0x07,0x00,0x00,0x00,/*欢0*/
/*84*/      0x00,0x00,0x00,0x67,0x7e,0x04,0xf4,0x16,
     0x00,0x00,0x00,0xc8,0x7c,0x6c,0x6c,0xe8,
     0x17,0xff,0x83,0x00,0x00,0x00,0x00,0x00,
     0x70,0x60,0xff,0x7f,0x0c,0x00,0x00,0x00,/*迎1*/
/*88*/      0x00,0x00,0x00,0x38,0xf7,0xf0,0x33,0x32,
     0x00,0x00,0x60,0x60,0xfe,0x64,0xfc,0x6c,
     0x33,0x33,0x30,0x31,0x3f,0x00,0x00,0x00,
     0xfc,0xc0,0xf0,0x9f,0x07,0x02,0x00,0x00,/*使2*/
/*8c*/      0x00,0x00,0x08,0x0f,0x0c,0x0c,0x0f,0x0c,
     0x00,0x00,0x02,0xff,0x63,0x63,0xff,0x63,
     0x0f,0x18,0x18,0x38,0xf0,0x00,0x00,0x00,
     0xff,0x63,0x63,0x63,0x63,0x43,0x00,0x00,/*用3*/
/*90*/      0x00,0x00,0x40,0xff,0xc7,0x44,0x5b,0x46,
     0x00,0x00,0x00,0xfe,0x66,0xe6,0x86,0xe6,
     0x7a,0x41,0x47,0x40,0x7f,0x00,0x00,0x00,
     0x3e,0x86,0x86,0x06,0xfe,0x04,0x00,0x00,/*图4*/
/*94*/      0x00,0x00,0x00,0x7f,0x33,0x33,0xff,0xff,
     0x00,0x00,0x00,0xc7,0x1c,0x00,0xc7,0xcc,
     0x1b,0x1b,0x33,0xf3,0xc3,0x00,0x00,0x00,
     0x30,0x01,0x07,0x1c,0xf8,0x00,0x00,0x00,/*形5*/
/*98*/      0x00,0x00,0x01,0x01,0x01,0x19,0x1f,0x18,
     0x00,0x00,0x80,0xf0,0xfc,0x80,0xfc,0x0c,
     0x1f,0x08,0x12,0x76,0xc4,0x00,0x00,0x00,
     0xf8,0x08,0x4c,0x67,0x23,0x01,0x00,0x00,/*点6*/
/*9c*/      0x00,0x00,0x00,0xfd,0x67,0x68,0x79,0x6f,
     0x00,0x00,0x60,0x60,0xff,0xe0,0xb0,0xfc,
     0x6d,0x7b,0x67,0x60,0x60,0x40,0x00,0x00,
     0xb0,0xfc,0xff,0x30,0x30,0x30,0x00,0x00,/*阵7*/
/*a0*/      0x00,0x10,0x30,0x70,0xb0,0x10,0x10,0x10,
     0x00,0x00,0x18,0x24,0x46,0x42,0x02,0x06,
     0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xf0,
     0x06,0x0c,0x00,0x08,0x10,0x60,0x22,0x7e,/*12 8*/
/*a4*/      0x00,0x00,0x38,0x62,0x42,0x42,0x62,0x36,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,
     0x18,0x1c,0x26,0x46,0x42,0x42,0x43,0x3e,
     0x32,0x34,0x18,0x08,0x1c,0x24,0x26,0x47,/*8x 9*/
/*a8*/      0x00,0x00,0x06,0x08,0x10,0x20,0x20,0x60,
     0x00,0x00,0x00,0x04,0x0c,0x14,0x14,0x24,
     0x5e,0x62,0x42,0x43,0x43,0x42,0x62,0x3c,
     0x24,0x44,0x44,0x7f,0x04,0x04,0x04,0x04,/*64 10*/
/*ac*/      0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
     0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
     0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
     0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,/*....11*/
/*b0*/      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,/*全黑12*/
/*b4*/      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*全白13*/
/*b8*/      0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*上边14*/
/*bc*/      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,/*下边15*/
/*c0*/      0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*左边16*/
/*c4*/      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,/*右边17*/
/*c8*/      0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
     0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*左上18*/
/*cc*/      0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0xff,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,/*右上19*/
/*d0*/      0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xff,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,/*左下20*/
/*d4*/      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
     0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xff /*右下21*/
     };
void r_st(uchar w);    
void wdata(bit cd_flag,uchar d);   /*数据写操作*/
void dmod(uchar x0,uchar x1,uchar c);
void smod(uchar x1,uchar c);
void nmod(uchar c);

/* 使用寄存0 组     */
#pragma registerbank(0)
void soft_10ms(){
     register int i;
     for(i=0;i<711;i++);
}
/* 初始化       */
void initcomm(void)
{
  ie=0;
  p0=0xff;      p1=0xff;   p2=0xff;   p3=0xff;
  tmod=0x11; th0 = 0;   tl0 = 0;   tr0 = 1;
  et0 = 1;   ea = 1;
}

/* 初始化 lcd240128     */
void initlcd(void)
{
  dmod(0x00,0x00,0x40); /*文本显示区域首地址*/
  dmod(0x1e,0x00,0x41); /*文本显示宽度和一行显示字节数*/
  dmod(0x00,0x08,0x42); /*图形显示区域首地址*/
  dmod(0x1e,0x00,0x43); /*图形显示宽度,一行显示所占字节*/
  dmod(0x03,0x00,0x22); /*cgram首地址 00011 100000000 000 = 1c00h*/
  nmod(0xa7);         /*光标形状设置*/            
  nmod(0x80);         /*显示方式:逻辑“或”合成*/
  nmod(0x9c);         /*显示开关设置,开文本和图形显示*/
}
/* lcd 清0*/
void clear(void)
{
  dmod(0x00,0x00,0x24);     /*显示存储器首地址*/
  nmod(0xb0);             /*自动写方式*/
  for (i = 0;i < 0x2000;i++)
  {
    r_st(3);             /*等待自动写状态*/
    wdata(0,0);
  }
  nmod(0xb2);                   /*自动写结束*/
}
/****************************************************
读状态字
cd_flag = 1 读命令通到。 = 0 读数据通到。
w = 0 指令读,写状态,   返回1 准备好 返回0 忙。
w = 1 数据读,写状态,   返回1 准备好 返回0 忙。
w = 2 数据自动读状态,   返回1 准备好 返回0 忙。
w = 3 数据自动写状态,   返回1 准备好 返回0 忙。
w = 5 控制运行检测可能性,返回1 准备好 返回0 忙。
w = 6 屏读/栲贝出错状态, 返回1 正确 返回0 出错。
w = 7 闪烁状态检测,   返回1 正常显示 返回0 关显示。
******************************************************/
void r_st (uchar w)    
{
  uchar data i = 0;              
  uchar data c;  
  cd = 1;   lcdbus = 0xff;   ce = 0;
  while (--i)
  {
    rd = 0;     c = lcdbus;     rd = 1;     ce = 1;
    if ((w == 1) && ((c & 3) == 3))            return;
    if ((w == 3) && (c & 8))              return;      
  }
}
void wdata(bit cd_flag,uchar d)   /*数据写操作*/
{
  cd = cd_flag;
  lcdbus = d;
  ce = 0;   wr = 0;   wr = 1;   ce = 1;   cd = 0;
}
/*双参数指令*/
void dmod(uchar x0,uchar x1,uchar c)
{
  r_st(1);   wdata(0,x0);
  r_st(1);   wdata(0,x1);
  r_st(1);   wdata(1,c);
}
/*单参数指令*/
void smod(uchar x1,uchar c)
{
  r_st(1);   wdata(0,x1);
  r_st(1);   wdata(1,c);
}
/*无参数指令*/
void nmod(uchar c)
{
  r_st(1);   wdata(1,c);
}
/*************************************************************
建立cgram 函数(图形方式)
  *p 汉字库字符首地址
*************************************************************/
void cgram(uchar code *p)
{
  dmod(0x00,0x1c,0x24);
  nmod(0xb0);
  for (i = 0;i < 0x0400;i++)
    wdata(0,*p++);
  nmod(0xb2);    
}      

/*************************************************************
汉字写入函数(文本方式)
  o_y y 坐标(0-3)*2 改7为3, 只有4行
  o_x x 坐标(0-14)*2
  d_code 写入字符代码
*************************************************************/
void wri_ct(uchar code *p,uchar o_y,uchar o_x)
{
  uint c;
  c = o_y * 0x1e + o_x;
  dmod(c,c>> 8,0x24);
  smod(*p++,0xc0);
  smod(*p++,0xc0);
  c += 0x1e;
  dmod(c,c>> 8,0x24);
  smod(*p++,0xc0);
  smod(*p++,0xc0);      
  }
/****绘点子函数 o_y y 坐标(0-63,127)   o_x x 坐标(0-239)****/
void wri_d(uchar o_y,uchar o_x)
{
  uint c;
  c = o_y * 0x1e;
  dmod(c + (o_x / 8),(c + (o_x / 8) + 0x0800) >> 8,0x24);
  nmod((~(o_x % 8)) | 0xf8);
}          
/****   主函数   ****/
void main(void) using 0
{
  uchar ii,jj;
  ce = 1;   rst = 0;          
  initcomm();         /*初始化*/
  for(i = 0;i < 0x1000;i++) ;
  rst = 1;           /*复位*/
  fs = 0;
  initlcd();           /*初始化 lcd240128 */
  clear();           /* lcd 清0*/
  cgram(tab);
  while(1)
  {
     for(ii=0;ii<2;ii++)
     {
           for(jj=0;jj<15;jj++){wri_ct(han11,ii*2,jj*2);}
     }
     for(ii=0;ii<150;ii++){soft_10ms();}

     for(ii=0;ii<2;ii++)
     {
           for(jj=0;jj<15;jj++){wri_ct(han12,ii*2,jj*2);}
     }
     for(ii=0;ii<150;ii++){soft_10ms();}

     for(ii=0;ii<2;ii++)
     {
           for(jj=0;jj<15;jj++){wri_ct(han13,ii*2,jj*2);}
     }
     wri_ct(han0,2,3);      //wri_ct(han0,4,3);
     wri_ct(han1,2,6);      //wri_ct(han1,4,6);
     wri_ct(han2,2,9);      //wri_ct(han2,4,9);
     wri_ct(han3,2,12);      //wri_ct(han3,4,12);
     wri_ct(han4,2,15);      //wri_ct(han4,4,15);
     wri_ct(han5,2,18);      //wri_ct(han5,4,18);
     wri_ct(han6,2,21);      //wri_ct(han6,4,21);
     wri_ct(han7,2,24);      //wri_ct(han7,4,24);
     for(jj=0;jj<15;jj++){wri_ct(han14,0,jj*2);}
//      for(jj=0;jj<15;jj++){wri_ct(han15,6,jj*2);}
     for(jj=0;jj<2;jj++){wri_ct(han16,jj*2,0);}
     for(jj=0;jj<2;jj++){wri_ct(han17,jj*2,28);}
     wri_ct(han18,0,0);      wri_ct(han19,0,28);
//      wri_ct(han20,6,0);      wri_ct(han21,6,28);
     for(ii=0;ii<150;ii++){soft_10ms();}  
  }
}
离线阳光999
发帖
52
只看该作者 1楼 发表于: 2008-03-10
你得先确定你的lcd是否为t6963c的或兼容t6963c的
离线顺义火腿
只看该作者 2楼 发表于: 2008-03-23
是t6963c的

[quote=阳光999]你得先确定你的lcd是否为t6963c的或兼容t6963c的[/quote]