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

📄 lcd12864_arm.h

📁 LCD12864arm(lpc21xx)驱动程序 C语言板
💻 H
字号:
/*********************************************************************/
/*********            LCD12864_arm.H ARM driver            *************/
/********** 		 Written by yinlei---20070806			 ****************/
/*********************************************************************/
//--------------------------------------
// 数据端口说明!!!!!!!!!! //全为P0口,修改时请修改LcdIOInit()函数和 ChangeOutPut()函数对应参数
const unsigned int RS = (1<<18);			
const unsigned int RW = (1<<17);		
const unsigned int Elcd = (1<<16);			

const unsigned int D7 = (1<<15);				
const unsigned int D6 = (1<<14);
const unsigned int D5 = (1<<13);
const unsigned int D4 = (1<<12);
const unsigned int D3 = (1<<11);
const unsigned int D2 = (1<<10);
const unsigned int D1 = (1<<9);
const unsigned int D0 = (1<<8);


//---------------------------------------光标记录

extern unsigned int LCDx=0;
extern unsigned int LCDy=0;

//---------------------------------------外部函数----------------------------------------
void Init_Lcd12864(void); 										//LCD RESET
void ClearAS(void);
void Set_Lcd_xy(unsigned char x,unsigned char y);				 //定位光标
//---------------------------------------------------------
void DispChar(unsigned int x,unsigned int y,int dataW);			  //定点显示字符
extern int  putchar  (int  c);									  //PUTCHAR 重定义
//-----------------------------------------------------------------------
//-----------------------内部函数----------------------------------------
void LcdIOInit();									//IO初始化
void WaitForEnable(void); 							//忙信号检测
void LcdWrite_C(int CMD,unsigned char AttribC);		//write Control Charactor
void LcdWrite_D(int dataW); 						//写一个数据
unsigned int LcdRead(void);							//read a data from LCD
void LCD12864_ARM_DELAY(void);								//内部延时
//-------------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-------------------------------------------------------------------------
#define LCD_BUSY_FLAG D7 //用于检查写忙信号
//-----------------------------------------------------------------------
//----------------------具体子函数---------------------------------------

void Set_Lcd_xy(unsigned char x,unsigned char y)
{
		LCDx=x;
		LCDy=y;				
}

//-----------------初始化-------------------------------
void Init_Lcd12864(void)
{	
	LcdIOInit();
	LcdWrite_C(0x30,0); //显示模式设置(不测试忙信号)共三次
	LcdWrite_C(0x30,1);
	LcdWrite_C(0x0c,1);//0x0f->all on,show arrow;0x0c->no arrow
	ClearAS();
}
//-------------------------------------------------------------------
//-----------------------------------------------------------------------
void ClearAS(void)
{
	LcdWrite_C(0x01,1);
}
//=======================================================//
//              按指定位置显示一个字符                   //
//=======================================================//
void DispChar(unsigned int x,unsigned int y,int dataW) 
{	int temp,t;
	
	LcdWrite_C(0x30,1);				//command back

	temp=x&0x0f;
	t=y>>1;
	y&=0x01;
	if(temp&0x01)
	{	
		temp=temp>>1;
		if(y)temp|=0x10;
		temp|=0x80;
		if(t)temp|=0x08;
		LcdWrite_C(temp,1);
		LcdRead();
		LcdWrite_D(dataW);	
	}
	else
	{	
		temp=temp>>1;
		if(y)temp|=0x10;
		temp|=0x80;
		if(t)temp|=0x08;
		LcdWrite_C(temp,1);
		LcdWrite_D(dataW);
	}
}

extern  int putchar (int a)
{
	if(LCDx==16){LCDx=0;LCDy++;}
	if(LCDy==4){LCDy=0;}	
//	LcdDisplayBuffer[LCDy][LCDx]=a;
	if(a!='\n')
	{
		DispChar(LCDx,LCDy,a);
		LCDx++;
	}
	else{LCDx=0;LCDy++;}
	return 1;
}

//-------------------------------------------------------
//-------------------------------------------------------//
//数据转换输出
//---------------------------------------------------------//

void ChangeOutPut( int a)
{
//	IO0CLR|=(D0|D1|D2|D3|D4|D5|D6|D7);
	IO0CLR|=(0xff<<8);
	IO0SET|=(a<<8);		
 }
//-----------------------------------------------------------//
//LCDIO初始化设置
//-----------------------------------------------------------//
void LcdIOInit()
{											  	
	PINSEL1&=~0x0000003f;								//设置RS、RW、Elcd口为GPIO
	PINSEL0&=~0Xffff0000;								//设置D0~D7口为GPIO
	IO0DIR|=(D0|D1|D2|D3|D4|D5|D6|D7|RS|Elcd|RW);		//设置为输出模式
}

//------------------------------------------------------//
//写控制字符子程序: E=1 RS=0 RW=0
//------------------------------------------------------//
void LcdWrite_C( int CMD,unsigned char AttribC ) 
{	
	if (AttribC)WaitForEnable(); // 检测忙信号?
	IO0CLR|=RS; 		   //RS=0
	IO0CLR|=RW;		   //RW=0	
	IO0SET|=Elcd;
	ChangeOutPut(CMD); 			// 送控制字子程序
	LCD12864_ARM_DELAY();
//	LCD12864_ARM_DELAY();
//	LCD12864_ARM_DELAY();
//	LCD12864_ARM_DELAY();		   
	IO0CLR|=Elcd; 				// 操作允许脉冲信号 
}
//------------------------------------------------------//
//当前位置写字符子程序: E =1 RS=1 RW=0
//------------------------------------------------------//
void LcdWrite_D(int dataW ) 
{	
	WaitForEnable();				 // 检测忙信号
	IO0SET|=RS;			 			//RS=1
	IO0CLR|=RW;			 			//RW=0	
	IO0SET|=Elcd;
	ChangeOutPut(dataW);			//数据发送
	LCD12864_ARM_DELAY();
//	LCD12864_ARM_DELAY();
//	LCD12864_ARM_DELAY();
//	LCD12864_ARM_DELAY();	  
	IO0CLR|=Elcd; 					// 操作允许脉冲信号 
}
//------------------------------------------------------//
//读模块子程序:E=1 RS=1 RW=1
//------------------------------------------------------//

unsigned int LcdRead(void)
{	
	unsigned int dataW;
	IO0DIR&=~(D0|D1|D2|D3|D4|D5|D6|D7);			//设置为输入模式
	IO0DIR|=RS;									//设置为输出模式
	IO0DIR|=(Elcd|RW);							//设置为输出模式

	WaitForEnable();							 // 检测忙信号
	IO0SET|=RS;									 //RS=1
	IO0SET|=RW;									 //RW=1
	IO0SET|=Elcd;								 //Elcd=1
	LCD12864_ARM_DELAY();								
	dataW=(IO0PIN&(D0|D1|D2|D3|D4|D5|D6|D7));
	IO0CLR|=Elcd;								// 操作允许脉冲信号
	IO0DIR|=(D0|D1|D2|D3|D4|D5|D6|D7);			//设置为输出模式
    return dataW;
}


//------------------------------------------------------//
//正常读写操作之前必须检测LCD控制器状态: CS=1 RS=0 RW=1
//DB7: 0 LCD控制器空闲; 1 LCD控制器忙
//------------------------------------------------------//
void WaitForEnable( void )
{	
	IO0DIR&=~(D0|D1|D2|D3|D4|D5|D6|D7);			//设置为输入模式
	IO0DIR|=(RS|Elcd|RW);						//设置为输出模式
	IO0CLR|=RS;									 //RS=0
	IO0SET|=RW;									 //RW=1
	IO0SET|=Elcd;								 //E=1
	while(IO0PIN&LCD_BUSY_FLAG);
	IO0CLR|=Elcd;								 //E=0
	IO0DIR|=(D0|D1|D2|D3|D4|D5|D6|D7);			//设置为输出模式

} 
//--------------------------------------------------------------------------
//内部延时			   //速度匹配用!
//---------------------------------------------------------------------------
void LCD12864_ARM_DELAY(void)
{
	unsigned char i;
	for(i=0;i<255;i++);
}

//-------------------End LCD12864.H-----------------------------------------

⌨️ 快捷键说明

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