Monday, 23 July 2018

Scrolling String on 16X2 LCD to ARM Microcontroller (LPC2148)

Aim:

The main aim of this project is how to interface a 16X2 LCD to LPC2148 micro-controller.

Description:


The most commonly used Character based LCDs are based on Hitachi’s HD44780 controller or other which are compatible with HD44580. In this tutorial, we will discuss about character based LCDs, their interfacing with various microcontrollers, various interfaces (8-bit/4-bit), programming, special stuff and tricks you can do with these simple looking LCDs which can give a new look to your application.
We are already know about how LCD works and atmega8 micro-controller. Here atmega8 has 3 PORTS. In the programming first you have to set the direction of PORT. The bellow steps are LCD programming using atmega8 microcontroller.
Instruction Register (IR) and Data Register (DR)
There are two 8-bit registers in HD44780 controller Instruction and Data register. Instruction register corresponds to the register where you send commands to LCD e.g LCD shift command, LCD clear, LCD address etc. and Data register is used for storing data which is to be displayed on LCD. when send the enable signal of the LCD is
asserted, the data on the pins is latched in to the data register and data is then moved automatically to the DDRAM and hence is displayed on the LCD. Data Register is not only used for sending data to DDRAM but also for CGRAM, the address where you want to send the data, is decided by the instruction you send to LCD.We will discuss more on LCD instuction set further in this tutorial.
Commands and Instruction set
Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by the MCU. Before starting the internal operation of the LCD, control information is temporarily stored into these registers to allow interfacing with various MCUs, which operate at different speeds, or various peripheral control devices. The internal operation
of the LCD is determined by signals sent from the MCU. These signals, which include register selection signal (RS), read/write signal (R/W), and the data bus (DB0 to DB7), make up the LCD instructions (Table 3). There are four categories of instructions that:
  • Designate LCD functions, such as display format, data length, etc.
  • Set internal RAM addresses
  • Perform data transfer with internal RAM
  • Perform miscellaneous functions
LCD Initialization
Before using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending set of commands to initialize the LCD. It is the user who has to decide whether an LCD has to be initialized by instructions or by internal reset circuit. we will dicuss both ways of initialization one by one.
Sending Commands to LCD
To send commands we simply need to select the command register. Everything is same as we have done in the initialization routine. But we will summarize the common steps and put them in a single subroutine. Following are the steps:
  •  Move data to LCD port
  • select command register
  • select write operation
  • send enable signal
  • wait for LCD to process the command
Sending Data to LCD
To send data we simply need to select the data register. Everything is same asthe command routine. Following are the steps:
  • Move data to LCD port
  • select data register
  • select write operation
  • send enable signal
  • wait for LCD to process the data

Block Diagram

4 lcd

Schematic

Code

// **************************************************
// Project: Scrolling string in LCD using LPC2148
// Author: Hack Projects India
// Module description: Operate a LCD
// **************************************************
#include <LPC214x.H>                       /* LPC214x definitions */

#define RS (1<<16)  //Set/Reset Pin (Control_Pin)
#define EN (1<<17)

void Delay(unsigned int time)
{
 unsigned int i,j;
 for(i=0;i<time;i++)
 for(j=0;j<250;j++);
}

void cmd_lcd(unsigned int cmd)
{
 IOCLR1=RS;  
 IOSET1=EN;
 IOSET1=((cmd)&(0xff))<<18; 
    Delay(50);
    IOCLR1=EN; 
 IOCLR1=RS; 
 IOCLR1=((cmd)&(0xff))<<18;
}
void data_lcd(unsigned int data)
{
    IOSET1=RS; 
 IOSET1=EN;
 IOSET1=((data)&(0xff))<<18;   
    Delay(50);
    IOCLR1=EN;   
    IOCLR1=RS;
 IOCLR1=((data)&(0xff))<<18;
}

void init_lcd()
{                  
    cmd_lcd(0X38);              //8 BIT LCD
    cmd_lcd(0X06);              //DISPLAY OFF CURSOR OFF
    cmd_lcd(0X0C);              //DISPLAY ON CURSOR OFF
    cmd_lcd(0X01);              //CLEAR THE LCD
}
int main (void) 
{
 unsigned char s[]="Hack Projects India ",i,j;
 IODIR1=0XfffF0000;
 init_lcd();   
    Delay(50);
 while(1)
 {  
   cmd_lcd(0x80); // Initial starting possion
   i=0;
   for(;s[i]!='\0';)
   data_lcd(s[i++]); // Print the data up to null character
   i=0;
   j=s[0]; // Take the 1st character in j
   for(;s[i]!='\0';i++)
   s[i] = s[i+1]; // Shift the characters in array
   s[i-1]=j; // Take the 1st character in last
   s[i]='\0'; // Finally take null character
   Delay(500);
 }  
}

Downloads:

The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:


    No comments:

    Post a Comment