📄 lcd_320x240.c
字号:
/**************************************************************
The initial and control for 320×240 16Bpp TFT LCD--LTS350Q1_PE1 & LQ035Q7DB02
**************************************************************/
#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
#include "2410slib.h"
#include "LCD.h"
extern unsigned char xyx_240_320[]; //宽240,高320
#define LCDFRAMEBUFFER 0x32000000
#define ADCPRS 39
volatile unsigned short LCD_BUFER[SCR_YSIZE_TFT_240320][SCR_XSIZE_TFT_240320];
U32 (*frameBuffer16BitTft240320)[SCR_XSIZE_TFT_240320/2];
unsigned save_rGPCUP,save_rGPCDAT,save_rGPCCON;
unsigned save_rGPDUP,save_rGPDDAT,save_rGPDCON;
unsigned lcd_count;
void Lcd_Port_Init(void)
{
save_rGPCCON=rGPCCON;
save_rGPCDAT=rGPCDAT;
save_rGPCUP=rGPCUP;
save_rGPDCON=rGPDCON;
save_rGPDDAT=rGPDDAT;
save_rGPDUP=rGPDUP;
rGPCUP=0xffffffff; // Disable Pull-up register
rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
rGPDUP=0xffffffff; // Disable Pull-up register
rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
printf("\r\nInitalize the LCD Port\r\n ");
}
void LcdInit( void )
{
frameBuffer16BitTft240320=(U32 (*)[SCR_XSIZE_TFT_240320/2])LCDFRAMEBUFFER;
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)|(1<<3)|(0<<0); //FRM5:6:5,HSYNC and VSYNC are inverted
rLCDSADDR1=(((U32)frameBuffer16BitTft240320>>22)<<21)|M5D((U32)frameBuffer16BitTft240320>>1);
rLCDSADDR2=M5D( ((U32)frameBuffer16BitTft240320+(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
rLPCSEL&=(~7); // Disable LPC3600
rTPAL=0; // Disable Temp Palette
}
void Lcd_Lpc3600Enable(void)
{
rLPCSEL&=~(7);
rLPCSEL|=(7); // 240320,Enable LPC3600
}
void Lcd_EnvidOnOff(int onoff)
{
if(onoff==1)
rLCDCON1|=1; // ENVID=ON
else
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}
/// Lcd Opetion Function
void PutPixel(U32 x,U32 y,U32 c)
{
if(x<SCR_XSIZE_TFT_240320 && y<SCR_YSIZE_TFT_240320)
frameBuffer16BitTft240320[(y)][(x)/2]=( frameBuffer16BitTft240320[(y)][x/2]
& ~(0xffff0000>>((x)%2)*16) ) | ( (c&0x0000ffff)<<((2-1-((x)%2))*16) );
}
void Glib_ClearScr(U32 c, int type)
{
unsigned int i, j ;
type = type ;
for(j=0;j<SCR_YSIZE_TFT_240320;j++)
for(i=0;i<SCR_XSIZE_TFT_240320;i++)
PutPixel(i,j,c);
}
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;
}
}
}
}
}
/**************************************************************
320×240 16Bpp TFT LCD全屏填充特定颜色单元或清屏
**************************************************************/
void Lcd_ClearScr(U16 c)
{
U32 x,y ;
for( y = 0 ; y < SCR_YSIZE_TFT_240320 ; y++ )
{
for( x = 0 ; x < SCR_XSIZE_TFT_240320 ; x++ )
{
PutPixel( x, y, c);
}
}
}
/**************************************************************
在LCD屏幕上画一个矩形
**************************************************************/
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屏幕上指定坐标点画一个指定大小的图片
**************************************************************/
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+8] | (bmp[p+8]<<8) ;
if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
//if ( ( (x0+x) < 320) && ( (y0+y) < 240) )
PutPixel(y0+y,x0+x, c);
//LCD_BUFER[y0+y][x0+x] = c ;
p = p + 2 ;
}
}
}
void LcdTest( void )
{
unsigned short i,j;
unsigned short *ptr;
Lcd_Port_Init() ;
LcdInit() ;
// ptr = (ushort*)xl ;
printf("\r\nLCD Test") ;
// Lcd_Lpc3600Enable() ;
Lcd_EnvidOnOff(1) ;
Glib_ClearScr( 0, 0 ) ;
//Lcd_ClearScr(0x1f); Paint_Bmp( 0, 0, 225, 300, xyx_240_320 );
Paint_Bmp( 0, 0,240 ,320 , xyx_240_320 );
// Lcd_ClearScr(0x1f);
/*Glib_Line(0,0,319,239,0x1f);
Glib_Line(319,0,0,239,0x1f);
Glib_Line(0,0,319,0,0x1f);
Glib_Line(0,238,319,238,0x1f);
Glib_Line(1,0,1,239,0x1f);
Glib_Line(319,0,319,238,0x1f);*/
Delay(30000) ; //延时3秒
Delay(30000) ;
}
void __irq Adc_or_TsAuto(void)
{
rINTSUBMSK|=(BIT_SUB_ADC|BIT_SUB_TC); // Mask sub interrupt (ADC and TC)
// TC(Touch screen Control) Interrupt
if(rADCTSC&0x100)
{
//Uart_Printf("\nStylus Up!!\n");
rADCTSC&=0xff; // Set stylus down interrupt
}
else
{
// Uart_Printf("\nStylus Down!!\n");
// <Auto X-Position and Y-Position Read>
rADCTSC=(0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);
// Stylus Down,Don't care,Don't care,Don't care,Don't care,XP pullup Dis,Auto,No operation
rADCCON|=0x1; // Start Auto conversion
while(rADCCON & 0x1); //check if Enable_start is low
while(!(0x8000&rADCCON)); // Check ECFLG
Uart_Printf("\r\n Touch X Y Position\n");
Uart_Printf("X-Posion[AIN5] is %04d\n", (0x3ff&rADCDAT0));
Uart_Printf("Y-Posion[AIN7] is %04d\n", (0x3ff&rADCDAT1));
rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
// Stylus Up,Don't care,Don't care,Don't care,Don't care,XP pullup En,Normal,Waiting mode
}
rSUBSRCPND|=BIT_SUB_TC;
rINTSUBMSK=~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
void Ts_Auto(void)
{
Uart_Printf("[触摸屏测试程序.]\n");
Uart_Printf("请点击触摸屏进行测试,请注意串口输出内容\n");
rADCDLY=(50000); // ADC Start or Interval Delay
rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|(0);
// Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
rADCTSC=(0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);//tark
// Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode
pISR_ADC=(unsigned)Adc_or_TsAuto;
rINTMSK=~(BIT_ADC);
rINTSUBMSK=~(BIT_SUB_TC);
// rINTSUBMSK|=BIT_SUB_TC;
// rINTMSK|=BIT_ADC;
//Uart_Printf("[Touch Screen Test.]\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -