The Solomon Systech SSD1351 module is a CMOS driver for an OLED matrix display, making it useful for displaying information in a compact manner. The SSD1351 includes built-in hardware such as display RAM (GDDRAM) and an oscillator, making it convenient to couple with an MCU. The particular SSD1351 module used with the library, SSD1351.h, is the SPI variant. The Characters.h library is called upon in line #6 of the following code to include a list of commonly used ASCII characters.

/*             OLED Display: Solomon Systech SSD1351 (library)                */
/*                          Filename: SSD1351.h                               */
/*                      Communication Protocol: SPI                           */
/*                          Author: Michael                                   */

#include "Characters.h"                                                         

void OLED_Command(uint8_t command)                                                        // Function to write commands to SSD1351
{                                          
    D_C = 0;                                                                              // D_C pin LOW for command mode
    SPI1BUFL = command;                                                                   // Write command
    while(SPI1STATLbits.SPITBF == 1);                                                     // Wait for transmit buffer to empty
}

void OLED_Data(uint8_t data)                                                              // Function to write data to SSD1351
{
    D_C = 1;                                                                              // D_C pin HIGH for data mode
    SPI1BUFL = data;                                                                      // Write data    
    while(SPI1STATLbits.SPITBF == 1);
}

void OLED_Clear(void)
{
    
   OLED_Command(0b00010101);                                                              // Column Address                                                                
   OLED_Data(0b00000000);                                                                 // Start address
   OLED_Data(0b01111111);                                                                 // End address
   
   OLED_Command(0b01110101);                                                              // Row address
   OLED_Data(0b00000000);                                                                 // Start address 
   OLED_Data(0b01111111);                                                                 // End address

   OLED_Command(0b01011100);                                                              // Write RAM (enable MCU to write data into GDDRAM)

   for (uint8_t column = 0; column < 128; column ++)
   {
       for (uint8_t row = 0; row < 128; row ++)
       {
           OLED_Data(0b00000000);
           OLED_Data(0b00000000);
       }
   }          
    
}

void OLED_Setup(void)                                                                     // Function to setup operating conditions for SSD1351
{

   OLED_Command(0b11111101);                                                              // Command Lock
   OLED_Data(0b00010010);                                                                 // Unlock OLED driver to enter commands
   OLED_Command(0b11111101);                                                              // Command Lock
   OLED_Data(0b10110001);                                                                 // Commands A2, B1, B3, BB, BE, C1 accessible

   OLED_Command(0b10101110);                                                              // Sleep Mode ON/OFF (sleep mode ON (display OFF))

   OLED_Command(0b10110011);                                                              // Front Clock Divider (DivSet)/Oscillator Frequency
   OLED_Data(0b11010001);                                                                 // Oscillator frequency (0b11010001) DIVSET (divide by 1)             

   OLED_Command(0b11001010);                                                              // MUX Ratio
   OLED_Data(0b01111111);                                                                 // 127

   OLED_Command(0b10100010);                                                              // Display Offset
   OLED_Data(0b00000000);                                                                 // Vertical scroll by row from Row 0 to Row 0    

   OLED_Command(0b10100001);                                                              // Display Start Line
   OLED_Data(0b00000000);                                                                 // Vertical scroll by RAM from Row 0

   OLED_Command(0b10100000);                                                              // Re-map/Colour Depth (Display RAM to Panel)
   OLED_Data(0b00110101);                                                                 // See SSD1351 datasheet

   OLED_Command(0b10110101);                                                              // GPIO
   OLED_Data(0b00001010);                                                                 // GPIO1 (pin output LOW) GPIO0 (pin output LOW)

   OLED_Command(0b10101011);                                                              // Function Selection
   OLED_Data(0b00000001);                                                                 // Select 8-bit parallel interface &  Enable internal VDD regulator

   OLED_Command(0b10110100);                                                              // Segment Low Voltage (VSL)
   OLED_Data(0b10100000);                                                                 // External VSL
   OLED_Data(0b10110101);                                                                 // Fixed    
   OLED_Data(0b01010101);                                                                 // Fixed

   OLED_Command(0b11000001);                                                              // Contrast Current for Colour A,B,C
   OLED_Data(0b11111111);                                                                 // Contrast value Colour A (Red)
   OLED_Data(0b11111111);                                                                 // Contrast value Colour B (Green)       
   OLED_Data(0b11111111);                                                                 // Contrast value Colour C (Blue)

   OLED_Command(0b10111001);                                                              // Reset to default Look Up Table

   OLED_Command(0b10110001);                                                              // Phase 1 / Pre-charge (Phase 2) period 
   OLED_Data(0b10000010);                                                                 // Phase 2 period (8 DCLK(s) clocks) Phase 1 period (5 DCLK(s) clocks)     

   OLED_Command(0b10110010);                                                              // Display Enhancement
   OLED_Data(0b10100100);                                                                 // Enhance display performance
   OLED_Data(0b00000000);                                                                 // Fixed
   OLED_Data(0b00000000);                                                                 // Fixed 

   OLED_Command(0b10111011);                                                              // Pre-charge voltage
   OLED_Data(0b00010111);                                                                 // Pre-charge voltage (0.50 x VCC)  

   OLED_Command(0b10110110);                                                              // Second Pre-charge Period
   OLED_Data(0b00001000);                                                                 // 8 DCLKS

   OLED_Command(0b10111110);                                                              // VCOMH Voltage
   OLED_Data(0b00000101);                                                                 // VCOMH (0.82 x VCC)

   OLED_Command(0b10100110);                                                              // Display Mode (reset to normal display)                              

   OLED_Clear();
   
   OLED_Command(0b10101111);                                                              // Sleep Mode ON/OFF (sleep mode OFF (display ON))
   
}

void OLED_String(uint8_t OLED_Row, uint8_t OLED_Column, char OLED_String[], char Colour)  // Function to write characters to SSD1351 (character rows: 1 to 16) (character columns: 1 to 16) (character input) (colour input: white ('W') red ('R') green ('G') blue ('B'))
{

    uint8_t j = 0;                                                                        // Character counter (j) represents total number of characters in OLED_String
    
    for (uint8_t i = 0; i < 16; i++)                                                      // Maximum of 16 character blocks (1 block = 8(pixel rows) x 8(pixel columns)) (128 pixel columns) span across OLED display
    {
        
        if (OLED_String[i] > 0)
        {
            j++;                                                                          // Increase value of j by 1 if character present
        }
        
        else
        {
            break;                                                                        // Terminate for loop if no more characters present
        }

    }

    for(uint8_t i = 0; i < j; i++)                                                        // Print characters in OLED_String
    {
        
        for(uint8_t r = 0; r < 941; r++)                                                  // Cycle through all 91 character rows ([0] to [90]) of Character_Lookup table
        {
            
            if(OLED_String[i] == Character_Lookup[r][0])                                  // First column ([0]) of Character_Lookup table used to search for matching character
            {
                
                for(uint8_t c = 1; c < 9; c++)                                            // Cycle through columns [1] to [8] of character block, for matching character, of Character_Lookup table
                {
               
                    for(uint8_t b = 0; b < 8; b++)                                        // Cycle through each bit in current column from MSB to LSB
                    {

                        OLED_Command(0b00010101);                                         // Column Address
                        OLED_Data((OLED_Column - 1)*8 + (c - 1));                         // Start
                        OLED_Data((OLED_Column - 1)*8 + (c - 1));                         // End
                        
                        OLED_Command(0b01110101);                                         // Row Address
                        OLED_Data((OLED_Row - 1)*8 + b);                                  // Start
                        OLED_Data((OLED_Row - 1)*8 + b);                                  // End
                        
                        OLED_Command(0b01011100);                                         // Write RAM (enable MCU to write data into GDDRAM)
                        
                        if(((Character_Lookup[r][c] >> b) & 0b00000001) == 1)             // If current bit is 1
                        {
                            
                            if (Colour == 'R')                                            // Set character colour to Red RGB (255, 0, 0)
                            {
                                OLED_Data(0b11111000);
                                OLED_Data(0b00000000);
                            }

                            else if (Colour == 'G')                                       // Set character colour to Green RGB (0, 255, 0)
                            {
                                OLED_Data(0b00000111);
                                OLED_Data(0b11100000);
                            }

                            else if (Colour == 'B')                                       // Set character colour to Blue RGB (0, 0, 255)    
                            {
                                OLED_Data(0b00000000);
                                OLED_Data(0b00011111);
                            }
                            
                            else if (Colour == 'W')                                       // Set character colour to White RGB (255, 255, 255)
                            {
                                OLED_Data(0b11111111);
                                OLED_Data(0b11111111);
                            }
  
                        }
                        
                        else
                        {
                            OLED_Data(0b00000000);                                        // Set character colour to Black RGB (0, 0, 0)
                            OLED_Data(0b00000000);
                        }
                        
                    }
                    
                }
                
                OLED_Column ++;                                                           // Move to next character in OLED_String
                break;                                                                    // Terminate for loop once character block is complete
                
            }
                
        }
        
    }

}

The following list describes how each of the functions in the SSD1351.h library works:

  • OLED_Command (line #8): Writes individual commands to the SSD1351
  • OLED_Data (line #15): Writes data to the SSD1351
  • OLED_Setup (line #22): Sets specific operating conditions for the SSD1351
  • OLED_Clear (line #90): Clears the GGDRAM of the SSD1351
  • OLED_String (line #114): Writes pixels, in a custom colour, representing ASCII characters to the GDDRAM of the SSD1351 with a character input

Figure 1 represents the character 2 displayed on the SSD1351 OLED display.

Figure 1: Character Block Array

The display is comprised of an array of pixels, i.e., LEDs, spanning 128 x 128. There is an array of character blocks (orange squares) spanning 16 x 16, each of which is comprised of an array of pixels, spanning 8 × 8. In each character block, a custom character font can be displayed. This is demonstrated in Figure 2.

Figure 2: Character Block

The character 2 is displayed in a custom font; however, it seems pixelated close-up. By zooming out, the pixelations appear to be less prevalent, as shown in Figure 1. Figure 3 represents the set of SPI commands that are transmitted by the MCU to the SSD1306 to result in the character 2 being displayed.

Figure 3: Character 2

The SSD1351 module waits for individual bits of pixel data within each byte, after which the GDDRAM is updated, which in turn updates a pixel state, i.e., ON or OFF, in the OLED display. Referring back to Figure 2, pixels are updated from Row 0 to Row 7, corresponding to the LSB and MSB, for each column. All the pixels in Row 7 and Column 7 are left turned OFF. This is to give some space between characters that are displayed next to each other. Referring back to Figure 1, a character can be displayed in any of the orange squares by transmitting the GDDRAM Row and Column Start and End Addresses of the square using the OLED_String function. This function accepts a character row input from 1 to 16 and a character column input from 1 to 16, in addition to allowing four selectable colours, i.e, white (‘W’), red (‘R’), green (‘G), and blue (‘B’).