独闷闷网

 找回密码
 立即注册
搜索
查看: 3353|回复: 0
打印 上一主题 下一主题
收起左侧

[原创] T6963芯片驱动的12864液晶模块的C语言程序

[复制链接]
跳转到指定楼层
楼主
发表于 2013-12-25 00:06:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
//来自电子开发者论坛
//                   T6963驱动芯片 12864 液晶模块
//***************************************************************************
//连线表:  CPU=89C52                                                        *
//C/D=P2.0           /CE=P2.7            FS=P3.5         /WR=/WR   /RD=/RD  *
//FOSC=12MHz         D0-D7=P0.0-P0.7     /RSET=/(CPU RSET)                  *
//***************************************************************************
#include <reg52.h>
#include <intrins.h>
#include <stdio.h>
#define uint  unsigned int
#define uchar unsigned char
#define Graphic 1
#define TXT  0
#define LcmLengthDots 128
#define LcmWidthDots 64
void Delay(uint MS);
sbit CSP = P2^7;
sbit RSP = P2^0;
sbit WRP = P3^6;
sbit RDP = P3^7;
sbit RES = P2^1;
#define LcmDataBus P0
char xdata LcmDataPort _at_ 0x0000;
char xdata LcmCmdPort  _at_ 0x0100;
sbit FS = P3^5;

uchar code bmp1[];
uchar code str1[];
//来自电子开发者论坛
//指令&数据读写状态
void CheckRWCD(void)
{
CSP = 0;
WRP = 1;
RSP = 1;
LcmDataBus = 0xff;
RDP = 0;
while((LcmDataBus & 0x03) != 0x03);
RDP = 1;
CSP = 1;
// while((LcmCmdPort & 0x03) != 0x03); //低电平忙
}
//数据自动写状态
void CheckAutoWrite(void)
{
CSP = 0;
WRP = 1;
RSP = 1;
LcmDataBus = 0xff;
RDP = 0;
while((LcmDataBus & 0x08) ==0 );
RDP = 1;
CSP = 1;
// while((LcmCmdPort & 0x08) == 0); //低电平忙
}
//一个数据子写入函数
void LcmWriteData(uchar uData)   
{
CSP = 0;
RDP = 1;
RSP = 0;
LcmDataBus = uData;
WRP = 0;
WRP = 1;
CSP = 1;
LcmDataBus = 0xff;
// LcmDataPort = uData;
}
//一个数据读出函数
uchar LcmReadData( void )
{
uchar uData;
    CSP = 0;
WRP = 1;
RSP = 0;
LcmDataBus = 0xff;
RDP = 0;
uData = LcmDataBus;
RDP = 1;
CSP = 1;
// uData = LcmDataPort;
return uData;
}
//来自电子开发者论坛
//无参数指令写入函数
void LcmWriteCommand(uchar Command)   
{
CheckRWCD();    //检测指令读写状态
CSP = 0;
RDP = 1;
RSP = 1;
LcmDataBus = Command;
WRP = 0;
WRP = 1;
CSP = 1;
LcmDataBus = 0xff;
// LcmCmdPort = Command;
}
//单参数指令写入函数
void LcmWriteCommandWith1Par(uchar Parameter,uchar Command)
{
LcmWriteData(Parameter);
LcmWriteCommand(Command);
// CheckRWCD();    //检测指令读写状态
// LcmDataPort = Parameter;
// CheckRWCD();
// LcmCmdPort = Command;
}
//双参数指令写入函数
void LcmWriteCommandWith2Par(uchar Parameter1,uchar Parameter2,uchar Command)
{
LcmWriteData(Parameter1);
LcmWriteData(Parameter2);
LcmWriteCommand(Command);
// CheckRWCD();    //检测指令读写状态
// LcmDataPort = Parameter1;
// CheckRWCD();
// LcmDataPort = Parameter2;
// CheckRWCD();
// LcmCmdPort = Command;
}
//LCM初始化函数
void LcmInit( void )
{
RES = 0;
    Delay(10);
RES = 1;
    Delay(30);
LcmWriteCommandWith2Par(0x00,0x00,0x40); //设置文本显示区首地址
LcmWriteCommandWith2Par(LcmLengthDots/8,0x00,0x41); //设置文本显示区宽度
LcmWriteCommandWith2Par(0x00,0x08,0x42); //设置图形显示区首地址0x0800
LcmWriteCommandWith2Par(LcmLengthDots/8,0x00,0x43); //设置图形显示区宽度
LcmWriteCommand(0xA7);   //设置光标形状 8x8方块
LcmWriteCommand(0x81);   //显示方式设置 文本xor图形(异或)
LcmWriteCommand(0x9C);   //显示开关设置 文本开,图形开,光标闪烁关
}
//延时函数
void Delay(uint MS)
{
uchar us,usn;
while(MS!=0)    //12M Crystal
{
  usn = 2;
  while(usn!=0)
  {
   us=0xf2;
   while (us!=0){us--;};
   usn--;
  }
  MS--;
}
}
//通过按键设定延时函数
void DelayKey(unsigned char HalfSecond)
{     //Delay_key加入时间参数0.5秒一级
unsigned int i;
for(i=0;i<50*HalfSecond;i++)  //12M Crystal
{
  Delay(10);
}
}
//清显示存储器函数
void LcmClear( uchar FillByte )
{
uint i = 8192; //此处仅清8K RAM,如果您32K RAM都使用,请修改i=32768(后面也要改)
if(FillByte)  //注意如果填充ff时,如果RAM仅使用了8K,那么8192次会写入到文本区
{   //会形成乱码.(24064出厂时候默认将R7断开,即默认使用8KRAM)
  i -= 2*1024;//所以如果填入ff时候要扣除2K的文本区
    LcmWriteCommandWith2Par(0x00,0x08,0x24); //填充0xff时候要在图形区
}
else
  LcmWriteCommandWith2Par(0x00,0x00,0x24);
LcmWriteCommand(0xB0);   //进入自动写
while(i--)
{
  CheckAutoWrite();
  LcmWriteData( FillByte );
}
LcmWriteCommand(0xB2);   //退出自动写
}
//设定显示地址函数
void LocateXY(uchar x,uchar y,uchar mode)
{
uint  temp;
temp= LcmLengthDots/8*y + x;
if(mode)    //mode=1为Graphic
{     //如果图形模式要加上图形区首地址0x0800
  temp+=0x0800;
}
LcmWriteCommandWith2Par(temp&0xff,temp/256,0x24);
}
//显示一个ASCII码函数
void PutChar(uchar x,uchar y,uchar CharByte)
{
LocateXY(x,y,TXT);
LcmWriteCommandWith1Par(CharByte,0xC4);
}
//显示一个字符串函数
void PutString(uchar x,uchar y,uchar *str)
{
while(*str != 0)
{
  if(x> 15)  //自动换行
  {
   x=0;
   y++;
  }
  PutChar(x,y,*str);
  ++x;
  ++str;
}
}
//显示一副图片函数
void DisplayOneBmp(uchar *puts)
{
uchar i,j;
uint  X=0;
LocateXY(0,0,Graphic);
LcmWriteCommand(0xB0);   //进入自动写
for(i=0;i<LcmWidthDots;i++)
{
  for(j=0;j<LcmLengthDots/8;j++)
  {
   CheckAutoWrite();
   LcmWriteData(puts[X]);
   X++;
  }
}
LcmWriteCommand(0xB2);   //退出自动写
}
//反显一副图片函数
void ReverseOneBmp( void )
{     //利用数据一次读写操作
uchar i,j,X;  //只能对一段RAM取反
LocateXY(0,0,Graphic);
for(i=0;i<LcmWidthDots;i++)
{
  for(j=0;j<LcmLengthDots/8;j++)
  {
   LcmWriteCommand(0xC5); //读数据,地址不变
   CheckRWCD();
   X = LcmReadData();
   X = ~X;
   LcmWriteCommandWith1Par(X,0xC0);
  }
}
}
//显示点阵子函数
void DisplayDots(uchar DotByte,uchar n)
{
     uchar i,j;
     LocateXY(0,0,Graphic);
     LcmWriteCommand(0xB0);                  //进入自动写
     for(i=0;i<LcmWidthDots/n;i++)
     {
           for(j=0;j<LcmLengthDots/8*n;j++)
           {
                 CheckAutoWrite();
                 LcmWriteData(DotByte);
           }
           DotByte=~DotByte;
     }
     LcmWriteCommand(0xB2);                  //退出自动写
}
//来自电子开发者论坛
//主函数
void main(void)        
{
uchar i;
FS =0;
Delay(60);
LcmInit();
LcmClear(0);
while(1)
{
  DisplayOneBmp(bmp1); //显示一副图片
  DelayKey(3);
  ReverseOneBmp();  //反显当前图片
  DelayKey(3);
  LcmClear(0);  //清屏,此处不清屏可观察文本xor图形的显示效果
  for(i=0;i<8;i++)   //显示一屏字符串
   PutString(0,i,str1);
  DelayKey(3);
  LcmClear(0);
  LcmClear(0xff);  //全黑检测
  DelayKey(3);
  DisplayDots(0x55,1);
  DelayKey(3);
  DisplayDots(0xaa,1);
  DelayKey(3);
  DisplayDots(0x33,2);
  DelayKey(3);
  DisplayDots(0xcc,2);
  DelayKey(3);
  DisplayDots(0xF0,4);
  DelayKey(3);
  DisplayDots(0x0F,4);
  DelayKey(3);
}
}


//代码区
uchar code str0[]=    "Welcome to use lcm 12864 !    ";
uchar code str1[]= {
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41
};

uchar code bmp1[]={
//********************************************************//
//***** 源图形宽度 * 高度:128 * 64
//***** 调整后宽度 * 高度:128 * 64
//***** 字模格式:横向取模,冗余模式,字节正序,正色取模,
//***** 位图点阵占用1024字节
//********************************************************//
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,
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,
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,
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,
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,
0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x06,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x80,0x30,0xDF,0x06,0x0C,0x01,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xF9,0x80,0x33,0xDF,0x06,0xFF,0xE1,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xF9,0xFC,0x33,0x1B,0x0C,0xFF,0xE1,0x8C,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1B,0xFC,0x03,0x1B,0x0C,0x0C,0x01,0x8C,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xDB,0x0C,0x03,0x1B,0x1C,0xFF,0xC1,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xDB,0x6C,0x7B,0x1B,0x1C,0xFF,0xC1,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x71,0x60,0x7B,0x1B,0x1C,0xCC,0xC1,0x8C,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x60,0x1B,0x1B,0x0C,0xFF,0xC1,0x8C,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x60,0x1B,0x5F,0x0C,0xFF,0xC1,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x78,0x60,0x1B,0xDF,0x0C,0x0C,0x01,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x6C,0xF0,0x1B,0x98,0x0C,0x6C,0x01,0x8C,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xC9,0xD8,0x18,0x18,0x0C,0x78,0x01,0x8C,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xC3,0x9C,0x3C,0x18,0x0C,0x1E,0x03,0x0C,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x8F,0x0E,0x77,0xFF,0x8D,0xF7,0xE3,0x0C,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x04,0x23,0xFF,0x8C,0xE1,0xC6,0x0C,0xE0,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,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,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,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,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,0x03,0x00,0x00,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x3F,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFE,0x3F,0x7F,0xC0,0x00,0x00,0x00,
0x00,0x00,0x02,0x03,0x81,0xC0,0xF0,0x18,0x03,0xFE,0x33,0x7F,0xC0,0x00,0x00,0x00,
0x00,0x00,0x06,0x04,0x42,0x21,0x08,0x18,0x03,0x00,0x36,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x0E,0x08,0x24,0x11,0x08,0x28,0x03,0x00,0x36,0x6C,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x08,0x24,0x12,0x00,0x28,0x3F,0xFC,0x36,0x6C,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x22,0x22,0xE0,0x48,0x3F,0xFC,0x33,0x7F,0x80,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x41,0xC3,0x10,0x88,0x30,0x0C,0x33,0x7F,0x80,0x00,0x00,0x00,
0x00,0x00,0x02,0x00,0x82,0x22,0x08,0x88,0x30,0x0C,0x33,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x01,0x04,0x12,0x09,0x08,0x3F,0xFC,0x37,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x02,0x04,0x12,0x09,0xFC,0x3F,0xFC,0x36,0xFF,0xC0,0x00,0x00,0x00,
0x00,0x00,0x02,0x04,0x04,0x12,0x08,0x08,0x60,0x06,0x30,0xFF,0xC0,0x00,0x00,0x00,
0x00,0x00,0x02,0x08,0x02,0x21,0x10,0x08,0x66,0x66,0x30,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x0F,0xE1,0xC0,0xE0,0x08,0xC6,0x63,0x30,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC6,0x63,0x30,0x0C,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,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,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,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,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,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,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
乐于分享,勇于质疑!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|独闷闷网 ( 粤ICP备12007667号-2 )

GMT+8, 2024-11-29 16:28 , Processed in 0.152048 second(s), 19 queries .

快速回复 返回顶部 返回列表