STM32 Learning Road - LCD (3)

Publisher:花海鱼Latest update time:2018-04-17 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


  1. void lcd_DrawPicture(u16 StartX,u16 StartY,u8 Dir,u8 *pic)  

  2. {  

  3.   u32  i=8, len;  

  4.   u16 temp,x,y;  

  5.         

  6.   /**************************************/  

  7.     /*a1 length: 240 width: 400*/  

  8.     /*a2 Length: 400 Width: 240*/  

  9.       

  10.   x=((uint16_t)(pic[2]<<8)+pic[3])-1; //Get the length of the image from the image array  

  11.   y=((uint16_t)(pic[4]<<8)+pic[5])-1; //Get the height of the image from the image array      

  12.   

  13.   if(Dir==0){  

  14.     LCD_WR_CMD(0x0003,0x1030); //Image display direction is from the bottom left, row and column increments  

  15.         LCD_WR_CMD(0x0210, StartX); //Horizontal display area start address 0-239  

  16.     LCD_WR_CMD(0x0211, StartX+x); //End address of horizontal display area 0-239  

  17.     LCD_WR_CMD(0x0212, StartY); //Vertical display area start address 0-399  

  18.     LCD_WR_CMD(0x0213, StartY+y); //End address of vertical display area 0-399  

  19.     

  20.     LCD_WR_CMD(0x0200, StartX); //Horizontal display area address  

  21.     LCD_WR_CMD(0x0201, StartY); //vertical display area address  

  22.   }    

  23.   else if(Dir==1){  

  24.     LCD_WR_CMD(0x0003,0x1018); //Image display direction is from the bottom left, row increasing, column decreasing  

  25.         LCD_WR_CMD(0x0210, StartY); //Horizontal display area start address 0-239  

  26.     LCD_WR_CMD(0x0211, StartY+y); //End address of horizontal display area 0-239  

  27.     LCD_WR_CMD(0x0212, 399-(x+StartX)); //Vertical display area start address 0-399  

  28.     LCD_WR_CMD(0x0213, 399-StartX); //Vertical display area end address 0-399  

  29.     

  30.     LCD_WR_CMD(0x200, StartY); //Horizontal display area address  

  31.     LCD_WR_CMD(0x201, 399-StartX); //vertical display area address  

  32.   }    

  33.   LCD_WR_REG(0x0202); //Write data to the display area  

  34.   

  35.    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    

  36.   

  37.   while(i<(len+8)) { //Start incrementing from the 9th position of the image array  

  38.     temp=(uint16_t)( pic[i]<<8)+pic[i+1]; //16-bit bus, need to send 2 bytes of data at a time  

  39.     LCD_WR_Data(temp); //Send the extracted 16-bit pixel data to the display area  

  40.     i=i+2; //Add 2 to the modulo position to get the next pixel data  

  41.   }  

  42. }  

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



  1. while(i<(len+8)) { //Start incrementing from the 9th position of the image array  

  2.     temp=(uint16_t)( pic[i]<<8)+pic[i+1]; //16-bit bus, need to send 2 bytes of data at a time  

  3.     LCD_WR_Data(temp); //Send the extracted 16-bit pixel data to the display area  

  4. 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.


Keywords:STM32 Reference address:STM32 Learning Road - LCD (3)

Previous article:STM32F4——TFT-LCD principle and FSMC
Next article:STM32-FSMC-NOR FLASH

Recommended ReadingLatest update time:2024-11-16 15:57

Is the first year of fingerprint scanner under LCD screen coming?
    Recently, fingerprint recognition under LCD screens has become a hot topic in the mobile phone industry. Fingerprints are currently the most widely used method for secure unlocking and payment on smartphones. Currently, the fingerprint recognition function under the screen is mostly implemented in OLED screens,
[Mobile phone portable]
Is the first year of fingerprint scanner under LCD screen coming?
【STM32】GPIO related configuration registers, library functions, bit operations
STM32F1xx official information: "STM32 Chinese Reference Manual V10" - Chapter 8 General and Multiplexed Function IO (GPIO and AFIO) "Cortex-M3 Definitive Guide (Chinese)" Chapter 5 Bit-band Operation Hardware Hookup Assume that the hardware connection of the marquee experiment is as shown in the figure above,
[Microcontroller]
【STM32】GPIO related configuration registers, library functions, bit operations
Use 74HC595 to change LCD1602 into a serial data interface
The interface of LCD1602 is parallel, it has 8 data lines and 3 control lines. So 11 lines are needed to control its normal operation. Although it can also work in the form of 4-bit data lines, the most streamlined form is 6 lines. A netizen wants to use 74HC595 for serial-to-parallel conversion and wants to use 4 l
[Microcontroller]
Use 74HC595 to change LCD1602 into a serial data interface
Error: Flash Download failed - " appears during stm32 debugging
That is, the Flash programming algorithm in MDK is not configured or is not configured correctly. After adding it,
[Microcontroller]
Error: Flash Download failed -
Using STM32 DSP library for FFT transformation
/* *************************************************** *************************************************** ***** FileName:dsp_asm.h **************************************** *************************************************** *************** */ #ifndef __DSP_ASM_H__ #define __DSP_ASM_H__ ***********************
[Microcontroller]
STM32 Development Board Learning Diary-[3] TIM timer output comparison
Use Timer for periodic timing   In some applications of STM32, users have the requirement to execute certain programs periodically. The timer can be used to generate a fixed time period to meet such requirements. STM32 related features: STM32 advanced timers TIM1, TIM8, general timers TIM2, TIM3, TIM4, TIM5; the
[Microcontroller]
STM32 serial port receives character string and controls LED
Serial port related configuration GPIO_InitTypeDef GPIO_InitStructure;     USART_InitTypeDef USART_InitStructure;     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;             GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;    GPIO_InitStru
[Microcontroller]
STM32 serial port receives character string and controls LED
Solar-LED Street Light Solution Based on STM32 MCU
As fossil energy is decreasing and the problem of global warming caused by excessive greenhouse gas emissions is becoming more and more important, people are actively developing various types of renewable energy on the one hand, and advocating green environmental protection technologies for energy conservation and e
[Microcontroller]
Solar-LED Street Light Solution Based on STM32 MCU
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号