📄 lcd_320240.c
字号:
/**************************************************************
The initial and control for 320×240 16Bpp TFT LCD----3.5寸竖屏
**************************************************************/
#include <string.h>
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "LCD_LTV350QV_FOE.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 320240
#define LCD_XSIZE_TFT_320240 (320)
#define LCD_YSIZE_TFT_320240 (240)
#define SCR_XSIZE_TFT_320240 (320)
#define SCR_YSIZE_TFT_320240 (240)
#define HOZVAL_TFT_320240 (LCD_XSIZE_TFT_320240-1)
#define LINEVAL_TFT_320240 (LCD_YSIZE_TFT_320240-1)
#define LTV350QV_POE 0x1d //device ID
#define LTV350QV_VBPD 5 //垂直同步信号的后肩
#define LTV350QV_VFPD 4 //垂直同步信号的前肩
#define LTV350QV_VSPW 3 //垂直同步信号的脉宽
#define LTV350QV_HBPD 12 //水平同步信号的后肩
#define LTV350QV_HFPD 20 //水平同步信号的前肩
#define LTV350QV_HSPW 18 //水平同步信号的脉宽
//simulate the SPI timing order.
#define LTV350QV_CS 8
#define LTV350QV_SCL 9
#define LTV350QV_SDI 10
#define LTV350QV_RST 0
//micro for LTV350QV_POE
#define CS_H rGPCDAT |=1<<LTV350QV_CS
#define CS_L rGPCDAT &=~(1<<LTV350QV_CS)
#define SCLK_H rGPCDAT |=1<<LTV350QV_SCL
#define SCLK_L rGPCDAT &=~(1<<LTV350QV_SCL)
#define SDI_H rGPCDAT |=1<<LTV350QV_SDI
#define SDI_L rGPCDAT &=~(1<<LTV350QV_SDI)
#define RST_H rGPDDAT |=1<<LTV350QV_RST
#define RST_L rGPDDAT &=~(1<<LTV350QV_RST)
#define SDI_STATE rGPCDAT & (1<<LTV350QV_SDI)
typedef struct _LTV350qv_spi_data_{
U8 Device_ID; //ID of the device
U16 Index; //index of register
U16 Structure; //structure to be writed
}LTV350QV_SPI_Data;
#define CLKVAL_TFT_320240 (6)
//FCLK=180MHz,HCLK=90MHz,VCLK=6.5MHz
#define LCD_BLANK 16
#define C_UP ( LCD_XSIZE_TFT_320240 - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE_TFT_320240 - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE_TFT_320240 - LCD_BLANK*4 ) / 6 )
static void Lcd_Init(void);
static void Lcd_EnvidOnOff(int onoff);
//static void Lcd_Lpc3600Enable(void);
//static void Lcd_PowerEnable(int invpwren,int pwren);
static void MoveViewPort(void);
static void Lcd_MoveViewPort(int vx,int vy);
static void PutPixel(U32 x,U32 y,U32 c);
//static void Glib_Rectangle(int x1,int y1,int x2,int y2,int color);
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[]);
void LTV350QV_Powen_OFF(void);
void LTV350QV_Power_ON(void);
void LTV350QV_Write(U16 index, U16 regdata);
void LTV350QV_Short_Delay(U8 time);
void LTV350QV_Reset(void);
//extern unsigned char gImage_girl[]; //宽240,高320
//extern unsigned char gImage_flower[];
extern unsigned char flower_320_240[];
//extern unsigned char flower_240_320[];
volatile static unsigned short LCD_BUFER[SCR_YSIZE_TFT_320240][SCR_XSIZE_TFT_320240];
/*****************************************
* *for LTV350QV_POE TFT LCD
*****************************************/
//short delay for about 90*time ns
void LTV350QV_Short_Delay(U8 time)
{
unsigned int i;
for(i=0;i<time*80;i++) ; //about 360 ns
}
//****************************************
void LTV350QV_Reset(void)
{
RST_L;
Delay(100);
RST_H;
Delay(1);
}
void LTV350QV_Register_Write(LTV350QV_SPI_Data regdata)
{
U8 i,temp1;
U16 temp2;
U32 temp3;
//write index
temp1=regdata.Device_ID<<2 | 0<<1 | 0<<0; //register index
temp2=regdata.Index;
temp3=(temp1<<24) | (temp2<<8);
CS_L;
LTV350QV_Short_Delay(1);
for(i=0;i<24;i++)
{
SCLK_L;
if(temp3 & (1<<(31-i)) ) //if is H
SDI_H;
else
SDI_L;
LTV350QV_Short_Delay(1); //setup time
SCLK_H;
LTV350QV_Short_Delay(1); //hold time
}
CS_H;
LTV350QV_Short_Delay(5);
//write instruction
temp1=regdata.Device_ID<<2 | 1<<1 | 0<<0; //instruction
temp2=regdata.Structure;
temp3=(temp1<<24) | (temp2<<8);
CS_L;
LTV350QV_Short_Delay(1);
for(i=0;i<24;i++)
{
SCLK_L;
if(temp3 & (1<<(31-i)) ) //if is H
SDI_H;
else
SDI_L;
LTV350QV_Short_Delay(1);
SCLK_H;
LTV350QV_Short_Delay(1);
}
CS_H;
}
U16 LTV350QV_Register_Read(U8 index)
{
U8 i,temp1;
U16 temp2;
U32 temp3;
//write index
temp1=LTV350QV_POE<<2 | 0<<1 | 1<<0; //register index
temp2=index;
temp3=(temp1<<24) | (temp2<<8);
CS_L;
LTV350QV_Short_Delay(1);
for(i=0;i<24;i++)
{
SCLK_L;
if(temp3 & (1<<(31-i)) ) //if is H
SDI_H;
else
SDI_L;
LTV350QV_Short_Delay(1); //setup time
SCLK_H;
LTV350QV_Short_Delay(1); //hold time
}
CS_H;
LTV350QV_Short_Delay(5);
//read instruction
temp1=(LTV350QV_POE<<2 | 1<<1 | 1<<0); //instruction
temp3=temp1<<24;
CS_L;
LTV350QV_Short_Delay(1);
for(i=0;i<8;i++) //send device ID
{
SCLK_L;
if(temp3 & (1<<(31-i)) ) //if is H
SDI_H;
else
SDI_L;
LTV350QV_Short_Delay(1); //setup time
SCLK_H;
LTV350QV_Short_Delay(1); //hold time
}
temp2=0;
rGPCCON &=~(1<<20); //SDI input
for(i=0;i<16;i++) //read data from the register
{
SCLK_L;
LTV350QV_Short_Delay(1);
SCLK_H;
LTV350QV_Short_Delay(1);
if(SDI_STATE) //if H
temp2 |=1<<(15-i);
else //if L
;
LTV350QV_Short_Delay(1);
}
CS_H;
return temp2;
}
/****************************************
* *
****************************************/
void LTV350QV_Write(U16 index, U16 regdata)
{
LTV350QV_SPI_Data WriteData;
WriteData.Device_ID=LTV350QV_POE; //0x1d
WriteData.Index=index; //
WriteData.Structure=regdata;
LTV350QV_Register_Write(WriteData);
}
/****************************************
* *power ON sequence
****************************************/
void LTV350QV_Power_ON(void)
{
LTV350QV_Write(9, 0x0000);
Delay(150);
LTV350QV_Write(9, 0x4000);
LTV350QV_Write(10, 0x2000);
LTV350QV_Write(9, 0x4055);
Delay(550);
LTV350QV_Write(1, 0x409d);
LTV350QV_Write(2, 0x0284);
LTV350QV_Write(3, 0x0100);
LTV350QV_Write(4, 0x3000);
LTV350QV_Write(5, 0x4003);
LTV350QV_Write(6, 0x000a);
LTV350QV_Write(7, 0x0021);
LTV350QV_Write(8, 0x0c00);
LTV350QV_Write(10, 0x0103);
LTV350QV_Write(11, 0x0301);
LTV350QV_Write(12, 0x1f0f);
LTV350QV_Write(13, 0x1f0f);
LTV350QV_Write(14, 0x0707);
LTV350QV_Write(15, 0x0307);
LTV350QV_Write(16, 0x0707);
LTV350QV_Write(17, 0x0000);
LTV350QV_Write(18, 0x0004);
LTV350QV_Write(19, 0x0000);
Delay(200);
LTV350QV_Write(9, 0x4a55);
LTV350QV_Write(5, 0x5003);
}
/**********************************
* *power OFF sequence
**********************************/
void LTV350QV_Powen_OFF(void)
{
/* GON -> 0, POC -> 0 */
LTV350QV_Write(9, 0x4055);
/* DSC -> 0 */
LTV350QV_Write(5, 0x4003);
/* VCOMG -> 0 */
LTV350QV_Write(10, 0x0000);
Delay(20);
/* AP[2:0] -> 000 */
LTV350QV_Write(9, 0x4000);
}
//*************************************************************
/**************************************************************
320×240 16Bpp TFT LCD数据和控制端口初始化
**************************************************************/
static void Lcd_Port_Init(void)
{
rGPCUP = 0xffffffff; // enable Pull-up register
rGPCCON = 0xaa9556a9; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
rGPDUP=0xffffffff;
rGPDCON=0xaaaaaaaa;
CS_H;
SCLK_H;
SDI_H;
Uart_Printf("\nLcd_Port_Init OK !\n");
}
/**************************************************************
320×240 16Bpp TFT LCD功能模块初始化
**************************************************************/
static void Lcd_Init(void)
{
rLCDCON1=(CLKVAL_TFT_320240<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
// TFT LCD panel,16bpp TFT,ENVID=off
rLCDCON2=(LTV350QV_VBPD<<24)|(LINEVAL_TFT_320240<<14)|(LTV350QV_VFPD<<6)|(LTV350QV_VSPW);
rLCDCON3=(LTV350QV_HBPD<<19)|(HOZVAL_TFT_320240<<8)|(LTV350QV_HFPD);
rLCDCON4=(MVAL<<8)|(LTV350QV_HSPW);
rLCDCON5=(1<<11)|(1<<10)|(1<<9)|(1<<8)|(0<<6)|(BSWP<<1)|(HWSWP); //FRM5:6:5,VCLK,HSYNC and VSYNC are inverted
rLCDSADDR1=(((U32)LCD_BUFER>>22)<<21)|M5D((U32)LCD_BUFER>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFER+(SCR_XSIZE_TFT_320240*LCD_YSIZE_TFT_320240*2))>>1 );
rLCDSADDR3=(((SCR_XSIZE_TFT_320240-LCD_XSIZE_TFT_320240)/1)<<11)|(LCD_XSIZE_TFT_320240/1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -