📄 lcd_320x240.c
字号:
tmp = x2 - x1;
for ( i=0;i<=tmp;++i ) {
PutPixel(x1+i,y,color);
}
return;
}
void draw_rectangle(int start_x,int start_y,int end_x,int end_y,U16 color)
{
draw_vline(start_x, start_y, end_y, color);
draw_vline(end_x, start_y, end_y, color);
draw_hline(start_x, end_x, start_y, color);
draw_hline(start_x, end_x, end_y, color);
return;
}
/*
* (start_x,start_y) : coordinate of the top-left-corner of the rectangle
* (end_x,end_y) : coordinate of the bottom-right-corner of the rectangle
* this rectangle is filled with pixels which color is the same as the frame
*/
void draw_full_rectangle(int start_x, int start_y, int end_x, int end_y, U16 color)
{
int i = 0;
int tmp = 0;
tmp = end_x - start_x;
for ( i=0;i<tmp;++i ) {
draw_vline(start_x+i, start_y,end_y, color);
}
return;
}
/*
* display an ascii character
* x,y : coordinates of the start pixel
* codes : the the bytes serial to be displayed
* the size of the ascii characters is 8*16
* color : the color of the character
*/
static void write_en(int x, int y, unsigned char* codes, U16 color)
{
int i = 0;
/* total 16 bytes codes*/
for ( i=0;i<16;++i ) {
int j = 0;
x += 8;
for ( j=0;j<8;++j ) {
--x;
if ( (codes[i]>>j) & 0x1 ) {
PutPixel(x, y, color);
}
}
/* move to the next line : x axis unchanged, y axis increase 1 */
++y;
}
return;
}
/*
* display a Chinese character
* x,y : coordinates of the start pixel
* codes : the bytes serial to be displayed
* the size of the Chinese characters is 16*16
* color : the color of the character
*/
static void write_cn(int x, int y, unsigned char* codes, U16 color)
{
int i;
/* total 2*16 bytes codes */
for(i=0;i<16;i++) {
int j = 0;
for (j=0;j<2;++j) {
int k = 0;
x += 8*(j+1);
for ( k=0;k<8;++k ){
--x;
if ( ( codes[2*i+j] >> k) & 0x1 ) {
PutPixel(x,y,color);
}
}
}
/* move to the next line : x axis unchanged, y axis increase 1 */
x -= 8;
++y;
}
return;
}
void display_char(signed int x, unsigned int y, char str,U16 color)
{
unsigned char* ptr;
unsigned int ch;
ch=str;
if(x>=240){x=0;y+=16;}
ptr = ASCII_FONT_BITMAP + 16*ch;
/* 显示字符 */
write_en(x, y+4,ptr,color);
}
void display_cn(signed int x, unsigned int y, char* str,U16 color)
{
unsigned char* ptr;
unsigned int ch;
unsigned int cl;
unsigned int offset;
ch = (unsigned int)str[0];
cl = (unsigned int)str[1];
if ( (ch>=0xa1)&&(ch<0xf8) && (cl>=0xa1)&&(cl<0xff) ) {
/* 到了行末就换行 */
if(x>=240){x=0;y+=16;}
/* 计算汉字在字库里的偏移量 */
offset = ( (ch-0xa1)*94+(cl-0xa1) )*32;
/* 计算汉字所在的地址 */
ptr = GB2312_16X16_FONT_BITMAP + offset;
/* 显示汉字 */
write_cn(x, y,ptr,color);
}
}
void display_string(unsigned int x, unsigned int y, char* str,int count,U16 color)
{
unsigned char* ptr;
unsigned int ch;
unsigned int cl;
unsigned int offset;
unsigned int pos=0;
while (*str&&pos<count){
// printf("%x:%x::",ch,cl);
ch = (unsigned int)str[0];
cl = (unsigned int)str[1];
if ( (ch>=0xa1)&&(ch<0xf8) && (cl>=0xa1)&&(cl<0xff) ) {
/* 到了行末就换行 */
if(x>=240){x=0;y+=16;}
/* 计算汉字在字库里的偏移量 */
offset = ( (ch-0xa1)*94+(cl-0xa1) )*32;
/* 计算汉字所在的地址 */
ptr = GB2312_16X16_FONT_BITMAP + offset;
/* 显示汉字 */
write_cn(x, y,ptr,color);
/* 下一个汉字 */
x += 16;
str += 2; /* 一个汉字占2字节 */
pos+=2;
}else{ /* ASCII字符 */
if(x>=240){x=0;y+=16;}
/* 计算字符所在的地址 */
ptr = ASCII_FONT_BITMAP + 16*ch;
/* 显示字符 */
write_en(x, y+4,ptr,color);
/* 计算字符所在的地址 */
//ptr = ASCII_FONT_BITMAP + 16*cl;
/* 显示字符 */
//write_en(x+8, y+4,ptr,color);
pos+=1;
/* 换行 */
x += 8;str += 1; /* an ascii character holds 1 byte */
}
}
return;
}
/* (x,y) -- coordinate of the center of the circle */
void draw_circle(int x, int y, int r, U16 color)
{
int x1 = 0;
int y1 = r;
int p = 3 - 2 * r;
while(x1 <= y1 ) {
PutPixel(x + x1, y + y1, color);
PutPixel(x - x1, y + y1, color);
PutPixel(x + x1, y - y1, color);
PutPixel(x - x1, y - y1, color);
PutPixel(x + y1, y + x1, color);
PutPixel(x - y1, y + x1, color);
PutPixel(x + y1, y - x1, color);
PutPixel(x - y1, y - x1, color);
if(p < 0)
p+= 4 * x1++ +6;
else
p+= 4 * (x1++ - y1--) + 10;
}
return;
}
/*-----------------------------------------------------------------------------
* 在LCD屏幕上指定坐标点画一个指定大小的图片
*/
void Paint_Bmp(int x0, int y0, int h, int l, unsigned char bmp[])
{
int x, y;
U32 c;
int p = 0;
for( y = 0 ; y < l ; y++ )
{
for( x = 0 ; x < h ; x++ )
{
c = bmp[p+1] | (bmp[p]<<8) ;
if ( ( (x0+x) < SCR_XSIZE_TFT_320240) && ( (y0+y) < SCR_YSIZE_TFT_320240) )
LCD_BUFER[y0+y][x0+x] = c ;
p = p + 2 ;
}
}
}
/*
* while write datas to LCD frame buffer, LCD will display them.
* a pixel of the LCD is mapped to a bits block in the frame buffer
* a pixel holds 12 bits in the frame buffer ( color LCD ):
* R - 5 bits ( 16-12 )
* G - 6 bits ( 11-6 )
* B - 6 bits ( 5-0 )
*/
/*-----------------------------------------------------------------------------
* test LTV350QV-F05
*/
void Test_Lcd_LTV350QVF05(void)
{
int i;
Lcd_Port_Init();
Lcd_Init();
Lcd_EnvidOnOff(1);
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) ); //clear screen
// Lcd_ClearScr(0xffff); //fill all screen with some color
// Glib_FilledRectangle( 50, 50, 270, 190, 0x0000); //fill a Rectangle with some color
// Glib_FilledRectangle( 100, 100, 220, 140, 0xf800); //fill a Rectangle with some color
#ifdef DEBUG
Uart_Printf( "\nrGPBCON=0x%x\n", rGPBCON );
Uart_Printf( "\trGPBUP=0x%x\n", rGPBUP );
Uart_Printf( "rGPCCON=0x%x\n", rGPCCON );
Uart_Printf( "\trGPCUP=0x%x\n", rGPCUP );
Uart_Printf( "rGPDCON=0x%x\n", rGPDCON );
Uart_Printf( "\trGPDUP=0x%x\n", rGPDUP );
Uart_Printf( "rGPGCON=0x%x\n", rGPGCON );
Uart_Printf( "\trGPGUP=0x%x\n\n", rGPGUP );
Uart_Printf( "rLCDCON1=0x%x\n", rLCDCON1 );
Uart_Printf( "rLCDCON2=0x%x\n", rLCDCON2 );
Uart_Printf( "rLCDCON3=0x%x\n", rLCDCON3 );
Uart_Printf( "rLCDCON4=0x%x\n", rLCDCON4 );
Uart_Printf( "rLCDCON5=0x%x\n\n", rLCDCON5 );
Uart_Printf( "rLCDSADDR1=0x%x\n", rLCDSADDR1 );
Uart_Printf( "rLCDSADDR2=0x%x\n", rLCDSADDR2 );
Uart_Printf( "rLCDSADDR3=0x%x\n\n", rLCDSADDR3 );
Uart_Printf( "rLCDINTMSK=0x%x\n", rLCDINTMSK );
Uart_Printf( "rLPCSEL=0x%x\n", rLPCSEL );
Uart_Printf( "rTPAL=0x%x\n\n", rTPAL );
#endif
//LOGO
/*Glib_FilledRectangle(0, 0, 320, 35, 0x0);
Delay(50);
Glib_FilledRectangle( 5, 35, 315, 40, 0xf800); //Red,top
Glib_FilledRectangle(10, 40, 310, 45, 0x07e0); //Green,top
Glib_FilledRectangle(15, 45, 305, 50, 0x001f); //Blue,top
Delay(50);
Glib_FilledRectangle( 5, 37, 9, 200, 0xf800); //Red,left
Glib_FilledRectangle(10, 45, 15, 195, 0x07e0); //Green,left
Glib_FilledRectangle(16, 50, 20, 190, 0x001f); //Blue,left
Delay(50);
Glib_FilledRectangle(311, 40, 315, 200, 0xf800); //Red,right
Glib_FilledRectangle(305, 45, 310, 195, 0x07e0); //Green,right
Glib_FilledRectangle(300, 50, 304, 190, 0x001f); //Blue,right
*/
Delay(50);
//Paint_Bmp(20, 50, 280, 190, uCdragon_logo); //picture
Delay(50);
draw_full_rectangle(20,50,240,100,0xf800);
//write_en(0,120,test_char,0xf800);
display_string(20,120,"我是HEATON!的",strlen("我是HEATON!的"),0xf800);
display_string(20,136,"我是HEATON!的",strlen("我是HEATON!的"),0xf800);
//display_string(20,120,"Hello",strlen("Hello"),0xf800);
/*Glib_FilledRectangle( 5, 200, 315, 206, 0xf800); //Red,button
Glib_FilledRectangle( 10,195, 310, 200, 0x07e0); //Green,button
Glib_FilledRectangle( 16,190, 304, 195, 0x001f); //Blue,button
//Glib_FilledRectangle(0, 206, 320, 240, 0x0);*/
Lcd_MoveViewPort(0,0);
}
/* the lcd_240x320.c end */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -