📄 lcd.c
字号:
WriteData( (unsigned char)(tempPtr & 0xff) );
WriteData( (unsigned char)(tempPtr /256) );//+BasePart2
WriteCommand( mRead ); // 读显示ram指令
//tempD = ReadDataLcm();
WaitForBusy();
tempD = ReadDataLcm(); // 读取当前显示数据
tempP = 1<<(unsigned char)(0x07-(Px & 0x0007));
// 根据预定属性决定写点或擦除
if( attr )
{
tempD |= tempP; // 画点
}
else
{
tempD &= ~tempP; // 消点
}
WriteCommand( CsrW ); // 重新设置光标地址
WriteData( (unsigned char)(tempPtr & 0xff) );
WriteData( (unsigned char)(tempPtr /256) );
WriteCommand( mWrite ); // 代码0x42,数据写入指令
WriteData( tempD ); // 写入合成数据
}
/*============================================================================
光标位定位,用于在1区图形方式下。
输入参数约定: x...水平方向字节单位坐标,即可以以半个汉字宽度设定水平坐标。
y...垂直方向以行线定位的坐标,可以定位到点单位。
左上角约定坐标为( 0, 0 )
============================================================================*/
void Locatexy(unsigned char x,unsigned char y, unsigned char attribs)
{
unsigned int temp;
temp = (unsigned int)y*paraP9+x;
if(attribs)
{
temp += BasePart2*256; // 如果需要就指向第二区,加上第二区首地址
}
WriteCommand( CsrW ); // 光标Locate,定位
WriteData( (unsigned char)(temp & 0xff) ); // 写入参数CSRL设置参数光标指针低8位
WriteData( (unsigned char)(temp /256 ) ); // 写入参数CSRH设置参数光标指针高8位
}
/*==============================================================================
; 汉字写入子程序(图形方式)。每次调用输出一个汉字
; 支持图形方式使用,完成汉字点阵码的输出。
; 携入参数: Ox,Oy....写入显示的左上角坐标,Ox是以字节单位,Oy以行扫描线单位
Ptr......汉字码,库内的排列编码,大型程序时请改用unsigned int类型
; 无返回数据。
==============================================================================*/
void PutCdotInGraph3( unsigned int Ox, unsigned char Oy,
unsigned int Cnumber, unsigned char DotWidth ,
unsigned char locate)
{
unsigned int tempPtr,Optr;
unsigned char tempCount1,tempCount2,nByte;
Optr = (unsigned int)Oy * paraP9 + Ox;
nByte = DotWidth/8;
if(DotWidth==12) nByte=2;
//if(DotWidth==8) DotWidth=16;
WriteCommand( CsrDirD ); // 自动右移。
tempPtr = (unsigned int)Cnumber * DotWidth*nByte;
if(DotWidth==8) tempPtr=tempPtr*2;
for (tempCount1=0;tempCount1<nByte;tempCount1++)
{
WriteCommand( CsrW ); // 光标定位指令
WriteData( (unsigned char)(Optr &0xff) ); // 设置光标地址CSR
WriteData( (unsigned char)(Optr /256 )+locate*0x40 );
WriteCommand( mWrite ); // ram写指令
switch(DotWidth)
{
/*
case 16: for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( Cdotlib[Cnumber].Msk[tempCount2*2+tempCount1] );
}
break;
*/
case 8: for(tempCount2=0;tempCount2<16;tempCount2++)
{
WriteData( nAsciiDot[tempPtr] );
tempPtr += nByte;
}
break;
/*
case 12:
for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( GB_12[tempPtr] );
tempPtr += nByte;
}
break; .
*/
case 16: for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
//WriteData( WordInEEP[tempPtr] );
tempPtr += nByte;
}
break;
case 24: for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
//WriteData( Cdot24lib[tempPtr] ); // 写入数据
tempPtr += nByte;
}
break;
}
tempPtr = Cnumber * DotWidth*nByte + tempCount1 + 1;
Optr++;
}
}
/*==============================================================================
; 汉字写入子程序(图形方式)。每次调用输出一个汉字
; 支持图形方式使用,完成汉字点阵码的输出。
; 携入参数: Ox,Oy....写入显示的左上角坐标,Ox是以字节单位,Oy以行扫描线单位
Ptr......汉字码,库内的排列编码,大型程序时请改用unsigned int类型
; 无返回数据。
==============================================================================*/
void PutCdotInGraph( unsigned int Ox, unsigned char Oy,
unsigned int Cnumber, unsigned char DotWidth ,
unsigned char locate)
{
unsigned int tempPtr,Optr;
unsigned char tempCount1,tempCount2,nByte;
Optr = (unsigned int)Oy * paraP9 + Ox;
nByte = DotWidth/8;
if(DotWidth==12) nByte=2;
//if(DotWidth==8) DotWidth=16;
WriteCommand( CsrDirD ); // 自动右移。
tempPtr = (unsigned int)Cnumber * DotWidth*nByte;
if(DotWidth==8) tempPtr=tempPtr*2;
for (tempCount1=0;tempCount1<nByte;tempCount1++)
{
WriteCommand( CsrW ); // 光标定位指令
WriteData( (unsigned char)(Optr &0xff) ); // 设置光标地址CSR
WriteData( (unsigned char)(Optr /256 )+locate*0x40 );
WriteCommand( mWrite ); // ram写指令
switch(DotWidth)
{
/*
case 16: for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( Cdotlib[Cnumber].Msk[tempCount2*2+tempCount1] );
}
break;
*/
case 8: for(tempCount2=0;tempCount2<16;tempCount2++)
{
WriteData( nAsciiDot[tempPtr] );
tempPtr += nByte;
}
break;
/*
case 12:
for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( GB_12[tempPtr] );
tempPtr += nByte;
}
break;
*/
case 16: for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( GB_16[tempPtr] );
tempPtr += nByte;
}
break;
case 24: for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
//WriteData( Cdot24lib[tempPtr] ); // 写入数据
tempPtr += nByte;
}
break;
}
tempPtr = Cnumber * DotWidth*nByte + tempCount1 + 1;
Optr++;
}
}
void PutCdotInGraph2( unsigned int Ox, unsigned char Oy,
unsigned int Cnumber, unsigned char DotWidth )
{
unsigned int tempPtr,Optr;
unsigned char tempCount1,tempCount2,nByte;
Optr = (unsigned int)Oy * paraP9 + Ox+0x4000;
nByte = DotWidth/8;
if(DotWidth==12)
{
nByte=2;
}
WriteCommand( CsrDirD ); // 自动右移。
tempPtr = (unsigned int)Cnumber * DotWidth*nByte;
if(DotWidth==8)
{
tempPtr=tempPtr*2;
}
for (tempCount1=0;tempCount1<nByte;tempCount1++)
{
WriteCommand( CsrW ); // 光标定位指令
WriteData( (unsigned char)(Optr &0xff) ); // 设置光标地址CSR
WriteData( (unsigned char)(Optr /256 ) );
WriteCommand( mWrite ); // ram写指令
switch(DotWidth)
{
/*
case 16: for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( Cdotlib[Cnumber].Msk[tempCount2*2+tempCount1] );
}
break;
*/
case 8: for(tempCount2=0;tempCount2<16;tempCount2++)
{
WriteData( nAsciiDot[tempPtr] );
tempPtr += nByte;
}
break;
/*
case 12:
for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( GB_12[tempPtr] );
tempPtr += nByte;
}
break;
*/
case 16: for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( GB_16[tempPtr] );
tempPtr += nByte;
}
break;
case 24: for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
//WriteData( Cdot24lib[tempPtr] ); // 写入数据
tempPtr += nByte;
}
break;
}
tempPtr = Cnumber * DotWidth*nByte + tempCount1 + 1;
Optr++;
}
}
//汉字反显
void PutCdotInGraph_2( unsigned int Ox, unsigned char Oy,
unsigned int Cnumber, unsigned char DotWidth ,
unsigned char locate)
{
unsigned int tempPtr,Optr;
unsigned char tempCount1,tempCount2,nByte;
Optr = (unsigned int)Oy * paraP9 + Ox;
nByte = DotWidth/8;
if(DotWidth==12) nByte=2;
//if(DotWidth==8) DotWidth=16;
WriteCommand( CsrDirD ); // 自动右移。
tempPtr = (unsigned int)Cnumber * DotWidth*nByte;
if(DotWidth==8) tempPtr=tempPtr*2;
for (tempCount1=0;tempCount1<nByte;tempCount1++)
{
WriteCommand( CsrW ); // 光标定位指令
WriteData( (unsigned char)(Optr &0xff) ); // 设置光标地址CSR
WriteData( (unsigned char)(Optr /256 )+locate*0x40 );
WriteCommand( mWrite ); // ram写指令
switch(DotWidth)
{
/*
case 16: for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( Cdotlib[Cnumber].Msk[tempCount2*2+tempCount1] );
}
break;
*/
case 8:
for(tempCount2=0;tempCount2<16;tempCount2++)
{
WriteData( ~nAsciiDot[tempPtr] );
tempPtr += nByte;
}
break;
/*
case 12:
for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( ~GB_12[tempPtr] );
tempPtr += nByte;
}
break;
*/
case 16:
for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
WriteData( ~GB_16[tempPtr] );
tempPtr += nByte;
}
break;
case 24:
for(tempCount2=0;tempCount2<DotWidth;tempCount2++)
{
tempPtr += nByte;
}
break;
}
tempPtr = Cnumber * DotWidth*nByte + tempCount1 + 1;
Optr++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -