Learn To Write Code For 8051, Arduino, AVR, dsPIC, PIC, STM32 ARM Microcontroller, etc.
Coding Embedded Controller With C/C++.
Printed Circuit Board (PCB) Project For Electronics Hobbyists.
The PCF8574 could be used for a HD44780 based character LCD controlling using the 4-bit data transfer mode. The popular one's is an Arduino TWI LCD driving using this chip.
A long hours running program
This chip has only 8 bits inputs/outputs. So it can interface with an 8-bit character LCD using the 4-bit data transfer mode. Using this method the micro-processor need to send the 8-bit command or data two time, first the higher nibble and then the lower nibble. For more information about using the PCF8574 please see this post. If you are a beginner in micro-controller programming you can see this post about 4-bit LCD interfacing.
I use use my own DIY PCF8574AP character LCD module. Its schematic is shown below.
PCF8574AP Character LCD Module Schematic
Its slave address are 0x70 and 0x71.
DIY PCF8574AP Character LCD Module
DIY PCF8574AP Character LCD Module
You can use an Arduino PCF8574 LCD module with different address.
Arduino PCF8574 LCD module
Arduino PCF8574 LCD module
In this example, The micro-controller send a counter variable to the display. It updates for every 250ms. I use the I2C module of PIC16F887. The program written in C using MPLABX IDE and its XC8 C compiler. It's free to use.
An SH1106 is a 132x64 LED display driver with controller. This chip support 8-bit 6800-series parallel interface, 8-bit 8080-series parallel interface, Serial Peripheral Interface (SPI), and Inter Integrated Circuit (I2C) bus interface. It usually come with an 1.3 inches 128x64 OLED display module with an SPI or an I2C interface.
PIC16F887 OLED Display
Using this module with an Arduino is very popular. Some programmer creates a simple game console using this display. Arduino platform has a lot of libraries and graphic for this LCD module.
1.3 Inches 1106 128x64 IIC OLED Module
1.3 Inches 1106 128x64 IIC OLED Module
Without Arduino we can check the LCD Wiki website for programming and interfacing with this device using different micro-processor.
For full specification please check product datasheet. The LCD is mounted on a PCB with a ready to use I2C interface. Its supply voltage is 5VDC by default.
Using only two-wire data bus the controller can communicate with multiple devices. This I2C display is writable and readable.
The micro-processor writes command or data to this display. It begin by an I2C start bit, device address (eg. 0x78), Acknowledge bit (A), Control Byte, Data Byte, and an I2C stop bit.
Data/Command (D/C) bit of the control byte determine between display RAM data and command as it's shown in the picture above.
Display RAM Data can also be read from this display module.
To use it properly we need to set its display commands using a command set below.
Set Low Column Address: (00H - 0FH)
Set Higher Column Address: (10H - 1FH)
Set Pump voltage value: (30H - 33H)
Set Display Start Line: (40H - 7FH)
Set Contrast Control Register: (Double Bytes Command), The Contrast Control Mode Set (81H), Contrast Data Register Set (00H - FFH)
Set Segment Re-map: (A0H - A1H)
Set Entire Display OFF/ON: (A4H - A5H)
Set Normal/Reverse Display: (A6H - A7H)
Set Multiplex Ration: (Double Bytes Command), Multiplex Ration Mode Set: (A8H), Multiplex Ration Data Set: (00H - 3FH).
Set DC-DC OFF/ON: (Double Bytes Command), DC-DC Control Mode Set: (ADH), DC-DC ON/OFF Mode Set: (8AH - 8BH).
Display OFF/ON: (AEH - AFH)
Set Page Address: (B0H - B7H)
Set Common Output Scan Direction: (C0H - C8H)
Set Display Offset: (Double Bytes Command), Display Offset Mode Set: (D3H), Display Offset Data Set: (00H - 3FH)
Set Display Clock Divide Ratio/Oscillator Frequency: (Double Bytes Command), Divide Ratio/Frequency Mode Set: (D5H), Divide Ratio/Oscillator Frequency Data Set: (00H - FFH).
Set Dis-Charge/Pre-Charge Period: (Double Bytes Command), Pre-charge Period Mode Set: (D9H), Dis-charge/Pre-charge Period Data Set: (00H - FFH)
Set Common pads hardware configuration: (Double Bytes Command), Common Pads Hardware Configuration Mode Set: (DAH), Sequential/Alternative Mode Set: (02H - 12H).
For a fully explained text, you can check its datasheet. These command are summerized in a command table below.
Command Table 1
Command Table 2
We can see its user's manual include programming tutorial to get used to this display controller.
PIC16F887 MPLABX IDE and XC8 Programming
An 8-bit PIC16F887 is suitable for this display controller since it has a high speed I2C module inside. I configure this module with a clock frequency of 200kHz. The program will send a 8x16 character text to the display.
/*
* File: main.c
* Author: Admin
*
* Created on January 8, 2024, 8:50 PM
*/
#include <xc.h>
#include "config.h"
#include "sh1106.h"
#define _XTAL_FREQ 20000000UL
void main(void){
display_init();
__delay_ms(100);
display_clear(0);
display_text_8x16(0,0,"SH1106 I2C OLED");
display_text_8x16(0,1,"And PIC16F887");
display_text_8x16(0,2,"Programming With");
display_text_8x16(0,3,"MPLABX IDE XC8");
__delay_ms(5000);
display_clear(0);
while(1){
display_text_8x16(0,0,"PIC16F887 SH1106");
__delay_ms(2500);
uint8_t h=15;
for(uint8_t i=0;i<10;i++){
display_char_8x16(h,1,'0'+i);
h+=10;
}
__delay_ms(2500);
h=0;
for(uint8_t i=0;i<14;i++){
display_char_8x16(h,2,'A'+i);
h+=10;
}
__delay_ms(2500);
h=0;
for(uint8_t i=0;i<14;i++){
display_char_8x16(h,3,'N'+i);
h+=10;
}
__delay_ms(10000);
display_clear(255);
__delay_ms(10000);
display_clear(0);
__delay_ms(1000);
}
return;
}
Only text fonts requires a lot of program space. To get additional fonts and graphic we can add an SPI or an I2C EEPROM or even a Flash memory to store those data.
Protues Simulation
Protues has an LCD module for SSD1306. It's very similar to the SH1106. However simulating this module in Protues is slower than a physical hardware.