LCD Interfacing-ARM LPC2148 Embedded C

LCD Interfacing-ARM LPC2148 
Introduction:


This Code is specially developed for LCD on ALS ARM LPC2148 Evaluation Board.

A 16*2 Alphanumeric display with backlight is provided on Evaluation Board.

  • Mode of Operation:- LCD is interfaced using 4 bit Mode.
  • Port Details:   P0.2 to P0.7  are used for LCD interfacing.
RS = 0 for sending Command to the LCD, controlled by port P0.2
RS = 1 for sending Data to the LCD, controlled by port P0.2
EN = 0 for disabling the LCD ,controlled by port P0.3
EN = 1 for enabling the LCD, controlled by port P0.3
D4 to D7 (P0.4 to P0.7) – data lines



Program:


// LCD INTERFACING USING LPC2148
//----------------------------------------------------------------
// CONTROLLER   : LPC-2148
// Developed By  : Abhay Kagalkar
//----------------------------------------------------------------
#include <lpc214x.h >
#include<stdio.h>

//Function prototypes
void delay(unsigned int);
void comm(void);
void writeData(void);
void data(void);
void lcd_initialize(void);
void writeCommand(void);
void clr_display(void);


unsigned char temp1;
unsigned long int temp,r=0;
unsigned char *ptr;
unsigned char data1[] = "CODESEXPLORER",data2[] = "ABHAY KAGALKAR";

int main()
{
    IO0DIR = 0x000000FC;  //configure o/p lines for lcd
    lcd_initialize();              //lcd intialisation
    delay(3200);
    clr_display();   //clear display
    delay(3200);
    temp1 = 0x80;   //Display starting address of first line 
    comm();
    ptr = data1;
    while(*ptr!='\0')
    {
    temp1 = *ptr;
      data();
 ptr ++;
    }
    temp1 = 0xC0;   // Display starting address of second line 1st pos
    comm();
    ptr = data2;
    while(*ptr!='\0')
    {
     temp1 = *ptr;
     data();
        ptr ++;
    }
   while(1);

}  //end of main()
 void delay(unsigned int r1)
{
 for(r=0;r<r1;r++);
}
// lcd initialisation routine.
void lcd_initialize(void)
{
 temp = 0x30;
 writeCommand();
 delay(3200);

 temp = 0x30;
 writeCommand();
 delay(3200);

 temp = 0x30;
 writeCommand();
 delay(3200);

 temp = 0x20; // change to 4 bit mode from default 8 bit mode
 writeCommand();
 delay(3200);

 temp = 0x28; // load command for lcd function setting with lcd in 4 bit mode,
 comm();    // 2 line and 5x7 matrix display
 delay(3200);

 comm();
 temp1 = 0x0C; // load a command for display on, cursor on and blinking off
 delay(800);

 temp1 = 0x06;  // command for cursor increment after data dump
 comm();
 delay(800);

 temp1 = 0x80;  // set the cursor to beginning of line 1
 comm();
 delay(800);
}

void comm(void)
{
    temp = temp1 & 0xf0;
    writeCommand();
    temp = temp1 & 0x0f;
    temp = temp << 4;
    writeCommand();
    delay(500);
}

// command nibble o/p routine
void writeCommand(void)         //write the values to command reg
{
 IO0CLR  = 0x000000FC;  // clear the port lines.
 IO0SET  = temp;    // Assign the value to the PORT lines
 IO0CLR  = 0x00000004;  // clear bit  RS = 0
 IO0SET  = 0x00000008;    // E=1
 delay(10);
 IO0CLR  = 0x00000008;
}
// data nibble
void writeData(void)   ////write the values to  data reg
{
 IO0CLR = 0x000000FC; // clear the port lines.
 IO0SET = temp;   // Assign the value to the PORT lines
 IO0SET = 0x00000004;    // set bit  RS = 1
 IO0SET = 0x00000008;    // E=1
 delay(10);
 IO0CLR = 0x00000008;
}
// data o/p routine which also outputs high nibble first
// and lower nibble next
void data(void)
{
    temp = temp1 & 0xf0;
    temp = temp ;//<< 6;
    writeData();
    temp= temp1 & 0x0f;
    temp= temp << 4;
    writeData();
    delay(100);
}
void clr_display(void)
{
    temp1 = 0x01;
    comm();
    delay(500);
}



Download the Code with HEX File:
 To Download the Code click on the link below:
 LCD Program Download

1 comment:

  1. Change the value of data1 string variable to your desired string to make that display on first line.And that of data2 to display in second line

    ReplyDelete

Powered by Blogger.