管理提醒: 本帖被 qq2440 从 micro2440技术交流专区 移动到本区(2013-11-18)
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "LCD_LTS350Q1_PE1.h"
#include "bmp123.h"
#define MVAL (13)
#define MVAL_USED (0)
#define INVVDEN (1)
#define BSWP (0)
#define HWSWP (1)
#define M5D(n) ((n)&0x1fffff)//to get lower 21 bits
//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)
#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=180,HCLK=90,VCLK=6.5MHz
// GPB1/TOUT1 for Backlight control(PWM)
//#define GPB1_TO_OUT() do{rGPBUP&=0xfffd;rGPBCON&=0xfffffff3;rGPBCON|=0X00000004;}while(0);
#define GPB1_TO_OUT() (rGPBUP&=0xfffd,rGPBCON&=0xfffffff3,rGPBCON|=0X00000004)
#define GPB1_TO_1() (rGPBDAT|=0x0002)
#define GPB1_TO_0() (rGPBDAT&=0xfffd)
//extern void Uart_Printf(char *f,...);
static void Lcd_PowerEnable(int invpwren,int pwren);
volatile static unsigned short LCD_BUFFER[SCR_YSIZE_TFT_240320][SCR_XSIZE_TFT_240320];
//LCD 初始化
static void Lcd_Init()
{
rGPCUP=0x0;//enable Pull-up register
rGPCCON=0xaaaa02a9;
rGPDUP=0x0;
rGPDCON=0xaaaaaaaa;//VD[15:8]
rLCDCON1=(CLKVAL_TFT_240320<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|(0);
//tft lcd panel ,12bpp tft ,envid=off
//[0] 0 = Disable the video output and the LCD control signal.
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);
//STN/TFT: Frame buffer start address 1 register
rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)
|(M5D((U32)LCD_BUFFER>>1));
//STN/TFT: Frame buffer start address 2 register
rLCDSADDR2=M5D(((U32)LCD_BUFFER+(SCR_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 );
//STN/TFT: Virtual screen address set
rLCDSADDR3=(((SCR_XSIZE_TFT_240320-LCD_XSIZE_TFT_240320)/1)<<11)
|(LCD_XSIZE_TFT_240320/1);
rLCDINTMSK|=(3);
rTCONSEL&=(~7);//DISABLE LPC3480
//TFT: Temporary palette register.
rTPAL=0x0;
}
static void Lcd_EnvidOnOff(int onoff)
{
if(onoff==1)
rLCDCON1|=1;//ENVID=ON
else
rLCDCON1=rLCDCON1&0x3fffe;
}
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);
//ENABLE LCD POWER ENABLE FUNCTION
rLCDCON5=rLCDCON5&(~(1<<3))|(pwren<<3);
rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5);
}
//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;
// LCD_BUFFER[(y)][(x)]=(LCD_BUFFER[(y)][x]
// & ~(0xffff0000>>((x)%2)*16) ) | ( (c&0x0000ffff)<<((2-1-((x)%2))*16) );
}
//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;
}
static void Glib_Line(int x0,int y0,int x1,int y1,int color)
{ //bresenhamline
int i,x,y,dx,dy,m;
float k,e;
if(x0>x1)
{
m=x0;x0=x1;x1=m;
m=y0;y0=y1;y1=m;
}
dx = x1-x0;
dy = y1-y0;
k =(float) dy/dx;
e = 0.5; x=x0; y=y0;
for( i=0; i<=dx; i++)
{
PutPixel(x,y,color);
x++; e=e+k;
if(e <0)
{ y--;
e=e+1;
}
}
if(y0>y1)
{
m=x0;x0=x1;x1=m;
m=y0;y0=y1;y1=m;
}
dx = x1-x0;
dy = y1-y0;
k =(float) dx/dy;
e = -0.5; x=x0; y=y0;
for( i=0; i<=dy; i++)
{
PutPixel(x,y,color);
y++; e=e+k;
if(e >=0)
{ x++;e=e-1;}
}
}
//画一个矩形
static void Glib_Rectangle(int x1,int y1,int x2,int y2,int color)
{
Glib_Line(x1,y1,x2,y1,color);
Glib_Line(x1,y1,x1,y2,color);
Glib_Line(x1,y2,x2,y2,color);
Glib_Line(x2,y2,x2,y1,color);
}
//填充一个矩形
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,const 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;
}
}
//extern flower1_320_240;
void Lcd_Tft_NEC35_Init(void)
{//turn on the blacklight
GPB1_TO_OUT();
GPB1_TO_1();
Lcd_Init();
//LcdBkLtSet(70);
Lcd_PowerEnable(0,1);
Lcd_EnvidOnOff(1);
Lcd_ClearScr(0);//((0x00<<11)|(0xxx<<5)|(0x00))
//Paint_Bmp(0,0,240,320,bmp123);
Paint_Bmp(0,0,240,320,flower1_240_320);
}
void Main(void)/////############# Main()
{
int i,j;
ChangeMPllValue(127,2,1);//405Mhz
ChangeClockDivider(0, 12); //HCLK=FCLK=2PCLK
MMU_DisableICache(); //NANDFLASH USE HCLK
MMU_DisableDCache();
//GPB8 7 6 5 0 beep
//01 0101 0100 0000 0000
rGPBCON = 0x15401;
rGPBDAT=(0x0<<5);//led all on
Port_Init();
Uart_Init(0,115200);
Uart_Select(0);
Uart_Printf("\n");
Uart_Printf(" @@ the main is running @@\n");
Lcd_Tft_NEC35_Init();
Glib_Rectangle(10,10,100,100,0x70);
Glib_FilledRectangle(100,110,240,240,800);
Glib_Line(0,0,240,240,0xe0);
}