ARM9(S3C2440)的LCD显示——程序实例讲解

结合上一篇文章中的LCD理论知识,下面是结合FL2440开发板的实例程序,所用的LCD是16位320*240

操作的大概步骤是先初始化LCD,然后是写我们所需要的函数,最基础的是像素点显示函数,然后是划线函数,字符显示函数,图片显示函数等等,然后就是写主函数完成我们的任务。

#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.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)//定义LCD尺寸,是按像素来的
#define LCD_YSIZE_TFT_320240  (240)

//TFT 320240

#define SCR_XSIZE_TFT_320240  (320)//X尺寸
#define SCR_YSIZE_TFT_320240  (240)//Y尺寸

//TFT320240
#define HOZVAL_TFT_320240 (LCD_XSIZE_TFT_320240-1)//分辨率  可以参考数据手册,就是这样设置的要减1
#define LINEVAL_TFT_320240 (LCD_YSIZE_TFT_320240-1)

//Timing parameter for LCD LQ035Q7DB02
#define VBPD_320240  (3)  //垂直同步信号的后肩
#define VFPD_320240  (5)  //垂直同步信号的前肩
#define VSPW_320240  (15)  //垂直同步信号的脉宽

#define HBPD_320240  (58)  //水平同步信号的后肩  5
#define HFPD_320240  (15)  //水平同步信号的前肩
#define HSPW_320240  (8)  //水平同步信号的脉宽

#define CLKVAL_TFT_320240 (9) //  10
//FCLK=180MHz,HCLK=90MHz,VCLK=6.5MHz
extern unsigned char tu[];//这就是由软件转化的图片数据,是加入到工程中的C语言文件

volatile static unsigned short LCD_BUFFER[SCR_YSIZE_TFT_320240][SCR_XSIZE_TFT_320240];//数据缓冲区

unsigned char nian1616[]={0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80,0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80,
0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80
};//年//取模软件生成的字符数据
unsigned char nian2424[]={0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x03,0x00,0x00,0x06,0x00,0x08,0x07,
0xFF,0xFC,0x0C,0x08,0x00,0x08,0x08,0x00,0x10,0x08,0x00,0x20,0x08,0x20,0x46,0x08,
0x70,0x07,0xFF,0x80,0x06,0x08,0x00,0x06,0x08,0x00,0x06,0x08,0x00,0x06,0x08,0x0C,
0x39,0xFF,0xF0,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x0C,0x00,0x00,
0x0C,0x00,0x00,0x0C,0x00,0x00,0x00,0x00};
unsigned char yue2424[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x20,0x01,0xFF,0xF0,0x01,0x00,0x20,0x01,
0x00,0x20,0x01,0x00,0x20,0x01,0x00,0x20,0x01,0xFF,0xE0,0x01,0x00,0x20,0x01,0x00,
0x20,0x01,0x00,0x20,0x01,0x00,0x20,0x01,0x00,0x20,0x01,0xFF,0xE0,0x01,0x00,0x20,
0x01,0x00,0x20,0x03,0x00,0x20,0x02,0x00,0x20,0x06,0x00,0x20,0x04,0x04,0x60,0x08,
0x03,0xE0,0x10,0x00,0xC0,0x00,0x00,0x00};
unsigned char yue1616[]={0x07,0xF0,0x04,0x10,0x04,0x10,0x04,0x10,0x07,0xF0,0x04,0x10,0x04,0x10,0x04,0x10,
0x07,0xF0,0x04,0x10,0x08,0x10,0x08,0x10,0x10,0x10,0x20,0x50,0x40,0x20,0x00,0x00};//月
unsigned char ri1616[]={0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,0x00,0x00,0x00,0x00};//日

static void Lcd_Init(void)
{
    rGPCUP=0xffffffff; // Disable Pull-up register
    rGPCCON=0xaaaa56a9; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND

    rGPDUP=0xffffffff; // Disable Pull-up register
    rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]

 rLCDCON1=(CLKVAL_TFT_320240<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
     // TFT LCD panel,12bpp TFT,ENVID=off
 rLCDCON2=(VBPD_320240<<24)|(LINEVAL_TFT_320240<<14)|(VFPD_320240<<6)|(VSPW_320240);
 rLCDCON3=(HBPD_320240<<19)|(HOZVAL_TFT_320240<<8)|(HFPD_320240);
 rLCDCON4=(MVAL<<8)|(HSPW_320240);
 rLCDCON5=(1<<11)|(1<<9)|(1<<8)|(1<<3)|(BSWP<<1)|(HWSWP);
 //rLCDCON5=(1<<11)|(0<<9)|(0<<8)|(0<<6)|(BSWP<<1)|(HWSWP); //FRM5:6:5,HSYNC and VSYNC are inverted

 rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
 rLCDSADDR2=M5D( ((U32)LCD_BUFFER+(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);
 rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
    //rTCONSEL|=((1<<4)|1); // Disable LCC3600, LPC3600
 rTPAL=0; // Disable Temp Palette
}


static void Lcd_EnvidOnOff(int onoff)
{
    if(onoff==1)
 rLCDCON1|=1; // ENVID=ON
    else
 rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}


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
    //Enable LCD POWER ENABLE Function
    rLCDCON5=rLCDCON5&(~(1<<3))|(pwren<<3);   // PWREN
    rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5);   // INVPWREN
}


static void PutPixel(U32 x,U32 y, U32 c )//实际上c在这是16位数据,即是三种颜色调成的颜色数据
{
 if ( (x < SCR_XSIZE_TFT_320240) && (y < SCR_YSIZE_TFT_320240) )
  LCD_BUFFER[(y)][(x)] = c;//在指定的位置显示指定的颜色
}


static void Lcd_ClearScr( U32 c)
{
 unsigned int x,y ;
  
    for( y = 0 ; y < SCR_YSIZE_TFT_320240 ; y++ )
    {
     for( x = 0 ; x < SCR_XSIZE_TFT_320240 ; x++ )
     {
   LCD_BUFFER[y][x] = c ;
     }
    }
}

 


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);
}


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);
}


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) ;//将文件中的数据转化成16位的数据

   if ( ( (x0+x) < SCR_XSIZE_TFT_320240) && ( (y0+y) < SCR_YSIZE_TFT_320240) )
    LCD_BUFFER[y0+y][x0+x] = c ;
   
      p = p + 2 ;
     }
    }
}

void Draw_Text16(int x,int y,int color,unsigned char ch[])//显示16*16汉字

{

       unsigned short int i,j;

       unsigned char mask,buffer;

      

       for(i=0;i<16;i++)

       {

              mask=0x80;                  //掩码,用作取出每一位

              buffer=ch[i*2];             //提取一行的第一个字节

              for(j=0;j<8;j++)

              {                  

                     if(buffer&mask)//这一位为1则显示

                     {

                            PutPixel(x+j,y+i,color);        //为笔画上色

                     }

                     mask=mask>>1; //用以取出下一位                 

              }

              mask=0x80;                  //掩码

              buffer=ch[i*2+1];         //提取一行的第二个字节

              for(j=0;j<8;j++)

              {                  

                     if(buffer&mask)

                     {

                            PutPixel(x+j+8,y+i,color);           //为笔画上色

                     }

                     mask=mask>>1;                  

              }

       }

}
void Draw_Text24(int x,int y,int color,unsigned char ch[])//显示24*24汉字

{

       unsigned short int i,j;

       unsigned char mask,buffer;

      

       for(i=0;i<24;i++)

       {

              mask=0x80;                  //掩码

              buffer=ch[i*3];             //提取一行的第一个字节

              for(j=0;j<8;j++)

              {                  

                     if(buffer&mask)

                     {

                            PutPixel(x+j,y+i,color);        //为笔画上色

                     }

                     mask=mask>>1;                  

              }

              mask=0x80;                  //掩码

              buffer=ch[i*3+1];         //提取一行的第二个字节

              for(j=0;j<8;j++)

              {                  

                     if(buffer&mask)

                     {

                            PutPixel(x+j+8,y+i,color);           //为笔画上色

                     }

                     mask=mask>>1;                  

              }
              mask=0x80;                  //掩码

              buffer=ch[i*3+2];         //提取一行的第三个字节

              for(j=0;j<8;j++)

              {                  

                     if(buffer&mask)

                     {

                            PutPixel(x+j+16,y+i,color);           //为笔画上色

                     }

                     mask=mask>>1;                  

              }

       }

}
//绘制大小为8×16的ASCII码

void Draw_ASCII(int x,int y,int color, unsigned char ch[])

{

       unsigned short int i,j;

       unsigned char mask,buffer;

      

       for(i=0;i<16;i++)

       {

              mask=0x80;

              buffer=ch[i];

              for(j=0;j<8;j++)

              {                  

                     if(buffer&mask)

                     {

                            PutPixel(x+j,y+i,color);

                     }

                     mask=mask>>1;                  

              }

       }

}


void Lcd_Tft_LTV350QV_F05_Init(void)//初始化LCD
{
    Lcd_Init();
 Lcd_PowerEnable(0, 1);
    Lcd_EnvidOnOff(1);  //turn on vedio
 Lcd_ClearScr(0xffff);  //fill all screen with some color
 
}

void Lcd_Tft_LTV350QV_F05_Test( void )
{
    //Uart_Printf("nTest LTS350Q1_PE1 (TFT LCD)!n");
  Lcd_Tft_LTV350QV_F05_Init();

 Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x1f)  )  ;  //clear screen
 Draw_Text16(160,120,0xffff,nian1616);

 Uart_Getch() ;  //等待输入字符,这里没有这个函数,在另一个文件中,因为只有停止或延时一定时间才能看清显示的内容

 Paint_Bmp( 0, 0, 320, 240, tu);//显示图片
 while(1);
}
//*************************************************************

你可能感兴趣的:(c,function,buffer,360,each,任务)