LCD_NEC35.c
上传用户:zbk8730
上传日期:2017-08-10
资源大小:12168k
文件大小:13k
- /**************************************************************
- The initial and control for 320×240 16Bpp TFT LCD----LCD_LTV350QV-F04
- **************************************************************/
- #include "option.h"
- #include "2440addr.h"
- #include "2440lib.h"
- #include "2440slib.h"
- #include "LCD_LTS350Q1_PE1.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)
- #define SCR_XSIZE_TFT_240320 (240)
- #define SCR_YSIZE_TFT_240320 (320)
- //TFT240320
- #define HOZVAL_TFT_240320 (LCD_XSIZE_TFT_240320-1)
- #define LINEVAL_TFT_240320 (LCD_YSIZE_TFT_240320-1)
- //Timing parameter for NEC3.5"
- #define VBPD_240320 (1) //垂直同步信号的后肩
- #define VFPD_240320 (5) //垂直同步信号的前肩
- #define VSPW_240320 (1) //垂直同步信号的脉宽
- #define HBPD_240320 (36) //水平同步信号的后肩
- #define HFPD_240320 (19) //水平同步信号的前肩
- #define HSPW_240320 (5) //水平同步信号的脉宽
- #define CLKVAL_TFT_240320 (4)
- //FCLK=180MHz,HCLK=90MHz,VCLK=6.5MHz
- // GPB1/TOUT1 for Backlight control(PWM)
- #define GPB1_TO_OUT() (rGPBUP &= 0xfffd, rGPBCON &= 0xfffffff3, rGPBCON |= 0x00000004)
- #define GPB1_TO_1() (rGPBDAT |= 0x0002)
- #define GPB1_TO_0() (rGPBDAT &= 0xfffd)
- static void Lcd_PowerEnable(int invpwren,int pwren);
- volatile static unsigned short LCD_BUFFER[SCR_YSIZE_TFT_240320][SCR_XSIZE_TFT_240320];
- /**************************************************************
- 320×240 16Bpp TFT LCD功能模块初始化
- **************************************************************/
- static void Lcd_Init(void)
- {
- rGPCUP = 0x00000000;
- rGPCCON = 0xaaaa02a9;
-
- // rGPDUP=0xffffffff; // Disable Pull-up register
- rGPDUP = 0x00000000;
- rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]
- rLCDCON1=(CLKVAL_TFT_240320<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
- // TFT LCD panel,12bpp TFT,ENVID=off
- rLCDCON2=(VBPD_240320<<24)|(LINEVAL_TFT_240320<<14)|(VFPD_240320<<6)|(VSPW_240320);
- rLCDCON3=(HBPD_240320<<19)|(HOZVAL_TFT_240320<<8)|(HFPD_240320);
- rLCDCON4=(MVAL<<8)|(HSPW_240320);
- rLCDCON5 = (1<<11) | (1<<10) | (1<<9) | (1<<8) | (0<<7) | (0<<6)
- | (1<<3) |(BSWP<<1) | (HWSWP);
- rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
- rLCDSADDR2=M5D( ((U32)LCD_BUFFER+(SCR_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 );
- rLCDSADDR3=(((SCR_XSIZE_TFT_240320-LCD_XSIZE_TFT_240320)/1)<<11)|(LCD_XSIZE_TFT_240320/1);
- rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
- rTCONSEL &= (~7) ; // Disable LPC3480
- rTPAL=0; // Disable Temp Palette
- }
- /**************************************************************
- LCD视频和控制信号输出或者停止,1开启视频输出
- **************************************************************/
- static void Lcd_EnvidOnOff(int onoff)
- {
- if(onoff==1)
- rLCDCON1|=1; // ENVID=ON
- else
- rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
- }
- /**************************************************************
- 240×320 8Bpp TFT LCD 电源控制引脚使能(注意:在NEC3.5" 驱动板中实际并没有该函数相应的硬件支持)
- **************************************************************/
- static void Lcd_PowerEnable(int invpwren,int pwren)
- {
- //GPG4 is setted as LCD_PWREN
- rGPGUP=rGPGUP&(~(1<<4))|(1<<4); // Pull-up disable
- rGPGCON=rGPGCON&(~(3<<8))|(3<<8); //GPG4=LCD_PWREN
- rGPGDAT = rGPGDAT | (1<<4) ;
- // invpwren=pwren;
- //Enable LCD POWER ENABLE Function
- rLCDCON5=rLCDCON5&(~(1<<3))|(pwren<<3); // PWREN
- rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5); // INVPWREN
- }
- /**************************************************************
- 240×320 16Bpp TFT LCD单个象素的显示数据输出
- **************************************************************/
- static void PutPixel(U32 x,U32 y, U32 c )
- {
- if ( (x < SCR_XSIZE_TFT_240320) && (y < SCR_YSIZE_TFT_240320) )
- LCD_BUFFER[(y)][(x)] = c;
- }
- /**************************************************************
- 240×320 16Bpp TFT LCD全屏填充特定颜色单元或清屏
- **************************************************************/
- static void Lcd_ClearScr( U32 c)
- {
- unsigned int x,y ;
-
- for( y = 0 ; y < SCR_YSIZE_TFT_240320 ; y++ )
- {
- for( x = 0 ; x < SCR_XSIZE_TFT_240320 ; x++ )
- {
- LCD_BUFFER[y][x] = c ;
- }
- }
- }
- /**************************************************************
- LCD屏幕显示垂直翻转
- // 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_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,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 = y0 ; y < l ; y++ )
- {
- for( x = x0 ; x < h ; x++ )
- {
- c = bmp[p+1] | (bmp[p]<<8) ;
- if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
- LCD_BUFFER[y0+y][x0+x] = c ;
-
- p = p + 2 ;
- }
- }
- }
- /**************************************************************
- **************************************************************/
- void Lcd_Tft_NEC35_Init(void)
- {
- //qjy: turn on the blacklight!
- GPB1_TO_OUT();
- GPB1_TO_1();
- Lcd_Init();
- LcdBkLtSet( 70 ) ;
- Lcd_PowerEnable(0, 1);
- Lcd_EnvidOnOff(1); //turn on vedio
- Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) );
- #define LCD_BLANK 12
- #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
- Glib_Line( LCD_BLANK,LCD_BLANK, (LCD_XSIZE_TFT_240320-LCD_BLANK), (LCD_YSIZE_TFT_240320-LCD_BLANK), 0x0000 ) ;
- Glib_Line( LCD_BLANK,(LCD_YSIZE_TFT_240320-LCD_BLANK), (LCD_XSIZE_TFT_240320-LCD_BLANK), LCD_BLANK, 0x0000 ) ;
- Glib_Line( (LCD_XSIZE_TFT_240320/2),(LCD_BLANK*2 + V_BLACK*0), (LCD_XSIZE_TFT_240320/2), (LCD_BLANK*2 + V_BLACK*6), 0x0000 ) ;
-
- }
- void Lcd_Tft_NEC35_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( (0x1f<<11) | (0x00<<5) | (0x00) ) ; //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) | (0x1f) ) ; //clear screen
- Uart_Printf( "LCD clear screen is finished! press any key to continue!n" );
- Uart_Getch() ; //wait uart input
- Lcd_ClearScr( (0x1f<<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( (0x1f<<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_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
- Glib_Line( LCD_BLANK,LCD_BLANK, (LCD_XSIZE_TFT_240320-LCD_BLANK), (LCD_YSIZE_TFT_240320-LCD_BLANK), 0x0000 ) ;
- Glib_Line( LCD_BLANK,(LCD_YSIZE_TFT_240320-LCD_BLANK), (LCD_XSIZE_TFT_240320-LCD_BLANK), LCD_BLANK, 0x0000 ) ;
- Glib_Line( (LCD_XSIZE_TFT_240320/2),(LCD_BLANK*2 + V_BLACK*0), (LCD_XSIZE_TFT_240320/2), (LCD_BLANK*2 + V_BLACK*6), 0x0000 ) ;
- Uart_Getch() ; //Any Key To Next
- Paint_Bmp(0, 0, 240, 320, flower1_240_320);
- Paint_Bmp(0, 0, 240, 320, FriendlyARM_pic_240x320);
- Uart_Printf("bmp,Any Key To Next!n");
- Uart_Getch() ;
-
- }
- //*************************************************************