📄 color_lcd_test.c
字号:
/*********************************************************************************************
* File: lcdapp.c
* Author: Embest
* Desc: LCD control and display functions
* History:
* Y.J.Guo, Programming modify, April 12, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include <string.h>
#include "2410lib.h"
#include "lcdlib.h"
#include "glib.h"
#include "lcd.h"
/*------------------------------------------------------------------------------------------*/
/* constant define */
/*------------------------------------------------------------------------------------------*/
#define LCD_BUF_SIZE (SCR_XSIZE_TFT_640480*SCR_YSIZE_TFT_640480/2)
#define LCD_ACTIVE_BUFFER (0x33800000)
#define LCD_VIRTUAL_BUFFER (0x33800000 + LCD_BUF_SIZE)
#define LCD_D_OFF rGPCDAT &= ~(1 << 4);
#define LCD_D_ON rGPCDAT |= (1 << 4);
/*------------------------------------------------------------------------------------------*/
/* extern variables */
/*------------------------------------------------------------------------------------------*/
#ifdef BOARDTEST_EXH
#undef BOARDTEST
#endif
#ifndef BOARDTEST
extern const UINT8T g_ucBitmap[][76800];
extern UINT8T g_ucAscii8x16[];
//extern UINT8T g_auc_Ascii6x8[];
extern UINT8T g_auc_hzk24[];
#endif
/*------------------------------------------------------------------------------------------*/
/* function declare */
/*------------------------------------------------------------------------------------------*/
void Lcd_DspAscII6x8(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T * s);
void Lcd_DspAscII8X16(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T * s);
//void Lcd_DspHz12(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T *s);
//void Lcd_DspHz16(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T *s);
void Lcd_DspHz24(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T *s);
//void Lcd_DspHz24s(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T *s);
void Lcd_Draw_HLine(INT16T usX0, INT16T usX1, INT16T usY0, UINT8T ucColor, UINT16T usWidth);
void Lcd_Draw_VLine (INT16T usY0, INT16T usY1, INT16T usX0, UINT8T ucColor, UINT16T usWidth);
void lcd_clr(void);
/*********************************************************************************************
* name: lcd_init_app
* func: lcd application initialization code
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_init_app()
{
Lcd_port_init();
Lcd_Init(MODE_CSTN_8BIT);
Glib_Init(MODE_CSTN_8BIT);
Glib_ClearScr(GREEN-20, MODE_CSTN_8BIT);
Lcd_PowerEnable(0, 1);
Lcd_EnvidOnOff(1);
uart_printf(" [STN 256 COLOR(8bit/1pixel) LCD TEST]\n");
}
/*********************************************************************************************
* name: lcd_init_app_end
* func: end lcd application initialization
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_init_app_end()
{
Lcd_EnvidOnOff(0);
Lcd_Port_Return();
}
#ifndef BOARDTEST
/*********************************************************************************************
* name: Lcd_DspHz24
* func: display 24x24 Chinese Symbol on Lcd
* para: UINT16T x0 -- x coordinate of start point
* UINT16T y0 -- y coordinate of start point
* UINT8T Forecolor -- foreground color of lcd
* UINT8T *s -- string to display
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Lcd_DspHz24(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T *s)
{
INT16T i,j,k,x,y,xx;
UINT8T qm,wm;
INT32T ulOffset;
INT8T hzbuf[72],temp[2];
for(i = 0; i < strlen((const char*)s); i++)
{
if(((UINT8T)(*(s+i))) < 161)
{
temp[0] = *(s+i);
temp[1] = '\0';
break;
}
else
{
qm = *(s+i) - 176; //161;
wm = *(s+i + 1) - 161;
ulOffset = (INT32T)(qm * 94 + wm) * 72;
for (j = 0; j < 72; j ++)
{
hzbuf[j] = g_auc_hzk24[ulOffset + j];
}
for(y = 0; y < 24; y++)
{
for(x = 0; x < 24; x++)
{
k = x % 8;
if (hzbuf[y * 3 + x / 8] & (0x80 >> k))
{
xx = x0 + x + i*12;
PutPixel( xx, y + y0, (UINT8T)ForeColor);
}
}
}
i++;
}
}
}
#endif
/*********************************************************************************************
* 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:
*********************************************************************************************/
#define XWIDTH 6
extern UINT8T g_ucAscii6x8[];
void Lcd_DspAscII6x8(UINT16T usX0, UINT16T usY0,UINT8T ForeColor, UINT8T* pucChar)
{
UINT32T i,j;
UINT8T ucTemp;
while( *pucChar != 0 )
{
for( i=0; i < 8; i++ )
{
ucTemp = g_ucAscii6x8[(*pucChar) * 8 + i];
for( j = 0; j < 8; j++ )
{
if( (ucTemp & (0x80 >> j)) != 0 )
{
PutPixel(usX0 + i, usY0 + 8 - j, (UINT8T)ForeColor);
}
}
}
usX0 += XWIDTH;
pucChar++;
}
}
#ifndef BOARDTEST
/*********************************************************************************************
* name: Lcd_DspAscII8X16
* func: display 8x16 AscII Symbol on Lcd
* para: UINT16T x0 -- x coordinate of start point
* UINT16T y0 -- y coordinate of start point
* UINT8T Forecolor -- foreground color of lcd
* UINT8T *s -- string to display
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Lcd_DspAscII8X16(UINT16T x0, UINT16T y0, UINT8T ForeColor, UINT8T * s)
{
INT16T i,j,k,x,y,xx;
UINT8T qm;
INT32T ulOffset;
INT8T ywbuf[16],temp[2];
for(i = 0; i < strlen((const char*)s); i++)
{
if((UINT8T)*(s+i) >= 161)
{
temp[0] = *(s + i);
temp[1] = '\0';
return;
}
else
{
qm = *(s+i);
ulOffset = (INT32T)(qm) * 16;
for (j = 0; j < 16; j ++)
{
ywbuf[j] = g_ucAscii8x16[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;
PutPixel( xx, y + y0, (UINT8T)ForeColor);
}
}
}
}
}
}
#endif
/*********************************************************************************************
* name: lcd_clr
* func: clear LCD screen
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_clr(void)
{
UINT32T i;
UINT32T *pDisp = (UINT32T*)LCD_ACTIVE_BUFFER;
for (i = 0; i < (SCR_XSIZE_CSTN * SCR_YSIZE_CSTN /4); i++)
{
*pDisp = ALLWHITE;
}
}
/*********************************************************************************************
* name: lcd_clr_rect
* 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 lcd_clr_rect(INT16T usLeft, INT16T usTop, INT16T usRight, INT16T usBottom, UINT8T ucColor)
{
UINT32T i, j;
UINT8T *pDisp = (UINT8T*)LCD_ACTIVE_BUFFER;
for (i = usLeft; i < usRight; i++)
for (j = usTop; j < usBottom; j++)
{
PutPixel(i,j,ucColor);
//*(pDisp+i+j) = ucColor;
}
}
/*********************************************************************************************
* 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(INT16T usLeft, INT16T usTop, INT16T usRight, INT16T usBottom, UINT8T 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(INT16T usX0, INT16T usY0, INT16T usX1, INT16T usY1, UINT8T ucColor, UINT16T usWidth)
{
INT16T usDx;
INT16T usDy;
INT16T y_sign;
INT16T x_sign;
INT16T decision;
INT16T 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++ )
{
PutPixel(wCurx, wpy, ucColor);
}
for( wpy = wNexty - usWidth / 2;
wpy <= wNexty + usWidth / 2; wpy++ )
{
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++ )
{
PutPixel(wpx, wCury, ucColor);
}
for( wpx = wNextx - usWidth / 2;
wpx <= wNextx + usWidth / 2; wpx++ )
{
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(INT16T usX0, INT16T usX1, INT16T usY0, UINT8T ucColor, UINT16T usWidth)
{
INT16T usLen;
if( usX1 < usX0 )
{
GUISWAP (usX1, usX0);
}
while( (usWidth--) > 0 )
{
usLen = usX1 - usX0 + 1;
while( (usLen--) > 0 )
{
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 (INT16T usY0, INT16T usY1, INT16T usX0, UINT8T ucColor, UINT16T usWidth)
{
INT16T usLen;
if( usY1 < usY0 )
{
GUISWAP (usY1, usY0);
}
while( (usWidth--) > 0 )
{
usLen = usY1 - usY0 + 1;
while( (usLen--) > 0 )
{
PutPixel(usX0, usY0 + usLen, ucColor);
}
usX0++;
}
}
/*********************************************************************************************
* name: color_lcd_test()
* func: LCD test function
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void color_lcd_test(void)
{
int i;
uart_printf("\n LCD display Test Example (please look at LCD screen)\n");
lcd_init_app();
#ifndef BOARDTEST
Lcd_DspHz24(50,10,BLUE,"英蓓特三星实验平台");
#endif
Lcd_DspAscII6x8(90,120,BLUE," Embest EduKit-III");
Lcd_DspAscII6x8(50,140,GREEN,"ShenZhen Embest Info&Tech Co.,LTD");
Glib_Rectangle(10,40,310,230,RED);
Glib_Rectangle(15,45,305,225,GREEN);
Glib_Rectangle(20,50,300,220,BLUE);
Glib_Rectangle(25,55,295,215,GREEN);
LCD_D_ON;
delay(8000);
#ifndef BOARDTEST
while(1)
{
for (i=0; i < 5; i++)
{
BitmapView((UINT8T*)(g_ucBitmap[i]));
delay(8000);
}
}
#endif
uart_printf(" end.\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -