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

📄 lcd.c

📁 12864点阵液晶显示读写驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 /***-----------------------------------------------------------------------
**
**  Abstract:    LCD.c
**
**  Author(s):   guoxiaojian
**
**  Creation Date: 2008.6.25
**
**  Current Version: Initial revision
**-------------------------------------------------------------------------
**------ Copyright  yaneng  2008  - All rights reserved-  CONFIDENTIAL-----
**--------------------------- Change By XXX -------------------------------
**
**  Revision:        
**                   
**  Changes:          
**
***-----------------------------------------------------------------------------*/
#ifndef   _LCD_C
#define   _LCD_C
/********************************************************************************
**  Include files
********************************************************************************/      
#ifndef   _REG52_H                     
   #include      "REG52.H"   
#endif
/*
#ifndef   _STDLIB_H				
   #include      "STDLIB.H" 
#endif
*/
#ifndef   _INTRINS_H				
   #include      "INTRINS.H" 
#endif

#ifndef   _MATH_H
   #include      "MATH.H" 
#endif

#ifndef   _LCD_H				
   #include      "LCD.H" 
#endif

#ifndef   _KEY_H				
   #include      "KEY.H" 
#endif

#ifndef   _TIMER_H				
   #include      "TIMER.H" 
#endif

#ifndef   _MAIN_H				
   #include      "MAIN.H" 
#endif

#undef    _LCD_C
#endif
 /***-----------------------------------------------------------------------
**
**  Abstract:   
**
**  Parameters:  void
**
**  Returns:     void
**
**  Calling Function(s):
**
**  Author(s):  Kiven GUO
**
**  Creation Date:2008.07.09
**
**  Current Version: 
**
**  Required execution rate:   
***----------------------------------------------------------------------
*/
/************************************************************************
****************LCD 状态检查***************************************/
void CheckState(void)
{
	unsigned char dat;
	DI	= 0;
	RW	= 1;
	do{
	P0	= 0xFF;
	E	= 1;
	_nop_();
	dat	= P0;
	_nop_();
	E	= 0;}
	while(dat & 0x80) ;
}
/************************************************************************
****************LCD 屏幕选择***************************************/
void SelectScreen(unsigned char screen)
{ //北京显示器:负有效 cs1: 0--右; cs2: 0--左
	switch(screen)
	{ 
		case 0: 
			CS1=1;//全屏
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
			CS2=1; 
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
			break; 
		case 1:
			CS1=1;//左屏
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); 
			CS2=0;
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
			break;
		case 2: 
			CS1=0;//右屏
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); 
			CS2=1;
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); 
			break;
		default :
			CS1=0;//不选
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); 
			CS2=0;
			_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); 
			break;		
	}
}
/************************************************************************
****************LCD数据发送***************************************/
void WriteData( unsigned char DataByte)
{
	CheckState();
	DI	= 1;
	RW	= 0;
	P0	= DataByte;
	E	= 1;
	_nop_();
	E	= 0; 
	_nop_();
}
/************************************************************************
****************LCD指令发送***************************************/
void WriteCommand( unsigned char CommandByte)
{
	CheckState();
	DI	= 0;
	RW	= 0;
	P0	= CommandByte;
	E	= 1;
	_nop_();
	E	= 0; 
	_nop_();
}

/************************************************************************
****************LCD  行地址X(0~7)设定**********************************************/
void SetLine(unsigned char line)
{
	line=line & 0x07; // 0<=line<=7
	line=line | 0xb8; //1011 1xxx
	WriteCommand(line);
}
/************************************************************************
****************LCD  列地址Y(0~63)设定**********************************************/
void SetColumn(unsigned char col)
{
	col=col & 0x3f; // 0=<column<=63
	col=col | 0x40; //01xx xxxx
	WriteCommand(col);
}
/************************************************************************
****************LCD  其起始地址Z(0~63)设定**********************************************/
void SetStartLine(unsigned char startline) //0--63
{
	startline=startline & 0x07;
	startline=startline | 0xc0; //1100 0000
	WriteCommand(startline);
}
/************************************************************************
****************LCD   开关显示**********************************************/
void SetOnOff(unsigned char onoff)
{
	onoff=0x3e | onoff; //0011 111x
	WriteCommand(onoff);
}
/************************************************************************
****************LCD   清屏*********************************************/
void ClearScreen(unsigned char screen)
{ 
	unsigned char i,j;
	SelectScreen(screen);
	for(i=0;i<8;i++)
	{ 
		SetLine(i);
		for(j=0;j<64;j++)
		{
			WriteData(0x00);
		}
	}
}
/************************************************************************
****************LCD屏初始化**********************************************/
void LCDInit(void)
{
	RST = 0;
	Delay(50);
	RST = 1;
	Delay(50);
	SelectScreen(0);
	SetOnOff(0); //关显示
	ClearScreen(1);//清屏
	ClearScreen(2);
	SelectScreen(0);
	SetOnOff(1); //开显示
	SelectScreen(0);
	SetStartLine(0); //开始行:0
}
/************************************************************************
**************************LCD 反显************************************/
void ReverseShowUnit(unsigned char i,unsigned char j)
{
	unsigned char m,n,q;
	if(j<24)						
		ShowUnit(j);
	m	= i/4;
	n	= i%4;
	n = n*2;
	q = m*8+n;
	if(m==1 || m==4)
	{
		SelectScreen(1);
		ShowBody(48,n,q,0,16,0);	
		SelectScreen(2);
		ShowBody(0,n,q,16,32,0);
	}
	else
	{
		SelectScreen(ColumnSelect[1][m]);
		ShowBody(ColumnSelect[0][m],n,q,0,32,0);
	}
}
/************************************************************************
**************************LCD 单元显示************************************/
void ShowUnit(unsigned char i)
{
	unsigned char m,n,q;

	m	= i/4;
	n	= i%4;

	n = n*2;
	q = m*8+n;
	if(m == 1 || m == 4)						//中间列
	{
		SelectScreen(1);
		ShowBody(48,n,q,0,16,1);	
		SelectScreen(2);
		ShowBody(0,n,q,16,32,1);
	}
	else
	{
		SelectScreen(ColumnSelect[1][m]);			
		ShowBody(ColumnSelect[0][m],n,q,0,32,1);
	}
}
/************************************************************************
**************************LCD 界面(一)显示初始化************************************/
void ShowUnitInit(void)
{
	unsigned char m;
	for(m=0;m<8;m++)
		ShowLCDData(1,0,m,0x00,8);
	for(m=0;m<8;m++)
		ShowLCDData(1,40,m,0x00,8);
	for(m=0;m<8;m++)
		ShowLCDData(2,16,m,0x00,8);
	for(m=0;m<8;m++)
		ShowLCDData(2,56,m,0x00,8);
}
/************************************************************************
**************************LCD 项目测试显示单元*********************/
void FaceShowUnit(unsigned char i)
{
	unsigned char m,n,q;

	m	= i/4;
	n	= i%4;

	n = n*2;
	q = m*8+n;

	SelectScreen(1);			
	ShowBody(0,2,q,0,32,1);
	ShowLCDData(1,32,2,0x00,32);
	ShowLCDData(1,32,3,0x00,32);

}
/************************************************************************
**************************LCD 显示子函数************************************/
void ShowBody(unsigned char col,unsigned char line,unsigned char q,unsigned char k0,unsigned char k1,unsigned char t)
{								//t=0 字母项目反显 t=1 字母项目显示
	unsigned char j,k;
	unsigned char temp;
	for(j=0;j<2;j++)
	{
		SetColumn(col);
		SetLine(line);
		for(k=k0;k<k1;k++)
		{
			if(t==0)
			{
				temp = ~ARRAY8_BufScreen[q][k];	
				WriteData(temp);
			}
			else 
				WriteData(ARRAY8_BufScreen[q][k]);
		}
		line++;
		q++;
	}
}
/************************************************************************
**************************LCD 测试界面显示************************************/
void Showface2(void)
{
	ClearShowArea();			
	FaceShowUnit(Menu_Item);
	ShowSampNumbAndTime(SampNumb,SampTime);

	ShowLCDData(1,28,0,0x00,36);				//清除菜单栏显示
	ShowLCDData(1,28,1,0x80,36);

	ShowLCDData(2,0,2,0x00,8);
	ShowLCDData(2,0,3,0x00,8);
	ShowLCDData(2,0,0,0x00,36);
	ShowLCDData(2,0,1,0x80,36);

	ShowMenu(0,0);								//打印	
	ShowMenu(1,0);								//返回
	ShowLapseTime(Menu_Item,0);							//定时1显示
	SelectScreen(1);

}
/************************************************************************
**************************清楚显示区域**********************************/
void ShowSampNumbAndTime(unsigned char Numb,unsigned char Tim)
{
	ShowSmallNumber(Numb,4);				//样本编号
	ShowSmallNumber(Tim,6);					//测试次数
	for(Tim=4;Tim<8;Tim++)		//显示区域与编号的分割线
	{
		SetColumn(31);
		SetLine(Tim);
		WriteData(0xff);				
	}
	for(Tim=2;Tim<4;Tim++)
	{
		SetColumn(63);
		SetLine(Tim);
		WriteData(0xff);				
	}
}
/************************************************************************
**************************清楚显示区域**********************************/
void ClearShowArea(void)
{
	ShowLCDData(1,32,4,0x01,32);				//清除显示区域
	ShowLCDData(1,32,5,0x00,32);
	ShowLCDData(1,32,6,0x00,32);
	ShowLCDData(1,32,7,0x00,32);
	ShowLCDData(2,0,4,0x01,64);
	ShowLCDData(2,0,5,0x00,64);
	ShowLCDData(2,0,6,0x00,64);
	ShowLCDData(2,0,7,0x00,64);
}
/************************************************************************
**************************LCD 16进制转8421码******************************/
void NumbTo8421(unsigned int number)
{
	unsigned char i;
	number = number + number/1000*0x0600 + number/100*0x0060 + number/10*0x0006;
	for(i=4;i>0;i--)
	{
		Dis_Value[i-1].U   = 0;
	}
	for(i=4;i>0;i--)
	{
		Dis_Value[i-1].U   = number;
		number >>= 4;
	}	
}
/************************************************************************
**************************LCD Number显示******************************/
void ShowSmallNumber(unsigned int number,unsigned char line)
{						//line=4:标本号  line=6 测试号
	unsigned char j,k,m,n;
	unsigned char g,h;
	SelectScreen(1);	
	NumbTo8421(number);

	for(j=line;j<line+2;j++)
	{
		SetColumn(0);
		SetLine(j);
		n = 0;
		for(m=0;m<4;m++)
		{
			k = Dis_Value[m].U *2;
			if(k != 0)
				n=1;		
			if(n!=0 || k!=0)
			{
				for(g=0;g<8;g++)
				{

⌨️ 快捷键说明

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