当前位置:网站首页>Based on STM32F103 0.96 inch OLED LCD driver (IIC communication)

Based on STM32F103 0.96 inch OLED LCD driver (IIC communication)

2022-06-24 19:23:00 Me-Space

One 、 summary

OLED The driving methods are 8080、6800、3 Line /4 Line SPI as well as IIC, Able to display characters 、 Picture of Chinese characters , No word library needs to obtain the display content array through the mold taking software . This experiment uses IIC Communication protocol ,SSD1306 Driver chip OLED screen .

Two 、 Experimental materials

1、0.96 " OLED screen .
2、 Minimum system STM32F103C8T6.
3、 There are several DuPont lines .

3、 ... and 、 connection

Function pin GPIO
GNDGND
VCCVCC
SCLPA6
SDAPA7

Four 、 Program code

1、GPIO initialization

void Oled_Init(void)
{
    
	IIC_Pin_Init();//iic Pin initialization 
	
	OLED_Send_Command(0xAE);//--turn off oled panel
	OLED_Send_Command(0x02);//---SET low column address
	OLED_Send_Command(0x10);//---SET high column address
	OLED_Send_Command(0x40);//--SET start line address SET Mapping RAM Display Start Line (0x00~0x3F)
	OLED_Send_Command(0x81);//--SET contrast control register
	OLED_Send_Command(0xCF); // SET SEG Output Current Brightness
	OLED_Send_Command(0xA1);//--SET SEG/Column Mapping 0xa0 Reverse left and right  0xa1 normal 
	OLED_Send_Command(0xC8);//SET COM/Row Scan Direction 0xc0 Up and down reversed  0xc8 normal 
	OLED_Send_Command(0xA6);//--SET normal display
	OLED_Send_Command(0xA8);//--SET multiplex ratio(1 to 64)
	OLED_Send_Command(0x3f);//--1/64 duty
	OLED_Send_Command(0xD3);//-SET display offSET Shift Mapping RAM Counter (0x00~0x3F)
	OLED_Send_Command(0x00);//-not offSET
	OLED_Send_Command(0xd5);//--SET display clock divide ratio/oscillator frequency
	OLED_Send_Command(0x80);//--SET divide ratio, SET Clock as 100 Frames/Sec
	OLED_Send_Command(0xD9);//--SET pre-charge period
	OLED_Send_Command(0xF1);//SET Pre-Charge as 15 Clocks & Discharge as 1 Clock
	OLED_Send_Command(0xDA);//--SET com pins hardware configuration
	OLED_Send_Command(0x12);
	OLED_Send_Command(0xDB);//--SET vcomh
	OLED_Send_Command(0x40);//SET VCOM Deselect Level
	OLED_Send_Command(0x20);//-SET Page Addressing Mode (0x00/0x01/0x02)
	OLED_Send_Command(0x02);//
	OLED_Send_Command(0x8D);//--SET Charge Pump enable/disable
	OLED_Send_Command(0x14);//--SET(0x10) disable
	OLED_Send_Command(0xA4);// Disable Entire Display On (0xa4/0xa5)
	OLED_Send_Command(0xA6);// Disable Inverse Display On (0xa6/a7) 
	OLED_Send_Command(0xAF);//--turn on oled panel
	OLED_Send_Command(0xAF); /*display ON*/ 
	
	OLED_Clear(0x00); // Clear the screen 
}

2、 Writing data

void Oled_Write_Data(u8 data)
{
    
	IIC_Start();
	IIC_Send_Data(0x78);// Address 
	IIC_Send_Data(0x40);// Writing data 
	IIC_Send_Data(data);// Instructions 
	IIC_Stop();
}

3、 Write orders

void OLED_Send_Command(u8 com)
{
    
	IIC_Start();
	IIC_Send_Data(0x78);// Address 
	IIC_Send_Data(0x00);// Write instructions   The first 6 Bit control write data / command 
	IIC_Send_Data(com);// Instructions 
	IIC_Stop();
}

4、 Clear the screen

void OLED_Clear(u8 clear_dat)
{
     
	u8 i = 0, j = 0;
	
	for(i = 0; i < 8; i++)
	{
    
		OLED_Send_Command(0xB0 + i);
		OLED_Send_Command(0X00);  // Low column address 
		OLED_Send_Command(0X10);  // High column address 
		for(j = 0; j < 128; j++)
		{
    
			Oled_Write_Data(clear_dat);
		}
	}

}

5、 Display position

void Oled_Address(u8 row,u8 col)
{
    
	OLED_Send_Command(0xB0 + row);
	OLED_Send_Command(0X10 + ((col & 0xf0) >> 4));  // High column address 
	OLED_Send_Command(0X00 + (col & 0x0f)); 
}

6、 Show characters

void Oled_Display_Char(u8 page,u8 col,char ch)
{
    
	u8 loca = ch - ' ';
	u8 i = 0;
	
	// Page address 
	Oled_Address(page,col);
	for(i = 0; i < 8; i++)
	{
    
		Oled_Write_Data(Aciss_8X16[loca * 16 + i]);
	}
	Oled_Address(page + 1,col);
	for(i = 0; i < 8; i++)
	{
    
		Oled_Write_Data(Aciss_8X16[loca * 16 + 8 + i]);
	}
}

7、 display string

void Oled_Display_String(u8 page,u8 col,char *str)
{
    
	while(*str)
	{
    
		Oled_Display_Char(page,col,*str);
		col += 8;
		str++;
	}
}

8、 Display Chinese characters or pictures

void Oled_Display_Pic(u8 wight,u8 high,u8 page,u8 col,u8 *str)
{
    
	u8 i = 0, j = 0;
	
	for(i = 0; i < high / 8; i++)
	{
    
		Oled_Address(page + i,col);
		for(j = 0; j < wight;j++)
		{
    
			Oled_Write_Data(str[wight * i + j]);
		}
	}
}

9、 The main function

int main(void)
{
    
	char buf[] = {
    "There is no luck"};
	char buf1[] = {
    "There is only"};
	char buf2[] = {
    "word."};
	char author[] = {
    "Qing"};
	
	Sys_Delay_Init();
	Oled_Init();
// Oled_Display_Char(0,0,'A');// Displays a single character 
	
	//There is no luck.There is only work. Luck doesn't exist , Hard work is the last word .
	Oled_Display_String(0,0,buf); // display string 
	Oled_Display_String(2,0,buf1); // display string 
	Oled_Display_String(4,0,buf2); // display string 
	Oled_Display_String(6,80,author);
	while(1)
	{
    
		
	}
}

5、 ... and 、 Experimental results

 Insert picture description here

Procedures and relevant information
link :https://pan.baidu.com/s/1Bo093SotTLxs1NgNwa01nQ
Extraction code :ygrv

If there is any mistake, please point out , thank you !

原网站

版权声明
本文为[Me-Space]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211331529624.html