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.
Previous article:IIC read and write AT24Cxx (S3C2440)
Next article:Nand Flash Operation (S3C2440)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- In-depth Linux kernel architecture (Chinese version)
- Ask for points
- [GD32E503 Review] + Transplanting TencentOS-tiny
- Piezoelectric Driven Power Amplifier Application--Piezoelectric Ceramic Impedance Test
- Altium Designer v21.7.1.17
- VGA display image
- Is there any chip solution with dual adjustable PWM frequency and duty cycle?
- Basic principles and driving waveforms of BLDC six-step commutation method
- [Xianji HPM6750EVKMINI Review] 5# HPM6750 Camera Usage
- MSP430FR604x, MSP430FR504x for Air and Water Flow Metering Applications Datasheet