echo '' ;

Archives

8051 Interface – LCD


Interfacing an LCD (Liquid Crystal Display) with the 8051 microcontroller is a common practice in embedded systems for displaying information. Here’s a brief overview of 8051 Interface LCD

  • Hardware Connections: Connect the data lines (D0-D7) of the LCD to the GPIO pins of the 8051. Connect the control lines (RS, RW, E) to specific GPIO pins. Optionally, connect the backlight control pin and adjust the contrast using a potentiometer.
  • Initialization: Send initialization commands to the LCD to configure its operation mode, display settings, and other parameters. This typically involves sending specific command codes over the data lines.
  • Sending Data: To display characters or strings on the LCD, send the ASCII codes of the characters over the data lines while setting the RS (Register Select) line appropriately to indicate data transmission mode.
  • Sending Commands: To control the operation of the LCD (such as clearing the display, setting the cursor position, etc.), send command codes over the data lines while setting the RS line to indicate command transmission mode.
  • Timing Considerations: Ensure proper timing between data/command transmissions and the strobing of the E (Enable) line to ensure reliable communication with the LCD.
  • Busy Flag Checking: Check the busy flag of the LCD before sending new commands or data to ensure that the LCD is ready to receive new instructions.
  • Writing Custom Characters: Some LCDs allow you to define custom characters by programming specific patterns into the CGRAM (Character Generator RAM) of the LCD.
  • Example Code: Here’s a basic example of initializing and sending data to an LCD connected to an 8051 microcontroller:
Read more: 8051 Interface – LCD

Uses of LCD

  • Displaying Information: LCDs (Liquid Crystal Displays) are used to visually display information such as text, numbers, and symbols.
  • Interface Compatibility: They can be easily interfaced with 8051 microcontrollers through parallel or serial communication interfaces.
  • Textual Output: LCDs allow for the display of textual information, making them suitable for user interfaces or information panels.
  • Low Power Consumption: They typically consume less power compared to other display technologies, making them suitable for battery-powered devices.
  • Compact Size: LCD modules come in various sizes, allowing for flexibility in design and integration into compact devices.
  • Backlighting Options: Some LCD modules offer backlighting options, enabling visibility in low-light conditions.
  • Dynamic Display: LCDs can be dynamically updated to show changing information or real-time data.
  • Multipurpose Usage: They find applications in various domains such as digital clocks, thermometers, calculators, and industrial control panels.

Next will see about code of 8051 Interface LCD

Code Header file (LCD8.h)

#define LCD_First_Line     0x80
#define LCD_Second_Line    0xc0
#define LCD_Curser_On          0x0f
#define LCD_Curser_Off         0x0c
#define LCD_Clear_Display 0x01
#define Lcd8_Data_Port         P2

sbit Lcd8_RS = P0^0;
sbit Lcd8_RW = P0^1;
sbit Lcd8_EN = P0^2;

void Lcd8_Init();
void Lcd8_Command(unsigned char);
void Lcd8_Write(unsigned char,unsigned char);
void Lcd8_Display(unsigned char,const unsigned char*,unsigned int);
void Lcd8_Decimal2(unsigned char,unsigned char);
void Lcd8_Decimal3(unsigned char,unsigned char);
void Lcd8_Decimal4(unsigned char,unsigned int);
void Delay(unsigned int);

void Lcd8_Init()
{
    Lcd8_Command(0x38);     //to select function set
    Lcd8_Command(0x06);     //entry mode set
    Lcd8_Command(0x0c);     //display on
    Lcd8_Command(0x01);     //clear display
}

void Lcd8_Command(unsigned char com)
{
    Lcd8_Data_Port=com;
    Lcd8_EN=1;
    Lcd8_RS=Lcd8_RW=0;
    Delay(125);
    Lcd8_EN=0;
    Delay(125);
}

void Lcd8_Write(unsigned char com,unsigned char lr)
{
    Lcd8_Command(com);

    Lcd8_Data_Port=lr;          // Data 
    Lcd8_EN=Lcd8_RS=1;
    Lcd8_RW=0;
    Delay(125);
    Lcd8_EN=0;
    Delay(125);
}

void Lcd8_Display(unsigned char com,const unsigned char *word,unsigned int n)
{
    unsigned char Lcd_i;

    for(Lcd_i=0;Lcd_i<n;Lcd_i++)
    { 
        Lcd8_Write(com+Lcd_i,word[Lcd_i]);
    }
}

void Lcd8_Decimal2(unsigned char com,unsigned char val)
{
    unsigned int Lcd_hr,Lcd_t,Lcd_o;

    Lcd_hr=val%100;
    Lcd_t=Lcd_hr/10;
    Lcd_o=Lcd_hr%10;
    
    Lcd8_Write(com,Lcd_t+0x30);
    Lcd8_Write(com+1,Lcd_o+0x30);
}


void Lcd8_Decimal3(unsigned char com,unsigned char val)
{
    unsigned int Lcd_h,Lcd_hr,Lcd_t,Lcd_o;

    Lcd_h=val/100;
    Lcd_hr=val%100;
    Lcd_t=Lcd_hr/10;
    Lcd_o=Lcd_hr%10;
    
    Lcd8_Write(com,Lcd_h+0x30);
    Lcd8_Write(com+1,Lcd_t+0x30);
    Lcd8_Write(com+2,Lcd_o+0x30);
}

void Lcd8_Decimal4(unsigned char com,unsigned int val) 
{
    unsigned int Lcd_th,Lcd_thr,Lcd_h,Lcd_hr,Lcd_t,Lcd_o;

    val = val%10000;
    Lcd_th=val/1000;
    Lcd_thr=val%1000;
    Lcd_h=Lcd_thr/100;
    Lcd_hr=Lcd_thr%100;
    Lcd_t=Lcd_hr/10;
    Lcd_o=Lcd_hr%10;

    Lcd8_Write(com,Lcd_th+0x30);
    Lcd8_Write(com+1,Lcd_h+0x30);
    Lcd8_Write(com+2,Lcd_t+0x30);
    Lcd8_Write(com+3,Lcd_o+0x30);
}

void Delay(unsigned int del)
{
    while(del--);
}     

Code Main File (LCD8_Interface_Main.c)

#include<reg51.h>
#include "LCD8.h"

void timer_init(void);

static unsigned char i;
static unsigned int x=100,y=150,cnt; 

void main()
{
    Lcd8_Init();
    Lcd8_Display(LCD_First_Line,"   Hello World  ",16);
    while(1)
    {
        Lcd8_Display(LCD_Second_Line," ArunEworld.com ",16);
    }//while(1)
}//void main()

ESP8266 NodeMCU Interface – LCD

The ESP8266 NodeMCU Interface with LCD allows you to integrate an LCD with your NodeMCU board, enabling you to create projects with visual feedback.

Read more: ESP8266 NodeMCU Interface – LCD

LCD 16×2 HD44780 Display Interface

  • We can easily add a 2×16 LCD to ESP8266.
  • But ESP8266 has less GPIO pins.
  • Two methods.
    • Using i2c driver
    • Using GPIO pins.

Code

This code provides basic functionality for interfacing with a 16×2 HD44780 LCD using an ESP8266 NodeMCU board. Adjustments may be needed based on your specific hardware setup and requirements.

-- Define GPIO pins for LCD connections
local PIN_RS = 1    -- GPIO5
local PIN_EN = 2    -- GPIO4
local PIN_D4 = 3    -- GPIO0
local PIN_D5 = 4    -- GPIO2
local PIN_D6 = 5    -- GPIO14
local PIN_D7 = 6    -- GPIO12

-- Function to send a command to LCD
local function lcd_command(cmd)
    gpio.write(PIN_RS, gpio.LOW)   -- Set RS pin LOW for command mode
    -- Send high nibble
    gpio.write(PIN_D4, bit.isset(cmd, 4) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D5, bit.isset(cmd, 5) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D6, bit.isset(cmd, 6) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D7, bit.isset(cmd, 7) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_EN, gpio.HIGH)
    gpio.write(PIN_EN, gpio.LOW)
    -- Send low nibble
    gpio.write(PIN_D4, bit.isset(cmd, 0) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D5, bit.isset(cmd, 1) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D6, bit.isset(cmd, 2) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D7, bit.isset(cmd, 3) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_EN, gpio.HIGH)
    gpio.write(PIN_EN, gpio.LOW)
    -- Delay for command execution
    tmr.delay(2000)  -- Adjust delay as needed
end

-- Function to send data to LCD
local function lcd_data(data)
    gpio.write(PIN_RS, gpio.HIGH)  -- Set RS pin HIGH for data mode
    -- Send high nibble
    gpio.write(PIN_D4, bit.isset(data, 4) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D5, bit.isset(data, 5) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D6, bit.isset(data, 6) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D7, bit.isset(data, 7) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_EN, gpio.HIGH)
    gpio.write(PIN_EN, gpio.LOW)
    -- Send low nibble
    gpio.write(PIN_D4, bit.isset(data, 0) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D5, bit.isset(data, 1) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D6, bit.isset(data, 2) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_D7, bit.isset(data, 3) and gpio.HIGH or gpio.LOW)
    gpio.write(PIN_EN, gpio.HIGH)
    gpio.write(PIN_EN, gpio.LOW)
    -- Delay for data transfer
    tmr.delay(2000)  -- Adjust delay as needed
end

-- Function to initialize the LCD
local function lcd_init()
    -- Set GPIO pins as outputs
    gpio.mode(PIN_RS, gpio.OUTPUT)
    gpio.mode(PIN_EN, gpio.OUTPUT)
    gpio.mode(PIN_D4, gpio.OUTPUT)
    gpio.mode(PIN_D5, gpio.OUTPUT)
    gpio.mode(PIN_D6, gpio.OUTPUT)
    gpio.mode(PIN_D7, gpio.OUTPUT)
    
    -- Initialization sequence
    tmr.delay(15000)  -- Wait for power-up
    lcd_command(0x33) -- Initialize
    lcd_command(0x32) -- Set to 4-bit mode
    lcd_command(0x28) -- 2 lines, 5x8 font
    lcd_command(0x0C) -- Display on, cursor off, blink off
    lcd_command(0x01) -- Clear display
    lcd_command(0x06) -- Increment cursor
end

-- Function to clear the LCD
local function lcd_clear()
    lcd_command(0x01) -- Clear display
end

-- Function to set cursor position
local function lcd_set_cursor(row, col)
    local offset = {0x00, 0x40}
    lcd_command(0x80 + offset[row] + col - 1)
end

-- Function to write a string to the LCD
local function lcd_write_string(str)
    for i = 1, #str do
        lcd_data(string.byte(str, i))
    end
end

-- Example usage
lcd_init()  -- Initialize the LCD
lcd_clear() -- Clear the LCD
lcd_set_cursor(1, 1) -- Set cursor to first row, first column
lcd_write_string("Hello, World!") -- Write a string to the LCD

Code Explanation

SectionExplanation
Initialization– The code initializes the LCD module by setting up the GPIO pins for communication and configuring the LCD settings.
Function Definitions– Defines helper functions for sending commands and data to the LCD, such as lcd_send_command and lcd_send_data. These functions handle the low-level communication with the LCD module.
LCD Initialization– Initializes the LCD by sending a sequence of commands to configure its display settings, such as the number of lines, cursor behavior, and display on/off settings.
Clearing the Display– Sends a command to clear the display and return the cursor to the home position.
Setting Cursor– Sets the cursor position on the LCD. The lcd_set_cursor function takes the row and column numbers as parameters and calculates the corresponding position based on the LCD’s row length.
Writing Characters– Writes characters to the LCD at the current cursor position. The lcd_write_char function sends data to the LCD to display the specified character.
Writing Strings– Writes strings to the LCD. The lcd_write_string function iterates over each character in the string and calls lcd_write_char to display them sequentially.
Main Function– Demonstrates how to use the defined functions to interact with the LCD. It initializes the LCD, clears the display, sets the cursor to the first position, and writes a string to the LCD.

Nokia-5110 PCD8544 Display interface

  • Required NodeMCU Modules (Firmware): GPIO Module
  • Required hardware: ESP8266 with Programmer (or)  NodeMCU Dev Kit, Nokia 5110 PCD8544 LCD Display,
  • Required software tools: ESPlorer IDE Tool

Code

`lua
-- https://www.aruneworld.com/embedded/esp8266/esp8266-nodemcu/
-- Tested By : Arun(20170212)
-- Example Name : AEW_LCD_Nokia-5110_PCD8544.lua
-- Reference data sheet: https://www.sparkfun.com/datasheets/LCD/Monochrome/Nokia5110.pdf

--------------------------------------------------------------------------------
-- The following code referred by this post: http://playground.arduino.cc/Code/PCD8544
-- You need to configure the pins you are using here
PIN_RESET = 0
PIN_SCE = 1
PIN_DC = 2
PIN_SDIN = 3
PIN_SCLK = 4

local LCD_D = gpio.HIGH
local LCD_C = gpio.LOW
local LCD_X = 84
local LCD_Y = 48

local chars = "\0\0\0\0\0\0\0\95\0\0\0\7\0\7\0\20\127\20\127\20\36\42\127\42\18\35\19\8\100\98\54\73\85\34\80\0\5\3\0\0\0\28\34\65\0\0\65\34\28\0\20\8\62\8\20\8\8\62\8\8\0\80\48\0\0\8\8\8\8\8\0\96\96\0\0\32\16\8\4\2\62\81\73\69\62\0\66\127\64\0\66\97\81\73\70\33\65\69\75\49\24\20\18\127\16\39\69\69\69\57\60\74\73\73\48\1\113\9\5\3\54\73\73\73\54\6\73\73\41\30\0\54\54\0\0\0\86\54\0\0\8\20\34\65\0\20\20\20\20\20\0\65\34\20\8\2\1\81\9\6\50\73\121\65\62\126\17\17\17\126\127\73\73\73\54\62\65\65\65\34\127\65\65\34\28\127\73\73\73\65\127\9\9\9\1\62\65\73\73\122\127\8\8\8\127\0\65\127\65\0\32\64\65\63\1\127\8\20\34\65\127\64\64\64\64\127\2\12\2\127\127\4\8\16\127\62\65\65\65\62\127\9\9\9\6\62\65\81\33\94\127\9\25\41\70\70\73\73\73\49\1\1\127\1\1\63\64\64\64\63\31\32\64\32\31\63\64\56\64\63\99\20\8\20\99\7\8\112\8\7\97\81\73\69\67\0\127\65\65\0\2\4\8\16\32\0\65\65\127\0\4\2\1\2\4\64\64\64\64\64\0\1\2\4\0\32\84\84\84\120\127\72\68\68\56\56\68\68\68\32\56\68\68\72\127\56\84\84\84\24\8\126\9\1\2\12\82\82\82\62\127\8\4\4\120\0\68\125\64\0\32\64\68\61\0\127\16\40\68\0\0\65\127\64\0\124\4\24\4\120\124\8\4\4\120\56\68\68\68\56\124\20\20\20\8\8\20\20\24\124\124\8\4\4\8\72\84\84\84\32\4\63\68\64\32\60\64\64\32\124\28\32\64\32\28\60\64\48\64\60\68\40\16\40\68\12\80\80\80\60\68\100\84\76\68\0\8\54\65\0\0\0\127\0\0\0\65\54\8\0\16\8\8\16\8\120\70\65\70\120"

local function shiftOut(d, cl, data)
    for index = 0, 7 do
        if bit.isset(data, 7 - index) then
            gpio.write(d, gpio.HIGH)
        else
            gpio.write(d, gpio.LOW)
        end
        gpio.write(cl, gpio.HIGH)
        tmr.delay(5)
        gpio.write(cl, gpio.LOW)
    end
end

local function LCDWrite(dc, data)
    gpio.write(PIN_DC, dc)
    gpio.write(PIN_SCE, gpio.LOW)
    shiftOut(PIN_SDIN, PIN_SCLK, data)
    gpio.write(PIN_SCE, gpio.HIGH)
end

function LcdSetPins(sclk, sdin, dc, sce, reset)
    PIN_SCLK = sclk
    PIN_SDIN = sdin
    PIN_DC = dc
    PIN_SCE = sce
    PIN_RESET = reset
end

function LcdLocate(x, y)
    LCDWrite(LCD_C, 64 + x)
    LCDWrite(LCD_C, 128 + y)
end

function LcdCharacter(character)
    LCDWrite(LCD_D, 0x00)
    for index = 0, 5 do
        LCDWrite(LCD_D, character)
    end
    LCDWrite(LCD_D, 0x00)
end

function LcdClear()
    local c = 84 * 6
    for index = 0, c do
        tmr.delay(5)
        LCDWrite(LCD_D, 0)
    end
end

function LcdPrintChar(c)
    LCDWrite(LCD_D, 0)
    local char_index = 1 + (string.byte(c) - 32) * 5
    for index = 0, 4 do
        LCDWrite(L

Code Explanation

This Lua code initializes and interacts with a Nokia 5110 LCD module (PCD8544 controller) using an ESP8266 NodeMCU board. The code provides a basic framework for interfacing with the Nokia 5110 LCD module using the ESP8266 NodeMCU board, allowing for the display of text and basic graphics. Here’s the explanation:

SectionExplanation
Initialization and Pins– Pins for interfacing with the LCD module are configured (RESET, SCE, DC, SDIN, SCLK).
– References and credits are provided in the comments.
LCD Character Data– Character data for the LCD is defined in the chars variable. Each character is represented by a series of bytes.
Shift Out Function– Sends data to the LCD module by shifting bits out through a specified pin.
LCD Write Function– Writes data to the LCD. Sets the appropriate data/command mode and then uses shiftOut to send the data.
Setting Pin Configuration– Allows setting the pins used for communication with the LCD dynamically.
LCD Cursor Positioning– Positions the cursor at the specified coordinates on the LCD.
Writing a Character– Writes a single character to the LCD at the current cursor position.
Clearing the LCD– Clears the entire LCD display.
Printing a Character– Prints a character to the LCD, advancing the cursor position accordingly.
Initialization– Initializes the LCD module with the appropriate settings.
Test Function– A test function that initializes the LCD and prints some sample text.

Next

ESP8266 NodeMCU Interface – LCD

NodeMCU Get Start
NodeMCU Build Firmware
NodeMCU Flash Firmware
NodeMCU IDE
ESP8266 NodeMCU Modules
NodeMCU Module–Firmware Info
NodeMCU Module – GPIO
NodeMCU Module – Node
NodeMCU Module – WiFi
NodeMCU Module – Timer
NodeMCU Module – I2C
NodeMCU Module – File
NodeMCU Module – NET
NodeMCU Module – HTTP
NodeMCU Module – MQTT
ESP8266 NodeMCU Interface
NodeMCU Interface LED
NodeMCU Interface Button
NodeMCU Interface 7 Seg
NodeMCU Interface LCD
NodeMCU Interface ADC
NodeMCU Interface DHT11
NodeMCU Interface MCP23008
NodeMCU Interface MCP23017
NodeMCU Interface ADXL345
NodeMCU Interface DS18B20
ESP8266 NodeMCU Tutorials
NodeMCU Tutorials Google Time
NodeMCU Tutorials WebServer
ESP8266 NodeMCU Projects
Imperial March Ringtone Play
WiFi Router Status Indicator
ESP8266 Home Automation
Others
NodeMCU All Post
Sitemap

Embedded Interface – LCD

Examples

  • Display Character
  • Display String
  • Display Decimal
    • Display one Digit Decimal
    • Display Two Digit Decimal
    • Display Three Digit Decimal
  • Auto scroll Display
  • Blink
  • Cursor On/Off
  • Custom Character
  • Display
  • Hello world
  • Scroll
  • Serial Display
  • Set Cursor
  • Text Direction

LCD Interface with Micro-controllers

Different LCD Displays

  • Nokia 5110 LCD Module with PCD8544 
  • Nokia 6610 
  • OLEDs 
  • 2×16 LCD- hd44780 
  • Nextion Display 

 

 

Next Topic

Embedded Interface 7 Segment (Add Soon)
Embedded Interface ADC (Add Soon)
Embedded Interface Button (Add Soon)
Embedded Interface EEPROM (Add Soon)
Embedded Interface LCD (Add Soon)
Embedded Interface LCD HD44780 (Add Soon)
Embedded Interface LED
Embedded Interface MCP23017
Embedded Interface Motor (Add Soon)
Embedded Interface PCF8574 and PCF8574A
Embedded Interface RTC (Add Soon)
Embedded Interface Switch
Embedded Interface Touch Kypad
Embedded Interface RGB LED (Add Soon)

Embedded Interface – LCD HD44780

  • HD44780 compliant controllers 16×2 Character LCD is a very basic and low-cost LCD module that is commonly used in electronic products and projects.
  • 16×2 means it contains 2 rows that can display 16 characters.
  • Its other variants such as 16×1 and 16×4 are also available in the market.
  • In these displays, each character is displayed using 5×8 or 5×10 dot matrix.

Experiments

  • Change Cursor Location Based on Key Input

LCD4 Bit Mode Functions

void Lcd4_Clear()   {    Lcd4_Cmd(0x00);    Lcd4_Cmd(0x01);    }    // clear screen 0x01

void Lcd4_DisplayOFF_BlinkON_CursorON()        {    Lcd4_Cmd(0x00);    Lcd4_Cmd(0x0B);    }    // 0x0B

void Lcd4_DisplayON_BlinkOFF_CursorOFF()    {    Lcd4_Cmd(0x00);    Lcd4_Cmd(0x0C);    }    // 0x0C

void Lcd4_DisplayON_BlinkOFF_CursorON()     {    Lcd4_Cmd(0x00);    Lcd4_Cmd(0x0D);    }    // 0x0C

void Lcd4_DisplayON_BlinkON_CursorOFF() {    Lcd4_Cmd(0x00);    Lcd4_Cmd(0x0E);    }    // 0x0E

//void Lcd4_Shift_Left()                      {   Lcd4_Cmd(0x01); Lcd4_Cmd(0x08); }   //  0x18

//void Lcd4_Shift_Right()                     {   Lcd4_Cmd(0x01); Lcd4_Cmd(0x0C); }   //  0x1C

 

 

Next Topic

Embedded Interface 7 Segment (Add Soon)
Embedded Interface ADC (Add Soon)
Embedded Interface Button (Add Soon)
Embedded Interface EEPROM (Add Soon)
Embedded Interface LCD (Add Soon)
Embedded Interface LCD HD44780 (Add Soon)
Embedded Interface LED
Embedded Interface MCP23017
Embedded Interface Motor (Add Soon)
Embedded Interface PCF8574 and PCF8574A
Embedded Interface RTC (Add Soon)
Embedded Interface Switch
Embedded Interface Touch Kypad
Embedded Interface RGB LED (Add Soon)