Featured Post

ARM- ADC and LCD Interface

In real world all natural quantities like temperature, pressure, light intensity etc. are analog. If we have to deal with such quantities us...

Friday, 7 May 2021

LCD Interface with ARM 2138 in 4 bit mode

The various LCD commands used to write data to LCD are given below : -

Various LCD commands used to write data to LCD

For Writing to LCD RS, RW and EN pins of a 16character 2 line LCD. It has 8 data pins can be configured in 4 bit and 8bit using proper commands. RS=1 for writing data, and RS=0 for register select for writing special character but for our program it is RS=1.

RW=0 I kept as such as we are writing data. EN=1 for enabling writing for 20 s and then EN=0 disabled.

Steps For LCD Interface With ARM 2138 In 4 Bit Mode

Step 1: initialize the LCD in 4 bit with 2 line.

Step2: create a library for writing a letter or strings.

The library is as follows.

Code For Creating Library For LCD Interface With ARM 2138 In 4 Bit Mode


#include <LPC21xx.h>

void Delay(unsigned long b)
{
    while (--b!=0);
}

void write_command(int cmd)
{
        IO1CLR |= 0x00f00000; // Clear Data pins
        IO1CLR |= 0x00040000; // RW = 0
        IO1CLR |= 0X00020000; // RS= 0,
        IO1SET |= 0x00f00000 & cmd; //Set Data pins
        IO1SET |= 0X00080000; // Enable = 1
        Delay(30000); // Provide Delay
        IO1CLR |= 0x00080000; // Set Enable=0
}

void write_data(int dat)
{
        IO1CLR |= 0x00f00000; // Clear Data pins4-D7
        IO1CLR |= 0x00040000; // RW= 0
        IO1SET |= 0X00020000; //RS= 1
        IO1SET |= 0x00f00000 & dat; // Set Data pins
        IO1SET |= 0X00080000; // Enable = 1
        Delay(30000); //Provide Delay
        IO1CLR |= 0x00080000; //Set Enable=0 
}

void lcd_data(char dat)
{
        write_data(dat << 16);
        write_data(dat << 20);
}

void lcd_command(char cmd)
{
        write_command(cmd << 16);
        write_command(cmd << 20);
}

void printlcd(char *CPtr)
{
        while(*CPtr != 0)
        {
                lcd_data(*CPtr);
                CPtr++;
                Delay(20000);
        }
}

void init_lcd(void)
{
        IO1DIR |= 0x00FE0000;
        Delay(200000) ;
        Delay(100000);
        write_command(0x30 << 16);
        Delay(100000);
        write_command(0x20 << 16);
        lcd_command(0x01); /* clear display */
        lcd_command(0x06); /* auto address inc */
        lcd_command(0x0c); /* cursor off */
        lcd_command(0x28); lcd_command(0x80); /* first location */

}

Then The Main Program For  LCD Interface With ARM 2138 In 4 bit Mode Calling This Header File As Follows To Write A String “Hello World” : -

#include <LPC21xx.h>
#include "lcd.h"

int main(void) 
{
        init_lcd();
        while(1)
        {
                lcd_command(0x01);
                lcd_command(0x80);
                printlcd("Welcome To");
                lcd_command(0xC0);
                printlcd("Hello World");
                Delay(50000000);
        }
}

Circuit Diagram For LCD Interface With ARM 2138 In 4 Bit Mode : -

Circuit Diagram For LCD Interface With ARM 2138 In 4 Bit Mode


No comments:

Post a Comment