mini2440 bare metal program TopPoly 3.5 LCD driver TopPoly-TD035STED4

Publisher:devilcoreLatest update time:2022-03-21 Source: eefocusKeywords:mini2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Regarding MDK configuration, please see the previous article

How to light up the LED lamp with mini2440 bare metal program based on MDK4.11 version

http://hi.baidu.com/如来大悲/blog/item/c6150233be4692a45edf0e02.html

/**************************************************************
The initial and control for 640×480 16Bpp TFT LCD----VGA
**************************************************************/
#define rGPCCON    (*(volatile unsigned *)0x56000020) //Port C control
#define rGPCDAT    (*(volatile unsigned *)0x56000024) //Port C data
#define rGPCUP     (*(volatile unsigned *)0x56000028) //Pull-up control C

#define rGPDCON    (*(volatile unsigned *)0x56000030) //Port D control
#define rGPDDAT    (*(volatile unsigned *)0x56000034) //Port D data
#define rGPDUP     (*(volatile unsigned *)0x56000038) //Pull-up control D

#define rGPGCON    (*(volatile unsigned *)0x56000060) //Port G control
#define rGPGDAT    (*(volatile unsigned *)0x56000064) //Port G data
#define rGPGUP     (*(volatile unsigned *)0x56000068) //Pull-up control G

// LCD CONTROLLER
#define rLCDCON1    (*(volatile unsigned *)0x4d000000) //LCD control 1
#define rLCDCON2    (*(volatile unsigned *)0x4d000004) //LCD control 2
#define rLCDCON3    (*(volatile unsigned *)0x4d000008) //LCD control 3
#define rLCDCON4    (*(volatile unsigned *)0x4d00000c) //LCD control 4
#define rLCDCON5    (*(volatile unsigned *)0x4d000010) //LCD control 5
#define rLCDSADDR1 (*(volatile unsigned *)0x4d000014) //STN/TFT Frame buffer start address 1
#define rLCDSADDR2 (*(volatile unsigned *)0x4d000018) //STN/TFT Frame buffer start address 2
#define rLCDSADDR3 (*(volatile unsigned *)0x4d00001c) //STN/TFT Virtual screen address set
#define rREDLUT     (*(volatile unsigned *)0x4d000020) //STN Red lookup table
#define rGREENLUT   (*(volatile unsigned *)0x4d000024) //STN Green lookup table
#define rBLUELUT    (*(volatile unsigned *)0x4d000028) //STN Blue lookup table
#define rDITHMODE   (*(volatile unsigned *)0x4d00004c) //STN Dithering mode
#define rTPAL       (*(volatile unsigned *)0x4d000050) //TFT Temporary palette
#define rLCDINTPND (*(volatile unsigned *)0x4d000054) //LCD Interrupt pending
#define rLCDSRCPND (*(volatile unsigned *)0x4d000058) //LCD Interrupt source
#define rLCDINTMSK (*(volatile unsigned *)0x4d00005c) //LCD Interrupt mask
#define rTCONSEL     (*(volatile unsigned *)0x4d000060) //LPC3600 Control --- edited by junon
#define PALETTE     0x4d000400       //Palette start address

#define U8 unsigned char
#define U16 unsigned short
#define U32 unsigned int

extern const unsigned char sunflower_240x320[];

#define LCD_WIDTH 240
#define LCD_HEIGHT 320
#define LCD_PIXCLOCK 4

#define LCD_RIGHT_MARGIN 36
#define LCD_LEFT_MARGIN 19
#define LCD_HSYNC_LEN 5

#define LCD_UPPER_MARGIN 1
#define LCD_LOWER_MARGIN 5
#define LCD_VSYNC_LEN 1

#define LCD_XSIZE LCD_WIDTH
#define LCD_YSIZE LCD_HEIGHT
#define SCR_XSIZE LCD_WIDTH
#define SCR_YSIZE LCD_HEIGHT


unsigned short LCD_BUFFER[SCR_YSIZE][SCR_XSIZE];

 

/**************************************************************
640×480 TFT LCD data and control port initialization
**************************************************************/
static void Lcd_Port_Init( void )
{
    rGPCUP=0xffffffff; // Disable Pull-up register
    rGPCCON=0xaaaa02a8; //Initialize VD[7:0],VM,VFRAME,VLINE,VCLK

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

/**************************************************************
640×480 TFT LCD功能模块初始化
**************************************************************/
static void LCD_Init(void)
{
#define M5D(n) ((n)&0x1fffff)
#define LCD_ADDR ((U32)LCD_BUFFER)
rLCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
   rLCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
   rLCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
   rLCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);

#if !defined(LCD_CON5)
#    define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
#endif
    rLCDCON5   = LCD_CON5;

    rLCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0);
    rLCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
    rLCDSADDR3 = LCD_WIDTH;       

    rLCDINTMSK |= 3;
rTCONSEL   &= (~7);

   rTPAL     = 0x0;
   rTCONSEL &= ~((1<<4) | 1);

   
}

/******************************************************************
LCD video and control signal output or stop, 1 to turn on video output
**************************************************************/
static void Lcd_EnvidOnOff(int onoff)
{
    if(onoff==1)
rLCDCON1|=1; // ENVID=ON
    else
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}

/**************************************************************
320×240 8Bpp TFT LCD 电源控制引脚使能
**************************************************************/
static void Lcd_PowerEnable(int invpwren,int pwren)
{
    //GPG4 is setted as LCD_PWREN
    rGPGUP = rGPGUP|(1<<4); // Pull-up disable
    rGPGCON = rGPGCON|(3<<8); //GPG4=LCD_PWREN
   
    //Enable LCD POWER ENABLE Function
    rLCDCON5 = rLCDCON5&(~(1<<3))|(pwren<<3);   // PWREN
    rLCDCON5 = rLCDCON5&(~(1<<5))|(invpwren<<5);   // INVPWREN
}


/******************************************************************
640×480 TFT LCD single pixel display data output
***********************************************************/
static void PutPixel(U32 x,U32 y,U16 c)
{
    if(x   LCD_BUFFER[(y)][(x)] = c;
}

/**************************************************************
640×480 TFT LCD full screen fills specific color units or clears the screen
***********************************************************/
static void Lcd_ClearScr( U16 c)
{
unsigned int x,y ;
  
    for( y = 0 ; y < SCR_YSIZE ; y++ )
    {
    for( x = 0 ; x < SCR_XSIZE ; 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, U16 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;
     }
    }
   }
}
}


/******************************************************************
Fill a rectangle with color on the LCD screen
***********************************************************/
static void Glib_FilledRectangle(int x1,int y1,int x2,int y2, U16 color)
{
    int i;

    for(i=y1;i<=y2;i++)
Glib_Line(x1,i,x2,i,color);
}

/******************************************************************
Draw a picture of a specified size at the specified coordinate point on the LCD screen
***********************************************************/
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 = 0 ; y < l ; y++ )
    {
    for( x = 0 ; x < h ; x++ )
    {
       c = bmp[p+1] | (bmp[p]<<8) ;

    if ( ( (x0+x) < SCR_XSIZE) && ( (y0+y) < SCR_YSIZE) )
     LCD_BUFFER[y0+y][x0+x] = c ;

       p = p + 2 ;
    }
    }
}

/**************************************************************
**************************************************************/
void TFT_LCD_Init(void)
{

    Lcd_Port_Init();
LCD_Init();
//LcdBkLtSet( 70 ) ;
Lcd_PowerEnable(0, 1);
    Lcd_EnvidOnOff(1);   //turn on vedio

    Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) );

Glib_FilledRectangle(0,0,240,320,0xffff);//Display a rectangle on the full screen
Paint_Bmp(0, 0, 240, 320, sunflower_240x320);//Display an image

}
int main()
{
TFT_LCD_Init();
}
//main.c(343): warning: #1-D: last line of file ends without a newline
//MDK likes to add a blank line at the end, otherwise a warning message will appear.


Keywords:mini2440 Reference address:mini2440 bare metal program TopPoly 3.5 LCD driver TopPoly-TD035STED4

Previous article:LCD of mini2440 bare machine
Next article:S3C2440 bare metal learning [2] - LCD driver principle and code analysis [I]

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号