当前位置:网站首页>OLED driven learning based on ssd1306 (II): addressing mode of ssd1306

OLED driven learning based on ssd1306 (II): addressing mode of ssd1306

2022-06-25 20:49:00 CharX

SPI Communication program :( Clock high idle , The rising edge reads data , From high to low )

void OLED_WR_Byte(u8 data,u8 cmd){
    unsigned char i = 0;
    if(cmd){//cmd Nonzero ,DC pull up , Write data mode 
        OLED_DC_High;
    }
    else{// Write command mode 
        OLED_DC_Low;
    }
    /**********SPI The main body ***********/
    for(i=0;i<8;i++){
        OLED_SCL_Low;
        if(data & 0x80){
            OLED_SDA_High;
        }
        else{
            OLED_SDA_Low;
        }
        OLED_SCL_High;
        data <<= 0x01;
    }
    OLED_SCL_High;
    /*****************************/
}

SSD1306 Introduction to addressing mode :

| Addressing mode selection command : 0x20

Optional mode : ( Page address 0x10, level 0x00, vertical 0x01)

  • 0x02: Page address addressing mode

In this mode , The monitor starts from a page column0→column127 scan , It should be noted that in this mode, the column address will automatically after receiving a write video memory command +1 however When the page is scanned to the ending column address, the pointer will return to the starting address of the page and the page address pointer will not automatically +1, This means that we need to manually select the page address in our program

Code example :( Write video memory function )

void OLED_Refresh(void){
u8 i,j;
for(i = 0;i<8;i++){
    OLED_WR_Byte(0xb0+i,OLED_WR_CMD);//
    OLED_WR_Byte(0x00,OLED_WR_CMD);
    OLED_WR_Byte(0x10,OLED_WR_CMD);
    for(j = 0;j<128;j++){
        OLED_WR_Byte(OLED_GDDRAM[j][i],OLED_WR_DATA);
    }
}
}

Write data together except full screen , You can also select a specified area for writing , Similar to the code above :

(: Official documents

That is, in the normal display mode , Page address addressing mode , When writing to video memory, you need to specify the starting address of the column first , Page address .

    • Set the lower four bits of the column address :0x00-0x0F
    • Set the upper four bits of the column address :0x10-0x1F
    • Set page address command :0xB0-0xBF(PAGE0-PAGE7)

Take the example in the official document for analysis :

command 0xB2 Set the page to be written to PAGE2; Low four digit command 0x03 And the senior four 0x00( The command sent is 0x10) Together they make up the address 0x03, From SEG3 Start writing to video memory .

For example :

1. Let's send the order first 0xB0,0x00,0x11, Then the write start position is pointed to PAGE2 Of SEG32(0x10)

2. send data 0101 0010B, that (SEG32,PAGE2) From top to bottom 2 individual , The first 5 individual , The first 7 A dot matrix is lit , After completion, the column address is automatically +1, That is, the video memory write position has reached (SEG33,PAGE2), If we send the data again, it will be written (SEG33,PAGE2). To advance , Until the write position reaches (SEG127,PAGE2) after , The next write position will return to (SEG32,PAGE2), If we want to continue writing to the next page, we need to send command 0xB3(0xB0-0xBF, Any one ) And specify the starting column address .

  • 0x00 Horizontal address addressing mode

This mode is in the page address addressing mode, and the page address automatically when the column address reaches the end +1, When both the column address and the page address reach the end , Both the column address and the page address are reset automatically

// Write video memory function 
void OLED_Refresh(void){
u8 i,j;
for(i = 0;i<8;i++){
    for(j = 0;j<128;j++){
        OLED_WR_Byte(OLED_GDDRAM[j][i],OLED_WR_DATA);
    }
}
}

  • 0x01 Vertical address addressing mode

Vertical addressing mode , seeing the name of a thing one thinks of its function , As opposed to horizontal addressing mode . Pictured above :

In the above horizontal address addressing mode and vertical address addressing mode , You cannot use the positioning command in page addressing mode , But it has its own commands

    • Set column address command 0x21
    • Set page address command 0x22 

  Column address setting command (0x21)

         The column address setting command consists of three commands , The first order is 0x21, the second , The third command sets the column start and end addresses respectively  

(0x00-0x7F and 0x00-0x7F)

Page address setting command (0x22) 

          The page address setting command, like the column address setting command, consists of three commands :

        0x22->(0x00-0x07)->(0x00-0x07)

        (: Examples of official documents

 

  In the example, the :

The starting column address is Col2, Terminate as Col125(0x21->0x02->0x7D);

The starting page address is PAGE1, The address of the termination page is PAGE2(0x22->0x01->0x06);

The addressing address is in horizontal addressing mode , Write the diagram as above :

原网站

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