?? lcd_240x320.c
字號:
/**************************************************************
The initial and control for 320×240 16Bpp TFT LCD----3.5寸豎屏
**************************************************************/
#include <string.h>
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"
#define MVAL (13)
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
#define INVVDEN (1) //0=normal 1=inverted
#define BSWP (0) //Byte swap control
#define HWSWP (1) //Half word swap control
#define M5D(n) ((n) & 0x1fffff) // To get lower 21bits
//TFT 240320
#define LCD_XSIZE_TFT_240320 (240)
#define LCD_YSIZE_TFT_240320 (320)
//TFT 240320
#define SCR_XSIZE_TFT_240320 (640)
#define SCR_YSIZE_TFT_240320 (480)
//TFT240320
#define HOZVAL_TFT_240320 (LCD_XSIZE_TFT_240320-1)
#define LINEVAL_TFT_240320 (LCD_YSIZE_TFT_240320-1)
//Timing parameter for LCD
#define VBPD_240320 (1) //垂直同步信號的后肩
#define VFPD_240320 (2) //垂直同步信號的前肩
#define VSPW_240320 (1) //垂直同步信號的脈寬
#define HBPD_240320 (49) //水平同步信號的后肩
#define HFPD_240320 (15) //水平同步信號的前肩
#define HSPW_240320 (13) //水平同步信號的脈寬
//#define CLKVAL_TFT_240320 (5)
#define CLKVAL_TFT_240320 (4)
//FCLK=180MHz,HCLK=90MHz,VCLK=6.5MHz
#define LCD_BLANK 16
#define C_UP ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE_TFT_240320 - LCD_BLANK*4 ) / 6 )
static void Lcd_Init(void);
static void Lcd_EnvidOnOff(int onoff);
static void PutPixel(U32 x,U32 y,U32 c);
static void Glib_FilledRectangle(int x1,int y1,int x2,int y2,int color);
static void Glib_Line(int x1,int y1,int x2,int y2,int color);
static void Lcd_ClearScr(U16 c);
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[]);
extern unsigned char girl13_240_320[]; //寬240,高320
extern unsigned char flower_240_320[];
volatile static unsigned short LCD_BUFER[SCR_YSIZE_TFT_240320][SCR_XSIZE_TFT_240320];
/**************************************************************
320×240 16Bpp TFT LCD數(shù)據(jù)和控制端口初始化
**************************************************************/
static void Lcd_Port_Init(void)
{
rGPCUP = 0x0; // enable Pull-up register
rGPCCON = 0xaaaa56a9; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
rGPDUP = 0x0 ; // enable Pull-up register
rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]
}
/**************************************************************
320×240 16Bpp TFT LCD功能模塊初始化
**************************************************************/
static void Lcd_Init(void)
{
//CLKVAL=5;MMODE=0;PNRMODE=11:11 = TFT LCD panel
//BPPMODE=1100=16 bpp for TFT;ENVID0=Disable the video output and the LCD control signal.
rLCDCON1=(CLKVAL_TFT_240320<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
//VBPD=2;LINEVAL=319;VFPD=2;VSPW=4
rLCDCON2=(VBPD_240320<<24)|(LINEVAL_TFT_240320<<14)|(VFPD_240320<<6)|(VSPW_240320);
//HBPD=8;HOZVAL=239;HFPD=8
rLCDCON3=(HBPD_240320<<19)|(HOZVAL_TFT_240320<<8)|(HFPD_240320);
//MVAL=13;HSPW=6
rLCDCON4=(MVAL<<8)|(HSPW_240320);
rLCDCON5=(1<<11)|(0<<9)|(0<<8)|(0<<6)|(BSWP<<1)|(HWSWP); //FRM5:6:5,HSYNC and VSYNC are inverted
rLCDSADDR1=(((U32)LCD_BUFER>>22)<<21)|M5D((U32)LCD_BUFER>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFER+(SCR_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 );
//OFFSIZE=640-240=400;PAGEWIDTH=240
rLCDSADDR3=(((SCR_XSIZE_TFT_240320-LCD_XSIZE_TFT_240320)/1)<<11)|(LCD_XSIZE_TFT_240320/1);
rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
rTPAL=0; // Disable Temp Palette
}
/**************************************************************
LCD視頻和控制信號輸出或者停止,1開啟視頻輸出
**************************************************************/
static void Lcd_EnvidOnOff(int onoff)
{
if(onoff==1)
{rLCDCON1|=1; // ENVID=ON
rCLKCON |= (1<<5);
}
else
{rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
rCLKCON &= ~(1<<5);
}
}
/**************************************************************
320×240 16Bpp TFT LCD單個象素的顯示數(shù)據(jù)輸出
**************************************************************/
static void PutPixel(U32 x,U32 y,U32 c)
{
if ( (x < SCR_XSIZE_TFT_240320) && (y < SCR_YSIZE_TFT_240320) )
LCD_BUFER[(y)][(x)] = c;
}
/**************************************************************
320×240 16Bpp TFT LCD全屏填充特定顏色單元或清屏
**************************************************************/
static void Lcd_ClearScr(U16 c)
{
unsigned int x,y ;
for( y = 0 ; y < SCR_YSIZE_TFT_240320 ; y++ )
{
for( x = 0 ; x < SCR_XSIZE_TFT_240320 ; x++ )
{
LCD_BUFER[y][x] = c;
}
}
}
/**************************************************************
LCD屏幕顯示垂直翻轉(zhuǎn)
// LCD display is flipped vertically
// But, think the algorithm by mathematics point.
// 3I2
// 4 I 1
// --+-- <-8 octants mathematical cordinate
// 5 I 8
// 6I7
**************************************************************/
static void Glib_Line(int x1,int y1,int x2,int y2,int 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_FilledRectangle(int x1,int y1,int x2,int y2,int color)
{
int i;
for(i=y1;i<=y2;i++)
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) ;
if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
LCD_BUFER[y0+y][x0+x] = c ;
p = p + 2 ;
}
}
//本圖片顯示是倒過來的,是旋轉(zhuǎn)了180度的顯示方式
/* for( y = l ; y > 0 ; y-- )
{
for( x = h ; x > 0 ; x-- )
{
c = bmp[p+1] | (bmp[p]<<8) ;
if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
LCD_BUFER[y0+y][x0+x] = c ;
p = p + 2 ;
}
}
*/
}
/**************************************************************
**************************************************************/
void Test_Lcd_Tft_240X320( void )
{
Uart_Printf("\nTest 240*320 TFT LCD !\n");
Lcd_Port_Init();
Lcd_Init();
Lcd_EnvidOnOff(1); //turn on vedio
Lcd_ClearScr(0xffff); //fill all screen with white
#define C_UP ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE_TFT_240320 - LCD_BLANK*4 ) / 6 )
Glib_FilledRectangle( LCD_BLANK, LCD_BLANK, ( LCD_XSIZE_TFT_240320 - LCD_BLANK ), ( LCD_YSIZE_TFT_240320 - 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
Lcd_ClearScr(0x00); //fill all screen with black
while(1)
{
Paint_Bmp( 0,0,240,320, flower_240_320) ; //paint a bmp
Delay(9000000);
Paint_Bmp( 0,0,240,320, girl13_240_320) ; //paint a bmp
Delay(9000000);
}
while(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -