QC

Hiển Thị OLDE Dùng 8051

 HIỂN THỊ OLED DÙNG 8051

Định dạng khung hình OLED

   Giao diện truyền thông I2C của OLED bao gồm bit địa chỉ phụ SA0, tín hiệu dữ liệu I2C-bus SDA và tín hiệu xung clock I2C-bus SCL. Cả dữ liệu và tín hiệu đồng hồ phải được kết nối với điện trở kéo lên.

Slave address bit (SA0):: Vì giao tiếp I2c phụ thuộc vào địa chỉ phụ (ID) và sẽ chỉ phản hồi nếu nó phù hợp. Thiết bị OLED SSD1306 sẽ phản hồi địa chỉ phụ theo sau bit địa chỉ phụ (bit “SA0”) và bit chọn đọc / ghi (bit “R / W #”) với định dạng byte sau,

B7B6B5B4B3B2B1B0
011110SA0R/W

Bit SA0 cung cấp một bit mở rộng cho địa chỉ phụ. Có thể chọn “0111100” hoặc “0111101” làm địa chỉ phụ của SSD1306.

Bit R / W được sử dụng để xác định chế độ hoạt động của giao diện I2C-bus.

R / W = 1, nó đang ở chế độ đọc.

R / W = 0, nó đang ở chế độ ghi.

- Tín hiệu dữ liệu I2C-bus (SDA): Chân SDA được sử dụng để gửi hoặc nhận thông tin giữa chủ và tớ. Điều này cũng sẽ được sử dụng để gửi xác nhận.

-Tín hiệu xung nhịp I2C-bus (SCL): Việc truyền thông tin trong I2C-bus được điều khiển bởi tín hiệu xung nhịp (SCL). Một bit thông tin được truyền / nhận trong một khoảng thời gian đồng hồ duy nhất của SCL.

Giao diện I2C-bus cho phép truy cập để ghi dữ liệu và lệnh vào thiết bị. Hình ảnh dưới đây cho thấy chế độ ghi của I2C-bus theo thứ tự thời gian.


1.Thiết bị chính bắt đầu giao tiếp dữ liệu theo điều kiện bắt đầu. Điều kiện bắt đầu được thiết lập bằng cách kéo SDA từ CAO xuống THẤP trong khi SCL vẫn ở mức CAO.

2.Địa chỉ nô lệ được gửi ngay sau Điều kiện bắt đầu. Đối với SSD1306, địa chỉ phụ là “b0111100” hoặc “b0111101” bằng cách thay đổi SA0 thành LOW hoặc HIGH (chân D / C hoạt động như SA0).

3.Chế độ ghi được thiết lập bằng cách đặt bit R / W thành logic “0”.

4.Một tín hiệu báo nhận sẽ được tạo ra sau khi nhận được một byte dữ liệu, bao gồm địa chỉ phụ và bit R / W.Bit xác nhận được định nghĩa là dòng SDA được kéo xuống trong khoảng thời gian CAO của xung đồng hồ liên quan đến báo nhận.

5. Sau khi truyền địa chỉ phụ, byte điều khiển hoặc byte dữ liệu có thể được gửi qua SDA. Một byte điều khiển chủ yếu bao gồm các bit Co và D / C # theo sau là sáu “0” ‘s. Nếu bit Co được đặt là logic “0”, việc truyền thông tin sau sẽ chỉ chứa các byte dữ liệu. Bit D / C xác định byte dữ liệu tiếp theo được hoạt động như một lệnh hoặc một dữ liệu. Nếu bit D / C được đặt thành logic “0”, nó xác định byte dữ liệu sau đây như một lệnh. Nếu bit D / C được đặt thành logic “1”, nó xác định byte dữ liệu sau là dữ liệu sẽ được lưu trữ tại GDDRAM. Con trỏ địa chỉ cột GDDRAM sẽ tự động tăng lên một sau mỗi lần ghi dữ liệu.

6.Bit báo nhận sẽ được tạo sau khi nhận từng byte điều khiển hoặc byte dữ liệu.

7.Chế độ ghi sẽ kết thúc khi một điều kiện dừng được áp dụng. Điều kiện dừng được thiết lập bằng cách kéo “SDA vào” từ THẤP đến CAO trong khi “SCL” vẫn ở mức CAO.

OLED Commands


CommandCommandDescription
0x00SSD1306_COMMANDThis command is used to indicate the next data byte is acted as a command.
0x40SSD1306_DATA_CONTINUEThis command sets the Display Start Line register to determine starting address of display RAM
0xAESSD1306_DISPLAY_OFFThis command is used to turn OFF the OLED display panel.
0xAFSSD1306_DISPLAY_ONThis command is used to turn ON the OLED display panel.
0x20SSD1306_MEMORY_ADDR_MODEIf horizontal address increment mode is enabled by command 20h, after finishing read/write one column data, it is incremented automatically to the next column address.
0x21SSD1306_SET_COLUMN_ADDRThis command is used to define the current read/write column address in graphic display data RAM.
0x22SSD1306_SET_PAGE_ADDRThis command is used to define the current read/write Line(Page as per data sheet) address in graphic display data RAM.
0x81SSD1306_SET_CONTRAST_CONTROLThis command sets the Contrast Setting of the display. The chip has 256 contrast steps from 00h to FFh. The segment output current increases as the contrast step value increases.
0xA6SSD1306_NORMAL_DISPLAYThis command sets the display to normal mode. In normal display a RAM data of 1 indicates an “ON” pixel.
0xA7SSD1306_INVERT_DISPLAYThis command sets the display to inverse mode. In normal display a RAM data of 0 indicates an “ON” pixel.


Command Write

void oledSendCommand(uint8_t cmd)
{
    oledSendStart(SSD1306_ADDRESS<<1); // Start the communication and send the OLED ID/Address in write mode
    oledSendByte(SSD1306_COMMAND);     // Indicate the following byte will be command
    oledSendByte(cmd);                 // Send the USer Command
    oledSendStop();                    // Stop the communication
}

Oled Init

Below Command needs to send to OLED for initialization:

  1. Display is OFF
  2. 128 x 64 Display Mode
  3. Normal segment and display data column address and row address mapping (SEG0 mapped to address 00h and COM0 mapped to address 00h)
  4. Shift register data clear in serial interface
  5. Display start line is set at display RAM address 0
  6. Column address counter is set at 0
  7. Normal scan direction of the COM outputs
  8. Contrast control register is set at 7Fh
  9. Normal display mode (Equivalent to A4h command)
void OLED_Init(void)
{ 
    oledSendCommand(SSD1306_DISPLAY_OFF);
    oledSendCommand(SSD1306_SET_DISPLAY_CLOCK_DIV_RATIO);
    oledSendCommand(0x80);
    oledSendCommand(SSD1306_SET_MULTIPLEX_RATIO);
    oledSendCommand(0x3F);
    oledSendCommand(SSD1306_SET_DISPLAY_OFFSET);
    oledSendCommand(0x0);
    oledSendCommand(SSD1306_SET_START_LINE | 0x0);
    oledSendCommand(SSD1306_CHARGE_PUMP);
    oledSendCommand(0x14);
    oledSendCommand(SSD1306_MEMORY_ADDR_MODE);
    oledSendCommand(0x00);
    oledSendCommand(SSD1306_SET_SEGMENT_REMAP | 0x1);
    oledSendCommand(SSD1306_COM_SCAN_DIR_DEC);
    oledSendCommand(SSD1306_SET_COM_PINS);
    oledSendCommand(0x12);
    oledSendCommand(SSD1306_SET_CONTRAST_CONTROL);
    oledSendCommand(0xCF);
    oledSendCommand(SSD1306_SET_PRECHARGE_PERIOD);
    oledSendCommand(0xF1);
    oledSendCommand(SSD1306_SET_VCOM_DESELECT);
    oledSendCommand(0x40);
    oledSendCommand(SSD1306_DISPLAY_ALL_ON_RESUME);
    oledSendCommand(SSD1306_NORMAL_DISPLAY);
    oledSendCommand(SSD1306_DISPLAY_ON);

    OLED_Clear();  /* Clear the complete LCD during init */
}


Example Code

#include "oled_i2c.h"

int main()
{		 
    OLED_Init();
    OLED_SetCursor(2,0);  //Set cursor at 2nd-line 0th-Position
    OLED_DisplayString("Oled Interface");	
    
    OLED_SetCursor(4,20); //Set cursor at 4th-line 20th-Position
    OLED_DisplayString("With 8051 From");
    
    OLED_SetCursor(6,30); //Set cursor at 6th-line 30th-Position
    OLED_DisplayString("uss-");    

    while(1);
}



Nap Code vào PY32F003 dùng Stlink

 Nap Code vào PY32F003 dùng Stlink Bước 1: Cài đặt  KeilC v5.39 theo link sau ( chú ý 5.39 keil c mới nạp ok). https://edge07.111.ir.cdn.ir/...