0.96 oled display picture

oled display picture

Previously used oled to display Chinese characters, characters and numbers. This article briefly introduces how to use oled to display pictures.
0.96 inch OLED
0.96 inch oled can only display pictures with a


Insert picture description here
single color and the pixels are not larger than 128 64, so the picture that suits your needs is not good Find. So we need to use other software to make pictures that meet the requirements. Here I used Image2Lcd and PCtoLCD2002 software. 1. Open the Image2Lcd software, click Open to select the picture Output data type: BMP format ( .bmp)
Scan mode: Horizontal scan
Output grayscale: Monochrome
In the lower left corner you can see that the input width and height of the picture are 1024, so you need to modify the width The height is within the range of 128x64.
Click Save.
2. PCtoLCD2002
opens the software, selects the graphics mode as the mode , opens the BMP picture just exported from Image2Lcd,
Insert picture description here
clicks on the settings, and sets the format. When setting the format here, you should set it according to your own OLED. The OLEDs produced by different manufacturers will be slightly different.
Finally, click to generate the font.
Insert picture description here
After the modulus is successful, you must write the program code
(I use the OLED to communicate with iic)
1 . Add a bmp.h file to the project,
create an array, and put the modulo data of the picture into the array.
2. Writing the main function.
This is the function that displays the picture in the oled.c file (when buying oled, it will be blank from after-sales Prostitutes)

//x0,y0:起点坐标
//x1,y1:终点坐标
//BMP[]:要写入的图片数组
void OLED_ShowPicture(u8 x0,u8 y0,u8 x1,u8 y1,u8 BMP[])
{
	u32 j=0;
	u8 x=0,y=0;
	if(y%8==0)y=0;
	else y+=1;
	for(y=y0;y<y1;y++)
	 {
		 OLED_WR_BP(x0,y);
		 for(x=x0;x<x1;x++)
		 {
			 OLED_WR_Byte(BMP[j],OLED_DATA);
			 j++;
     }
	 }
	 
}

With the function shown in the picture, you can call it directly in the main function, and finally update the display to the
specific process of oled , but I have encountered several problems that have not been resolved.
1. The keil5 software reports an error
after introducing the array call function, and compile the project An error occurred: expected a ";", and there was no missing ";" when the error was reported. Later I thought that the Chinese-English input method was wrong, so I deleted it and wrote it again, but I still reported an error. Various searches on the Internet also yielded no results. Finally, with the help of my companion, I found that adding ";" before the function definition solved it. It should be a bug. In short, it is very strange.
2. The image display flickers After
downloading the program, it is found that the image on oled always flickers in a very narrow range. My first reaction was that the width of the image was set incorrectly. I went back to the program and added the end point coordinates of the image display. After re-downloading, a new problem appeared, and the image disappeared after the display. When the board is powered off and on again, the image is still displayed after flashing, and then not displayed. At present, I haven't figured out the reason for this problem, nor have I found a solution. I can only continue to look for it next.

I’m a noob, please forgive me for any errors in the text.

Guess you like

Origin blog.csdn.net/m0_46507918/article/details/109139058