📄 lcd.c
字号:
/*======================================================================
File Name : Lcd.c
Description : LCD display driver
Modified Date : 18/Elenv/06 by GouLiang
=======================================================================*/
#include "lcd.h"
BOOL DrvFlag;
UCHAR CurPageNo, CurColNo; //The current page & column (0..3)/(0..121)
UCHAR bPutMode, Display_Font;
UCHAR High8Char;
#ifdef NOMOVX
void E1Busy( void )
{
DI = 0;
RW = 1;
OutData = 0xff;
while(1)
{
E1 = 1; _nop_(); _nop_();
if( BF_Flag == 0 ) break;
}
E1 = 0;
}
void WrDaE1( UCHAR dat )
{
DI = 1;
RW = 0;
P0 = dat;
_nop_(); _nop_();
E1 = 1;
_nop_(); _nop_();
E1 = 0;
}
void WrCoE1( UCHAR dat )
{
DI = 0;
RW = 0;
OutData = dat;
_nop_(); _nop_();
E1 = 1;
_nop_(); _nop_();
E1 = 0;
}
void E2Busy( void )
{
DI = 0;
RW = 1;
OutData = 0xff;
while( 1 )
{
E2 = 1; _nop_(); _nop_();
if( BF_Flag == 0 ) break;
}
E2 = 0;
}
void WrDaE2( UCHAR dat )
{
DI = 1;
RW = 0;
OutData = dat;
_nop_(); _nop_();
E2 = 1;
_nop_(); _nop_();
E2 = 0;
}
void WrCoE2( UCHAR dat )
{
DI = 0;
RW = 0;
OutData = dat;
_nop_(); _nop_();
E2 = 1;
_nop_(); _nop_();
E2 = 0;
}
#else
#endif
/*===================================
Name : WriteData
Parameter : dat -> LCD
Return : None
Description: Send the same data to
both of the LCD driver
Inside Function
===================================*/
void WriteData(UCHAR dat)
{
if(CurColNo < 122 && CurPageNo<4 )
{
if(GetDriver()==1)
{
#ifdef NOMOVX
E2Busy();
WrDaE2( dat );
#else
while( LCD_RD_DAT2 &0x80 );
LCD_WR_DAT2 = dat;
#endif
}
else
{
#ifdef NOMOVX
E1Busy();
WrDaE1( dat );
#else
while( LCD_RD_DAT1 &0x80 );
LCD_WR_DAT1 = dat;
#endif
}
CurColNo++;
SetDriver();
}
}
/*===================================
Name : LCD_SetCommCom
Parameter : cmd -> LCD command
Return : None
Description: Send the same command to
both of the LCD driver
Inside Function
===================================*/
void LCD_SetCommCom(UCHAR cmd)
{
#ifdef NOMOVX
E1Busy();
WrCoE1( cmd );
E2Busy();
WrCoE2( cmd );
#else
while( LCD_RD_DAT1 &0x80 );
LCD_WR_CMD1 = cmd;
while( LCD_RD_DAT2 &0x80 );
LCD_WR_CMD2 = cmd;
#endif
}
/*=============================
Name : LCD_Init
Parameter : None
Return : None
Description: LCD initialization
Extern Function
=============================*/
void LCD_Init(void)
{
LCD_SetCommCom(0xE2); //RESET
LCD_SetCommCom(0xAE); //DISPLAY OFF
LCD_SetCommCom(0xA4); //STATIC DRIVE OFF
LCD_SetCommCom(0xA9); //SELECT 1/32 DUTY
LCD_SetCommCom(0xA0); //ADC SELECT
LCD_SetCommCom(0xe0); //Display Of Order
LCD_SetCommCom(0xEE); //READ MODIFY WRITE OFF
LCD_SetCommCom(0xB8); //SET PAGE ADDRESS
LCD_SetCommCom(0x00); //SET COLUMN ADDRESS
LCD_SetCommCom(0xC0); //SET DISPLAY START LINE
LCD_SetCommCom(0xAF); //DISPLAY ON
}
/*==========================================
Name : LCD_SetPageCol
Parameter : PageNo -> Page number(0..3)
ColNo -> Column number(0..121)
Return : None
Description: Set the current position
Extern Function
==========================================*/
void LCD_SetPageCol( UCHAR PageNo, UCHAR ColNo )
{
UCHAR i;
if( ColNo > 121 ) //Column Control
{
CurColNo = 122;
return;
}
else CurColNo = ColNo;
if( PageNo > 3 ) //Page Control
{
CurPageNo=4;
return;
}
else CurPageNo = PageNo;
SetDriver(); //if CurPageNo>60 DrvFlag=1 else DrvFlag=0;
i = PageNo;
if( GetDriver() != 1 ) //Test DrvFlag == 1;
{
#ifdef NOMOVX
E1Busy();
WrCoE1( 0xB8 | i );
E1Busy();
WrCoE1( ColNo );
E2Busy();
WrCoE2( 0xB8 | i );
E2Busy();
WrCoE2( 0 );
#else
while( LCD_RD_DAT1 &0x80 ) ;
LCD_WR_CMD1 = 0xB8 | i; //Write Right Screen Of Page Address
while( LCD_RD_DAT1 &0x80 ) ;
LCD_WR_CMD1 = ColNo; //Write Right Screen of Column Address
while( LCD_RD_DAT2 &0x80 ) ;
LCD_WR_CMD2 = 0xB8 | i; //Write Left Screen of Page Address
while( LCD_RD_DAT2 &0x80 ) ;
LCD_WR_CMD2 = 0; //Write Left Screen of Column Address
#endif
}
else
{
#ifdef NOMOVX
E2Busy();
WrCoE2( 0xB8 | i );
E2Busy();
WrCoE2( ColNo - 61 );
#else
while( LCD_RD_DAT2 &0x80 ) ;
LCD_WR_CMD2 = 0xB8 | i;
while( LCD_RD_DAT2 &0x80 ) ;
LCD_WR_CMD2 = ColNo - 61;
#endif
}
}
/*============================================
Name : LCD_ClearPage
Parameter : PageNo -> Page number(0..3)
dat -> Need Write data(0 or 0xff)
Return : None
Description: Set the current position
Inside Function
=============================================*/
void LCD_ClearPage( UCHAR PageNo, UCHAR dat )
{
UCHAR i;
LCD_SetPageCol( PageNo, 0 );
for( i = 0; i != 122; i++ )
WriteData( dat );
}
/*==================================
Name : LCD_Clear
Parameter : None
Return : None
Description: Clear the entire screen
Inside Function
==================================*/
void LCD_Clear(void)
{
LCD_ClearPage( 3, 0x00 );
LCD_ClearPage( 2, 0x00 );
LCD_ClearPage( 1, 0x00 );
LCD_ClearPage( 0, 0x00 );
}
/*=======================================
Name : MediacyDisplay
Parameter : string -> The pointer of the
character string
Return : None
Description: Display a character string
Exter Function
=======================================*/
UCHAR MediacyDisplay( UCHAR code* string )
{
UCHAR TotalColNo = 0;
UINT ui;
while(1)
{
if( ( ( UINT_H( ui ) = *string ) & 0x80 )
&& ( ( UINT_L( ui ) = *( string + 1 ) ) & 0x80 ) )
{ //汉字区
TotalColNo += 0x10;
string++;
string++;
}
else
{ //ASII 区
if ( UINT_H(ui) == 0 )
break;
else if( UINT_H(ui) == '|') string++;
else if( UINT_H(ui) == '/') string++;
else if( UINT_H(ui) == '&') string++;
else if( Display_Font == 0 )
{
TotalColNo += 0x06;
string++;
}
else if( Display_Font == 1 )
{
TotalColNo += 0x08;
string++;
}
}
}
if ( TotalColNo >= 122 )
CurColNo = 0;
else if ( ( 122 - CurColNo ) <= TotalColNo )
CurColNo = CurColNo;
else
CurColNo = ( 122 - TotalColNo - CurColNo )/2 + CurColNo;
return( CurColNo );
}
/*=============================================
Name : Putc
Parameters : c -> Character
Return : None
Description: Display a character(8x16 Or 8x12)
Inside Function
=============================================*/
void putchar(UCHAR c)
{
UCHAR i;
UCHAR oldPageNo = CurPageNo;
UCHAR oldColNo = CurColNo;
if( High8Char != 0 )
{
if( c & 0x80 )
{
GetHZCode( ( High8Char << 8 ) | c );
High8Char = 0;
return;
}
else
{
if(c >= 0x20)
{
goto Nex;
}
}
}
if(c & 0x80 )
{
High8Char=c;
return;
}
Nex:if( c == '|')
{
bPutMode = 0;
return;
}
if( c == '/' )
{
bPutMode = 0xff;
return;
}
if( c == '&' )
{
bPutMode =0x80;
return;
}
if( Display_Font == 0 )
{
for( i = 0; i != 6; i++ )
WriteData( ASCII_SMALL[c-0x20][i] ^ bPutMode );
}
else if ( Display_Font == 1 )
{
for( i = 0; i != 8; i++ )
WriteData( ASCII_Lar[c-0x20][i] ^ bPutMode );
LCD_SetPageCol( oldPageNo + 1, oldColNo );
for( ; i != 16; i++ )
{
if ( bPutMode != 0x80 )
WriteData( ASCII_Lar[c-0x20][i] ^ bPutMode );
else WriteData( ASCII_Lar[c-0x20][i] );
}
LCD_SetPageCol( oldPageNo, oldColNo + 8 );
}
}
/*=============================================
Name : GetHZCode
Parameter : hz -> Chinese character
Return : None
Description: Display a chinese character(16x16)
Inside Function
=============================================*/
void GetHZCode( UINT hz )
{
CPUCHAR pFontMask;
UINT k,index= CH_DATA;
pFontMask = CH_INDEX;
while(1)
{
if(hz ==( k=*CPUINT(pFontMask)))
{
pFontMask = index;
break;
}
if( *pFontMask == '\0')
{
pFontMask = CH_DATA;
break;
}
pFontMask+=2;
index+=32;
}
if(1)
{
UCHAR i;
UCHAR oldPageNo = CurPageNo;
UCHAR oldColNo = CurColNo;
for(i=0; i!=16; i++)
{
if( bPutMode != 0x80 )
WriteData(pFontMask[i]^ bPutMode);
else
WriteData(pFontMask[i]);
}
LCD_SetPageCol(oldPageNo+1, oldColNo);
for(; i != 32; i++ )
{
WriteData(pFontMask[i] ^ bPutMode);
}
LCD_SetPageCol(oldPageNo, oldColNo+16);
}
}
/*=======================================
Name : Puts
Parameter : string -> The pointer of the
character string
Return : None
Description: Display a character string
Extern function
=======================================*/
void Puts ( UCHAR code* string )
{
UINT ui;
LCD_SetPageCol( CurPageNo, MediacyDisplay( string ) );
while( 1 )
{ //把"ui"转换为区位码的形式
if( ( ( UINT_H( ui ) = *string ) & 0x80 )
&& ( ( UINT_L( ui ) = *( string + 1 ) ) & 0x80 ) )
{ //汉字区
GetHZCode( ui );
string++;
string++;
}
else
{ //ASII 区
if( UINT_H(ui) == 0 )
return;
putchar( UINT_H(ui) );
string++;
}
}
}
/*=====================================================
Name : Display Pack Picture Flag
Parameter : ImageBuff -> First Address
Return : None
Description : Display a image
Characteristic: extern
====================================================*/
void PutIcon( UCHAR code *IconAdr )
{
UCHAR i;
UCHAR oldPageNo = CurPageNo;
UCHAR oldColNo = CurColNo;
for(i = 0; i != 20; i++ )
{
WriteData( *( IconAdr + i ) ^ bPutMode );
}
LCD_SetPageCol( oldPageNo + 1, oldColNo );
for(; i != 40; i++ )
{
WriteData( *( IconAdr + i ) ^ bPutMode );
}
LCD_SetPageCol( oldPageNo, oldColNo + 20 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -