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

📄 lcd.c

📁 LPC2134的bootloader , 请用ADS查看地址设定。
💻 C
字号:
typedef  unsigned char uchar;
typedef  unsigned int uint;

#include "PIN.h"
#include "config.h"
#include "font.h"
#include "PubFunc.h"

struct  ASCII_DotStruct{// ASCII字符字模显示数据结构
   char cIndex;       // 前面的ASCII字符索引
   char cDot[5];  // 后面的ASCII字符点阵数据
};

/*void delay(unsigned int cDelay)
{
	unsigned int i;
	unsigned int j;
	for (i=0; i<cDelay; i++)
	{
//		for (j=0; j<10; j++);
	}
}
*/
 struct ASCII_DotStruct g_cFont[] =
{
	' ', 0x00, 0x00, 0x00, 0x00, 0x00, 
	'1', 0x00, 0x84, 0xfe, 0x80, 0x00, 
	'2', 0xc4, 0xa2, 0x92, 0x8a, 0x84, 
	'3', 0x42, 0x82, 0x8a, 0x96, 0x62, 
	'4', 0x30, 0x28, 0x24, 0xfe, 0x20, 
	'5', 0x4e, 0x8a, 0x8a, 0x8a, 0x72, 
	'6', 0x78, 0x94, 0x92, 0x92, 0x60, 
	'7', 0x02, 0xe2, 0x12, 0x0a, 0x06, 
	'8', 0x6c, 0x92, 0x92, 0x92, 0x6c, 
	'9', 0x0c, 0x92, 0x92, 0x52, 0x3c, 
	'0', 0x7c, 0xa2, 0x92, 0x8a, 0x7c, 
	
	'A', 0xfc, 0x22, 0x22, 0x22, 0xfc, 
	'B', 0xfe, 0x92, 0x92, 0x92, 0x6c, 
	'C', 0x7c, 0x82, 0x82, 0x82, 0x44, 
	'D', 0xfe, 0x82, 0x82, 0x44, 0x38, 
	'E', 0xfe, 0x92, 0x92, 0x92, 0x82, 
	'F', 0xfe, 0x12, 0x12, 0x12, 0x02, 
	'G', 0x7c, 0x82, 0x92, 0x92, 0xf4, 
	'H', 0xfe, 0x10, 0x10, 0x10, 0xfe, 
	'I', 0x00, 0x82, 0xfe, 0x82, 0x00, 
	'J', 0x40, 0x80, 0x82, 0x7e, 0x02, 
	'K', 0xfe, 0x10, 0x28, 0x44, 0x82, 
	'L', 0xfe, 0x80, 0x80, 0x80, 0x80, 
	'M', 0xfe, 0x04, 0x18, 0x04, 0xfe, 
	'N', 0xfe, 0x08, 0x10, 0x20, 0xfe, 
	'O', 0x7c, 0x82, 0x82, 0x82, 0x7c, 
	'P', 0xfe, 0x12, 0x12, 0x12, 0x0c, 
	'Q', 0x7c, 0x82, 0xa2, 0x42, 0xbc, 
	'R', 0xfe, 0x12, 0x32, 0x52, 0x8c, 
	'S', 0x4c, 0x92, 0x92, 0x92, 0x64, 
	'T', 0x02, 0x02, 0xfe, 0x02, 0x02, 
	'U', 0x7e, 0x80, 0x80, 0x80, 0x7e, 
	'V', 0x3e, 0x40, 0x80, 0x40, 0x3e, 
	'W', 0x7e, 0x80, 0x70, 0x80, 0x7e, 
	'X', 0xc6, 0x28, 0x10, 0x28, 0xc6, 
	'Y', 0x0e, 0x10, 0xe0, 0x10, 0x0e, 
	'Z', 0xc2, 0xa2, 0x92, 0x8a, 0x86, 
	//a~z
	'a', 0x40, 0xa8, 0xa8, 0xa8, 0xf0, 
	'b', 0xfe, 0x88, 0x88, 0x88, 0x70, 
	'c', 0x70, 0x88, 0x88, 0x88, 0x88, 
	'd', 0x70, 0x88, 0x88, 0x88, 0xfe, 
	'e', 0x70, 0xa8, 0xa8, 0xa8, 0x30, 
	'f', 0x08, 0x08, 0xfc, 0x0a, 0x0a, 
	'g', 0x10, 0xa8, 0xa8, 0xa8, 0x78, 
	'h', 0xfe, 0x10, 0x08, 0x08, 0xf0, 
	'i', 0x00, 0x88, 0xfa, 0x80, 0x00, 
	'j', 0x40, 0x80, 0x88, 0x7a, 0x00, 
	'k', 0xfe, 0x20, 0x50, 0x88, 0x00, 
	'l', 0x00, 0x82, 0xfe, 0x80, 0x00, 
	'm', 0xf8, 0x08, 0xf8, 0x08, 0xf0, 
	'n', 0xf8, 0x10, 0x08, 0x08, 0xf0, 
	'o', 0x70, 0x88, 0x88, 0x88, 0x70, 
	'p', 0xf8, 0x28, 0x28, 0x28, 0x10, 
	'q', 0x10, 0x28, 0x28, 0x28, 0xf8, 
	'r', 0xf8, 0x10, 0x08, 0x08, 0x00, 
	's', 0x90, 0xa8, 0xa8, 0xa8, 0x48, 
	't', 0x08, 0x08, 0x7e, 0x88, 0x88, 
	'u', 0x78, 0x80, 0x80, 0x40, 0xf8, 
	'v', 0x38, 0x40, 0x80, 0x40, 0x38, 
	'w', 0x78, 0x80, 0x60, 0x80, 0x78, 
	'x', 0x88, 0x50, 0x20, 0x50, 0x88, 
	'y', 0x18, 0xa0, 0xa0, 0xa0, 0x78, 
	'z', 0x88, 0xc8, 0xa8, 0x98, 0x88,

	'!', 0x00, 0x00, 0xbe, 0x00, 0x00,	//!
	'"', 0x00, 0x0e, 0x00, 0x0e, 0x00,	//"	
	'#', 0x28, 0xfe, 0x28, 0xfe, 0x28,	//#
	'$', 0x48, 0x54, 0xfe, 0x54, 0x24,	//$
	'%', 0x46, 0x26, 0x10, 0xc8, 0xc4,	//%
	'$', 0x6c, 0x92, 0xaa, 0x44, 0xa0,	//&
	'(', 0x00, 0x38, 0x44, 0x82, 0x00,	//(
	')', 0x00, 0x82, 0x44, 0x38, 0x00,	//)
	'*', 0x28, 0x10, 0x7c, 0x10, 0x28,	//*
	'+', 0x10, 0x10, 0x7c, 0x10, 0x10,	//+
	'-', 0x10, 0x10, 0x10, 0x10, 0x10,	//-
	',', 0x00, 0xa0, 0x60, 0x00, 0x00,	//, 
	'.', 0x00, 0xc0, 0xc0, 0x00, 0x00,	//.
	'/', 0x40, 0x20, 0x10, 0x80, 0x40,	///
	':', 0x00, 0x6c, 0x6c, 0x00, 0x00,	//:
	';', 0x00, 0xac, 0x6c, 0x00, 0x00,	//;
	'<', 0x10, 0x28, 0x44, 0x82, 0x00,	//<
	'>', 0x00, 0x82, 0x44, 0x28, 0x10,	//>
	'=', 0x28, 0x28, 0x28, 0x28, 0x28,	//=
	'?', 0x04, 0x02, 0xa2, 0x12, 0x0c,	//?
	'[', 0x00, 0xfe, 0x82, 0x82, 0x00,	//[
	']', 0x00, 0x82, 0x82, 0xfe, 0x00,	//]
	'\\', 0x00, 0x00, 0xee, 0x00, 0x00,	//|
	'_', 0x80, 0x80, 0x80, 0x80, 0x80,	//_
	'^', 0x08, 0x04, 0x02, 0x04, 0x08,	//^
	'{', 0x10, 0x6c, 0x82, 0x82, 0x00,	//{
	'}', 0x00, 0x82, 0x82, 0x6c, 0x10,	//}
	'@', 0x7c, 0x82, 0xba, 0xaa, 0x3c,	// @
	//''''', 0x00, 0x00, 0x06, 0x00, 0x00	// '
};

void mymemcpy(unsigned char * cpDes, unsigned char * cpSource, unsigned int iBytes)
{
	unsigned int i;
	for (i=0; i<iBytes; i++)
	{
		cpDes[i] = cpSource[i];
	}
}
void mymemset(unsigned char * cpBuffer, unsigned char cValue, unsigned char cBytes)
{
	unsigned char i;
	for (i=0; i<cBytes; i++)
	{
		cpBuffer[i] = cValue;
	}
}

/***********************************************************************
* 函 数 名: SendCommand()
* 功能描述: 向LCD写一条指令
* 函数说明:
* 调用函数: 无
* 全局变量: 无
* 输 	入: cCommand
* 返 	回:
* 设 计 者:杨鹏 日期:2005-04-30
* 修 改 者:杨鹏 日期:
* 版    本:0.01
***********************************************************************/
void SendCommand(unsigned char cCommand)
{
	uint32   dat;
	dat    = (uint32)(cCommand);
	
	IO0CLR = LCD_E1 | LCD_E2; 
	IO0CLR = LCD_A0 | LCD_RW;
	IO1SET = (dat << 16) & 0xff0000;
	IO1CLR = (~(dat << 16)) & 0xff0000;
	IO1SET = (dat << 16) & 0xff0000;
	IO0SET = LCD_E1 | LCD_E2;
	delay(2);
	IO0CLR = LCD_E1 | LCD_E2; 
	delay(2);
	IO1SET = 0xff0000;
	IO0SET = LCD_E1 | LCD_E2;
}//SendCommand()

/***********************************************************************
* 函 数 名: LCDPutByte()
* 功能描述: LCD显示一个纵向的byte数据
* 函数说明:
* 调用函数: 无
* 全局变量: 无
* 输 	入: 无
* 返 	回:
* 设 计 者:杨鹏 日期:2005-04-30
* 修 改 者:杨鹏 日期:
* 版    本:0.01
***********************************************************************/
void LCDPutByte(unsigned char cX,unsigned char cY,unsigned char cData) 
{
	uint32   dat;
	if(cY<2)
	{
		cY=cY+2;
	}
	else
	{
		cY=cY-2;
	}
	IO0SET = LCD_E1 | LCD_E2;
	IO0CLR = LCD_A0 | LCD_RW;
	if (cX<61) 			//左边62列(master)
	{	
		dat    = (uint32)(0xb8|cY);     //SET Y POINT
		IO1SET = (dat << 16) & 0xff0000;
		IO1CLR = (~(dat << 16)) & 0xff0000;
		IO1SET = (dat << 16) & 0xff0000;
		IO0SET = LCD_E1;
		delay(2);
		IO0CLR = LCD_E1;
		delay(2);
		IO0SET = LCD_E1 | LCD_E2;
		dat    = (uint32)(0x00|cX);    //SET X POINT
		IO1SET = (dat << 16) & 0xff0000;
		IO1CLR = (~(dat << 16)) & 0xff0000;
		IO1SET = (dat << 16) & 0xff0000;
		IO0SET = LCD_E1;
		delay(2);
		IO0CLR = LCD_E1;
		delay(2);
		IO0SET = LCD_E1 | LCD_E2;
		IO0SET = LCD_A0;
		IO0CLR = LCD_RW;
		dat    = (uint32)(cData);      //SEND DATA
		IO1SET = (dat << 16) & 0xff0000;
		IO1CLR = (~(dat << 16)) & 0xff0000;
		IO1SET = (dat << 16) & 0xff0000;
		IO0SET = LCD_E1;
		delay(2);
		IO0CLR = LCD_E1;
		delay(2);
	}
	else 				//右边62列(slaver)
	{
		cX=cX-61;                     
		dat    = (uint32)(0x00|cX);   //SET X POINT
		IO1SET = (dat << 16) & 0xff0000;
		IO1CLR = (~(dat << 16)) & 0xff0000;
		IO1SET = (dat << 16) & 0xff0000;
		IO0SET = LCD_E2;
		delay(2);
		IO0CLR = LCD_E2;
		delay(2);
		IO0SET = LCD_E1 | LCD_E2;
		dat    = (uint32)(0xb8|cY);   //SET Y POINT
		IO1SET = (dat << 16) & 0xff0000;
		IO1CLR = (~(dat << 16)) & 0xff0000;
		IO1SET = (dat << 16) & 0xff0000;
		IO0SET = LCD_E2;
		delay(2);
		IO0CLR = LCD_E2;
		delay(2);
		IO0SET = LCD_E1 | LCD_E2;
		IO0SET = LCD_A0;
		IO0CLR = LCD_RW;
		dat    = (uint32)(cData);     //SEND DATA
		IO1SET = (dat << 16) & 0xff0000;
		IO1CLR = (~(dat << 16)) & 0xff0000;
		IO1SET = (dat << 16) & 0xff0000;
		IO0SET = LCD_E2;
		delay(2);
		IO0CLR = LCD_E2;
		delay(2);
	}
	IO0SET = LCD_E1 | LCD_E2;	
	IO1SET = 0xff0000;
}//LCDPutByte()

/***********************************************************************
* 函 数 名: LCDInit()
* 功能描述: 初始化LCD
* 函数说明:
* 调用函数: SendCommand(),LCDPutByte()
* 全局变量: 无
* 输 	入: 无
* 返 	回:
* 设 计 者:杨鹏 日期:2005-04-30
* 修 改 者:杨鹏 日期:
* 版    本:0.01
***********************************************************************/
void LCDInit(void)
{
	unsigned char  x,y;
	IO0CLR = LCD_E1 | LCD_E2;
	IO0CLR = LCD_A0 | LCD_RW;
	SendCommand(0xae);		//关闭显示
	SendCommand(0xc0);		//开始显示的行数是第一行
	SendCommand(0xa4);		//动态驱动
	SendCommand(0x00);		//开始显示的列数是第一列
	SendCommand(0xbb);		//设定显示的页为第3页
	SendCommand(0xa9);		//设置刷新频率为1/32
	SendCommand(0xa0);		//正向读取显示的RAM
	SendCommand(0xee);		//结束

	for (y=0;y<4;y++)
	{
		for (x=0;x<122;x++)
			LCDPutByte(x,y,0);
	}
	SendCommand(0xaf);		//允许显示

}
/***********************************************************************
* 函 数 名: WriteEnglish5X8()
* 功能描述: LCD显示5X8的英文
* 函数说明:
* 调用函数: LCDPutByte()
* 全局变量: 无
* 输 	入: cX,cY,*array
* 返 	回:
* 设 计 者:杨鹏 日期:2005-04-30
* 修 改 者:杨鹏 日期:
* 版    本:0.01
***********************************************************************/
void WriteEnglish5X8(unsigned char cX,unsigned char cY,unsigned char* array)
{
//**********以下为HEM12232A驱动*************
	unsigned char  cCol,cData;			
	for(cCol=0;cCol<5;cCol++)
	{
		cData=array[cCol];
		LCDPutByte(cX+cCol,cY,cData);
	}
	LCDPutByte(cX+cCol,cY,0);

}
//Modify by Michael
//mode: Black/Write reverse
//Layer: Upper line or lower line
//x: BMP original X-position
//width: BMP width
//bmp: BMP data. strlen should be width*2
void DisplayBmp(unsigned char mode, unsigned char layer, unsigned char x, unsigned char width, unsigned char *bmp)
{
	unsigned char cCol, cData;
	
	if(layer == 0)
		layer = 2;
	else
		layer = 0;
	for(cCol = 0; cCol < width; cCol++)
	{
		if(mode)
			cData = ~bmp[cCol];
	    else
	    	cData = bmp[cCol];
		LCDPutByte(x+cCol, layer, cData);
	}
	for(cCol = width; cCol < width*2; cCol++)
	{
		if(mode)
			cData = ~bmp[cCol];
		else
			cData = bmp[cCol];
		LCDPutByte(x+cCol-width, layer+1, cData);
	}
	
}

void DisplayString(unsigned char mode, unsigned char layer, unsigned char x, unsigned char len, char* str)
{
	uchar temp;
	uchar i;
	i = 0;
	for(i=0;i<len;i++)
//    while(str[i] != 0x00)
	{
    	temp = str[i] - ' ';
    	DisplayBmp(mode,layer,x+8*i,8,(unsigned char*)ascbuf+16*temp);
	}
	
}

void DisplayStr(unsigned char mode, unsigned char layer, unsigned char x, char* str)
{
	uchar temp;
	uchar i;
	i = 0;
//	for(i=0;i<Dalen;i++)
    while(str[i] != 0x00)
	{
    	temp = str[i] - ' ';
    	DisplayBmp(mode,layer,x+8*i,8,(unsigned char*)ascbuf+16*temp);
    	i++;
	}
}


void DisplayChar(unsigned char cLine, unsigned char cPosition, char cCharacter)
{
	unsigned char  cX = (cPosition * 6) % 122;
	unsigned char  cY = cLine;
	unsigned char  cCnt;
	for (cCnt=0; cCnt<sizeof(g_cFont) / sizeof(g_cFont[0]); cCnt++)
	{
		if (g_cFont[cCnt].cIndex == cCharacter)
		{
			break;
		}
	}
	WriteEnglish5X8(cX, cY, (unsigned char *)g_cFont[cCnt].cDot);
}
/*
void DisplayString(unsigned char cLine, unsigned char cPosition, char * cpP)
{
	unsigned char  cCnt = 0;
	while (*cpP != 0 && cCnt++ < 20)
	{
		DisplayChar(cLine, cPosition++, *cpP++);
	}
}
*/


// 0 = align center
// 1 = align left 
// 2 = align right
extern int strlen(char *);
void DisplayLine( unsigned char nLine, char* pCh, unsigned char ucAlign )
{
	unsigned char		chBuffer[ 20 ];
	int			nLen = strlen( pCh );

	if ( nLen > (int)0x14 )
	{
		nLen = 0x14;
	}

	mymemset( chBuffer, 0x20, 20 );

	if ( 0 == ucAlign )
	{
		mymemcpy((unsigned char *)&chBuffer[ (20 - nLen)/2 ],(unsigned char *) pCh, nLen );
	} else if ( 1 == ucAlign )
	{
		mymemcpy((unsigned char *) &chBuffer,(unsigned char *) pCh, nLen );
	} else
	{
		mymemcpy((unsigned char *) &chBuffer[ 20 - nLen ],(unsigned char *) pCh, nLen );
	}
//	DisplayString( nLine, 0,(char *)chBuffer );
}


void ClearLine( unsigned char nLine )
{
	//DisplayString( nLine, 0, "                    " );
	DisplayStr(0,nLine,0,"                ");
}

void ClearLcdAll()
{
	ClearLine( 0 );
	ClearLine( 2 );
}
void ClearScreen()
{
	ClearLine( 0 );
	ClearLine( 1 );
	ClearLine( 2 );
	ClearLine( 3 );
}

void TurnBacklight(unsigned char cStatus)
{
	if (cStatus == 0)
	{
		IO0CLR = LCD_BKL;
	}
	else
	{
		IO0SET = LCD_BKL;
	}
}

⌨️ 快捷键说明

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