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

📄 lcd.c

📁 S3CEV40教学平台的COLOR LCD实验程序
💻 C
字号:
/*********************************************************************************************
* File:	lcd.c
* Author:	embest	
* Desc:	LCD control and display functions
* History:	
*********************************************************************************************/

/*--- include files ---*/
#include "lcd.h"
#include "bmp.h"
#include "44b.h"

/*--- global variables ---*/
INT32U aLcdActiveBuffer[LCD_YSIZE][LCD_XSIZE/4];

/*--- extern variables ---*/
extern const INT8U aucTempBitmap[][76800];

/*--- function code ---*/
/*********************************************************************************************
* name:		Lcd_Init()
* func:		Initialize LCD Controller
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_Init (void)
{     
	rDITHMODE=0x12210;
	rDP1_2 =0xa5a5;      
	rDP4_7 =0xba5da65;
	rDP3_5 =0xa5a5f;
	rDP2_3 =0xd6b;
	rDP5_7 =0xeb7b5ed;
	rDP3_4 =0x7dbe;
	rDP4_5 =0x7ebdf;
	rDP6_7 =0x7fdfbfe;

	// disable,8B_SNGL_SCAN,WDLY=16clk,WLH=16clk,
	rLCDCON1=(0x0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	// LINEBLANK=10 (without any calculation) 
	rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);  
	rLCDCON3=0;
	// 256-color, LCDBANK, LCDBASEU
	rLCDSADDR1= (0x3<<27) | ( ((unsigned int)aLcdActiveBuffer>>22)<<21 ) | M5D((unsigned int)aLcdActiveBuffer>>1);
	rLCDSADDR2= M5D((((unsigned int)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE))>>1)) | (MVAL<<21);
	rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );

	//The following value has to be changed for better display.
	rREDLUT  =0xfdb96420; // 1111 1101 1011 1001 0110 0100 0010 0000
	rGREENLUT=0xfdb96420; // 1111 1101 1011 1001 0110 0100 0010 0000
	rBLUELUT =0xfb40;     // 1111 1011 0100 0000

	rLCDCON1=(0x1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
//	rPDATE=rPDATE&0x0e;
	rPDATE=0xfe;
	Lcd_Clr();
}

/*********************************************************************************************
* name:		Lcd_Clr()
* func:		clear LCD screen
* para:		none 
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_Clr(void)
{
	INT32U i;
	INT32U *pDisp = (INT32U*)aLcdActiveBuffer;
	
	for (i = 0; i < (SCR_XSIZE * SCR_YSIZE  / 4); i++)
	{
		*pDisp++ = ALLWHITE;
	}
}

/*********************************************************************************************
* name:		LcdClrRect()
* func:		fill appointed area with appointed color
* para:		usLeft,usTop,usRight,usBottom -- area's rectangle acme coordinate
*			ucColor -- appointed color value
* ret:		none
* modify:
* comment:	also as clear screen function 
*********************************************************************************************/
void LcdClrRect(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
{
	INT32U i, j;
	INT8U *pDisp = (INT8U*)aLcdActiveBuffer;
	
	for(i=usTop;i<=usBottom;i++)
	{
		for(j=usLeft;j<=usRight;j++)
		{
			LCD_PutPixel(j, i, ucColor);
		}
	}	

}

#ifdef MON_LCD
/*********************************************************************************************
* name:		LcdClrRect()
* func:		fill appointed area with appointed color
* para:		usLeft,usTop,usRight,usBottom -- area's rectangle acme coordinate
*			ucColor -- appointed color value
* ret:		none
* modify:
* comment:	also as clear screen function 
*********************************************************************************************/
void LcdClrRect(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
{
	INT16 i=0;
	INT16 k,l;
	INT16 m;
	
	INT32U ulColor = (ucColor << 28) | (ucColor << 24) | (ucColor << 20) | (ucColor << 16) | 
					(ucColor << 12) | (ucColor << 8) | (ucColor << 4) | ucColor;
	
	if((usRight-usLeft)<=8)
	{
		for(i=usTop;i<=usBottom;i++)
		{
			for(m=usLeft;m<=usRight;m++)
			{
				LCD_PutPixel(m, i, ucColor);
			}
		}	
		return;
	}

	if((usLeft%8)==0)
		k=usLeft;
	else
	{
		k=(usLeft/8)*8+8;
	}
	if(( usRight%8)==0)
		l= usRight;
	else
	{
		l=( usRight/8)*8;
	}

	for(i=usTop;i<=usBottom;i++)
	{
		for(m=usLeft;m<=(k-1);m++)
		{
			LCD_PutPixel(m, i, ucColor);
		}
		for(m=k;m<l;m+=8)
		{
			(*(INT32U*)(aLcdActiveBuffer + i * SCR_XSIZE / 2 + m / 2)) = ulColor;
		}
		for(m=l;m<=usRight;m++)
		{
			LCD_PutPixel(m, i, ucColor);
		}
	}
}
#endif

/*********************************************************************************************
* name:		Lcd_Draw_Box()
* func:		Draw rectangle with appointed color
* para:		usLeft,usTop,usRight,usBottom -- rectangle's acme coordinate
*			ucColor -- appointed color value
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_Draw_Box(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
{
	Lcd_Draw_HLine(usLeft, usRight,  usTop,    ucColor, 1);
	Lcd_Draw_HLine(usLeft, usRight,  usBottom, ucColor, 1);
	Lcd_Draw_VLine(usTop,  usBottom, usLeft,   ucColor, 1);
	Lcd_Draw_VLine(usTop,  usBottom, usRight,  ucColor, 1);
}

/*********************************************************************************************
* name:		Lcd_Draw_Line()
* func:		Draw line with appointed color
* para:		usX0,usY0 -- line's start point coordinate
*			usX1,usY1 -- line's end point coordinate
*			ucColor -- appointed color value
*			usWidth -- line's width
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_Draw_Line(INT16 usX0, INT16 usY0, INT16 usX1, INT16 usY1, INT8U ucColor, INT16U usWidth)
{
	INT16 usDx;
	INT16 usDy;
	INT16 y_sign;
	INT16 x_sign;
	INT16 decision;
	INT16 wCurx, wCury, wNextx, wNexty, wpy, wpx;

	if( usY0 == usY1 )
	{
		Lcd_Draw_HLine (usX0, usX1, usY0, ucColor, usWidth);
		return;
	}
	if( usX0 == usX1 )
	{
		Lcd_Draw_VLine (usY0, usY1, usX0, ucColor, usWidth);
		return;
	}
	usDx = abs(usX0 - usX1);
	usDy = abs(usY0 - usY1);
	if( ((usDx >= usDy && (usX0 > usX1)) ||
        ((usDy > usDx) && (usY0 > usY1))) )
    {
        GUISWAP(usX1, usX0);
        GUISWAP(usY1, usY0);
    }
    y_sign = (usY1 - usY0) / usDy;
    x_sign = (usX1 - usX0) / usDx;

    if( usDx >= usDy )
    {
        for( wCurx = usX0, wCury = usY0, wNextx = usX1,
             wNexty = usY1, decision = (usDx >> 1);
             wCurx <= wNextx; wCurx++, wNextx--, decision += usDy )
        {
            if( decision >= usDx )
            {
                decision -= usDx;
                wCury += y_sign;
                wNexty -= y_sign;
            }
            for( wpy = wCury - usWidth / 2;
                 wpy <= wCury + usWidth / 2; wpy++ )
            {
                LCD_PutPixel(wCurx, wpy, ucColor);
            }

            for( wpy = wNexty - usWidth / 2;
                 wpy <= wNexty + usWidth / 2; wpy++ )
            {
                LCD_PutPixel(wNextx, wpy, ucColor);
            }
        }
    }
    else
    {
        for( wCurx = usX0, wCury = usY0, wNextx = usX1,
             wNexty = usY1, decision = (usDy >> 1);
             wCury <= wNexty; wCury++, wNexty--, decision += usDx )
        {
            if( decision >= usDy )
            {
                decision -= usDy;
                wCurx += x_sign;
                wNextx -= x_sign;
            }
            for( wpx = wCurx - usWidth / 2;
                 wpx <= wCurx + usWidth / 2; wpx++ )
            {
                LCD_PutPixel(wpx, wCury, ucColor);
            }

            for( wpx = wNextx - usWidth / 2;
                 wpx <= wNextx + usWidth / 2; wpx++ )
            {
                LCD_PutPixel(wpx, wNexty, ucColor);
            }
        }
    }
}

/*********************************************************************************************
* name:		Lcd_Draw_HLine()
* func:		Draw horizontal line with appointed color
* para:		usX0,usY0 -- line's start point coordinate
*			usX1 -- line's end point X-coordinate
*			ucColor -- appointed color value
*			usWidth -- line's width
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_Draw_HLine(INT16 usX0, INT16 usX1, INT16 usY0, INT8U ucColor, INT16U usWidth)
{
	INT16 usLen;

    if( usX1 < usX0 )
    {
        GUISWAP (usX1, usX0);
    }

    while( (usWidth--) > 0 )
    {
        usLen = usX1 - usX0 + 1;
        while( (usLen--) > 0 )
        {
        	LCD_PutPixel(usX0 + usLen, usY0, ucColor);
        }
        usY0++;
    }
}

/*********************************************************************************************
* name:		Lcd_Draw_VLine()
* func:		Draw vertical line with appointed color
* para:		usX0,usY0 -- line's start point coordinate
*			usY1 -- line's end point Y-coordinate
*			ucColor -- appointed color value
*			usWidth -- line's width
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_Draw_VLine (INT16 usY0, INT16 usY1, INT16 usX0, INT8U ucColor, INT16U usWidth)
{
	INT16 usLen;

    if( usY1 < usY0 )
    {
        GUISWAP (usY1, usY0);
    }

    while( (usWidth--) > 0 )
    {
        usLen = usY1 - usY0 + 1;
        while( (usLen--) > 0 )
        {
        	LCD_PutPixel(usX0, usY0 + usLen, ucColor);
        }
        usX0++;
    }
}

/*--- extern variables ---*/
extern INT8U g_auc_Ascii8x16[];
/*********************************************************************************************
* name:		Lcd_DspAscII8x16()
* func:		display 8x16 ASCII character string 
* para:		usX0,usY0 -- ASCII character string's start point coordinate
*			ForeColor -- appointed color value
*			pucChar   -- ASCII character string
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_DspAscII8x16(INT16U x0, INT16U y0, INT8U ForeColor, INT8U * s)
{
	INT16 i,j,k,x,y,xx;
	INT8U qm;
	INT32U ulOffset;
	INT8 ywbuf[16],temp[2];
    
	for( i = 0; i < strlen((const char*)s); i++ )
	{
		if( (INT8U)*(s+i) >= 161 )
		{
			temp[0] = *(s + i);
			temp[1] = '\0';
			return;
		}
		else
		{
			qm = *(s+i);
			ulOffset = (INT32U)(qm) * 16;		//Here to be changed tomorrow
			for( j = 0; j < 16; j ++ )
			{
				ywbuf[j] = g_auc_Ascii8x16[ulOffset + j];
            }

            for( y = 0; y < 16; y++ )
            {
            	for( x = 0; x < 8; x++ ) 
               	{
                	k = x % 8;
			    	if( ywbuf[y]  & (0x80 >> k) )
			       	{
			       		xx = x0 + x + i*8;
			       		LCD_PutPixel(xx, y + y0, (INT8U)ForeColor);
			       	}
			   	}
            }
		}
	}
}

/*--- extern variables ---*/
extern INT8U g_auc_Ascii6x8[];
#define XWIDTH 				6
/*********************************************************************************************
* name:		Lcd_DspAscII6x8()
* func:		display 6x8 ASCII character string 
* para:		usX0,usY0 -- ASCII character string's start point coordinate
*			ForeColor -- appointed color value
*			pucChar   -- ASCII character string
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_DspAscII6x8(INT16U usX0, INT16U usY0,INT8U ForeColor, INT8U* pucChar)
{
	INT32U i,j;
	INT8U  ucTemp;

	while( *pucChar != 0 )
	{
		for( i=0; i < 8; i++ )
		{
  			ucTemp = g_auc_Ascii6x8[(*pucChar) * 8 + i];
  			for( j = 0; j < 8; j++ )
  			{
  				if( (ucTemp & (0x80 >> j)) != 0 )
  				{
  					LCD_PutPixel(usX0 + i, usY0 + 8 - j, (INT8U)ForeColor);
  				}  				
  			}
		}
		usX0 += XWIDTH;
		pucChar++;
	}
}

#ifndef Eng_v
/*********************************************************************************************
* name:		Lcd_DspHz16()
* func:		display chinese character string in 16x16 dot array
* para:		usX0,usY0 -- ASCII character string's start point coordinate
*			ForeColor -- appointed color value
*			pucChar   -- ASCII character string
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
extern const INT8U g_auc_HZK16[];
void Lcd_DspHz16(INT16U x0, INT16U y0, INT8U ForeColor, INT8U *s)
{
	INT16 i,j,k,x,y,xx;
	INT8U qm,wm;
	INT32U ulOffset;
	INT8 hzbuf[32],temp[2];

	for( i = 0; i < strlen((const char*)s); i++ )
	{
		if( ((INT8U)(*(s+i))) < 161 )
		{
			temp[0] = *(s+i);
			temp[1] = '\0';
			break;
		}
		else
		{
			qm = *(s+i) - 161;
    		wm = *(s + i + 1) - 161;
       		ulOffset = (INT32U)(qm * 94 + wm) * 32;
			for( j = 0; j < 32; j ++ )
            {
            	hzbuf[j] = g_auc_HZK16[ulOffset + j];
            }
            for( y = 0; y < 16; y++ )
            {
	        	for( x = 0; x < 16; x++ ) 
	            {
                	k = x % 8;
				   	if( hzbuf[y * 2 + x / 8]  & (0x80 >> k) )
				    {
				    	xx = x0 + x + i * 8;
				    	LCD_PutPixel( xx, y + y0, (INT8U)ForeColor);
				    }
			   	}
           	}
		    i++;
		}
	}
}
#endif

/*********************************************************************************************
* name:		Lcd_Test()
* func:		LCD test function
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Lcd_Test(void)
{
	int i, j;
	
	int hh=12,mm=12,ss=12;
    char time[30];
    sprintf(time,"%d:%d:%d",hh,mm,ss);
    Lcd_DspAscII8x16(90,120,BLUE,time);
    
    Uart_Printf("\n LCD display Test Example(please look at LCD screen)\n");
	/* initial LCD controller */
	Lcd_Init();
	/* clear screen */
	Lcd_Clr();
	Lcd_DspAscII8x16(10,0,BLUE,"Embest S3CEV40 ");
	Lcd_DspAscII8x16(10,20,BLUE,"ShenZhen Embest Info&Tech Co.,LTD");
	Lcd_Draw_Box(10,40,310,230,14);
	Lcd_Draw_Box(20,45,300,225,13);
	Lcd_Draw_Box(30,50,290,220,12);
	Lcd_Draw_Box(40,55,280,215,11);
	Lcd_Draw_Box(50,60,270,210,10);
	Lcd_Draw_Box(60,65,260,205,9);
	Lcd_Draw_Box(70,70,250,200,8);
	Lcd_Draw_Box(80,75,240,195,7);
	Lcd_Draw_Box(90,80,230,190,6);
	Lcd_Draw_Box(100,85,220,185,5);
	Lcd_Draw_Box(110,90,210,180,4);
	Lcd_Draw_Box(120,95,200,175,3);
	Lcd_Draw_Box(130,100,190,170,2);
	Lcd_DspHz16(10,10,BLUE,"英蓓特三星实验平台");
}

⌨️ 快捷键说明

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