This is simple interface of OLED (128x64) display with LPC804 Micro controller. OLED comes with SSD1306 display controller download the datasheet from here. SSD1306 has SPI and I2C interface but the one which i brought the module has only I2C.
The main reason for this post is, when we search on we about OLED interface lot of "Arduino" projects works are coming in the results. Only kids will use "Arduino" :smileyhappy:
Here we going to see how we can display text in OLED display.
Step1: Configure the IO pins for I2C
/* I2C0_SDA connect to P0_7 */
SWM_SetMovablePinSelect(SWM0, kSWM_I2C0_SDA, kSWM_PortPin_P0_7);
/* I2C0_SCL connect to P0_14 */
SWM_SetMovablePinSelect(SWM0, kSWM_I2C0_SCL, kSWM_PortPin_P0_14);
Step2: Initialize I2C for default configuration
/* Initialize the I2C master peripheral */
I2C_MasterInit(EXAMPLE_I2C_MASTER, &masterConfig, I2C_MASTER_CLOCK_FREQUENCY);
/* Create the I2C handle for the non-blocking transfer */
I2C_MasterTransferCreateHandle(EXAMPLE_I2C_MASTER, &g_m_handle, i2c_master_callback, NULL);
Step3: Initialize OLED commands
Sending basic set of commands to SSD1306 via I2C to Init the controller.
OLED_Init(); /* Cmds details will be provided later */
Step4: Print Text
The driver logic is same but the way of implementation will be different
void OLED_PrintText(uint8_t line,uint8_t x,uint8_t data[]){
uint8_t i,j,len,cmax;
len =strlen(data);
if( line<8){
if((x + len*6) > 127){
cmax=127;
}
else
{
cmax = x + len*6;
}
txBuff[0] = 0x00;
txBuff[1] = SSD1306_COLUMNADDR;
I2C_Transfer(SSD1306_I2C_ADDRESS, txBuff,2);
txBuff[0] = 0x00;
txBuff[1] = x;
I2C_Transfer(SSD1306_I2C_ADDRESS, txBuff,2);
txBuff[0] = 0x00;
txBuff[1] = cmax;
I2C_Transfer(SSD1306_I2C_ADDRESS, txBuff,2);
txBuff[0] = 0x00;
txBuff[1] = SSD1306_PAGEADDR;
I2C_Transfer(SSD1306_I2C_ADDRESS, txBuff,2);
txBuff[0] = 0x00;
txBuff[1] = line;
I2C_Transfer(SSD1306_I2C_ADDRESS, txBuff,2);
txBuff[0] = 0x00;
txBuff[1] = line;
I2C_Transfer(SSD1306_I2C_ADDRESS, txBuff,2);
txBuff[0] = 0x40;
for(j=0;j<len;j++){
for(i=0;i<5;i++){
txBuff[j*6 + i +1] = font[data[j]-32][i];
}
}
I2C_Transfer(SSD1306_I2C_ADDRESS, txBuff,cmax-x +1);
}
}
To be continue..
Thank you for your input!!