stm32 controls lcd to write characters, draw lines, Chinese characters, etc.

Publisher:RainbowGardenLatest update time:2016-10-05 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Algorithm for drawing straight lines

         When drawing a straight line, due to the granularity of the display on the LCD, the problem of the pace of the x and y axes is distinguished. The problem of pace involves the problem of slope. Therefore, even if the line drawing algorithm is completed, it is necessary to pay attention to the direction of the x and y axes relative to the LCD. Now a relatively rough line drawing algorithm is implemented.

void lcd_line(u16 x1,u16 y1,u16 x2,u16 y2,u16 Color)

{

         u16 temp,x,y;

         Set_direction(0);

         if((x1 == x2) && (y1 == y2))

         {

                   //Draw the origin

                   LCD_open_windows(x1,y1,1,1);    

         }

         else if(abs(y1-y2)>abs(x1-x2))

         {

                 //Move along the y axis, determine the size and swap

                   if(y1 > y2)

                   {

                            x1 ^= x2 ^= x1 ^= x2;

                            y1 ^= y2 ^= y1 ^= y2;

                   }

                   for( y = y1 ; y <= y2 ; y ++ )

                   {

                            x = x1 + (y - y1) * (x2 - x1) / (y2 - y1);    

                            LCD_ColorPoint(x ,y ,Color);

                   }

         }

         else

         {

                   if(x1 > x2)

                   {

                            x1 ^= x2 ^= x1 ^= x2;

                            y1 ^= y2 ^= y1 ^= y2;

                   }

                   for( x = x1 ; x <= x2 ; x ++ )

                   {

                            y = y1 + (x - x1) * (y2 - y1) / (x2 - x1);    

                            LCD_ColorPoint(x ,y ,Color);

                   }

         }

}

         The main thing is to pay attention to the slope problem and understand the properties of LCD. The slope is greater than 1. You must know that only by moving along the y-axis can the x-axis be dense without an obvious breakpoint.

 

 

2. Write in ascii.

To write ASCII, you can first make a font, take the corresponding font, such as 8 * 16. Since the principle of writing ASCII on LCD is mainly to dot, you can write a simple program for A.

unsigned char code_A[]=

{

/*------------------------------------------------ ----------------------------------

; If the data is garbled, please check the font format settings and pay attention to selecting the correct modulus direction and byte order.

; Source file / text: A

; Width × height (pixels): 8×16

; Font format/size: monochrome dot matrix LCD font, horizontal mode, byte positive order/16 bytes

; Data conversion date: 2015/2/10 15:00:31

-------------------------------------------------- ----------------------------*/

//0x08,0x10,0x01, //Number of pixels in width, number of pixels in height, number of bytes in width, parameter settings are optional

0x00,0x00,0x00,0x08,0x08,0x0C,0x14,0x14,0x12,0x1E,0x22,0x21,0x21,0x73,0x00,0x00,

};

//8 * 16 ascii characters

void lcd_ascii(u16 x,u16 y,const u8 *str,u16 Color)

{

    u8 i , j;

         u8 temp;

            

    for (i = 0;i < 16; i++)

    {

                   temp = str[i];

                   for(j = 0 ; j < 8 ; j ++)

                   {       

                            if((temp >> (7 - j) ) & 0x01 == 0x01)

                            {

                                     LCD_ColorPoint(x + (j) ,y + i,Color);         

                            }

                   }       

    }                           

}

The main principle is to get the value of each bit to be displayed, and if it is 1, just write the corresponding value.

 

 

 

 

 

 

unsigned char code_A_24x48[]=

{

/*------------------------------------------------ ----------------------------------

; If the data is garbled, please check the font format settings and pay attention to selecting the correct modulus direction and byte order.

; Source file / text: A

; Width × height (pixels): 24×48

; Font format/size: monochrome dot matrix LCD font, horizontal mode, byte sequence/144 bytes

; Data conversion date: 2015/2/10 15:09:19

-------------------------------------------------- ----------------------------*/

//0x18,0x30,0x03, //Number of pixels in width, number of pixels in height, number of bytes in width, parameter settings are optional

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x38,0x00,0x00,0x3C,0x00,0x00,0x7C,

0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x6C,0x00,0x00,0xCE,0x00,0x00,0xCE,0x00,

0x00,0xCE,0x00,0x00,0xC6,0x00,0x01,0x87,0x00,0x01,0x87,0x00,0x01,0x87,0x00,0x01,

0x83,0x00,0x03,0x03,0x80,0x03,0x03,0x80,0x03,0x03,0x80,0x03,0x03,0x80,0x06,0x01,

0xC0,0x07,0xFF,0xC0,0x06,0x01,0xC0,0x06,0x01,0xC0,0x0C,0x01,0xE0,0x0C,0x00,0xE0,

0x0C,0x00,0xE0,0x0C,0x00,0xE0,0x18,0x00,0xF0,0x18,0x00,0x70,0x18,0x00,0x70,0x18,

0x00,0x70,0x38,0x00,0x78,0xFE,0x01,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

 

 

void lcd_ascii_24x48(u16 x,u16 y,const u8 *str,u16 Color)

{

 

    u8 i,j,k;

         u8 buffer[3];

      

    for (i = 0;i < 48; i++)

    {

                   for(j = 0; j < 3 ; j ++)

                   {

                     buffer[j] = str[i * 3 + j];

                   }

 

            for( j = 0; j < 3 ; j ++)

            {

                         for (k = 0 ; k < 8 ; k++)

                            {

                                   if( ( buffer[j] >> (7 - k)) & 0x01 == 0x01)

                                     {

                                               LCD_ColorPoint(x + 8 * (j) + k,y + i,Color);

                                     }

                         }

                   }

         }

                                 

}

 

3. Write Chinese characters

 

unsigned char yuan[]=

{

/*------------------------------------------------ ----------------------------------

; If the data is garbled, please check the font format settings and pay attention to selecting the correct modulus direction and byte order.

; Source file / text: Yuan

; Width × height (pixels): 48 × 48

; Font format/size: monochrome dot matrix LCD font, horizontal mode, byte positive sequence/288 bytes

; Data conversion date: 2015/2/10 13:17:47

-------------------------------------------------- ----------------------------*/

//0x30,0x30,0x06, //Number of pixels in width, number of pixels in height, number of bytes in width, parameter settings are optional

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,

0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,

0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x0C,0x00,0x00,0x00,0x00,0xC0,0x1E,0x00,

0x00,0x1F,0xFF,0xFF,0xFF,0x00,0x00,0x08,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,

0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x40,0x00,0x00,

0x00,0xC0,0x00,0xE0,0x07,0xFF,0xFF,0xFF,0xFF,0xF0,0x03,0xFF,0xFF,0xFF,0xFF,0xF8,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x10,0x00,0x00,0x06,0x00,0x00,

0x3C,0x00,0x00,0x07,0xFF,0xFF,0xFC,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,

0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,

0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0xFF,0xFF,

0xF8,0x00,0x00,0x07,0xFF,0xFF,0xF8,0x00,0x00,0x07,0x0F,0x10,0x31,0x80,0x00,0x04,

0x1E,0x18,0x03,0xC0,0x00,0x00,0x3C,0x08,0x07,0xE0,0x00,0x00,0x78,0x0C,0x0F,0x00,

0x00,0x00,0xF8,0x06,0x1C,0x00,0x00,0x01,0xF8,0x07,0x70,0x00,0x00,0x07,0xB8,0x03,

0xC0,0x00,0x00,0x0E,0x38,0x01,0xC0,0x00,0x00,0x1C,0x38,0x00,0xE0,0x00,0x00,0x70,

0x38,0x00,0x70,0x00,0x01,0xC0,0x38,0x10,0x7C,0x00,0x03,0x00,0x38,0xE0,0x3F,0x00,

0x0C,0x00,0x3B,0xC0,0x0F,0xE0,0x10,0x00,0x3F,0x00,0x07,0xFC,0x00,0x00,0x7E,0x00,

0x03,0xF0,0x00,0x00,0x38,0x00,0x00,0xE0,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

 

 

//lcd displays 48 * 48 characters

void lcd_show_48x48(u16 x,u16 y,const u8 *str,u16 Color)

{

    u8 i,j,k;

         u8 buffer[6];

      

    for (i = 0;i < 48; i++)

    {

                   for(j = 0; j < 6 ; j ++)

                   {

                     buffer[j] = str[i * 6 + j];

                   }

                  

                   for( j = 0; j < 6 ; j ++)

                   {

                            for (k = 0 ; k < 8 ; k++)

                            {

                                  if( ( buffer[j] >> 7 - k) & 0x01 == 0x01)

                                     {

                                               LCD_ColorPoint(x + 8 * (j) + k,y + i,Color);

                                     }

                      }

                   }

    }

}

Reference address:stm32 controls lcd to write characters, draw lines, Chinese characters, etc.

Previous article:stm32 control DS1302
Next article:IAP learning of stm32

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号