Steps for STM32F1 to drive OLED

To sum up the concept of OLED above, the OLED module needs to pay attention to:

  1. To drive the communication interface of the OLED module and control the control pins of some OLED modules.

  2. To modify the value of the SSD1309 register to initialize the OLED module (method of issuing commands)

  3. Set the memory address mode, this will affect the string display driver

  4. Familiar with the commands of the SSD1309 controller, such as contrast, switch, scrolling and other commands. // Set some commands to achieve the effect of scrolling.

  5. The memory address mode generally used is the page address mode. After the display RAM is read and written, the column address pointer is automatically incremented by one. If the column address pointer reaches the end address of the column, the column address pointer is reset to the column start address and the page address pointer does not change.

  6. There is 128 * 64 bit of video memory, which can be defined like this: uint8_t OLED_GRAM [128] [8];

  7. OLED video memory, storage format is as follows.

[0]0 1 2 3 ... 127    

[1]0 1 2 3 ... 127    

[2]0 1 2 3 ... 127    

[3]0 1 2 3 ... 127    

[4]0 1 2 3 ... 127    

[5]0 1 2 3 ... 127    

[6]0 1 2 3 ... 127    

[7]0 1 2 3 ... 127

 

Combining your own projects, the steps to drive OLED:

  1. Make sure the OLED module and STM32F1 hardware wiring is correct. Need to connect and connect 7 pins, and handle the limiting pins.

    1. Reset pin RES # 

    2. 4-wire SPI interface (SCLK, SDIN, CS #, D / C #) // D0 acts as SCLK, D1 acts as SDIN

    3. Power, ground 

    4. D2 should remain open. From pins D3 to D7, E and R / W # (WR #) # can be connected to external ground.

  2. Set the IO connected between STM32F1 and OLED module.

    1. Set RES #, D / C #, CS #, SCLK, SDIN output

  3. Initialize the OLED display module

    1. STM32F1 sends commands to the OLED module through the SPI interface to initialize the OLED module. Generally, the initialization parameters given by the manufacturer are used, and no excessive modification is required. . .

    2. Send a command to the OLED module, this command is to modify the OLED related registers.

    3. General settings:

      OLED_WR_Byte(0xAE,OLED_CMD); //关闭显示
      
          OLED_WR_Byte(0xD5,OLED_CMD); //设置时钟分频因子,震荡频率
      
          OLED_WR_Byte(80,OLED_CMD);   //[3:0],分频因子;[7:4],震荡频率
      
          OLED_WR_Byte(0xA8,OLED_CMD); //设置驱动路数
      
          OLED_WR_Byte(0X3F,OLED_CMD); //默认0X3F(1/64)
      
          OLED_WR_Byte(0xD3,OLED_CMD); //设置显示偏移
      
          OLED_WR_Byte(0X00,OLED_CMD); //默认为0
      
          OLED_WR_Byte(0x40,OLED_CMD); //设置显示开始行 [5:0],行数.                                            
      
          OLED_WR_Byte(0x8D,OLED_CMD); //电荷泵设置
      
          OLED_WR_Byte(0x14,OLED_CMD); //bit2,开启/关闭
      
          OLED_WR_Byte(0x20,OLED_CMD); //设置内存地址模式
      
          OLED_WR_Byte(0x02,OLED_CMD); //[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10;
      
          OLED_WR_Byte(0xA1,OLED_CMD); //段重定义设置,bit0:0,0->0;1,0->127;
      
          OLED_WR_Byte(0xC0,OLED_CMD); //设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数
      
          OLED_WR_Byte(0xDA,OLED_CMD); //设置COM硬件引脚配置
      
          OLED_WR_Byte(0x12,OLED_CMD); //[5:4]配置    
      
          OLED_WR_Byte(0x81,OLED_CMD); //对比度设置
      
          OLED_WR_Byte(0xEF,OLED_CMD); //1~255;默认0X7F (亮度设置,越大越亮)
      
          OLED_WR_Byte(0xD9,OLED_CMD); //设置预充电周期
      
          OLED_WR_Byte(0xf1,OLED_CMD); //[3:0],PHASE 1;[7:4],PHASE 2;
      
          OLED_WR_Byte(0xDB,OLED_CMD); //设置VCOMH 电压倍率
      
          OLED_WR_Byte(0x30,OLED_CMD); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc;
      
          OLED_WR_Byte(0xA4,OLED_CMD); //全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏)
      
          OLED_WR_Byte(0xA6,OLED_CMD); //设置显示方式;bit0:1,反相显示;0,正常显示                                   
      
          OLED_WR_Byte(0xAF,OLED_CMD); //开启显示    
      
          OLED_Clear();
      
      或者:
      
          OLED_WR_Byte(0xFD,OLED_CMD);    //Command Lock  ( SSD1309 use, SSD1305 no use )
      
          OLED_WR_Byte(0x12,OLED_CMD);    // Unlock Driver IC (0x12/0x16)       
      
          OLED_WR_Byte(0xAE,OLED_CMD);    // Set Display Off
      
          OLED_WR_Byte(0xD5,OLED_CMD);    //Set Display Clock Divide Ratio/Oscillator Frequency      设置时钟分频
      
          OLED_WR_Byte(0xA0,OLED_CMD);    //
      
          OLED_WR_Byte(0xA8,OLED_CMD);    //Set Multiplex Ratio        设置多路复用比率
      
          OLED_WR_Byte(0x3F,OLED_CMD);    //
      
          OLED_WR_Byte(0xD3,OLED_CMD);    //Set Display Offset
      
          OLED_WR_Byte(0x00,OLED_CMD);    //
      
          OLED_WR_Byte(0x40,OLED_CMD);    // Set Display Start Line
      
          OLED_WR_Byte(0xA1,OLED_CMD);    // Set SEG/Column Mapping (0xA0/0xA1)
      
          OLED_WR_Byte(0xC8,OLED_CMD);    // Set COM/Row Scan Direction (0xC0/0xC8)
      
          OLED_WR_Byte(0xDA,OLED_CMD);    //Set COM Pins Hardware Configuration
      
          OLED_WR_Byte(0x12,OLED_CMD);    // Set Alternative Configuration (0x02/0x12)    
      
          OLED_WR_Byte(0x81,OLED_CMD);    //Set Current Control
      
          OLED_WR_Byte(0xFF,OLED_CMD);    //     
      
          OLED_WR_Byte(0xD9,OLED_CMD);    //Set Pre-Charge Period
      
          OLED_WR_Byte(0x82,OLED_CMD);    //
      
          OLED_WR_Byte(0xDB,OLED_CMD);    //Set VCOMH Deselect Level
      
          OLED_WR_Byte(0x34,OLED_CMD);    //
      
          //OLED_WR_Byte(0x20,OLED_CMD);
      
          //OLED_WR_Byte(0x02,OLED_CMD);    // Set Page Addressing Mode (0x00/0x01/0x02)
      
          OLED_WR_Byte(0xA4,OLED_CMD);    // Set Entire Display On/Off (0xA4/0xA5)
      
          OLED_WR_Byte(0xA6,OLED_CMD);    // Set Normal/Inverse Display (0xA6/0xA7)
      
          OLED_Clear(); //清屏
      
          HAL_Delay(10);
      
          OLED_WR_Byte(0xAF,OLED_CMD);        //Set Display On
      
          HAL_Delay(200);

       

  4.  Realize the "word", "string", "number" and other drivers, these drivers can be called by the upper layer application, which is convenient for project layering.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Published 105 original articles · Like 30 · Visits 160,000+

Guess you like

Origin blog.csdn.net/happygrilclh/article/details/105640776