📄 lcdinit.c
字号:
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "Lcdinit.h"
extern unsigned char __CHS[];
extern unsigned char __VGA[];
U16 (*frameBuffer16BitTft)[SCR_XSIZE_TFT];
#ifdef ATLOG
#include "iphone.c"
#endif
/*-----------------------------------------------------------------------------
* 初始化液晶
*/
void LcdInit(void)
{
frameBuffer16BitTft = (U16 (*)[SCR_XSIZE_TFT])LCDFRAMEBUFFER;
rLCDCON1 = (CLKVAL_TFT<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0; // TFT LCD panel,16bpp TFT,ENVID=off
rLCDCON2 = (VBPD<<24)|(LINEVAL_TFT<<14)|(VFPD<<6)|(VSPW);
rLCDCON3 = (HBPD<<19)|(HOZVAL_TFT<<8)|(HFPD);
rLCDCON4 = (MVAL<<8)|(HSPW);
rLCDCON5 = (1<<11)|(0<<9)|(0<<8)|(HWSWP<<0); //FRM5:6:5,HSYNC and VSYNC are inverted
rLCDSADDR1 = (((U32)frameBuffer16BitTft>>22)<<21)|M5D((U32)frameBuffer16BitTft>>1);
rLCDSADDR2 = M5D( ((U32)frameBuffer16BitTft+(SCR_XSIZE_TFT*LCD_YSIZE_TFT*2))>>1 );
rLCDSADDR3 = (((SCR_XSIZE_TFT-LCD_XSIZE_TFT)/1)<<11)|(LCD_XSIZE_TFT/1);
rLCDINTMSK |= (3); // MASK LCD Sub Interrupt
rTCONSEL &=~((1<<4)|1); // Disable LCC3600, LPC3600
rTPAL = 0; // Disable Temp Palette
rLCDCON1 |= 1; // ENVID=ON
}
/*-----------------------------------------------------------------------------
* 320 x 240 TFT LCD单个象素的显示数据输出
*/
static void PutPixel(U32 x,U32 y,U16 c)
{
if(x<SCR_XSIZE_TFT && y<SCR_YSIZE_TFT)
frameBuffer16BitTft[(y)][(x)] = c;
}
/*-----------------------------------------------------------------------------
* LCD画直线函数
*/
static void Glib_Line(int x1, int y1, int x2, int y2, U16 color)
{
int dx, dy, e;
dx = x2 - x1;
dy = y2 - y1;
if(dx >= 0)
{
if(dy >= 0) // dy>=0
{
if(dx >= dy) // 1/8 octant
{
e = dy-dx/2;
while(x1 <= x2)
{
PutPixel(x1, y1, color);
if(e > 0) {y1+=1; e-=dx;}
x1 += 1;
e += dy;
}
}
else // 2/8 octant
{
e = dx-dy/2;
while(y1 <= y2)
{
PutPixel(x1, y1, color);
if(e > 0) {x1+=1; e-=dy;}
y1 += 1;
e += dx;
}
}
}
else // dy<0
{
dy = -dy; // dy=abs(dy)
if(dx >= dy) // 8/8 octant
{
e = dy-dx/2;
while(x1 <= x2)
{
PutPixel(x1, y1, color);
if(e > 0) {y1-=1; e-=dx;}
x1 += 1;
e += dy;
}
}
else // 7/8 octant
{
e = dx-dy/2;
while(y1 >= y2)
{
PutPixel(x1, y1, color);
if(e > 0) {x1+=1; e-=dy;}
y1 -= 1;
e += dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 3/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
/**************************************************************
在LCD屏幕上画一个矩形
**************************************************************/
static void Glib_Rectangle(int x1,int y1,int x2,int y2,int color)
{
Glib_Line(x1,y1,x2,y1,color);
Glib_Line(x2,y1,x2,y2,color);
Glib_Line(x1,y2,x2,y2,color);
Glib_Line(x1,y1,x1,y2,color);
}
/*-----------------------------------------------------------------------------
* 在LCD屏幕上用颜色填充一个矩形
*/
static void Glib_FilledRectangle(int x1, int y1, int x2, int y2, U16 color)
{
int i;
for(i = y1; i <= y2; i++) { // 用n条直线填满区域!
Glib_Line(x1, i, x2, i, color);
}
}
/*-----------------------------------------------------------------------------
* 在LCD屏幕上指定坐标点画一个指定大小的图片
*/
static 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) ;
//c = bmp[p] ;
if ( ( (x0+x) < SCR_XSIZE_TFT) && ( (y0+y) < SCR_YSIZE_TFT) )
frameBuffer16BitTft[y0+y][x0+x] = c ;
p = p + 2 ;
}
}
}
/*-----------------------------------------------------------------------------
* 320 x 240 TFT LCD全屏填充特定颜色单元或清屏
*/
static void Lcd_ClearScr( U16 c)
{
unsigned int x, y;
for( y = 0 ; y < SCR_YSIZE_TFT ; y++ )
{
for( x = 0 ; x < SCR_XSIZE_TFT ; x++ )
{
frameBuffer16BitTft[y][x] = c ;
}
}
}
/**************************************************************
在LCD屏幕上指定坐标点写ASCII码
**************************************************************/
void Lcd_PutASCII(unsigned int x,unsigned int y,unsigned char ch,unsigned int c,unsigned int bk_c,unsigned int st)
{
unsigned short int i,j;
unsigned char *pZK,mask,buf;
pZK = &__VGA[ch*16];
for( i = 0 ; i < 16 ; i++ )
{
mask = 0x80;
buf = pZK[i];
for( j = 0 ; j < 8 ; j++ )
{
if( buf & mask )
{
PutPixel(x+j,y+i,c);
}else
{
if( !st )
{
PutPixel(x+j,y+i,bk_c);
}
}
mask = mask >> 1;
}
}
}
/**************************************************************
在LCD屏幕上指定坐标点写汉字
**************************************************************/
void Lcd_PutHZ(unsigned int x,unsigned int y,unsigned short int QW,unsigned int c,unsigned int bk_c,unsigned int st)
{
unsigned short int i,j;
unsigned char *pZK,mask,buf;
pZK = &__CHS[ ( ( (QW >> 8) - 1 )*94 + (QW & 0x00FF)- 1 )*32 ];
for( i = 0 ; i < 16 ; i++ )
{
//左
mask = 0x80;
buf = pZK[i*2];
for( j = 0 ; j < 8 ; j++ )
{
if( buf & mask )
{
PutPixel(x+j,y+i,c);
}else
{
if( !st )
{
PutPixel(x+j,y+i,bk_c);
}
}
mask = mask >> 1;
}
//右
mask = 0x80;
buf = pZK[i*2 + 1];
for( j = 0 ; j < 8 ; j++ )
{
if( buf & mask )
{
PutPixel(x+j + 8,y+i,c);
}else
{
if( !st )
{
PutPixel(x+j + 8,y+i,bk_c);
}
}
mask = mask >> 1;
}
}
}
//----------------------
void Lcd_printf(unsigned int x,unsigned int y,unsigned int c,unsigned int bk_c,unsigned int st,char *fmt,...)
{
char __LCD_Printf_Buf[256];
va_list ap;
unsigned char *pStr = (unsigned char *)__LCD_Printf_Buf;
unsigned int i = 0;
va_start(ap,fmt);
vsprintf(__LCD_Printf_Buf,fmt,ap);
va_end(ap);
while(*pStr != 0 )
{
switch(*pStr)
{
case '\n' :
{
break;
}
default:
{
if( *pStr > 0xA0 & *(pStr+1) > 0xA0 ) //中文输出
{
Lcd_PutHZ( x , y , (*pStr - 0xA0)*0x0100 + *(pStr+1) - 0xA0 , c , bk_c , st);
pStr++;
i++;
x += 16;
}else //英文输出
{
Lcd_PutASCII( x , y , *pStr , c , bk_c , st );
x += 8;
}
break;
}
}
pStr++;
i++;
if( i > 256 ) break;
}
}
/**************************************************************
320×240 16Bpp TFT LCD移动观察窗口
**************************************************************/
static void Lcd_MoveViewPort(int vx,int vy)
{
U32 addr;
SET_IF();
#if (LCD_XSIZE_TFT<32)
while((rLCDCON1>>18)<=1); // if x<32
#else
while((rLCDCON1>>18)==0); // if x>32
#endif
addr=(U32)frameBuffer16BitTft+(vx*2)+vy*(SCR_XSIZE_TFT*2);
rLCDSADDR1= ( (addr>>22)<<21 ) | M5D(addr>>1);
rLCDSADDR2= M5D(((addr+(SCR_XSIZE_TFT*LCD_YSIZE_TFT*2))>>1));
CLR_IF();
}
/**************************************************************
320×240 16Bpp TFT LCD移动观察窗口
**************************************************************/
static void MoveViewPort(void)
{
int vx=0,vy=0,vd=1;
Uart_Printf("\n*Move the LCD view windos:\n");
Uart_Printf(" press 8 is up\n");
Uart_Printf(" press 2 is down\n");
Uart_Printf(" press 4 is left\n");
Uart_Printf(" press 6 is right\n");
Uart_Printf(" press Enter to exit!\n");
while(1)
{
switch( Uart_GetKey() )
{
case '8':
if(vy>=vd)vy-=vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '4':
if(vx>=vd)vx-=vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '6':
if(vx<=(SCR_XSIZE_TFT-LCD_XSIZE_TFT-vd))vx+=vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '2':
if(vy<=(SCR_YSIZE_TFT-LCD_YSIZE_TFT-vd))vy+=vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '\r':
return;
default:
break;
}
//Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
//Lcd_MoveViewPort(vx,vy);
}
}
/*
void Lcd_Test( void )
{
// Lcd_Tft_LTS350Q1_PE1_Init();
Uart_Printf("\nTest LTV350QV-F05 (TFT LCD)!\n");
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) ) ; //clear screen
Uart_Printf( "\nLCD clear screen is finished! press any key to continue!\n" );
Uart_Getch() ; //wait uart input
Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f) ) ; //clear screen
Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
Uart_Getch() ; //wait uart input
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x1f) ) ; //clear screen
Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
Uart_Getch() ; //wait uart input
Lcd_ClearScr( (0x00<<11) | (0x3f<<5) | (0x00) ) ; //clear screen
Uart_Printf( "LCD clear screen is finished! press any key to continue!\n" );
Uart_Getch() ; //wait uart input
Lcd_ClearScr(0xffff); //fill all screen with some color
#define LCD_BLANK 12
#define C_UP ( LCD_XSIZE_TFT - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE_TFT - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE_TFT - LCD_BLANK*4 ) / 6 )
Glib_FilledRectangle( LCD_BLANK, LCD_BLANK, ( LCD_XSIZE_TFT - LCD_BLANK ), ( LCD_YSIZE_TFT - LCD_BLANK ),0x0000); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*0), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*1),0x001f); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*1), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*2),0x07e0); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*2), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*3),0xf800); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*3), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*4),0xffe0); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*4), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*5),0xf81f); //fill a Rectangle with some color
Glib_FilledRectangle( (LCD_BLANK*2), (LCD_BLANK*2 + V_BLACK*5), (C_RIGHT), (LCD_BLANK*2 + V_BLACK*6),0x07ff); //fill a Rectangle with some color
Glib_Line( LCD_BLANK,LCD_BLANK, (LCD_XSIZE_TFT-LCD_BLANK), (LCD_YSIZE_TFT-LCD_BLANK), 0x0000 ) ;
Glib_Line( LCD_BLANK,(LCD_YSIZE_TFT-LCD_BLANK), (LCD_XSIZE_TFT-LCD_BLANK), LCD_BLANK, 0x0000 ) ;
Glib_Line( (LCD_XSIZE_TFT/2),(LCD_BLANK*2 + V_BLACK*0), (LCD_XSIZE_TFT/2), (LCD_BLANK*2 + V_BLACK*6), 0x0000 ) ;
//Uart_Getch() ; //Any Key To Next
Paint_Bmp(0, 0, 240, 320, iphone_pic);
// Paint_Bmp(0, 0, 240, 320, BOOTLOG);
// Paint_Bmp(0, 0, 240, 320, FriendlyARM_pic_240x320);
Uart_Printf("bmp,Any Key To Next!\n");
Uart_Getch() ;
MoveViewPort();
}
*/
#ifdef ATLOG
void LcdDrawMap (void)
{
int x,y;
int i;
i = 0;
for(y=0; y<LCD_YSIZE_TFT; y++){
for(x=0; x<LCD_XSIZE_TFT; x++)
frameBuffer16BitTft[y][x] = BOOTLOG[i++];
}
}
#endif
void LcdDisplay(void)
{
U16 i,j=0;
LcdInit();
Lcd_ClearScr(0);
Lcd_ClearScr(255);
Glib_Line(10,20,123,220,COLOR_RED_TFT16);
for(;j<(LCD_YSIZE_TFT-10);j++)
PutPixel(120,j,0);
for(i=0;i<(LCD_XSIZE_TFT-10);i++)
PutPixel(i,160,0);
//Lcd_Test();
/*
#ifdef ATLOG
LcdDrawMap();
#endif
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -