LCD Operation (S3C2440)

Publisher:数字梦行Latest update time:2019-05-10 Source: eefocusKeywords:LCD  S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Let's first briefly introduce the operating principle of LCD. As shown in the LCD schematic diagram below, each dot in it is a pixel.


Imagine an electron gun that emits light of various colors as it moves. There are many details here, so let's sort them out one by one.


How does the electron gun move?

Answer: There is a CLK clock line connected to the LCD. Every time CLK (high and low levels) is sent, the electron gun moves one pixel.


How is the color determined?

Answer: It is determined by the three groups of wires connecting the LCD: R (Red), G (Green), and B (Blue).


How does the electron gun know that it should jump to the next line?

Answer: There is an HSYNC signal line connected to the LCD. Every time a pulse (high or low level) is emitted, the electron gun jumps to the next line.


How does the electron gun know that it should jump to the origin?

Answer: There is a VSYNC signal line connected to the LCD. Every time a pulse (high or low level) is emitted, the electron gun jumps to the origin.


Where does the data on the RGB lines come from?

Answer: A video memory (FrameBuffer) is allocated in the internal memory, which stores the data to be displayed. The LCD controller reads the data from it and transmits it to the electron gun through three groups of RGB lines. The electron gun then projects the data onto the display screen in sequence.


Who sends the previous signal to the LCD?

Answer: The LCD controller in S3C2440 is used to control the signal.


The above is verified by JZ2440 schematic diagram, the LCD controller interface diagram is shown below. Chapter17 lesson1 002.jpg


①It is the clock signal. Every time a CLK comes, the electron gun moves one pixel;


② is used to transmit color data;


③ is the vertical synchronization signal, FRAME (frame);


④ is the horizontal synchronization signal, LINE;


Let's take a look at the LCD chip manual. Chapter17 lesson1 003.jpg


First, VLED+ and VLED- are the backlight power supplies. VDD and VDD are the LCD power supplies.


R0-R7, G0-G7, B0-B7 are red, green and blue color signals.


PCLK is the pixel clock signal. DISP is the pixel switch.


HSYNC and VSYNC are horizontal and vertical direction signals respectively.


DE data enable. X1, Y1, X2, Y2 are touch screen signals.


It can be seen that LCD has many signals, and these signals must be transmitted according to the timing diagram to display correctly. Refer to the timing of JZ2440_4.3-inch LCD manual_AT043TN24 as follows: Chapter17 lesson1 004.png


Starting from the smallest pixel, the electron gun gets data from the data lines Dn0-Dn7 at the falling edge of CLK (this development board is the falling edge), transmits it to the display screen, and then moves to the next position. The source of the data on Dn0-Dn7 is the FrameBuffer introduced earlier. In this way, it moves from the leftmost side of a row to the rightmost side of a row, completing the display of a row, assuming it is x.


After the last data of a row is printed, the Hsync line synchronization signal will be received. According to the timing diagram, an Hsync cycle can be roughly divided into five parts: thp, thb, 1/tc, thd, and thf. Thp is called the pulse width. This time cannot be too short. If it is too short, the electron gun may not recognize it. After the electron gun correctly recognizes thp, it will move from the rightmost end to the leftmost end. The time of this movement is thb, which is called the moving time. thf indicates how long it will take for Hsync to come after the rightmost pixel is displayed.


Similarly, when the electron gun moves from the top to the bottom row by row, the Vsync vertical synchronization signal moves the electron gun back to the top. In Vsync, tvp is the pulse width, tvb is the moving time, and tvf indicates how long it will take for Vsync to come after the bottom row of pixels is displayed. Assuming there are y rows in total, the resolution of the LCD is x*y.


For the display principle, you can refer to this blog: http://www.cnblogs.com/shangdawei/p/4760933.html


There is an LCD display configuration diagram as follows: Chapter17 lesson1 005.jpg


When an HSYNC signal is sent, the electron gun will move from the rightmost side to the leftmost side, spending the HBP duration, and after reaching the rightmost side, it will wait for the HSYNC signal to return after the HFP duration. Therefore, HBP and HFP determine the black frames on the left and right respectively.


Similarly, when a VSYNC signal is sent, the electron gun will move from the bottom to the top, spending the VBP time. After reaching the bottom, it will wait for the VFP time for the VSYNC signal to return. Therefore, VBP and VFP determine the black frames at the top and bottom respectively. The middle gray area is the effective display area.


Let's solve the last question: How many bits per pixel (BPP) does it occupy in the FrameBuffer? In the previous LCD pin function diagram, R0-R7, G0-G7, B0-B7, each pixel occupies 3*8=24 bits, that is, the BPP of the LCD in hardware is fixed.


Although the pins on the LCD are fixed, we can make choices based on actual conditions when using them. For example, our JZ2440 uses 16BPP, so the LCD only needs R0-R4, G0-G5, B0-B4 to connect to the SOC, 5+6+5=16BPP, and each pixel only occupies 16 bits of data.


Our idea of ​​writing a program is as follows:


Check the LCD chip manual to see the relevant timing parameters, resolution, and pin polarity;


Set the LCD controller register according to the above information to make it send the correct signal;


Allocate a FrameBuffer in the memory, use a certain number of bits to represent a pixel, and then tell the LCD controller the first address;


After that, the LCD controller can repeatedly take out the pixel data in the FrameBuffer, and send it to the electron gun with other control signals, and the electron gun will display it on the LCD. In the future, if we want to display an image, we only need to write a program to fill the corresponding data into the FrameBuffer, and the hardware will automatically complete the display operation.


The above content is reproduced from http://wiki.100ask.org/%E7%AC%AC017%E8%AF%BE_LCD%E7%BC%96%E7%A8%8B#.E7.AC.AC001.E8.8A.82_LCD.E7.A1.AC.E4.BB.B6.E5.8E.9F.E7.90.86


Let's start programming

Idea: Configure LCD related pins. Set LCD control registers, enable, and test.


The LCD used is 4.3 inches, set to 32BPP, and the pixels are x480, y272

The newly created files are lcddrv.c lcddrv.h lcdlib.c lcdlib.h.

In lcddrv.c, configure LCD related pins, initialize LCD and set LCD special registers. Configure to 32bpp

In lcdlib.c, the LCD is tested by calling the functions in LCDDRV to output full-screen red, green, and blue.


lcddrv.c



#include "lcddrv.h"


void Lcd_Port_Init(void)

{

    /* Initialize pin: backlight pin*/

GPBCON &= ~0x3;

GPBCON |= 0x01;


/* LCD dedicated pins */

GPCCON = 0xaaaaaaaa;

GPDCON = 0xaaaaaaaa;


/* PWREN */

GPGCON |= (3<<8);

    

}


void TFT_Lcd_Init(void)

{

int addr, fb_base;

/* 

         * Set the LCD controller's control registers LCDCON1~5

         * 1. LCDCON1:

         * Set the frequency of VCLK: VCLK(Hz) = HCLK/[(CLKVAL+1)x2]

         * Select LCD type: TFT LCD   

         * Set display mode: 32BPP

         * Disable LCD signal output first

         * 2. LCDCON2/3/4:

         * Set the time parameters of the control signal

         * Set the resolution, i.e. the number of rows and columns

         * Now, the display frequency can be calculated according to the formula:

         * When HCLK=100MHz,

         * Frame Rate = 1/[{(VSPW+1)+(VBPD+1)+(LIINEVAL+1)+(VFPD+1)}x

         *              {(HSPW+1)+(HBPD+1)+(HFPD+1)+(HOZVAL+1)}x

         * {2x(CLKVAL+1)/(HCLK)}]

         *            = 60Hz

         * 3. LCDCON5:

         * When the display mode is set to 8BPP, the data format in the palette is: 5:6:5

         * Set the polarity of HSYNC and VSYNC pulses (this needs to refer to the specific LCD interface signal): Invert

         * Byte swap enable

         */

LCDCON1 = (5<<8) | (3<<5) | (0xd<<1) ;

LCDCON2 = (1<<24) | (271<<14) | (1<<6) | (9<<0);

LCDCON3 = (1<<19) | (479<<8) | (1<<0);

LCDCON4 = (40<<0);

LCDCON5 = (0<<10) | (1<<9) | (1<<8) | (0<<7) | (0<<6) | (0<<5) | (1<<11) | 0;

fb_base = 0x33c00000;

addr = fb_base & ~(1<<31);

LCDSADDR1 = (addr >> 1);


addr = fb_base + 480*272*32/8;

addr >>=1;

addr &= 0x1fffff;

LCDSADDR2 = addr;


}


void TFT_Lcd_Enalbe(void)

{

/* Backlight pin: GPB0 */

GPBDAT |= (1<<0);

/* pwren: provide AVDD to LCD */

LCDCON5 |= (1<<3);

/* LCDCON1'BIT 0: Set whether the LCD controller outputs a signal*/

LCDCON1 |= (1<<0);

}



lcdlib.c



#include "lcdlib.h"



void lcd_test(void)

{

int x, y;

unsigned int *p2;

Lcd_Port_Init();

TFT_Lcd_Init();

TFT_Lcd_Enalbe();


/* Let the LCD output the entire screen in red */


/* 0xRRGGBB */


p2 = (unsigned int *)0x33c00000;

for (x = 0; x < 480; x++)

for (y = 0; y < 272; y++)

*p2++ = 0xff0000;

/* Let the LCD output the entire screen green */

p2 = (unsigned int *)0x33c00000;

for (x = 0; x < 480; x++)

for (y = 0; y < 272; y++)

*p2++ = 0x00ff00;


/* Let LCD output the entire screen blue */

p2 = (unsigned int *)0x33c00000;

for (x = 0; x < 480; x++)

for (y = 0; y < 272; y++)

*p2++ = 0x0000ff;

}




The experimental results are:

In LCD, the full screen is displayed first in red, then green, then blue.


Keywords:LCD  S3C2440 Reference address:LCD Operation (S3C2440)

Previous article:IIC read and write AT24Cxx (S3C2440)
Next article:Nand Flash Operation (S3C2440)

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号