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

📄 lcddrv.c

📁 LPC213x系列微处理器操作SED1335液晶显示屏的驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
   LCDWriteCmd(LC_CSRW);         	  					// CURSOR WRITE COMMAND
   LCDWriteData(0x00);        						// Cursor position low byte
   LCDWriteData(0x00);        						// Cursor position high byte
-----*/
ClrSCR(1);

}

/*===========文本模式操作函数===========*/

/**********************************************************
Name:  void Locate(int x, char y)	  					  *
Description:   Goto X Y coor	 			 	  		  *
Input:         X,Y	  									  *
Output:        none										  *
Misc:          											  *
**********************************************************/
void TextLocate(char x, char y)
{
   int Address;
   unsigned char low;
   unsigned char high;

   Address = (y * (GUI_LCM_XMAX>>3)) + x;

   low  = Address & 0xff;
   high = Address >> 8;

   LCDWriteCmd(LC_CSRW);         	 		   	 	    // CURSOR WRITE COMMAND
   LCDWriteData(low);       						// Cursor position low byte
   LCDWriteData(high);      						// Cursor position high byte
}

/**********************************************************
Name:  void Cursor(unsigned char)						  *
Description:   0-> Cursor off							  *
               1-> Cursor on							  *
Input:         ON/OFF	  								  *
Output:        none										  *
Misc:          											  *
**********************************************************/
void Cursor(char cursor)
{
   LCDWriteCmd(LC_DISP_ON);         				    // DISPLAY ON COMMAND
   if (cursor == 0)
      //LCDWriteData(0x14);
      //LCDWriteData(0x54);
      LCDWriteData(0x14);
   else
      //LCDWriteData(0x17);
      //LCDWriteData(0x56);
      LCDWriteData(0x16);
}

/****************************************************
*  显示十进制数                                     *
*  输入:   X       :横坐标。8个半角字符为单位 0-16*
*           Y       :列坐标。纵向1个像素为单位 0-64*
*           Num     :需要显示的数字                *
*           Bit     :需要显示的数字的位数          *
****************************************************/
void DEC_Num_Disp(char X,char Y,unsigned int Num,char Bit)
{
   char i   = 0;
   char LCD_Buff[3] = {0};
   
   if (Bit>3)
   {
        Bit = 3;
   }
   
   for (i=0;i<Bit;i++)
   {
	   LCD_Buff[i] = Num%10;  
      Num = Num/10;
   }
	TextLocate(X,Y);
	LCDWriteCmd(LC_MWRITE);
   for (i=0;i<Bit;i++)
   { 
		 LCDWriteData((LCD_Buff[Bit-1-i]+0x30));
   }   
}

/****************************************************
*  显示带小数点的数                                 *
*  输入:   X       :横坐标。8个半角字符为单位 0-16*
*           Y       :列坐标。纵向1个像素为单位 0-64*
*           Num     :需要显示的数字                *
*           Bit     :需要显示的数字的位数          *
*           Point   :小数点所在的位                *
****************************************************/
void PointNum_Disp(char X,char Y,unsigned int Num,char Bit,char Point)
{
   char i   = 0;
   char LCD_Buff[4] = {0};
   for (i=0 ; i<Bit ; i++)                          //依次把数据写入缓冲区中
   {
	  if(i==Point)                                   //插入小数点
	  {
		   LCD_Buff[i] = 0xfe;
		   i++;
	  }
	  LCD_Buff[i] = Num%10;
	  Num = Num/10;
   }
	TextLocate(X,Y);
	LCDWriteCmd(LC_MWRITE);
   for (i=0 ; i<Bit ; i++)                           //依次将缓冲区的数据显示
   {
      LCDWriteData(LCD_Buff[Bit-1-i]+0x30);
   } 
}

/*********************************************************************************
Name:  void LCDWriteString(char X,char Y,char *ptr)  							 *
Description:   Write a string to the LCD 				 	  			  		 *
Input:         Address 		  	 	 											 *
               String															 *
Output:        none																 *
Misc:          String must be ended by \0										 *
*********************************************************************************/
void LCDWriteString(char X,char Y,char *ptr)
{
   //int i;
   TextLocate(X,Y);
   LCDWriteCmd(LC_MWRITE);       						// LCD WRITE MEMORY
   while(*ptr != 0x00)
   {
	   LCDWriteData(*ptr++);
	}	  
}

/********************************************************************
Name:  UseTxtFill(char x1, char y1, char x2, char y2, char FillMode)*
Description:   Use Txt mode fill appointed area            			*
Input:         Appointed area adress        			   			*
               Mode of fill block. 1--fill  0--clear	  			*
Output:        none										  			*
Misc:          											  			*
********************************************************************/
void UseTxtFill(char x1, char y1, char x2, char y2, char FillMode)
{
   unsigned int startAddr=0x0000;
	char LSBa, MSBa,len,wid;
	startAddr = 40*y1+x1;

   for(wid=0;wid<(y2-y1);wid++)
	{
      LSBa=startAddr&0xFF;
	   MSBa=(startAddr>>8)+0x10;
		  LCDWriteCmd(LC_CSRW);                            //send cursor address
	   LCDWriteData(LSBa);           
	   LCDWriteData(MSBa);
	   LCDWriteCmd(LC_CSRDIR1);							//set move direction of cursor
	   LCDWriteCmd(LC_MWRITE);							//send disp data
	   for(len=0;len<=(x2-x1);len++)
	   {
		   	 LCDWriteData(FillMode);	
	   }
	   startAddr+=40;
   }
}


/*===========图形模式操作函数===========*/

/*********************************************************************************
*********************************************************************************/
void GraphicLocate(int X, char Y)
{
   char LSB,MSB;
	//StartAddr = ()+
}
/*********************************************************************************
Name:  void LCDDisplay_bmp(int x,char y,int length,char Width,const char *dat)   *
Description:   Write a Bit-Map to LCD 				 	  			  		 	 *
Input:         Address 		  	 	 											 *
               BMP Size(Width & Length)											 *
               BMP Data 														 *
Output:        none																 *
Misc:          String must be ended by \0										 *
*********************************************************************************/
void LCDDisplay_bmp(int x,char y,int length,char Width,const char *dat)
{
 	unsigned int startAddr=0x0000;
	char LSBa, MSBa,len,wid;
	//startAddr = 40*y+x + 0x2600;
	startAddr = 40*y+x;
	LCDWriteCmd(LC_CSRDIR1);

	for(wid=0;wid<Width;wid++)
	{        	  
 	   LSBa=startAddr&0xFF;
	   MSBa=(startAddr>>8);   
	   LCDWriteCmd(LC_CSRW);
	   LCDWriteData(LSBa);           
	   LCDWriteData(MSBa);
	   LCDWriteCmd(LC_MWRITE);
	   for(len=0;len<(length>>3);len++)
	   { 
         LCDWriteData(*(dat++));	
	   }
	   startAddr+=40;
   }   
}

/**********************************************************
Name:  void GPART(void)								      *
Description:   Clear appointed area of Graphic Screen     *
Input:         Appointed area adress        			  *
               Mode of fill block. 1--fill  0--clear	  *
Output:        none										  *
Misc:          											  *
**********************************************************/
void GPART(int x1, char y1, int x2, char y2, char FillMode)
{
   unsigned int startAddr=0x0000;
	char LSBa, MSBa,len,wid;
	///startAddr = 40*y1+(x1>>3) +0x2600;
	startAddr = 40*y1+(x1>>3);

   for(wid=0;wid<=(y2-y1);wid++)
	{        	  
      LSBa=startAddr&0x00FF;
	   MSBa=(startAddr>>8);
		  LCDWriteCmd(LC_CSRW);                            //send cursor address
	   LCDWriteData(LSBa);           
	   LCDWriteData(MSBa);
	   LCDWriteCmd(LC_CSRDIR1);							//set move direction of sursor
	   LCDWriteCmd(LC_MWRITE);							//send disp data
	   for(len=0;len<=((x2-x1)>>3);len++)
	   {
		   	 LCDWriteData(FillMode);	
	   }
	   startAddr+=40;
   }
}

/**********************************************************
Name:  void GPix(int x, int y, unsigned char stat)		  *
Description:   Disp a pixel on screen		 			  *
Input:         x,y---Position of pixel					  *
               state:1--Draw a pixel; 0--Clear a pixel    *
Output:        none			   		  		   	 		  *
Misc:          											  *
**********************************************************/
void GPix(int x, char y, char state)
{
   unsigned int Address;
   unsigned char Offset,low,high,byte;

   //Address = (y * 40) + (x>>3) + 0x2600;
   Address = (y * 40) + (x>>3);
   Offset = x - ((x>>3)<<3);

   low  = Address & 0xff;
   //high =(Address>> 8) + 0x10;
   high =(Address>> 8);

   LCDWriteCmd(LC_CSRW);         	   	 	            // CURSOR WRITE COMMAND
   LCDWriteData(low);         						// Cursor position low byte
   LCDWriteData(high);        						// Cursor position high byte

   LCDWriteCmd(LC_MREAD);         						// READ LCD MEMORY COMMAND
   byte = LCDReadData();      						// Read data at position

   if (state != 0)
      byte |= (0x80 >> Offset);
   else
      byte &= (~(0x80 >> Offset));

   LCDWriteCmd(LC_CSRW);         	  					// CURSOR WRITE COMMAND
   LCDWriteData(low);         						// Cursor position low byte
   LCDWriteData(high);        						// Cursor position high byte

   LCDWriteCmd(LC_MWRITE);       						// LCD WRITE MEMORY COMMAND
   LCDWriteData(byte);        						// Write byte
}

/*************************************************************
Name:  void GBox(int x1, char y1, int x2, char y2,char state)*
Description:   draw a box	 	 	 	 	 			  	 *
Input:         x1\y1\x2\y2--position of box	 			  	 *
Output:        state:1--Draw; 0--Clear    				  	 *
Misc:          				  								 *
*************************************************************/
void GBox(int x1, char y1, int x2, char y2,char state)
{
   int i;

   for (i=x1;i<=x2;i++)
      GPix(i,y1,state);        // Top line
   for (i=x1;i<=x2;i++)
      GPix(i,y2,state);        // Bottom line
   for (i=y1;i<=y2;i++)
      GPix(x1,i,state);        // Left side
   for (i=y1;i<=y2;i++)
      GPix(x2,i,state);        // Right side
}

/**********************************************************
Name:  void TextBox(int x, char y, int length,char state) *
Description:   			   		   	   			   		  *
Input:         Text cursor!								  *
Output:        none		   		   	   			   		  *
Misc:          											  *
**********************************************************/
void TextBox(int x, char y, int length,char state)
{
   GBox(((x-1)<<3),((y-1)<<3),(((length<<3)+((x-1)<<3))-2),(y*12),state);
}

/**********************************************************
Name:  void GLine(int x1, char y1, int x2, char y2)
Description:   draw a line
Input:         none
Output:        none
Misc:       
**********************************************************/
void GLine(int x1, char y1, int x2, char y2,char state)
{
   int dx,dy,stepx,stepy,fraction;

   dy = y2 - y1;
   dx = x2 - x1;

   if (dy < 0)
   {
      dy = -dy;
      stepy = -1;
   }
   else
   {
      stepy = 1;
   }

   if (dx < 0)
   {
      dx = -dx;
      stepx = -1;
   }
   else
   {
      stepx = 1;
   }

   dy <<= 1;
   dx <<= 1;

   GPix(x1,y1,state);

   if (dx > dy)
   {
      fraction = dy - (dx >> 1);
      while (x1 != x2)
      {
         if (fraction >= 0)
         {
            y1 += stepy;
            fraction -= dx;
         }
         x1 += stepx;
         fraction += dy;
         GPix(x1,y1,state);
      }
   }
   else
   {
      fraction = dx - (dy >> 1);
      while (y1 != y2)
      {
         if (fraction >= 0)
         {
            x1 += stepx;
            fraction -= dy;
         }
         y1 += stepy;
         fraction += dx;
         GPix(x1,y1,state);
      }
   }
}





/*


uchar fnST01(void)		// 状态位STA1,STA0判断(读写指令和读写数据)
{
	uchar i,status;
	
	for(i=10;i>0;i--)
	{
		ReadStatus;
		status = LCMCW;
		ReadOK;
		if((status & 0x03) == 0x03)
			break;
	}
	return i;	// 若返回零,说明错误
}

uchar fnST2(void)		// 状态位ST2判断(数据自动读状态)
{
	uchar i,status;
	
	for(i=10;i>0;i--)
	{
		ReadStatus;
		status = LCMCW;
		ReadOK;
		if((status & 0x04) == 0x04)
			break;
	}
	return i;	// 若返回零,说明错误
}

uchar fnST3(void)		// 状态位ST3判断(数据自动写状态)
{
	uchar i,status;
	
	for(i=10;i>0;i--)
	{
		ReadStatus;
		status = LCMCW;
		ReadOK;
		if((status & 0x08) == 0x08)
			break;
	}
	return i;	// 若返回零,说明错误
}

uchar fnST6(void)		// 状态位ST6判断(屏读/屏拷贝状态)
{
	uchar i,status;
		
	for(i=10;i>0;i--)
	{
		ReadStatus;
		status = LCMCW;
		ReadOK;
		if((status & 0x40) == 0x40)
			break;
	}
	return i;	// 若返回零,说明错误
}

uchar fnPR1(uchar uCmd,uchar uPar1,uchar uPar2)	// 写双参数的指令
{
	if(fnST01() == 0)
		return 1;
	WriteData;	
	LCMDW = uPar1;
	WriteOK;
	if(fnST01() == 0)
		return 2;
	WriteData;
	LCMDW = uPar2;
	WriteOK;
	if(fnST01() == 0)
		return 3;
	WriteCmd;
	LCMCW = uCmd;
	WriteOK;
	return 0;	// 返回0成功
}

uchar fnPR11(uchar uCmd,uchar uPar1)	// 写单参数的指令
{
	if(fnST01() == 0)
		return 1;
	WriteData;
	LCMDW = uPar1;
	WriteOK;
	if(fnST01() == 0)
		return 2;
	WriteCmd;
	LCMCW = uCmd;
	WriteOK;

⌨️ 快捷键说明

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