📄 19264.c
字号:
// CA19264A Demo Program
//***************************************************************************
//* Create by :liujun 2005.02.28 *
//***************************************************************************
//连线表: CPU=89C52 *
//RS=P3.0 R/W=P3.1 E=P3.2 CS1=P3.3 CS2=P3.4 *
//SysClock=12MHz DB0-DB7=P1.0-P1.7 /Reset=InBoard *
//***************************************************************************
#include<reg52.h>
#include<stdlib.h>
#include<intrins.h>
#include<stdio.h>
/********************引脚定义********************/
sbit RS =P3^0; //数据指令
sbit RW =P3^1; //读写
sbit E =P3^2; //使能
sbit CS1 =P3^3; //1片选
sbit CS2 =P3^4; //2片选
unsigned char Page; //页 地址
unsigned char Col; //列 地址
unsigned char code BMP1[];
unsigned char code BMP2[];
void Delay(unsigned int MS);
void wtcom(void);
/***************************/
/*检查Busy */
/***************************/
void BusyL(void)
{
CS1= 0;
CS2= 0;
wtcom();
}
void BusyM(void)
{
CS1= 0;
CS2= 1;
wtcom();
}
void BusyR(void)
{
CS1= 1;
CS2= 0;
wtcom();
}
void wtcom(void)
{
RS = 0; //指令
RW = 1;
P1 = 0xFF; //输出0xff以便读取正确
E = 1;
_nop_();
while(P1 & 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; //写
P1 = y; //设置页面地址
E = 1;
_nop_();
E = 0;
_nop_();
wtcom(); /* waitting for enable */
RS = 0;
RW = 0;
P1 = x; //设置列地址
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*写指令 */
/***************************/
void WriteCommandL( unsigned char CommandByte )
{
BusyL();
P1 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandM( unsigned char CommandByte )
{
BusyM();
P1 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandR( unsigned char CommandByte )
{
BusyR();
P1 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*读数据 */
/***************************/
unsigned char ReadData( void )
{
unsigned char DataByte;
Locatexy(); /*坐标定位,返回时保留分区状态不变 */
RS = 1; /*数据输出*/
RW = 1; /*读入 */
P1 = 0xFF; //输出0xff以便读取正确
E = 1; /*读入到LCM*/
_nop_();
DataByte = P1; /*数据读出到数据口P1 */
E = 0;
_nop_();
return DataByte;
}
/***************************/
/*写数据 */
/***************************/
void WriteData( unsigned char DataByte )
{
Locatexy(); /*坐标定位,返回时保留分区状态不变 */
RS = 1; /*数据输出*/
RW = 0; /*写输出 */
P1 = 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(); //空读一次
temp = ReadData();
temp = ~temp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -