OLED display picture

Today, a friend asked me about taking fonts. I didn't have much contact with the software for taking fonts before. Today, I tried imag2lcd to take out bmp files, and then displayed pictures through stm32 and oled.

First click Open to open a picture you want to display (some picture formats are not supported). The maximum width and height should be 128*64. After configuring according to the following figure, remember to adjust the brightness and contrast to make it clearer, and then set the its saved.Note the output image below (54, 64)

Open ptolcd2002, select the graphics mode in the mode, click on the same graphic as the folder in the software to open the saved bmp file with ptolcd2002, (remember the option, the image size under the help bar), here I am (54*64) - software If the problem is not clear, you can also view it in the output image below the previous imag2lcd software.

insert image description here

Then there is the configuration of the font, which is configured according to the code requirements as shown in the figure.

insert image description here

Then click to generate the font and put it into the prepared array, the following is the pig page I took out

unsigned char nao1[]=
{
    
    
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,
0xC0,0x40,0xC0,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0xE0,0x30,0x18,0x08,0x98,
0xF0,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x7E,
0xC1,0x86,0x86,0xCC,0x4C,0x20,0x1C,0x03,0x00,0x00,0x1C,0x2A,0x3E,0x2B,0x1D,0xE1,
0x53,0xF3,0x52,0xA4,0x46,0x0B,0x18,0x1C,0x23,0xC1,0xA1,0x31,0x0F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x06,0x04,0xE8,0x38,0x18,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0xC0,0x20,0x10,0x10,0x10,0x20,
0xC1,0x06,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xE0,0xC0,0x00,0x00,0x00,0x00,
0x00,0x3F,0x60,0xC0,0x83,0x04,0x08,0x18,0x10,0x10,0x10,0x18,0x08,0x04,0x00,0x00,
0x01,0x02,0x04,0x04,0x04,0x82,0xC1,0x38,0x0F,0x00,0x00,0x00,0x00,0xC0,0xE0,0x80,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x01,0x01,0x03,0x03,0x06,0x84,0xFC,0x1C,0x06,0x01,0x01,0x03,0x02,0x06,0x04,0x04,
0x04,0x0C,0x0C,0x0C,0x0C,0x0C,0x04,0x04,0x06,0x02,0x03,0x03,0x0E,0x78,0xCC,0x06,
0x86,0x43,0x43,0x81,0x03,0x03,0x80,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0xA0,0x20,0x20,0x20,0x20,0x40,0xC0,0x00,0x00,0xF8,0x1F,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0xFE,0xE1,0x22,0x22,0x12,0x0B,0x0F,0xC0,0x60,0x10,0x10,
0x10,0x90,0x60,0x00,0x00,0x00,0x80,0x40,0x41,0x42,0x42,0x42,0x42,0x43,0xC0,0x06,
0x07,0x04,0x04,0x04,0xC4,0x44,0x44,0x74,0x14,0x1C,0x1C,0xF4,0x04,0x04,0x04,0x04,
0x84,0x44,0x44,0x74,0x14,0x1C,0x1C,0xF4,0x04,0x04,0x04,0x04,0x07,0x00,0x02,0x60,
0x60,0xA0,0x21,0x21,0x21,0x21,0x21,0x20,0xC0,0x00,0x00,0x07,0x08,0x08,0x08,0x08,
0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x04,0x04,
0x04,0x07,0x00,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x04,0x07,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x04,0x04,0x04,0x03,0x00,
};

This is a project file sent by a friend. The code has been written by the merchant. It's really fragrant.

/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
{
    
     	
 unsigned int j=0;
 unsigned char x,y;
  
  if(y1%8==0) y=y1/8;      
  else y=y1/8+1;
	for(y=y0;y<y1;y++)
	{
    
    
		OLED_Set_Pos(x0,y);
    for(x=x0;x<x1;x++)
	    {
    
          
	    	OLED_WR_Byte(BMP[j++],OLED_DATA);	    	
	    }
	}
} 

The function has four formal parameters, x and y can be understood as rows and columns, x0 is the start column to be displayed, x1 is the end column, y0 is the start row, y1 is the end row (the row here is a multiple of 8), If the size of the output image above is (54, 64), then the difference between the start column and the end column must be 54, that is, x1-x0=54, and similarly (y1-y0)*8=64. Finally, the main function calls the OLED_DrawBMP(); function to display it.

 OLED_DrawBMP(73,0,127,8,nao1);	//靠右显示	
 OLED_DrawBMP(0,0,54,8,nao1);//靠左显示	

The above is the whole process. If there is any error, please point out the great God. If it is unclear, you can comment and communicate directly. If you need related software or programs, you can comment directly!

Guess you like

Origin blog.csdn.net/qq_52487856/article/details/120029561