📄 lcd_drv.c
字号:
#include "config.h" /* system configuration */
#include "lib_mcu\mp3\mp3_drv.h" /* mp3 driver definition */
#include "modules\display\lcd_drv.h"
#define CMD_SET_LOWER_COLUMN_ADDRESS(x) (x&0xf)
#define CMD_SET_HIGHER_COLUMN_ADDRESS(x) 0x10|((x>>4)&0xf)
#define CMD_SET_PAGE_ADDRESS(x) 0xb0|(x&0xf)
void _MultiNop(int time)
{
int i;
int delayLoopCount=400;
for(;time>0;time--)
for(i=0;i<delayLoopCount;i++);
}
void LCDDataOut(Uchar Data)
{
int i;
for(i=0;i<8;i++)
{
if(Data&0x80)
LCD_SDA= TRUE;
else
LCD_SDA = FALSE;
Data = (Data<<1)&0xfe;
LCD_CLK = FALSE;
LCD_CLK = TRUE;
}
}
void LCDSendCMD(Uchar Command)
{
LCD_DC= FALSE;
LCD_CS1= FALSE;
//_MultiNop(1);
LCDDataOut(Command);
LCD_CS1= TRUE;
}
void LCDSendData(Uchar Data)
{
LCD_DC= TRUE;
LCD_CS1= FALSE;
// _MultiNop(1);
LCDDataOut(Data);
LCD_CS1= TRUE;
}
void Draw2Digit( Uchar Pos, Uchar HexCode );
void Draw8x6Icons( Uchar Page, Uchar Column, Uchar Index );
void LCDDisplayInit()
{
int j;
LCD_RESET = TRUE;
LCD_CS1= FALSE;
LCD_SDA= TRUE;
LCD_DC = TRUE;
LCD_CLK = TRUE;
LCD_RESET = FALSE;
for(j=0;j<0xFFFF;j++)
{
_MultiNop(5);
}
LCD_RESET = TRUE;
for(j=0;j<0xFFFF;j++)
{
_MultiNop(5);
}
BacklightTurnOff;
LCDSendCMD(0xE2);//RESET
LCDSendCMD(0xa0);//zgz [ADC Select]
LCDSendCMD(0xC8);//zgz [SHL Select]
LCDSendCMD(0xA3);//zgz [LCD Bias Select 1/9]
for(j=0;j<0xFFFF;j++) //Waiting for 50% rising of VOUT
{
_MultiNop(2);
}
LCDSendCMD(0x2C);//zgz [Power Control:VC=1,VR=0,VF=0]
for(j=0;j<0xFFFF;j++) //Waiting for 50% rising of VOUT
{
_MultiNop(2);
}
LCDSendCMD(0x2E);//zgz [Power Control:VC=1,VR=1,VF=0]
for(j=0;j<0xFFFF;j++) //Waiting for>=1ms
{
_MultiNop(2);
}
LCDSendCMD(0x2F);//zgz [Power Control:VC=1,VR=1,VF=1]
for(j=0;j<0xFFFF;j++)
{
_MultiNop(2);
}
LCDSendCMD(0x21);//zgz [Regulator Resistor Select (LCD 浓度)] play:21
LCDSendCMD(0x81);//zgz [Reference Voltage Register Set (Brightness)]
LCDSendCMD(0x24);//zgz [Electronic volume setting (Brightness setting)]
//LCDSendCMD(0x40);//START LINE
//LCDSendCMD(0xe0);//
LCDSendCMD(0xa4);
LCDSendCMD(0x81);//contrast
LCDSendCMD(0x20);//default contrast 40
LCDSendCMD(0xaf);//display On
// LCDSendCMD(0xa5);//FULL display]
}
/*=============================================================================
Description:
OK-02/10
=============================================================================*/
void SetLCDAddress( Uchar Page, Uchar Column )
{
// Page
LCDSendCMD(CMD_SET_PAGE_ADDRESS(Page));
// Column setting
LCDSendCMD(CMD_SET_LOWER_COLUMN_ADDRESS(Column));
LCDSendCMD(CMD_SET_HIGHER_COLUMN_ADDRESS(Column));
}
/*=============================================================================
Description:
!!! Data in XRAM !!!
OK-02/11
=============================================================================*/
/*
void PutXdataToLCD( Uchar pBuffer, Uchar Loop )
{
do {
LCDSendData( *pBuffer );
pBuffer++;
}while (--Loop);
}
*/
/*=============================================================================
Description:
!!! Data in CODE !!!
=============================================================================*/
void PutCodeToLCD( Byte *pBuffer, Uchar Loop )
{
do {
LCDSendData( *pBuffer );
pBuffer++;
}while (--Loop);
}
/*=============================================================================
Description:
0 <= Value <= 7, total 8 step
=============================================================================*/
void LCDSetContrast( Uchar Value )
{
LCDSendCMD( 0x20 + Value );
}
/*=============================================================================
Description:
display special data or clear screen
=============================================================================*/
void LCDClearLine( Uchar page, Uchar column, Uint16 Length )
{
SetLCDAddress( page, column );
do{
LCDSendData( 0 );
}while( --Length );
}
/*=============================================================================
Description:
=============================================================================*/
void LCDPowerOff()
{
// turn off LCM
// mNT7502DisplayOff;
// clear all screen data
LCDSendCMD(0XA0);
// turn off power..
// mNT7502PowerOff;
}
/*=============================================================================
Description:
this function can directly access NT7502 module
to execute a NT7502 command
=============================================================================*/
void LCDSendCommand( Uchar cmd )
{
LCDSendCMD( cmd );
}
/*=============================================================================
Description:
this function can directly access NT7502 module
to write a data to NT7502
=============================================================================*/
void Draw8x6Icons( Uchar Page, Uchar Column, Uchar Index )
{
SetLCDAddress( Page , Column );
PutCodeToLCD( &Icon8x6[Index][0], 6 );
}
void Draw2Digit( Uchar Pos, Uchar HexCode )
{
int i,j;
i = HexCode / 10;
j = HexCode %10;
//CalVar2.be.h8 = HexCode / 10;
//CalVar2.be.l8 = HexCode / 10;
if ( i > 9 )
i = 9;
Draw8x6Icons( 2, Pos, i );
Draw8x6Icons( 2, Pos + 6, j );
}
void prints(unsigned char * temp)
{
while((*temp)!='\0')
{
LCDSendData(*temp);
temp++;
}
}
void PutToChina(Uchar Page ,Uchar Column,Byte *prt )
{
// Uchar i;
//SetLCDAddress( Page, Column );
/* for(i=0;i<32;i++);
{
if(i==16)
{
SetLCDAddress( Page , Column+1);
}
LCDSendData(*prt);
prt++;
}
*/
Uchar Loop=32;
do {
if(Loop==16)
{
SetLCDAddress( Page+1 , Column);
}
LCDSendData( *prt );
prt++;
}while (--Loop);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -