Interfacing PIC16F877A with SSD1306 OLED display | Simulation

Опубликовано: 11 Январь 2025
на канале: Electronics Developer
1,307
like

-------------------------
📌Introduction
-------------------------
This is an example shows how to write texts on SSD1306 OLED display (128×64 pixel) using PIC16F877A microcontroller. In this project the SSD1306 OLED is configured to work in I2C mode. So, make sure that your SSD1306 OLED display is configured to work in I2C mode, some displays need jumper placing or some soldering.
A small video shows Proteus simulation of this project at the end of the post.

This topic is for interfacing PIC microcontroller devices with limited RAM with SSD1306 OLED display, if the MCU device has sufficient RAM (as an example with more than 1024 byte for 128×64 Pixel display).The SSD1306 OLED display communicates with the master device over I2C mode, SPI mode or 8-bit parallel mode.
Generally the SSD1306 OLED requires a RAM buffer with all screen data, for example if we’ve a 128×64 Pixel display then we’ve to use a buffer of 1024 bytes (128×64/8). The problem is when we want to write a single pixel we’ve to overwrite another 7 pixels, therefore we need to know the status of the other 7 pixels.
Another problem with this type of displays (the SSD1306 controller chip) is it doesn’t allow any reading from its RAM when it works in serial mode (I2C or SPI).

In this example the SSD1306 works in I2C mode and the PIC16F877A has a limited RAM of 368 bytes which means using a buffer of 1024 byte is not possible.

I wrote a small driver for the SSD1306 OLED in order to be able to write texts, this driver works with SSD1306 displays with resolution of 128×64, 128×32 and 96×16 pixel, it splits the 128×64 pixel display into 21 columns and 8 rows, the 128×32 pixel into 21 columns and 4 rows, the 96×16 pixel into 16 columns and 2 rows. So in a display of 128×64 pixel we can write up to 168 character (21×8). The driver has a built-in font of 5×7.

-------------------------
📌Circuit Design
-------------------------
(All grounded terminal are connected together)

The PIC16F877A microcontroller has one hardware I2C module with SDA on pin RC4 (#23) and SCL on pin RC3 (#18). The SDA pin of the MCU is connected to the SDA pin of the display and the SCL pin of the MCU is connected to the SCL pin of the display.
The reset pin of the display is connected to pin RD4 (#27) of the microcontroller.

The SSD1306 OLED display DC pin is connected to VDD which means the I2C slave address of the display is 0x7A.

-------------------------
📌 Tags
-------------------------
#pc16f877a #ssd1306 #electronics

-------------------------
📌 The Code
-------------------------
SSD1306_Init(vccstate, i2caddr); initializes the display, i2caddr is the display address.

SSD1306_StartScrollRight(start, stop); scroll right
SSD1306_StartScrollLeft(start, stop); scroll left
SSD1306_StartScrollDiagRight(start, stop); scroll diagonal right
SSD1306_StartScrollDiagLeft(start, stop); scroll diagonal left
SSD1306_StopScroll(); stop scrolling

SSD1306_ClearDisplay(); clears the display.
SSD1306_FillScreen(); fills the whole screen.
SSD1306_Dim(dim); dim the display, dim can be 1 (true) or 0 (false).
SSD1306_InvertDisplay(i); inverts the display, i can be 1 or 0.

SSD1306_GotoXY(x, y); move cursor to position (x, y).
SSD1306_PutC(c); draws a character c on the screen position (x, y).
SSD1306_PutCustomC(char *c); draws a custom character c on the screen. c dimension should be 5×7. The default resolution of the DS18B20 is 12 bits.Source Code give in comment section.

📌 Tune With us so you never miss any update
------------------------------------------------------------------------------------------------------------------------------------------------------
🏷️Telegram : https://t.me/electronicsdeveloper
🏷️Facebook :   / electronicsdeveloper  
🏷️Instagram :   / electronics_developer  
🏷️Tweeter : https://twitter.com/Electronics_Dev?s=09
🏷️LinkedIn :   / electronics-with-shreyash  
🏷️Pinterest :   / electronics_developer  

Copyright Disclaimer under Section 107 of the copyright act 1976
-------------------------------------------------------------------------------------------------------------------------------------------------------
Copyright Disclaimer under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favour of fair use.

-------------------------------------------------------------------------------------------------------------------------------------------------------
About Electronics Developer : YouTube certified creative essentials and asset monetization
-------------------------------------------------------------------------------------------------------------------------------------------------------