⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 19264lcd.c

📁 普通19264图形液晶模块的单片机驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
									//  CA19264A  Demo Program
//***************************************************************************
//*  Create by :liujun     2005.02.28                                       *
//***************************************************************************
//连线表:  CPU=89C52                                                        *
//RS=P2.0     R/W=P2.1     E=P2.2     CS1=P2.3     CS2=P2.4                 *
//SysClock=12MHz           DB0-DB7=P2.0-P2.7       /Reset=InBoard           *
//因为这款液晶是两个片选,00 01 10表示三个芯片,三个片选各自代表一个道理是一样的。 
//***************************************************************************

#include <reg52.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>

/********************引脚定义********************/

sbit CS1 =P1^3; //1片选
sbit CS2 =P1^5; //2片选
sbit CS3 =P1^6; //3片选
sbit RS  =P1^0; //数据指令
sbit RW  =P1^1; //读写
sbit E   =P1^2; //使能
sbit RST =P1^5;//复位
//sbit Sbreak=P

unsigned char Page; //页 地址
unsigned char Col; //列 地址

unsigned char code BMP1[];
unsigned char code BMP2[];
char code Hanzi[];

void Delay(unsigned int MS);
void wtcom(void);

/***************************/
/*检查Busy                 */
/***************************/
void BusyL(void)
{
 CS1= 0;
 CS2= 1;
 CS3= 1;
 wtcom();
}

void BusyM(void)
{
 CS1= 1;
 CS2= 0;
 CS3= 1;
 wtcom();
}

void BusyR(void)
{
 CS1= 1;
 CS2= 1;
 CS3= 0;
 wtcom();
}

void wtcom(void)
{
 RS = 0;  //指令
 RW = 1;
 P2 = 0xFF; //输出0xff以便读取正确
 E  = 1;
 _nop_();
 while(P2 & 0x80); //Status Read Bit7 = BUSY
 E  = 0;
 _nop_();
}

/********************************************************/
/*根据设定的坐标数据,定位LCM上的下一个操作单元位置 */
/********************************************************/
void Locatexy(void)
{
 unsigned char x,y;
 switch (Col&0xc0) /*  col.and.0xC0 */
 {   /*条件分支执行  */
  case 0: {BusyL();break;}/*左区 */
  case 0x40: {BusyM();break;}/*中区 */
  case 0x80: {BusyR();break;}/*右区 */
 }
 x = Col&0x3F|0x40; /* col.and.0x3f.or.Set Y Address*/
 y = Page&0x07|0xB8; /* row.and.0x07.or.set Page */
 wtcom();  /* waitting for enable */
 RS = 0;   //指令
 RW = 0;   //写
 P2 = y;   //设置页面地址
 E  = 1;
 _nop_();
 E  = 0;
 _nop_();
 wtcom();  /*  waitting for enable */
 RS = 0;
 RW = 0;
 P2 = x;   //设置列地址
 E  = 1;
 _nop_();
 E  = 0;
 _nop_();
}

/***************************/
/*写指令                   */
/***************************/
void WriteCommandL( unsigned char CommandByte )
{
 BusyL();
 P2 = CommandByte;
 RS = 0;  //指令
 RW = 0;
 E  = 1;
 _nop_();
 E  = 0;
 _nop_();
}

void WriteCommandM( unsigned char CommandByte )
{
 BusyM();
 P2 = CommandByte;
 RS = 0;  //指令
 RW = 0;
 E  = 1;
 _nop_();
 E  = 0;
 _nop_();
}

void WriteCommandR( unsigned char CommandByte )
{
 BusyR();
 P2 = CommandByte;
 RS = 0;  //指令
 RW = 0;
 E  = 1;
 _nop_();
 E  = 0;
 _nop_();
}

/***************************/
/*读数据                   */
/***************************/
unsigned char ReadData( void )
{
 unsigned char DataByte;
 Locatexy(); /*坐标定位,返回时保留分区状态不变 */
 RS = 1;  /*数据输出*/
 RW = 1;  /*读入  */
 P2 = 0xFF;  //输出0xff以便读取正确
 E  = 1;  /*读入到LCM*/
 _nop_();
 DataByte = P2; /*数据读出到数据口P2 */
 E  = 0;
 _nop_();
 return DataByte;
}

/***************************/
/*写数据                   */
/***************************/
void WriteData( unsigned char DataByte )
{
 Locatexy(); /*坐标定位,返回时保留分区状态不变 */
 RS = 1;  /*数据输出*/
 RW = 0;  /*写输出  */
 P2 = DataByte; /*数据输出到数据口 */
 E  = 1;  /*写入到LCM*/
 _nop_();
 E  = 0;
 _nop_();
}

void LcmClear( void )
{
 Page = 0;
 Col  = 0;
 for(Page=0;Page<8;Page++)
  for(Col=0;Col<192;Col++)
   WriteData(0);
}

void LcmInit( void )
{
 WriteCommandL(0x3f); //开显示
 WriteCommandM(0x3f);
 WriteCommandR(0x3f);
 
 WriteCommandL(0xc0); //设置起始地址=0
 WriteCommandM(0xc0);
 WriteCommandR(0xc0);

 WriteCommandL(0x3f); //开显示
 WriteCommandM(0x3f);
 WriteCommandR(0x3f);

 LcmClear();
 Col = 0;
 Page= 0;
 Locatexy();
}
/*
void LcmPutDots( unsigned char DotByte )
{
 Page = 0;
 Col  = 0;
 for(Page=0;Page<8;Page++)
 {
  for(Col=0;Col<192;Col++)
  {
   WriteData( DotByte );
   DotByte = ~DotByte;
  }
 }
}  */

void LcmPutBMP( unsigned char *puts )
{
 unsigned int X=0;
 Page = 0;
 Col  = 0;
 for(Page=0;Page<8;Page++)
 {
  for(Col=0;Col<192;Col++)
  {
   WriteData( puts[X] );
   X++;
  }
 }
}

void LcmReverseBMP( void )
{
 unsigned char temp;
 Page = 0;
 Col  = 0;
 for(Page=0;Page<8;Page++)
 {
  for(Col=0;Col<192;Col++)
  {
   temp = ReadData(); //空读一次

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -