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

📄 lcd12864_c51.h

📁 GPS开发 NEA1803 51单片机与12864 由串口中断收取数据 显示经度纬度 高度 速度 时间 使用卫星数
💻 H
字号:
/*********************************************************************/
/*********            LCD12864_c51.H C51 driver            *************/
/****************	 Written by yinlei---20070801	******************/
/*********************************************************************/
//#include <intrins.h>
/****************************控制定义*********************************/
#define LCD_BUSY_FLAG 0x80 //用于检查写忙信号
#define LCD12864_CG_MODE_EN 0 //图形模式开关
#define LCD12864_PIXEL_EN 0 //安像素绘图使能
/****************************端口定义*********************************/
#define DATAPORT P0 // 数据端口!!!!!!!!!!
sbit RS = P1^4;
sbit RW = P1^3;
sbit Elcd = P1^2;
//---------------------光标记录
unsigned char LCDx=0;
unsigned char LCDy=0;

#if LCD12864_CG_MODE_EN
bit LCD12864_MODE_FLAG=0;			//0普通模式 1扩展模式
#endif
/****************************外部函数*********************************/
void Init_Lcd12864(void); //LCD RESET
void ClearAS(void);
void ResetCursor(unsigned char x,unsigned char y);			//光标归零
void DispChar(unsigned char x,unsigned char y,unsigned char dataW);
char putchar (char a);

#if LCD12864_CG_MODE_EN
void ClearCG(void);
void DisplayPicBasic(unsigned char x_start,unsigned char y_start,unsigned char x_end,unsigned char y_end,unsigned char *table);
	#if LCD12864_PIXEL_EN
	void WritePixel(unsigned char x,unsigned char y,bit color);
	bit ReadPixel(unsigned char x,unsigned char y);
	#endif
#endif

/****************************内部函数*********************************/

void WaitForEnable(void); //忙信号检测
void LcdWrite_C(unsigned char CMD,unsigned char AttribC);//write Control Charactor
void LcdWrite_D(char dataW); //写一个数据
unsigned char LcdRead(void);//read a data from LCD

/****************************函数实现*********************************/
//-----------------初始化-------------------------------
void Init_Lcd12864(void)
{	
	unsigned char i=3;
	while(i--)LcdWrite_C(0x30,0); //显示模式设置(不测试忙信号)共三次
#if LCD12864_CG_MODE_EN
	LcdWrite_C(0x34,1);		//扩展模式-->图形模式
	ClearCG();
#else
	LcdWrite_C(0x30,1);
#endif
	LcdWrite_C(0x0f,1);//all on
	LcdWrite_C(0x0c,1);//0x0f->all on,show arrow;0x0c->no arrow
	ClearAS();
}
//-------------------------------------------------------------------
void ClearAS(void)
{
	LcdWrite_C(0x01,1);
	ResetCursor(0,0);
}
//-----------------------------------------------------------------------
void ResetCursor(unsigned char x,unsigned char y)
{
	LCDx=x;
	LCDy=y;
}
//=======================================================//
//              按指定位置显示一个字符                   //
//=======================================================//
void DispChar(unsigned char x,unsigned char y,unsigned char dataW) 
{
	unsigned char temp,t;	
#if LCD12864_CG_MODE_EN
	if(LCD12864_MODE_FLAG)
	{
	//	LcdWrite_C(0x34,1);		//扩充指令集 显示关
		LcdWrite_C(0x30,1);  //command back
		LCD12864_MODE_FLAG=0;
	}
#endif			   	
	temp=x&0x0f;
	temp=temp>>1;	   //temp/2
	t=y>>1;
	if(t)temp|=0x08;	//2、3行操作
	y&=0x01;
	if(y)temp|=0x90;   //奇数行
	else temp|=0x80;	
	LcdWrite_C(temp,1);
	if(x&0x01)LcdRead();
	LcdWrite_D(dataW);
}
//-----------------------------------------------------------------------
char putchar (char a)
{
	if(LCDx==16){LCDx=0;LCDy++;}
	if(LCDy==4){LCDy=0;}	
	if(a!='\n')
	{
		DispChar(LCDx,LCDy,a);
		LCDx++;
	}
	else{LCDx=0;LCDy++;}
	return a;
}
//============================图形模式==============================
//x_end-x_start:0~8,y_end-y_start:0~64(图象大小为:(x_end-x_start)*16 X (y_end-y_start))
//&&!!x_end y_end 为图象的末边界+1
//==================================================================
#if LCD12864_CG_MODE_EN
void ClearCG(void)
{
	unsigned char i,j;
	if(~LCD12864_MODE_FLAG)
	{
		ClearAS();
		LcdWrite_C(0x34,1);		//扩充指令集 显示关	
		LCD12864_MODE_FLAG=1;
	}
	for(j=0;j<64;j++)
	{

		if(j<32)
		{
			LcdWrite_C(0x80+j,1);		//Y地址0
			LcdWrite_C(0x80,1);		//x地址0
		}
		else
		{
			LcdWrite_C(0x60+j,1);		//Y地址0
			LcdWrite_C(0x88,1);		//x地址0	
		}
		for(i=0;i<16;i++)
		{
			LcdWrite_D(0x00);	
		}
	}
}
void DisplayPicBasic(unsigned char x_start,unsigned char y_start,unsigned char x_end,unsigned char y_end,unsigned char *table)
{
	unsigned char temp_x=0,temp_y=0;
	unsigned int temp;
	if(~LCD12864_MODE_FLAG)
	{
		ClearAS();
		LcdWrite_C(0x34,1);		//扩充指令集 显示关	
		LCD12864_MODE_FLAG=1;
	}
	for(temp_y=y_start;temp_y<y_end;temp_y++)
	{
		if(temp_y<32)
		{
			LcdWrite_C(0x80+temp_y,1);		//Y地址0
			LcdWrite_C(0x80+x_start,1);		//x地址0
		}
		else
		{
			LcdWrite_C(0x60+temp_y,1);		//Y地址0
			LcdWrite_C(0x88+x_start,1);		//x地址0	
		}
		for(temp_x=x_start;temp_x<x_end;temp_x++)
		{
			temp=((temp_y-y_start)*(x_end-x_start)+(temp_x-x_start))*2;
			//temp=(temp_y-y_start)*(x_end-x_start)+temp_x-x_start;
			LcdWrite_D(*(table+temp));
			LcdWrite_D(*(table+temp+1));				
		}
	}
	LcdWrite_C(0x36,1);

}
	#if LCD12864_PIXEL_EN
	void WritePixel(unsigned char x,unsigned char y,bit color)
	{
		unsigned char temp_x,temp;
		if(~LCD12864_MODE_FLAG)
		{
//			ClearAS();
			LcdWrite_C(0x36,1);		//扩充指令集 显示开	
			LCD12864_MODE_FLAG=1;
		}
		temp_x=x>>4;
		if(y<32)
		{
			LcdWrite_C(0x80+y,1);		//Y地址0
			LcdWrite_C(0x80+temp_x,1);		//x地址0	
		}
		else
		{
			LcdWrite_C(0x60+y,1);		//Y地址0
			LcdWrite_C(0x88+temp_x,1);		//x地址0	
		}
		if(x&0x08)LcdRead();
		LcdRead();						//空操作
		temp=LcdRead();
		if(color)temp|=(0x80>>(x&0x07));
		else temp&=~(0x80>>(x&0x07));
//--------------------------------------------
		if(y<32)
		{
			LcdWrite_C(0x80+y,1);		//Y地址0
			LcdWrite_C(0x80+temp_x,1);		//x地址0	
		}
		else
		{
			LcdWrite_C(0x60+y,1);		//Y地址0
			LcdWrite_C(0x88+temp_x,1);		//x地址0	
		}
		if(x&0x08)LcdRead();
		LcdWrite_D(temp);
		LcdWrite_C(0x36,1);
	}
	bit ReadPixel(unsigned char x,unsigned char y)
	{
		unsigned char temp_x,temp;
		if(~LCD12864_MODE_FLAG)
		{
//			ClearAS();
			LcdWrite_C(0x36,1);		//扩充指令集 显示开	
			LCD12864_MODE_FLAG=1;
		}
		temp_x=x>>4;
		if(y<32)
		{
			LcdWrite_C(0x80+y,1);		//Y地址0
			LcdWrite_C(0x80+temp_x,1);		//x地址0	
		}
		else
		{
			LcdWrite_C(0x60+y,1);		//Y地址0
			LcdWrite_C(0x88+temp_x,1);		//x地址0	
		}
		if(x&0x08)LcdRead();	 
		LcdRead(); 				//空操作
		temp=LcdRead();
		LcdWrite_C(0x36,1);
		return temp&(0x80>>(x&0x07));
	}
	#endif
#endif

/****************************底层接口函数******************************/
//------------------------------------------------------//
//写控制字符子程序: E=1 RS=0 RW=0
//------------------------------------------------------//
void LcdWrite_C( unsigned char CMD,unsigned char AttribC ) 
{	
	if (AttribC) WaitForEnable(); // 检测忙信号?
	RS = 0; RW = 0;
	DATAPORT =CMD; // 送控制字子程序
	Elcd = 1;Elcd = 0; // 操作允许脉冲信号 
}
//------------------------------------------------------//
//当前位置写字符子程序: E =1 RS=1 RW=0
//------------------------------------------------------//
void LcdWrite_D( char dataW ) 
{	
	WaitForEnable(); // 检测忙信号
	RS = 1; RW = 0;
	DATAPORT = dataW;
	Elcd = 1;Elcd = 0; // 操作允许脉冲信号 
}
//------------------------------------------------------//
//读模块子程序:E=1 RS=1 RW=1
//------------------------------------------------------//
unsigned char LcdRead(void)
{	
	unsigned char dataW;
	WaitForEnable(); // 检测忙信号
//	Elcd = 0;
//	DATAPORT=0xff;	
	RS = 1; RW = 1;
	Elcd = 1;
//	for(dataW=0;dataW<100;dataW++);
	dataW=DATAPORT;
	Elcd = 0;		// 操作允许脉冲信号
    return dataW;
}
//------------------------------------------------------//
//正常读写操作之前必须检测LCD控制器状态: CS=1 RS=0 RW=1
//DB7: 0 LCD控制器空闲; 1 LCD控制器忙
//------------------------------------------------------//
void WaitForEnable( void )
{	
	DATAPORT = 0xff;
	RS =0; RW = 1; Elcd = 1;
	while( DATAPORT & LCD_BUSY_FLAG );
	Elcd = 0;
} 
/****************************End LCD12864_c51.H***************************/

⌨️ 快捷键说明

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