📄 lcd.c
字号:
//designed by zzf
//====================================================================
#include <string.h>
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "glib.h"
#include "lcd.h"
#include "DEMO256.h"
//16bpp
#define RGB16BPP 1
//24bpp
//#define RGB16BPP 0
////
#define LCDFRAMEBUFFER 0x33800000 //_NONCACHE_STARTADDRESS
// 1. The LCD frame buffer should be write-through or non-cachable.
// 2. The total frame memory should be inside 4MB.
// 3. To meet above 2 conditions, the frame buffer should be
// inside the following regions.
// 0x31000000~0x313ffffff,
// 0x31400000~0x317ffffff,
// 0x31800000~0x31bffffff,
// .....
// 0x33800000~0x33bffffff
////
#define M5D(n) ((n) & 0x1fffff) // To get lower 21bits
#define LCD_XSIZE_TFT_320240 (320)
#define LCD_YSIZE_TFT_320240 (240)
//16bpp
#define SCR_XSIZE_TFT_320240 (320)
#define SCR_YSIZE_TFT_320240 (240)
//24bpp
#define SCR_XSIZE_TFT_320240_24 (320*2)
#define SCR_YSIZE_TFT_320240_24 (240*2)
extern unsigned char flower1_320_240[];//自定义的图片//16bpp
extern unsigned char flower2_320_240[];//自定义的图片//24bpp
volatile static unsigned short LCD_BUFFER_16bpp[SCR_YSIZE_TFT_320240][SCR_XSIZE_TFT_320240];//halfword
volatile static unsigned short LCD_BUFFER_24bpp[SCR_YSIZE_TFT_320240_24][SCR_XSIZE_TFT_320240_24];//halfword
///////////////////////////////////////////////////////////////////////////
void TMS350_Test_Lcd_Tft_24Bit_320240(void);
void TMS350_LCD_CONTROLER_SetUP16(void);
void SPI_Write(unsigned char Index,unsigned short REG_DATA);
void Init_Display( void );
void InitSPI(void);
void RGB_Start_PATTERN16(void);
void delay_lcd(unsigned int msDelay);
static void Lcd_ClearScr( U32 c);
static void Paint_Bmp_16bpp(int x0,int y0,int h,int l,unsigned char bmp[]);
///////////////////////////////////////////////////////////////////////////
void TMS350_LCD_CONTROLER_SetUP24(void);
static void Paint_Bmp_24bpp(int x0,int y0,int h,int l,unsigned char bmp[]);
//Power supply should always be turned on/off by the "Power on/off sequence"
void LCD_POWER_ON_Sequence(void);
void LCD_DISPLAY_ON_Sequence(void);
void LCD_POWER_OFF_Sequence(void);
void LCD_DISPLAY_OFF_Sequence(void);
void LCD_Stand_by_IN_Sequence(void);
void LCD_Stand_by_Cancel_Sequence(void);
//////////////////////////////////////////////////////////////////////////
void Lcd_Test(void)
{
int i;
Uart_Printf("\n====== LCD Test program start ======\n");
//###zzf-add###
//black white led on
rGPBDAT=(rGPBDAT|0x02);
Uart_Printf("\nblack white led on\n");
Uart_Printf("\n0.Lms350--TFT320X240 24Bit\n");
Uart_Printf("\nPress only Enter key to exit : ");
while(1)
{
i=1;
i = Uart_GetIntNum();
if(i==-1) break;
if(i==0 )
{
TMS350_Test_Lcd_Tft_24Bit_320240();
}
}
Uart_Printf("\n====== LCD Test program end ======\n");
//###zzf-add###
//black white led off
//rGPBDAT=(rGPBDAT&(~0x02));
// Uart_Printf("\nblack white led off\n");
}
//################################TMS350####################################
//#########################################################################
//#########################################################################
void TMS350_Test_Lcd_Tft_24Bit_320240(void)
{
Uart_Printf("\nLMs350gf03-001_Test_Lcd_Tft_24Bit\n\r");
Init_Display();
LCD_POWER_ON_Sequence();
LCD_DISPLAY_ON_Sequence();
#if RGB16BPP
Uart_Printf("\nbegin display\n\r");
RGB_Start_PATTERN16();
Uart_Getch() ; //Any Key To Next
Uart_Printf("\n display off\n\r");
LCD_DISPLAY_OFF_Sequence();
Uart_Printf("\nin stand_by \n\r");
LCD_Stand_by_IN_Sequence();
Uart_Getch(); //Any Key To Next
Uart_Printf("\nCancel stand_by \n\r");
LCD_Stand_by_Cancel_Sequence();
LCD_POWER_ON_Sequence();
LCD_DISPLAY_ON_Sequence();
Uart_Printf("bmp1,Any Key To Next!\n");
Paint_Bmp_16bpp(0, 0, 320, 240, flower1_320_240);
Uart_Getch();
Uart_Getch(); //Any Key To Next
Lcd_ClearScr(0x0000);
Uart_Getch();
#else
Paint_Bmp_24bpp(0, 0, 320*2, 240*2, flower2_320_240);
Uart_Getch() ;
#endif
LCD_DISPLAY_OFF_Sequence();
LCD_POWER_OFF_Sequence();
Uart_Printf("LCD display off!\n");
Uart_Printf("LCD Test Complete!\n");
}
//******************************** TFT CONTROLER SETUP***********************************
void TMS350_LCD_CONTROLER_SetUP16(void)
{
delay_lcd(2000);
rLCDCON1 = (8 << 8) | /* VCLK = HCLK / ((CLKVAL + 1) * 2) -> About 7 Mhz */
(0 << 7) | /* 0 : Each Frame */
(3 << 5) | /* TFT LCD Pannel */
(12 << 1) | /* 16bpp Mode */
(0 << 0) ; /* Disable LCD Output */
rLCDCON2= (16 << 24) | /* VBPD : 16 */
(239 << 14) | /* Virtical Size : 240 - 1 */
(6 << 6) | /* VFPD : 3 */
(2 << 0) ; /* VSPW : 2 */
rLCDCON3= (9 << 19) | /* HBPD : 9 */
(319 << 8) | /* HOZVAL_TFT : 320 - 1 */
(6 << 0) ; /* HFPD : 6 */
rLCDCON4 = (0 << 8) | /* MVAL : 0 */
(2 << 0) ; /* HSPW : 2 */
rLCDCON5 = // (0 << 12) | /* BPP24BL : LSB valid */
(1 << 11) | /* FRM565 MODE : 5:6:5 Format */
(1 << 10) | /* INVVCLK : VCLK Falling Edge */
(1 << 9) | /* INVVLINE : Inverted Polarity */
(1 << 8) | /* INVVFRAME : Inverted Polarity */
(0 << 7) | /* INVVD : Normal */
(0 << 6) | /* INVVDEN : Norma */
(1 << 5) | /* INVPWREN : Normal */
(1 << 4) | /* INVENDLINE : Normal */
(1 << 3) | /* PWREN : Disable PWREN */
(0 << 2) | /* ENLEND : Disable LEND signal */
(0 << 1) | /* BSWP : Swap Disable */
(1 << 0) ; /* HWSWP : Swap Enable */
rLCDSADDR1=(((U32)LCD_BUFFER_16bpp>>22)<<21)|M5D((U32)LCD_BUFFER_16bpp>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFFER_16bpp+(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);
// rTCONSEL &= (~7) ; // Disable LPC3480
rTCONSEL |= 0x0;
rLCDINTMSK |= 0x3;
rTPAL=0; // Disable Temp Palette
rLCDCON1 |= 0x1;
}
//******************************** TFT CONTROLER SETUP***********************************
void TMS350_LCD_CONTROLER_SetUP24(void)
{
delay_lcd(2000);
// frameBuffer24BitTft240320=(U32 (*)[SCR_XSIZE_TFT_240320])LCDFRAMEBUFFER;
rLCDCON1 = (8 << 8) | /* VCLK = HCLK / ((CLKVAL + 1) * 2) -> About 7 Mhz */
(0 << 7) | /* 0 : Each Frame */
(3 << 5) | /* TFT LCD Pannel */
(13 << 1) | /* 16bpp Mode */
(0 << 0) ; /* Disable LCD Output */
rLCDCON2= (16 << 24) | /* VBPD : 16 */
(239 << 14) | /* Virtical Size : 240 - 1 */
(6 << 6) | /* VFPD : 3 */
(2 << 0) ; /* VSPW : 2 */
rLCDCON3= (9 << 19) | /* HBPD : 9 */
(319 << 8) | /* HOZVAL_TFT : 320 - 1 */
(6 << 0) ; /* HFPD : 6 */
rLCDCON4 = (0 << 8) | /* MVAL : 0 */
(2 << 0) ; /* HSPW : 2 */
rLCDCON5 = (0 << 12) | /* BPP24BL : LSB valid */
//(1 << 11) | /* FRM565 MODE : 5:6:5 Format */
//(1 << 10) | /* INVVCLK : VCLK Falling Edge */
(1 << 9) | /* INVVLINE : Inverted Polarity */
(1 << 8);// | /* INVVFRAME : Inverted Polarity */
// (0 << 7) | /* INVVD : Normal */
// (0 << 6) | /* INVVDEN : Norma */
// (1 << 5) | /* INVPWREN : Normal */
// (1 << 4) | /* INVENDLINE : Normal */
// (1 << 3) | /* PWREN : Disable PWREN */
// (0 << 2) | /* ENLEND : Disable LEND signal */
// (0 << 1) | /* BSWP : Swap Disable */
// (1 << 0) ; /* HWSWP : Swap Enable */
rLCDSADDR1=(((U32)LCD_BUFFER_24bpp>>22)<<21)|M5D((U32)LCD_BUFFER_24bpp>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFFER_24bpp+(SCR_XSIZE_TFT_320240_24*LCD_YSIZE_TFT_320240*4))>>1 );
rLCDSADDR3=(((SCR_XSIZE_TFT_320240_24-LCD_XSIZE_TFT_320240)*2)<<11)|(LCD_XSIZE_TFT_320240*2);
rTCONSEL &= (~7) ; // Disable LPC3480
//rTCONSEL |= 0x0;
rLCDINTMSK |= 0x3;
rTPAL=0; // Disable Temp Palette
rLCDCON1 |= 0x1;
}
//##############################################
void InitSPI(void)
{
//Uart_Printf("spi start\r\n");
//set SPI-CLK,SPI-MO
rGPECON = (rGPECON & ~(0xf<<24)) | (0xa<<24);//GPE13,12;SPICLK,SPIMOSI
rGPEUP |= (0x3<<12) ; //pull up disable register for portE
rSPPRE0=0x20; //Baud rate = PCLK/2/(Prescaler value+1) =1M
rSPPIN0=(0<<2)|(1<<1)|(0<<0); //set the SPI pin control register
rSPCON0=(0<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(0<<0); //set the SPI control register
//set SPI--cs
rGPGCON= (rGPGCON& ~(0x3<<4)) | (0x1<<4); //Gpg2 setup to CS(output)
rGPGUP |= (0x1<<2) ;//pull up disable register for portg
rGPGDAT |= (1<<2);
delay_lcd(10);//1ms
}
//##############################################
void LCD_POWER_ON_Sequence(void)
{
// lcd REST////
rGPCCON = (rGPCCON& ~(0x3<<0)) | (0x1<<0);//gpc0 rest set for out
rGPCUP |=(0x1<<0) ; //pull up disable register for portg
rGPCDAT |=(1<<0); // Reset out put hight
delay_lcd(2);
rGPCDAT &= ~(1<<0); // Reset low active
delay_lcd(2);
rGPCDAT |=(1<<0); //Reset out put hight
delay_lcd(150);
////lcd REST END ////
SPI_Write(0x07,0x0000);
delay_lcd(500);
SPI_Write(0x12,0x1618);
SPI_Write(0x11,0x2225);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -