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 there is an electron gun that emits light of various colors while moving. 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 a CLK (high or low level) is issued, the electron gun moves one pixel. How is the color determined? Answer: It is determined by the three groups of lines connected to 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 issued, 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 issued, the electron gun jumps to the origin. Where does the data on the RGB line come from? Answer: A display memory (FrameBuffer) is divided in the memory, which stores the data to be displayed. The LCD controller reads the data from it and transmits it to the electron gun through the three groups of RGB lines. The electron gun then hits the display screen in turn. Who sends the previous signal to the LCD? Answer: The LCD controller in the S3C2440 controls the signal. The above is verified by the JZ2440 schematic diagram. The LCD controller interface diagram is shown below. Chapter17 lesson1 002.jpg ① 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 (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 LCD power supplies. R0-R7, G0-G7, and B0-B7 are red, green, and blue color signals. PCLK is the pixel clock signal. DISP is the pixel switch. HSYNC and VSYNC are the horizontal and vertical signals respectively. DE data is enabled. X1, Y1, X2, and 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 be displayed correctly. Referring to the timing of JZ2440_4.3-inch LCD manual_AT043TN24, it is as follows: Chapter17 lesson1 004.png Starting from the smallest pixel, the electron gun gets data from the data line Dn0-Dn7 every time 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 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. When 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 pulse width, and 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 movement 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. The tvp in Vsync is the pulse width, tvb is the movement 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. When an HSYNC signal is sent, the electron gun will move from the rightmost end to the leftmost end, spending the HBP time. After reaching the rightmost end, it will wait for the HSYNC signal for the HFP time before returning. 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 VBP time. After reaching the bottom, it will wait for VFP time for VSYNC signal to come back. Therefore, VBP and VFP determine the black frame at the top and bottom respectively. The middle gray area is the effective display area. Let's solve the last question: how many bits of BPP (Bits Per Pixels) does each pixel occupy in 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 LCD in hardware is determined. Although the pins on the LCD are fixed, we can make trade-offs according to the actual situation 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. The idea of writing a program is as follows: Check the LCD chip manual to check the relevant time parameters, resolution, and pin polarity; Set the LCD controller register according to the above information to let it send the correct signal; Allocate a FrameBuffer in the memory, use a 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, match it with other control signals, and send it to the electron gun, which will then 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.