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

📄 lcd.c

📁 嵌入式系统
💻 C
📖 第 1 页 / 共 5 页
字号:
@@ [Return]     : None
@@
@@ [Desc]       : Set color when drawing.
@@                Valid drawing function : apd_LCDDrawVline, apd_LCDDrawHline,
@@                                         apd_LCDDrawLine, apd_LCDDrawRect,
@@                                         apd_LCDDrawPixel, apd_LCDFillRect
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetColor(APD_LCD_COLOR color)
{
    current_gc.c = color;
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetFillPattern
@@
@@ [Summary]    : Set fill pattern
@@
@@ [Argument]   : fill_type : Fill pattern type (either of the following)
@@                            APD_LCD_FILL_SOLID
@@                            APD_LCD_FILL_DOT
@@                            APD_LCD_FILL_DIAGONAL
@@                            APD_LCD_FILL_BDIAGONAL
@@                            APD_LCD_FILL_DCROSS,
@@                            APD_LCD_FILL_HORIZONTAL
@@                            APD_LCD_FILL_VERTICAL
@@                            APD_LCD_FILL_CROSS
@@
@@ [Return]     : None
@@
@@ [Desc]       : Set fill pattern when drawing fill
@@                Valid drawing function : apd_LCDFillRect
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetFillPattern(
APD_LCD_FILL_TYPE fill_type
)
{
    current_gc.ft = fill_type;
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetRasterOperation
@@
@@ [Summary]    : Set raster operation
@@
@@ [Argument]   : rop : Raster operation (either of the following)
@@                      APD_LCD_ROP_S
@@                      APD_LCD_ROP_n_SoD
@@                      APD_LCD_ROP_nS_aD
@@                      APD_LCD_ROP_nS
@@                      APD_LCD_ROP_Sa_nD
@@                      APD_LCD_ROP_nD
@@                      APD_LCD_ROP_SeD
@@                      APD_LCD_ROP_n_SaD
@@                      APD_LCD_ROP_SaD
@@                      APD_LCD_ROP_n_SeD
@@                      APD_LCD_ROP_nS_oD
@@                      APD_LCD_ROP_So_nD
@@                      APD_LCD_ROP_SoD
@@
@@ [Return]     : None
@@
@@ [Desc]       : Set raster operation when drawing
@@                Valid drawing function : apd_LCDDrawVline, apd_LCDDrawHline,
@@                                         apd_LCDDrawLine, apd_LCDDrawRect,
@@                                         apd_LCDDrawPixel, apd_LCDFillRect
@@                                         apd_LCDDrawImage, apd_LCDDrawBMP
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetRasterOperation(
APD_LCD_ROP_TYPE rop
)
{
    current_gc.rop = rop;
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetGC
@@
@@ [Summary]    : Set drawing attribute
@@
@@ [Argument]   : gc : Graphics context
@@
@@ [Return]     : None
@@
@@ [Desc]       : Set drawing attribute (line type, line width, fill pattern,
@@                color and raster operation).
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetGC(
APD_LCD_GC *gc
)
{
    current_gc.lt = gc->lt;
    current_line_pat = LCD_LINE_PAT[current_gc.lt];
    current_gc.lw = gc->lw;
    current_gc.ft = gc->ft;
    current_gc.c = gc->c;
    current_gc.rop = gc->rop;
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDGetGC
@@
@@ [Summary]    : Get drawing attribute
@@
@@ [Argument]   : gc : Pointer to buffer of graphics context data
@@
@@ [Return]     : None
@@
@@ [Desc]       : Get drawing attribute (line type, line width, fill pattern,
@@                color and raster operation).
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDGetGC(
APD_LCD_GC *gc
)
{
    gc->lt = current_gc.lt;
    gc->lw = current_gc.lw;
    gc->ft = current_gc.ft;
    gc->c = current_gc.c;
    gc->rop = current_gc.rop;
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetDrawUpbase
@@
@@ [Summary]    : Set the upper panel base address.
@@
@@ [Argument]   : base : The address in memory drawing
@@
@@ [Return]     : None
@@
@@ [Desc]       : Set the base address of upper panel written in drawing data.
@@
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetDrawUpbase(
unsigned long   base
)
{
    LCD_DRAW_UPBASE = base;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetDrawLpbase
@@
@@ [Summary]    : Set the lower panel base address
@@
@@ [Argument]   : base : The address in memory drawing
@@
@@ [Return]     : None
@@
@@ [Desc]       : Set the base address of lower panel written in drawing data.
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetDrawLpbase(
unsigned long   base
)
{
    LCD_DRAW_LPBASE = base;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDRGB2Pixel
@@
@@ [Summary]    : Transform color model (RGB -> Pixel).
@@
@@ [Argument]   : rgb : Pointer to buffer of RGB color model data
@@
@@ [Return]     : Pixel color
@@
@@ [Desc]       : If bits per pixel is 16, transfer RGB color model
@@                into pixel color.
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
APD_LCD_COLOR apd_LCDRGB2Pixel(APD_LCD_RGB_COLOR *rgb)
{
    APD_LCD_COLOR color=0;          /* pixel color */

#if(APD_LCD_BPP == 16)
#ifdef APD_LCD_TFT
    color = rgb->intensity & 0x01;
    color = (color<<5) | (rgb->blue & 0x1F);
    color = (color<<5) | (rgb->green & 0x1F);
    color = (color<<5) | (rgb->red & 0x1F);
#else /* STN, COLOR */
    color = rgb->intensity & 0x01;
    color = (color<<4) | (rgb->blue & 0x0F);
    color = (color<<5) | (rgb->green & 0x0F);
    color = (color<<5) | (rgb->red & 0x0F);
    color = (color<<1);
#endif /* APD_LCD_TFT */
#endif

    return(color);
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDPixel2RGB
@@
@@ [Summary]    : Transform color model (Pixel -> RGB).
@@
@@ [Argument]   : color : Pixel color data
@@                rgb   : Pointer to buffer of RGB color model data
@@
@@ [Return]     : RGB color model
@@
@@ [Desc]       : If bits per pixel is 16, transform pixel color model
@@                into RGB color.
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDPixel2RGB(APD_LCD_COLOR color,APD_LCD_RGB_COLOR *rgb)
{
#if(APD_LCD_BPP == 16)
#ifdef APD_LCD_TFT
    rgb->red    = (unsigned char)(color & 0x1F);
    rgb->green  = (unsigned char)((color & 0x3E0)>>5);
    rgb->blue   = (unsigned char)((color & 0x7C00)>>10);
    rgb->intensity = (unsigned char)(color>>15);
#else /* STN, COLOR */
    rgb->red    = (unsigned char)(color & 0x0F);
    rgb->green  = (unsigned char)((color & 0x3C0)>>6);
    rgb->blue   = (unsigned char)((color & 0x7800)>>11);
    rgb->intensity = (unsigned char)(color>>15);
#endif /* APD_LCD_TFT */
#endif

    return;
}



/******************************************************************************/
void apd_LCDWriteFontColor(APD_LCD_POINT *point,APD_LCD_COLOR color)
{
	unsigned long *adrs;
	unsigned char hword, byte, bit;
	APD_LCD_COLOR tmp_color;
	tmp_color=color;
    	if (point->x < 0 || point->x >= APD_LCD_WIDTH ||
        point->y < 0 || point->y >= APD_LCD_HEIGHT)
        return;
        
	LCDGetPixelAdrs(point, &adrs, &hword, &byte, &bit);
	tmp_color=color;
	if(hword)
		{
			tmp_color = 0;
			//adrs--;
			tmp_color = (APD_LCD_COLOR)*adrs;
			tmp_color=((color<<16)|tmp_color);
		}
		apd_LCDSetColor(tmp_color);
    	LCDSetPixelByWord(adrs,tmp_color);
    	return;
}
				
//===============================================
// OK nov.18.2002

void apd_LCDDrawChar(APD_LCD_POINT *point ,unsigned char value,APD_LCD_COLOR color)
{
unsigned short inADDR=(unsigned short)(value-0x20)*CHARHEIGHT;
unsigned char DotData,k,k1;
unsigned long *adrs;
unsigned char hword, byte, bit;

APD_LCD_POINT pt;
pt.x=point->x;
pt.y=point->y;
	
   if (point->x < 0 || point->x+8 > APD_LCD_WIDTH || point->x >= APD_LCD_WIDTH||
   point->y < 0 || point->y+8 > APD_LCD_HEIGHT||point->y >= APD_LCD_HEIGHT)
    return;
    
   for(k=0;k<CHARHEIGHT;k++)
	{
	   DotData=SmallFnt8x8[inADDR];
	   for(k1=0;k1<8;k1++)
		{
 		  if((DotData&0x80)!=0)
			{
				apd_LCDWriteFontColor(&pt,color);	 	
    	    }
	      DotData=DotData<<1;
	      pt.x++;
		}
	  pt.y++;	
	  pt.x=point->x;
	  inADDR++;
	}		
}
/*******************************************************
;void LCDDrawStr(APD_LCD_POINT pt,char* str)
*******************************************************/
void apd_LCDDrawStr(APD_LCD_POINT *point,  char* str,APD_LCD_COLOR color)
{
	int len,i;
	unsigned char ch;
	APD_LCD_POINT pt;
	unsigned short x0,y0;
	x0 =point->x;
	y0 =point->y;
	if( (x0 >= APD_LCD_WIDTH)||(y0>=APD_LCD_HEIGHT) ) return;
	len = strlen(str);
	if( len <= 0 ) return;
	for( i=0; i<len; i++ )
	{
		ch = (unsigned char)str[i];
		if( ( (x0+8) < APD_LCD_WIDTH) && ((y0+8)<APD_LCD_HEIGHT) )
		{
			pt.x=x0;
			pt.y=y0;
			apd_LCDDrawChar(&pt,ch,color);
			x0+=CHARWIDTH;
		}
		else break;
	}
}
/**********************************************************************
**********************************************************************/

void apd_LCDDrawNum(APD_LCD_POINT *point,unsigned int num,APD_LCD_COLOR color)
{
	char msg[30];
	int i;
	for( i=0; i<30; i++ ) msg[i] = 0;
	sprintf( msg, "%d", num );
	apd_LCDDrawStr(point,msg,color);
}
/*******************************************************************
	Fill screen with assigned color
********************************************************************/
void apd_LCDFillScr(int color)
{	unsigned long           index;
	volatile unsigned int *video_ptr = VIDEO_RAM;
   	video_ptr = VIDEO_RAM;	//+x+y*0xa0-1;  
	for(index = 0; index < 38400; index++) //original, (SM)
   	{
  		*video_ptr++=color;
  	}
}
/*******************************************************************
	clear lcd screen
********************************************************************/
void apd_ClearLcd(void)
{
	unsigned long           index;
	volatile unsigned int *video_ptr = VIDEO_RAM;
   	video_ptr = VIDEO_RAM;	//+x+y*0xa0-1;  
	for(index = 0; index < 38400; index++) //original, (SM)
   	{
  		*video_ptr++=0x00;
  	}
}
/******************************************************************
	initial lcd
******************************************************************/
void apd_LCDInit(void)
{
  	LCDInit();
  	apd_LCDSetUpbase(VIDEO_PHY_RAM); // set video ram address
  	apd_LCDEnable();  
  	apd_ClearLcd();
  	apd_LCDOn();
	
}

/******************************************************************
	clear lcd H line
******************************************************************/
v

⌨️ 快捷键说明

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