LCD INTERFACING WITH LPC 2148 ARM 7

ARM (Advanced RISC Machine)is a 32 bit RISC processor architecture currently being developed by the ARM corporationThe business model behind ARM is based on licensing the ARM architecture to companies or system on chip products. ARM designs only architecture.

version

year

features

Implementations

V1

1985

The first commercial RISC(26bits).

ARM1

 

V2

1987

Coprocessor support

ARM2,ARM3

V3

1992

32bit MMU,64bit MAC

ARM6,ARM7

V4

1996

Thumb

ARM7TDMI,ARM8,ARM9TDMI,Strong ARM

V5

1999

DSP and jazelle extensions

ARM10

V6

2001

SIMD ,Thumb2,Trust zone ,Multiprocessing

ARM11,ARM11 MPCore

 

ARM7XXX

3Stage pipelining:-pipelining increase the speed of the controller .The instruction is fetched at first clock cycle. At next clock cycle the instruction is decoded and new instruction will fetch. In 3rd clock pulse the instruction decoded will execute and the previously fetched instruction will decode and also new instruction will fetch.           

MMU supports WINCE, LINUX, and SYMBIAN. Used in entry level mobile phones, mp3 players. Support both arm and thumb mode.

LPC 2148 is a 32 bit ARM7TDMI microcontroller in 64 pin package developed by Philips.

It has two ports port0 and port1 each with 32 pins. In port 1 only p1.16-p1.31 are user user accessible. Each port pins has different functions like GPIO, PWM, TX/RX etc..

The function of a pin can select using a register PINSEL. Two bits in the PINSEL register is used to select the function of one port pin. Using PINSEL0 we can only select the function of port0 pin up to 15.for remaining pins we can choose PINSEL1&PINSEL2.

The IODIR register is used to configure the direction of the pin if write one in this register corresponding pin become output. Using a register named IOSET, we can out a value through corresponding port. Using this register we can out only high level (1).writing zero in using IOSET register make no change in port pins. IOCLR register is used for making port pins low by writing high(1).

lcd

LCD (liquid crystal display) screen is an electronic display module.LCD 16x2 means it can display16 characters per line and there are two such lines.

DB0-DB7:-Data pins

The data and command are given through these pins.

EN:-enable  The lcd controller take the data from data pins only get a high to low transition in enable pin.

R/W : Mode of operation is select using this pin. Giving low to this pin for write something on lcd .read from lcd by making this pin in high state.

RS:: Register select pin.LCD has two registers namely data register and command register.

Writing commands codes for initializing the LCD. For display something on LCD first we have to initialize the LCD by giving some commands. Make RS pin low for giving commands. The LCD controller will take the values in data pins as commands when RS pin is in low state.

If RS is in high state the controller will take the values in data pins for displaying.

INSTRUCTION

HEX CODE

8bit ,1Line ,5x7Dots

0x30

8bit ,2Line ,5x7Dots

0x38

4bit ,1Line ,5x7Dots

0x20

bit ,2Line ,5x7Dots

0x28

Entry Mode

0x06

Display off cursor off

(clearing display without clearing content in DDRAM)

0x08

Display on cursor on

0x0E

Display on cursor off

0X0C

Display on cursor blinking

0X0F

Shift entire display left

0X18

Shift entire display right

0X1C

Move cursor left by one character

0X10

Move cursor right by one character

0x14

Clear display and DDRAM content

0x01

LCD can interface with a controller in two modes.

8bit mode: - in this mode using 8 port pins of the controller to give the data to LCD.this is the default mode.

4bit mode:-if we want to reduce the port pins of the controller for LCD we can use this mode.in this mode we supply data in the form of nibbles. Data pins D4-D7 are used in this mode.

Change the LCD to 4bit mode by giving commands.

LCD INTERFACING IN 8bit MODE

 

 

 

 

 

 

 

 

 

 

/* The program is done in keil uvision.*/

/**********************************************************/

#include <lpc214x.h>


void initLCD();                                                  //function declaration for initializing lcd                                                                                                                

void enable();                                                   // function declaration for enabling lcd                 

void LCD_WriteChar(char );                                       // function declaration for writing a character on lcd
   
void LCD_WriteString(char*);                                    // function declaration for writing a string on lcd

void LCD_Cmd(unsigned int);                                     // function declaration for giving commands to lcd

void delay();                                                   //delay

void main()

{

                IO0DIR = 0xFF;                                                   //make p0.0 –p0.7 as output for lcd

                IO1DIR |= (1<<16) | (1<<17);                      //p1.16&p1.17 output for EN and RS      

                IO0CLR = 0xFF;                                                  //clear p0.0 –p0.7

                IO1CLR = 0xFF;                                                  //clear p1.16&p1.17       

 initLCD();                                                            //function call for initializing lcd                

                 LCD_WriteString("...MEPITS.COM...");  // function call for write string on lcd

                LCD_Cmd(0x80 + 0x40);                                // to select next line on lcd                         

                LCD_WriteString("...MEPITS.COM...");

                while(1);                                                             //infinite loop   


}


void initLCD()                                                                     //function definition
             
{
            
                delay();                                                                                //delay call

                LCD_Cmd(0x38);                                              //command for 8bit, 2line mode                              

                LCD_Cmd(0x0F);                                              // command for display on cursor blinking

                LCD_Cmd(0x01);                                              // command for clear display

                LCD_Cmd(0x80);                                              //force cursor to beginning of the first row                        

}

void enable()

{
                delay();                                                                                //delay

                IO1SET |=  (1<<17);                                         //make EN pin high        

                delay();                                                                                                               

                IO1CLR |=(1<<17);                                           // make EN pin low

                delay();

}

void LCD_WriteChar(char c)

{

                IO1SET |= (1<<16);                                          //RS=1

                IO0CLR=0XFF;                                                //clear data pins

                IO0SET = c;                                                 //out data          

                enable();

}
void LCD_WriteString(char * string)         //string contains the address of the first location             

{
               

                         while (*string!='\0')                       //continue operation until get a’\0’                                                                                        

                                {

                                LCD_WriteChar(*string);              //function call

                                String++;                            //increment location     

                                }

}
void LCD_Cmd(unsigned int cmd)                            

{
                IO1CLR = (1<<16)|(1<<17);                                        //make EN&RS low

                IO0CLR =0XFF;                                                   //clear data pins

                IO0SET = cmd;                                                   //out command

                enable();                                                       //enable call      

}

void delay()                                                                    //delay function declaration                                                                      

{

int r=200000;

while(r--);

}


/*********************************************************************/

LCD INTERFACING IN FOUR BIT MODE

If we want to interface many peripherals with same controller, this requires a large number of ports or we need to be smart and utilize what we have to the fullest. Thus we have to reduce the number of pins required for controlling the peripherals.

If we interface an LCD in 8 bit mode we requires minimum of 11 pins. LCD module will work in both 8 bit and 4 bit modes. In 4bit mode operation only require 4 data pins in lcd D4 to D7

The basic operation of LCD is same as 8bit mode. For working LCD in 4 bit first we have to give a command for making the LCD in 4 bit mode. Data passing to the LCD is quite different because here we have only 4 data lines so first pass the upper nibble of the data and then lower nibble.

P0.16-P0.22 are used for LCD interfacing.

P0.16:-RS

P0.17:-RW

P0.18:-EN

P0.19-P0.22:- data pins

/*************************************************************************/

#include <lpc214x.h>

void initLCD();

void enable();

void LCD_WriteChar(char );

void LCD_WriteString(char*);

void LCD_Cmd(unsigned int);

void delay();

void LCD_Cnvrt(char);                    //convert function declaration

void main()

{

 IODIR0 = 0xF<<19;

 IO0DIR |= (1<<16) | (1<<17)|(1<<18);

                IO0CLR = 0xF<<19;

                IO1CLR = 0xF<<16;

                initLCD();

                LCD_WriteString("...MEPITS.COM...");   

                LCD_Cmd(0x80 + 0x40);

                LCD_WriteString("...MEPITS.COM...");

                while(1);             

}

void initLCD()

{

                                delay();

                                LCD_Cmd(0x28);

                                delay();

                                LCD_Cmd(0x0F);]

                                LCD_Cmd(0x01);

                                LCD_Cmd(0x80);                

}

void enable()

{

                                delay();

                                IO0SET |=  (1<<18);

                                delay();

                                IO0CLR |=(1<<18);

                                delay();

}

void LCD_WriteChar(char c)

{

                                IO0SET |= (1<<16);

                                IO0CLR=0XF<<19;

                                LCD_Cnvrt(c);                                    //convert function call

 }

void LCD_WriteString(char * string)

{

                                while (*string!='\0')

                                {

                                LCD_WriteChar(*string);

                                string++;

                                }

}

void LCD_Cmd(unsigned int cmd)

{

                                IO0CLR = (1<<16)|(1<<17)|(1<<18);

                                IO0CLR =0XF<<19;

                                LCD_Cnvrt(cmd);

}             

                 void LCD_Cnvrt(char c)                                

                                  {

                                  int i;

                                  i=c>>4;                                                 //write shift c four times

                                  IO0SET |=i<<19;

/*left shift the value in ‘I’ 19 times And out the  data(upper nibble)through PORT0. */


                                    enable();

                                    IO0CLR=0XF<<19;                                           

                                    i=c;

                                    IO0SET |=i<<19;

/*left shift the data in ‘I’ 19 times and out tha data(Lower nibble) through PORT0*/

                                enable();

                                }

void delay()

{

int r=200000;

while(r--);

 }                                           

/****************************************************************************/*

lpc2148

User Review (1)

SUJITH MATHEW   Kochi,Kerala

GOOD TUTORIAL

Reply  Report Abuse   12 April,2016 02:04
Related Items