The function is copied from the example of struggle, which can be regarded as some notes. However, the annotations of the example of struggle are not very detailed. Today I went to the forum of Zhengdian Atom, and I felt that Zhengdian Atom did a really good job.
All the information is open source, and most of the questions on the forum are answered patiently. This is really a very, very good after-sales service! ! I also secretly downloaded the information to take a look, (*^__^*) Hehe...
OK, let's get to the point:
Development board: Struggle V5
LCD: 3 inches 400X240
Let’s go straight to the code
void lcd_DrawPicture(u16 StartX,u16 StartY,u8 Dir,u8 *pic)
{
u32 i=8, len;
u16 temp,x,y;
/**************************************/
/*a1 length: 240 width: 400*/
/*a2 Length: 400 Width: 240*/
x=((uint16_t)(pic[2]<<8)+pic[3])-1; //Get the length of the image from the image array
y=((uint16_t)(pic[4]<<8)+pic[5])-1; //Get the height of the image from the image array
if(Dir==0){
LCD_WR_CMD(0x0003,0x1030); //Image display direction is from the bottom left, row and column increments
LCD_WR_CMD(0x0210, StartX); //Horizontal display area start address 0-239
LCD_WR_CMD(0x0211, StartX+x); //End address of horizontal display area 0-239
LCD_WR_CMD(0x0212, StartY); //Vertical display area start address 0-399
LCD_WR_CMD(0x0213, StartY+y); //End address of vertical display area 0-399
LCD_WR_CMD(0x0200, StartX); //Horizontal display area address
LCD_WR_CMD(0x0201, StartY); //vertical display area address
}
else if(Dir==1){
LCD_WR_CMD(0x0003,0x1018); //Image display direction is from the bottom left, row increasing, column decreasing
LCD_WR_CMD(0x0210, StartY); //Horizontal display area start address 0-239
LCD_WR_CMD(0x0211, StartY+y); //End address of horizontal display area 0-239
LCD_WR_CMD(0x0212, 399-(x+StartX)); //Vertical display area start address 0-399
LCD_WR_CMD(0x0213, 399-StartX); //Vertical display area end address 0-399
LCD_WR_CMD(0x200, StartY); //Horizontal display area address
LCD_WR_CMD(0x201, 399-StartX); //vertical display area address
}
LCD_WR_REG(0x0202); //Write data to the display area
len=2*((uint16_t)(pic[2]<<8)+pic[3])*((uint16_t)(pic[4]<<8)+pic[5]); //Calculate the number of bytes occupied by the image
while(i<(len+8)) { //Start incrementing from the 9th position of the image array
temp=(uint16_t)( pic[i]<<8)+pic[i+1]; //16-bit bus, need to send 2 bytes of data at a time
LCD_WR_Data(temp); //Send the extracted 16-bit pixel data to the display area
i=i+2; //Add 2 to the modulo position to get the next pixel data
}
}
This is the original example given by Struggle. The comments in it give the functions of each line later. Let's see how they are implemented in detail.
x=((uint16_t)(pic[2]<<8)+pic[3])-1; y=((uint16_t)(pic[4]<<8)+pic[5])-1;
Why do we need to calculate the length and width of the image in this way? At this time, we need to look at the array of the image. The image is converted into a hexadecimal array by the modulo software (Image2LCD is used here). It is a very long array, but
We only care about the first 8 characters here. This is the result of taking a 400X240 image (of course, only the first part)
This is the modulo of a 240X400 image:
I think the first 8 bits should be fixed, and the first 8 bits of the 240X400 format photos should be the same, and the 400X240 format should also be the same. Here I just downloaded two photos myself.
The result of the modulo is the same as the picture in the example given by Doudong, so I guess it is the same. I haven't studied it in detail. In addition, the modulo setting must be correct, so that the modulo result will be the same as above.
The same, the photo will be displayed normally, this issue will be discussed below. OK, back to the above analysis of length and width:
Now you can pick up a pen and do some calculations. Take 240X400 as an example: x=((uint16_t)(pic[2]<<8)+pic[3])-1; y=((uint16_t)(pic[4]<<8)+pic[5])-1;
pic[2] << 8 means 0x00 is shifted left by 8 bits, which is still 0x00, and then 0xF0 (decimal 240) is added, so x=240-1=239 (in order not to exceed the screen range)
Similarly, pic[4] << 8 is equal to 0x100, and then adding 0x90 is equal to 0x190 (decimal 400), so y=400-1=399;
The same is true for 400X240...
Then the next question is the display direction. dir=0 is vertical (240x400), dir=1 is horizontal (400x240), and then the next step is to write data. There are already comments above, so I won’t explain it here. If you don’t understand, you can read the previous article
len=2*((uint16_t)(pic[2]<<8)+pic[3])*((uint16_t)(pic[4]<<8)+pic[5]); Calculate the number of bytes occupied by the image. I don't quite understand it here. I don't know if I understand it correctly. According to my understanding, it is length x width. This is easy to understand.
Why do we need to multiply by 2? I think it is because we used two characters to calculate the length and width, so we need to multiply by 2 to divide it into 1 byte (these are written randomly, if you really know the correct answer, please help me solve it)
Next up
while(i<(len+8)) { //Start incrementing from the 9th position of the image array
temp=(uint16_t)( pic[i]<<8)+pic[i+1]; //16-bit bus, need to send 2 bytes of data at a time
LCD_WR_Data(temp); //Send the extracted 16-bit pixel data to the display area
i=i+2; //Add 2 to the modulo position to get the next pixel data
The initial value of i is 8, which is to skip the first 8 characters. This also shows that the first 8 characters should not be the content of the photo, but a prefix.
OK, that's it. Next, let's talk about the settings of the modeling software. If you are not careful, this thing will also make you spend a lot of time. Here we use Image2LCD
The first thing to note is the input settings: the maximum width and maximum height should match your photo. This photo is 400X240.
The second point to note is the output image: the output image is not (400,240) at the beginning. You need to set the maximum width and maximum height first, and then reload it as above, it will output the correct size format, otherwise the image cannot be displayed normally, or cannot be displayed at all.
The third point to note is that the high position is in front: you must check it, otherwise the image display will be abnormal!
As for how many bits of images are output, it depends on your LCD interface. For a 16-bit parallel port, choose 16-bit true color.
OK~ That's it. I won't upload the picture of the development board because the photo taken with my cell phone is not good.
Previous article:STM32F4——TFT-LCD principle and FSMC
Next article:STM32-FSMC-NOR FLASH
Recommended ReadingLatest update time:2024-11-16 15:57
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Question: About multi-channel output voltage regulation
- Compile the kernel separately, and uboot generates many files. Which one should I use?
- I recently encountered a problem when drawing the board and pulling the wires. I was a little confused and didn't understand it very clearly, so I came to teach you about "RF radio frequency signals"
- Question about the maximum current allowed by the EN pin of the LDO power chip
- Bose small speaker disassembly and repair
- Understanding Electromagnetic Radiation
- [Me and Yatli] + When a door closes outside, a new door opens here!
- Technological innovation promotes outdoor diagnosis and treatment
- We see that body fat detection, high-frequency radio frequency circuits, or ultrasonic detection all use sine waves instead of triangle waves,...
- MY-R16-EK166 FAQ Reference Manual