独闷闷网

 找回密码
 立即注册
搜索
查看: 2118|回复: 1
收起左侧

[原创] 液晶模块12232的C语言驱动程序

[复制链接]
发表于 2013-12-22 18:39:12 | 显示全部楼层 |阅读模式

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

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

x
//来自电子开发者论坛
//              12232系列 SED1520 示例程序
//连线表:       CPUClock=12Mhz                      *
//  LCM   -----   CPU                                           *
//  RES   -----   P3.0                                          *
//  E1    -----   P3.1                                          *
//  E2    -----   P3.2                                          *
//  RW    -----   P3.3                                          *
//  RS    -----   P3.4                                          *
//  DB0~7 -----   P1.0~P1.7                                     *
//***************************************************************
#include <reg52.h>
#include <intrins.h>
#define Uchar unsigned char
#define Uint  unsigned int
sbit RES=P3^0;
sbit E1 =P3^1;
sbit E2 =P3^2;
sbit RW =P3^3;
sbit RS =P3^4;
#define LcmDataBus P1
Uchar Page;
Uchar Col;
Uchar code HZB[];
Uchar code BMP1[];

void DelayUS(Uint US)
{
while(US!=0) {US--;}
}
void DelayMS(Uint MS)
{
Uchar us,usn;
while(MS!=0)
{
  usn = 2; //for 12M
  while(usn!=0)
  {
   us=0xf6;
   while (us!=0){us--;};
   usn--;
  }
  MS--;
}
}
//来自电子开发者论坛
void LcmWrCmd1( Uchar CommandByte )
{
RS = 0;
RW = 1;
LcmDataBus = 0xff;
E1 = 1;
while(LcmDataBus & 0x80);
E1 = 0;
LcmDataBus = CommandByte;
RS = 0;
RW = 0;
E1 = 1;
DelayUS(3);
E1 = 0;
DelayUS(3);
}
void LcmWrCmd2( Uchar CommandByte )
{
RS = 0;
RW = 1;
LcmDataBus = 0xff;
E2 = 1;
while(LcmDataBus & 0x80);
E2 = 0;
LcmDataBus = CommandByte;
RS = 0;
RW = 0;
E2 = 1;
DelayUS(3);
E2 = 0;
DelayUS(3);
}
void LcmWrDat( Uchar DataByte )
{
if(Col<61)  //Col在0-60左半屏
{
  LcmWrCmd1(0x03&age|0xB8);
  LcmWrCmd1(0x7F&Col);
  
  RS = 0;
  RW = 1;
  LcmDataBus = 0xff;
  E1 = 1;
  while(LcmDataBus & 0x80);
  E1 = 0;
  
  LcmDataBus = DataByte;
  RS = 1;
  RW = 0;
  E1 = 1;
  DelayUS(3);
  E1 = 0;
  DelayUS(3);
}
else   //Col在61-121右半屏
{
  LcmWrCmd2(0x03&age|0xB8);
  LcmWrCmd2(0x7F&(Col-61));
  
  RS = 0;
  RW = 1;
  LcmDataBus = 0xff;
  E2 = 1;
  while(LcmDataBus & 0x80);
  E2 = 0;
  
  LcmDataBus = DataByte;
  RS = 1;
  RW = 0;
  E2 = 1;
  DelayUS(3);
  E2 = 0;
  DelayUS(3);
}
}
Uchar LcmRdDat( void )
{
Uchar ReadData;
if(Col<61)  //Col在0-60左半屏
{
  LcmWrCmd1(0x03&age|0xB8);
  LcmWrCmd1(0x7F&Col);
  
  RS = 0;
  RW = 1;
  LcmDataBus = 0xff;
  E1 = 1;
  while(LcmDataBus & 0x80);
  E1 = 0;
  
  RS = 1;
  RW = 1;
  LcmDataBus = 0xff;
  E1 = 1;
  DelayUS(3);
  ReadData = LcmDataBus; //假读一次
  E1 = 0;
  DelayUS(3);
  E1 = 1;
  DelayUS(3);
  ReadData = LcmDataBus;
  E1 = 0;
  DelayUS(3);
  
}
else   //Col在61-121右半屏
{
  LcmWrCmd2(0x03&age|0xB8);
  LcmWrCmd2(0x7F&(Col-61));
  
  RS = 0;
  RW = 1;
  LcmDataBus = 0xff;
  E2 = 1;
  while(LcmDataBus & 0x80);
  E2 = 0;
  
  RS = 1;
  RW = 1;
  LcmDataBus = 0xff;
  E2 = 1;
  DelayUS(3);
  ReadData = LcmDataBus; //假读一次
  E2 = 0;
  DelayUS(3);
  E2 = 1;
  DelayUS(3);
  ReadData = LcmDataBus;
  E2 = 0;
  DelayUS(3);
}
return ReadData;
}
void LcmInit( void )
{
LcmWrCmd1(0xE2);
LcmWrCmd2(0xE2);

LcmWrCmd1(0xA4);
LcmWrCmd2(0xA4);

LcmWrCmd1(0xA9);
LcmWrCmd2(0xA9);

LcmWrCmd1(0xA0);
LcmWrCmd2(0xA0);

LcmWrCmd1(0xC0);
LcmWrCmd2(0xC0);

LcmWrCmd1(0);
LcmWrCmd2(0);

LcmWrCmd1(0xAF);
LcmWrCmd2(0xAF);
}
void LcmClear( Uchar FillByte )
{
Page = 0;
Col  = 0;
for(Page=0age<4age++)
{
  for(Col=0;Col<122;Col++)
  {
   LcmWrDat(FillByte);
  }
}
}
void LcmPutDots( Uchar DotByte,Uchar n )
{
Uchar i,j;
Page = 0;
Col  = 0;
for(Page=0age<(32/8)age++)
{
  Col=0;
  for(j=0;j<(124/n);j++)  //122不能被4整除,当作124来处理,多出2SEG不会显示
  {
   for(i=0;i<n;i++)
   {
    LcmWrDat( DotByte );
    Col++;
   }
   DotByte = ~DotByte;
  }
  if(n>=4) DotByte = ~DotByte;
}
}
void LcmPutHZ( Uchar HZcode )
{
Uchar i,j;
Uint  x;
x = 0x20*HZcode;
for(i=0;i<2;i++)
{
  for(j=0;j<16;j++)
  {
   LcmWrDat(HZB[x]);
   x++;
   Col++;
  }
  Page++;
  Col = Col-16;
}
Page = Page-2;
}
void LcmPutBMP( Uchar *puts )
{
Uint X=0;
Page = 0;
Col  = 0;
for(Page=0age<4age++)
{
  for(Col=0;Col<122;Col++)
  {
   LcmWrDat(puts[X]);
   X++;
  }
}
}
void LcmReverseBMP( void )
{
unsigned char temp;
Page = 0;
Col  = 0;
for(Page=0;Page<4;Page++)
{
  for(Col=0;Col<122;Col++)
  {
   temp = LcmRdDat();
   temp = ~temp;
   LcmWrDat(temp);
  }
}
}
//来自电子开发者论坛
void Main( void )  
{
Uchar HZ;
RES = 0;
DelayMS(10);
RES = 1;
DelayMS(30);
LcmInit();
LcmClear(0);
while(1)
{
  LcmPutBMP(BMP1);
  DelayMS(1200);
  
  LcmReverseBMP();
  DelayMS(1200);
  
  LcmPutDots(0x55,1);
  DelayMS(1200);
  
  LcmPutDots(0xAA,1);
  DelayMS(1200);
  
  LcmPutDots(0x33,2);
  DelayMS(1200);
  
  LcmPutDots(0xCC,2);
  DelayMS(1200);
  
  LcmClear(0xff);
  DelayMS(1200);
  
  LcmClear(0);
  DelayMS(1200);
  
  Page = 0;
  Col  = 21;
  for(HZ=0;HZ<5;HZ++)  
  {
   LcmPutHZ(HZ);
   Col = Col+16;
  }
  Page = 2;
  Col  = 13;
  for(HZ=5;HZ<11;HZ++)
  {
   LcmPutHZ(HZ);
   Col = Col+16;
  }
  DelayMS(1200);
}
}
Uchar code HZB[]={
/*--  文字:  正  --*/
0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,
0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
/*--  文字:  在  --*/
0x00,0x04,0x04,0xC4,0x64,0x9C,0x87,0x84,0x84,0xE4,0x84,0x84,0x84,0x84,0x04,0x00,
0x04,0x02,0x01,0x7F,0x00,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00,
/*--  文字:  检  --*/
0x08,0x88,0x68,0xFF,0x28,0x48,0x10,0x48,0x44,0x43,0x44,0x48,0x50,0x10,0x10,0x00,
0x02,0x01,0x00,0x7F,0x00,0x20,0x22,0x2C,0x21,0x2E,0x30,0x28,0x27,0x22,0x20,0x00,
/*--  文字:  测  --*/
0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,
0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,
/*--  文字:  中  --*/
0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,
/*--  文字:  文  --*/
0x08,0x08,0x08,0x08,0x78,0x88,0x09,0x0E,0x08,0x88,0x78,0x08,0x08,0x08,0x08,0x00,
0x40,0x40,0x40,0x20,0x20,0x11,0x0A,0x04,0x0A,0x11,0x10,0x20,0x60,0x20,0x20,0x00,
/*--  文字:  本  --*/
0x08,0x08,0x08,0x08,0x08,0xC8,0x38,0xFF,0x18,0x68,0x88,0x08,0x08,0x08,0x08,0x00,
0x08,0x08,0x04,0x02,0x05,0x04,0x04,0x7F,0x04,0x04,0x04,0x03,0x06,0x0C,0x04,0x00,
/*--  文字:  显  --*/
0x00,0x00,0x00,0x3E,0x2A,0xEA,0x2A,0x2A,0x2A,0xEA,0x2A,0x3E,0x00,0x00,0x00,0x00,
0x20,0x21,0x22,0x2C,0x20,0x3F,0x20,0x20,0x20,0x3F,0x28,0x24,0x23,0x20,0x20,0x00,
/*--  文字:  示  --*/
0x00,0x20,0x20,0x22,0x22,0x22,0x22,0xE2,0x22,0x22,0x22,0x22,0x22,0x20,0x20,0x00,
0x10,0x08,0x04,0x03,0x00,0x40,0x80,0x7F,0x00,0x00,0x01,0x02,0x0C,0x18,0x00,0x00,
/*--  文字:  模  --*/
0x10,0xD0,0xFF,0x50,0x90,0x04,0xF4,0x54,0x5F,0x54,0x54,0x5F,0xF4,0x04,0x00,0x00,
0x03,0x00,0xFF,0x00,0x00,0x84,0x85,0x45,0x35,0x0F,0x15,0x25,0x65,0xC4,0x44,0x00,
/*--  文字:  式  --*/
0x00,0x08,0x88,0x88,0x88,0x88,0x88,0x08,0xFF,0x08,0x09,0x0E,0x0A,0x08,0x00,0x00,
0x00,0x20,0x60,0x30,0x1F,0x10,0x08,0x08,0x00,0x07,0x18,0x20,0x40,0x80,0x70,0x00,
};
Uchar code BMP1[]={
0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x21,
0xF1,0x01,0x01,0x01,0x01,0x61,0x11,0x11,0x11,0xE1,0x01,0x01,0x61,0x11,0x11,0x11,
0xE1,0x01,0x81,0x81,0x01,0x81,0x81,0x81,0x01,0x01,0x21,0x11,0x91,0x91,0x61,0x01,
0x01,0x61,0x11,0x11,0x11,0xE1,0x01,0x01,0xFD,0x45,0x25,0xBD,0x55,0x55,0xB5,0x15,
0x05,0xFD,0x01,0x01,0x89,0x89,0xF9,0x89,0x89,0xF9,0x8D,0x49,0x21,0x91,0x49,0x01,
0x01,0x01,0x01,0xC1,0x41,0x41,0x7D,0x51,0x51,0x51,0xD1,0x11,0x01,0x01,0x01,0xF9,
0x49,0xA9,0x19,0x91,0xF1,0x9D,0xD1,0x91,0x91,0x11,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0xFF,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,0x9F,0x90,0x80,0x80,0x80,0x98,
0x94,0x92,0x91,0x90,0x80,0x80,0x98,0x94,0x92,0x91,0x90,0x80,0x90,0x99,0x96,0x86,
0x99,0x90,0x80,0x80,0x88,0x90,0x90,0x90,0x8F,0x80,0x80,0x98,0x94,0x92,0x91,0x90,
0x80,0x80,0xBF,0x92,0x91,0x94,0x95,0x9A,0x90,0x91,0x91,0xBF,0x80,0x80,0xA0,0x90,
0x8F,0x80,0x80,0xBF,0x80,0xA2,0x91,0x88,0x84,0x82,0x80,0xA0,0x98,0x83,0x8A,0xB2,
0x82,0x8A,0xB2,0x82,0x8B,0xB0,0x80,0x80,0x80,0xBF,0x84,0x84,0x83,0x84,0x84,0x84,
0xBF,0x84,0x84,0x84,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0xFF,0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFD,0x45,0x25,0xBD,0x55,0x55,
0xB5,0x15,0x05,0xFD,0x01,0x01,0x89,0x89,0xF9,0x89,0x89,0xF9,0x8D,0x49,0x21,0x91,
0x49,0x01,0x01,0x01,0x01,0xF9,0xA9,0xA9,0xA9,0xA9,0xA9,0xA9,0xFD,0x09,0x01,0x01,
0x01,0x41,0x49,0x49,0x49,0x49,0xC9,0x49,0x49,0x4D,0x69,0x41,0x01,0x21,0xA1,0xFD,
0xA1,0x09,0xE9,0xBD,0xA9,0xA9,0xBD,0xE9,0x09,0x01,0x21,0xA1,0xA1,0xA1,0xA1,0xA1,
0x21,0xFD,0x21,0x29,0x31,0x21,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0xFF,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0xBF,0x92,0x91,0x94,0x95,0x9A,0x90,0x91,0x91,0xBF,0x80,0x80,
0xA0,0x90,0x8F,0x80,0x80,0xBF,0x80,0xA2,0x91,0x88,0x84,0x82,0x80,0xA0,0xA2,0xA4,
0xA8,0xBF,0xA0,0xA0,0xBF,0xA8,0xA4,0xB2,0xA0,0x80,0x90,0x88,0x84,0x83,0x80,0xA0,
0xBF,0x80,0x81,0x82,0x84,0x98,0x80,0x83,0x80,0xBF,0xA0,0xA9,0xAB,0x9A,0x8E,0x8A,
0x9A,0xAB,0xA8,0x80,0x90,0xB0,0x90,0x9F,0x88,0x88,0x88,0x83,0x8C,0x90,0xA0,0xB8,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFF,
};

乐于分享,勇于质疑!
luoyouren 该用户已被删除
发表于 2013-12-23 00:03:24 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
乐于分享,勇于质疑!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2020-10-21 09:58 , Processed in 0.134263 second(s), 18 queries .

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