CH1115驱动

  • 已逐步停产,由SSD1312替代

初始化

#define OLED_INIT_LEN   28
const uint8_t OLED_INIT_CMD[] PROGMEM = {
  0xAE,             // display off
  0x00, 0x10, 0xB0, // set lower column address, higher column address, and page address
  0x40,             //set display start lines
  0x81, 0x00,       //contract control, default 0x80
  0x82, 0x00,       //iref resistor set and adjust ISEG
  0xA0,             // set segment remap 0xA0
  0xA2,             // set seg pads hardware configuration
  0xA4,             // disable entire display on (0xA4, 0xA5)
  0xA6,             // normal (0xA7 is reverse)
  0xA8,             // multiplex ratio
  0x3F,             // duty = 1/64
  0xC0,             // Com scan direction 0xC0
  0xD3, 0x00,       // set display offset
  0xD5, 0xA0,       // set osc division
  0xD9, 0x22,       // set pre-charge period
  0xDB, 0x40,       // set vcomh
  0x31,             // set pump 7.4v
  0xAD,             // set charge pump enable
  0x8B,             // set dc-dc enable (0x8A=disable; 0x8B=enable)
  0xAF
};
 
void ErOLED::sendCommand(uint8_t cmd){
  digitalWrite(OLED_DC, LOW);
  SPIWrite(cmd);
  digitalWrite(OLED_DC, HIGH);
}
 
void ErOLED::SPIWrite(uint8_t data) {
  #ifdef _software_SPI
    shiftOut(OLED_SDA, OLED_SCL, MSBFIRST, data);
  #else
    SPI.transfer(data);
  #endif
}
 
 
void ErOLED::init()
{
    #ifdef _software_SPI
    pinMode(OLED_SDA, OUTPUT);
    pinMode(OLED_SCL, OUTPUT);
    #endif
    
    pinMode(OLED_RST, OUTPUT);
    pinMode(OLED_DC, OUTPUT);
    digitalWrite(OLED_DC, HIGH);
    #ifndef _software_SPI
      SPI.begin();
    #endif
 
    digitalWrite(OLED_RST, HIGH);
    delay(10);
    digitalWrite(OLED_RST, LOW);
    delay(10);
    digitalWrite(OLED_RST, HIGH);
    delay(100);
 
    for (uint8_t i = 0; i < OLED_INIT_LEN; i++){
      sendCommand(pgm_read_byte(&OLED_INIT_CMD[i]));
    }
 
    delay(100);
}