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

📄 drv_1215.c

📁 Epson系列芯片开发的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
}

/***********************************************************************************************
 * vL1F01215TSetPixel
 *   Type :	void
 *   Ret val :	none
 *   Argument :	unsigned char usX:		range: 0~319
 *		unsigned char ucY:		range: 0~239
 *		unsigned char ucPixelGray:	range: 0~15
 *   Function :	Draw a pixel
 ***********************************************************************************************/
void vL1F01215TSetPixel(unsigned short usX, unsigned char ucY, unsigned char ucPixelGray )
{
	unsigned char ucGetPixel;
	
	if( usX >= LCD_SOLUTION_WIDTH || ucY >= LCD_SOLUTION_HEIGHT )
		 return ;
	
	ucGetPixel = ucL1F01215TGetPixel( usX, ucY ) & ( 0x0F << (( usX - ( usX / 2 * 2 )) * 4 ));
	*( ucpMemBaseAddr + ucY * ONE_LINE_BYTE_NUMBER + usX / 2 ) =  ucGetPixel | ( ucPixelGray << (( 1 - ( usX - usX / 2 * 2 )) * 4 ));
}

/***********************************************************************************************
 * ucL1F01215TGetPixel
 *   Type :	void
 *   Ret val :	none
 *   Argument :	unsigned short usX:		range:0~319
 *		unsigned char ucY:		range:0~239
 *   Function :	Draw a pixel
 ***********************************************************************************************/
unsigned char  ucL1F01215TGetPixel( unsigned short usX, unsigned char ucY )
{
	if( usX >= LCD_SOLUTION_WIDTH || ucY >= LCD_SOLUTION_HEIGHT)
		return 0;
	return ( *( ucpMemBaseAddr + ucY * ONE_LINE_BYTE_NUMBER + usX / 2 ));
}

/***********************************************************************************************
 * vL1F01215TDrawLine
 *   Type :	void
 *   Ret val :	none
 *   Argument :	unsigned short usX1:		range: 0~319
 *		unsigned char ucY1:		range: 0~239
 *		unsigned short usX2:		range: 0~319
 *		unsigned char ucY2:		range: 0~239
 *		unsigned char ucGray:		range: 0~15
 *   Function :	Draw a line
 ***********************************************************************************************/
void  vL1F01215TDrawLine(unsigned short usX1, unsigned char ucY1, unsigned short usX2, 
		unsigned char ucY2, unsigned char ucGray )
{
	unsigned char *ucpTmpDispMem = ucpMemBaseAddr;
	unsigned short  usMin, usMax;
	int     i;
	/*
	if( usX1 >= LCD_SOLUTION_WIDTH || ucY1 >= LCD_SOLUTION_HEIGHT)
		 return ;
	if( usX2 >= LCD_SOLUTION_WIDTH || ucY2 >= LCD_SOLUTION_HEIGHT)
		 return ;
	*/
	_CheckAndCorrectPointPosition( &usX1, &ucY1 );
	_CheckAndCorrectPointPosition( &usX2, &ucY2 );

	if( ucY1 == ucY2 )  // horizonal line
	{
		if(usX1 < usX2)
		{
			usMin =usX1;
			usMax =usX2;
		}
		else
		{
			usMin =usX2;
			usMax =usX1;
		}
		ucpTmpDispMem  = ucpMemBaseAddr + ucY1 * ONE_LINE_BYTE_NUMBER + usMin / 2;
		for( i = usMin / 2; i <= usMax / 2; i++ )
			*ucpTmpDispMem++ = ucGray + ( ucGray << 4 );
	}
	else if(usX1 == usX2)	// vertical line
	{
		if(ucY1 < ucY2)
		{
			usMin = ucY1;
			usMax = ucY2;
		}
		else
		{
			usMin = ucY2;
			usMax = ucY1;
		}
		
		ucpTmpDispMem  = ucpMemBaseAddr + usMin * ONE_LINE_BYTE_NUMBER + usX1 / 2;
		
		for( i = usMin; i <= usMax; i++ )
		{
			vL1F01215TSetPixel( usX1, ucY1 + i, ucGray );
			//*ucpTmpDispMem = ucGray + ( ucGray << 4 );
			//ucpTmpDispMem += ONE_LINE_BYTE_NUMBER;
		}
	}
	else	// diagonal line ,here use relative accurate algorithem
		_DrawDiagonalLine( usX1, ucY1 ,usX2, ucY2, ucGray );
}

/*
   Check whether a point is in a valid range,if not, correct its position.
*/
void   _CheckAndCorrectPointPosition( unsigned short* uspX, unsigned char* ucpY )
{
	if( *uspX  >= LCD_SOLUTION_WIDTH )
		*uspX  = LCD_SOLUTION_WIDTH -1;
	if( *ucpY >= LCD_SOLUTION_HEIGHT )
		*ucpY  = LCD_SOLUTION_HEIGHT-1;
}

/*
   _DrawDiagonalLine
*/
void	_DrawDiagonalLine( unsigned short usX1, unsigned char ucY1, unsigned short usX2, 
		unsigned char ucY2, unsigned char ucGray )
{
	unsigned short usXInterval, usYInterval;
	unsigned char bX1LessthanX2 = true, bY1LessthanY2 = true, bXIntervalEqualYInterval = false;
	unsigned short i,ushTmpX,uchTmpY,ushCount;
	short  shScale = 0;
	unsigned short *uspTmpDispMem = uspMemBaseAddr ;

	if( usX1 < usX2 )
	{
		usXInterval = usX2 - usX1;
	}
	else
	{
		usXInterval = usX1 - usX2;
		bX1LessthanX2 = false ;
	}
	
	if( ucY1 < ucY2 )
		usYInterval = ucY2 - ucY1 ;
	else
	{
		usYInterval = ucY1 - ucY2 ;
		bY1LessthanY2 = false ;
	}

	if( usXInterval == usYInterval )
		bXIntervalEqualYInterval = true;

	ushCount = usXInterval + usYInterval;
	ushTmpX  = usX1;
	uchTmpY  = ucY1;

	if( bX1LessthanX2 &&  bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= ucY2 - ucY1; i++ )
				vL1F01215TSetPixel( usX1 + i, ucY1 + i, ucGray );
		else
		{
			vL1F01215TSetPixel( usX1, ucY1, ucGray );
			for( i = 0; i < ushCount; i++ )
			{
				if( shScale >= 0 )
				{
					ushTmpX++;
					shScale -= usYInterval;
				}
				else
				{
					uchTmpY++;;
					shScale += usXInterval;
			        }
			        vL1F01215TSetPixel( ushTmpX, uchTmpY, ucGray );
			}
		}
		return ;
	}
	if( bX1LessthanX2 &&  !bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= usX2 - usX1; i++ )
				vL1F01215TSetPixel( usX1 + i, ucY1 - i, ucGray );
		else
		{
			vL1F01215TSetPixel( usX1, ucY1, ucGray );
			for( i = 0; i < ushCount; i++ )
			{
				if( shScale >= 0 )
				{
					ushTmpX++;
					shScale -= usYInterval;
				}
				else
				{
					uchTmpY--;
					shScale += usXInterval;
				}
				vL1F01215TSetPixel( ushTmpX, uchTmpY, ucGray );
			}
		}
		return ;
	}
	if( !bX1LessthanX2 &&  bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= usX1 - usX2; i++ )
				vL1F01215TSetPixel( usX1 - i, ucY1 + i, ucGray );
		else
		{
			vL1F01215TSetPixel( usX1, ucY1, ucGray );
			for( i = 0; i < ushCount; i++ )
			{
			 	if( shScale >= 0 )
			 	{
					ushTmpX--;
					shScale -= usYInterval;
				}
			   	else
				{
					uchTmpY++;
					shScale += usXInterval;
				}
				vL1F01215TSetPixel( ushTmpX, uchTmpY, ucGray );
			}
		}
		return ;
	}
	if( !bX1LessthanX2 &&  !bY1LessthanY2 )
	{
		if( bXIntervalEqualYInterval )
			for( i = 0; i <= usX1-usX2; i++ )
				vL1F01215TSetPixel( usX1 - i, ucY1 - i, ucGray );
		else
		{
			vL1F01215TSetPixel( usX1, ucY1, ucGray );
			for( i = 0; i < ushCount; i++ )
			{
				if( shScale >= 0 )
				{
					ushTmpX--;
					shScale -= usYInterval;
				}
				else
				{
					uchTmpY--;
					shScale += usXInterval;
				}
				vL1F01215TSetPixel( ushTmpX, uchTmpY, ucGray );
			}
		}
	}
}

/*******************************************************************************************
 * vL1F01215TDrawASCII 
 *	Type:	void
 *	Ret val:none
 *	Argument:unsigned char ucASCIIX:	the No. of LCD's column ( ucASCIIX: 0 ~ 320 / 8 - 1 = 39 )
 *		 unsigned char ucASCIIY:	the No. of LCD's line ( ucASCIIY: 0 ~ 240 /8 - 1 = 29 )
 *		 unsigned char ASCII:		the ASCII table lib
 *		the LCD is 320 * 240
 *	Function: Draw a ASCII on the LCD.
 *******************************************************************************************/
void vL1F01215TDrawASCII( unsigned char ucASCIIX, unsigned char ucASCIIY, unsigned char ASCII, unsigned char ucGray )
{
	unsigned char i, j, ucTmpByte, ucByte;

	for( i = 0; i < 8; i++ )
	{
		ucTmpByte = *( ASCIIchar + ( ASCII - 0x20 ) * 8 + i );
		for( j = 0; j < 4; j++ )
		{
			ucByte = ((( ucTmpByte & 0x80 ) >> 7 ) * ucGray ) << 4;
			ucTmpByte <<= 1;
			ucByte |= (( ucTmpByte & 0x80 ) >> 7 ) * ucGray;
			*( ucpMemBaseAddr + ( ucASCIIY * 8 + i ) * ONE_LINE_BYTE_NUMBER + ucASCIIX * 4 + j ) = ucByte;
			ucTmpByte <<= 1;
		}
/*		{
			ucByte = (( ucTmpByte & 0x01 ) * ucGray ) << 4 ;
			ucTmpByte >>= 1;
			ucByte |= ( ucTmpByte & 0x01 ) * ucGray;
			*( ucpMemBaseAddr + ( ucASCIIY * 8 + i ) * ONE_LINE_BYTE_NUMBER + ucASCIIX * 8 + j ) = ucByte;
			ucTmpByte >>= 1;
		}
*/
	}
}

/*******************************************************************************************
 * vL1F01215TDrawString 
 *	Type:	void
 *	Ret val:none
 *	Argument:unsigned char ucASCIIX:	the No. of LCD's column ( ucASCIIX: 0 ~ 320 / 8 - 1 = 39 )
 *		 unsigned char ucASCIIY:	the No. of LCD's line ( ucASCIIY: 0 ~ 240 /8 - 1 = 29 )
 *		 unsigned char *string:		the point to the string that want to be display
 *		the LCD is 320 * 240
 *	Function: Draw a string on the LCD.
 *******************************************************************************************/
void vL1F01215TDrawString( unsigned char ucASCIIX, unsigned char ucASCIIY, unsigned char *string, unsigned char ucGray )
{
	unsigned char i,j;
			
	for( i = 0; *string != '\0'; i++ )
	{		
		vL1F01215TDrawASCII( ucASCIIX, ucASCIIY, *string++, ucGray );
		if( ucASCIIX != 39 )
			ucASCIIX++;
		else
		{
			ucASCIIX = 0;
			ucASCIIY++;
		}
	}
}

void vDelay( void )
{
	unsigned long i;
	
	for( i = 0; i < 500000; i++ )
		asm(" nop ");	
}

void vDelay1( void )
{
	unsigned long i;
	
	for( i = 0; i < 250; i++ )
		asm(" nop ");	
}

void vL1F01215TDemo( void )
{
	signed short i;
	
	_Test_DrawVerticalStripe();
	
	vL1F01215TDrawASCII( 1, 2, 'a', 15 );
	vL1F01215TDrawASCII( 1, 3, 'b', 15 );
	vL1F01215TDrawASCII( 1, 4, 'c', 15 );
	vL1F01215TDrawASCII( 1, 0, 'e', 15 );

	vL1F01215TDrawASCII( 0, 1, 'a', 15 );
	vL1F01215TDrawASCII( 1, 1, 'b', 15 );
	vL1F01215TDrawASCII( 2, 1, 'c', 15 );
	vL1F01215TDrawASCII( 3, 1, 'e', 15 );
	
	vL1F01215TDrawString( 1, 2, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=,./;'[]`~!@#$%^&*()_+|:{}?><", 15 );
	
	vL1F01215TSetPixel( 0, 0, 15 );
	vL1F01215TSetPixel( 1, 0, 15 );
	vL1F01215TSetPixel( 0, 1, 15 );
	vL1F01215TSetPixel( 1, 1, 15 );	
	vL1F01215TSetPixel( 159, 1, 15 );
	vL1F01215TSetPixel( 160, 1, 15 );
	vL1F01215TSetPixel( 319, 0, 15 );
	vL1F01215TSetPixel( 319, 1, 15 );
	vL1F01215TSetPixel( 0, 119, 15 );
	vL1F01215TSetPixel( 0, 120, 15 );
	vL1F01215TSetPixel( 0, 239, 0 );
	vL1F01215TSetPixel( 1, 238, 0 );
	vL1F01215TSetPixel( 319, 239, 0 );
	vL1F01215TSetPixel( 319, 238, 0 );
	vL1F01215TSetPixel( 318, 239, 0 );
	vL1F01215TSetPixel( 318, 238, 0 );
	
	vL1F01215TClr( );
	
	vL1F01215TDrawLine( 0, 0, 319, 0, 15 );
	vL1F01215TDrawLine( 0, 0, 0, 239, 15 );
	vL1F01215TDrawLine( 319, 0, 319, 239, 15 );
	vL1F01215TDrawLine( 0, 239, 319, 239, 15 );
	
	while( 1 )
	{
		
		for( i = 0; i < 240; i++ )
		{
			vL1F01215TDrawLine( 0, 0, 319, i, 15 );
			vL1F01215TDrawLine( 0, 0, 319, i, 0 );
			vDelay1( );
		}
		for( i = 319; i >= 0; i-- )
		{
			vL1F01215TDrawLine( 0, 0, i, 239, 15 );
			vL1F01215TDrawLine( 0, 0, i, 239, 0 );
			vDelay1( );
		}
	}
		
	vL1F01215TDrawLine( 0, 0, 239, 239, 15 );
	vL1F01215TDrawLine( 0, 0, 319, 239, 15 );
	vL1F01215TDrawLine( 0, 0, 19, 239, 15 );
	vL1F01215TDrawLine( 0, 0, 319, 100, 15 );
	vL1F01215TDrawLine( 0, 0, 319, 10, 15 );
	
	vL1F01215TDrawLine( 0, 239, 319, 0, 15 );
	
	
LOOP:
	vSwivelView( 180 );
	vPutImage( &IMAGE1_4BPP, 320, 240 );
	vDelay( );
	vPutImage( &IMAGE2_4BPP, 320, 240 );
	vDelay( );
	vEnableSubWindow( );
	vPutImage( &IMAGE3_4BPP, 600, 400 );
	vDelay( );
	vDisableSubWindow( );
goto LOOP;
	
	vVideoInvert( );
	
	vSwivelView( 90 );
	vSwivelView( 180 );
	vSwivelView( 270 );
	
	vDelay( );
	
	ExitDriver( );
}

⌨️ 快捷键说明

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