----------------------------------------------------------------------------------------

1. Multiply two 16-bit binary numbers

AREA MULTIPLY , CODE, READONLY
ENTRY ;Mark first instruction to execute
START
MOV r1,#6400 ; STORE FIRST NUMBER IN R0
MOV r2,#3200 ; STORE SECOND NUMBER IN R1
MUL r3,r1,r2 ; MULTIPLICATION

NOP
NOP
NOP

END ;Mark end of file    
-----------------------------------------------------------------------------------------

2. Sum of the first 10 integer numbers

AREA SUM , CODE, READONLY
ENTRY ;Mark first instruction to execute
START

MOV r0, #10 ; STORE INTEGER NUMBER IN R0
MOV r1,r0 ; MOVE THE SAME NUMBER IN R1

RPT SUBS r1, r1, #1 ; SUBTRACTION

CMP r1, #0 ; COMPARISON
BEQ STOP
ADD r3,r0,r1; ; ADDITION
MOV r0,r3 ; Result
BNE RPT ; BRANCH TO THE LOOP IF NOT EQUAL

STOP

NOP
NOP
NOP

END ;Mark end of file    
----------------------------------------------------------------------------------------------

3. Factorial of a number

AREA FACTORIAL , CODE, READONLY
ENTRY ;Mark first instruction to execute
START

MOV r0, #7 ; STORE FACTORIAL NUMBER IN R0
MOV r1,r0 ; MOVE THE SAME NUMBER IN R1

FACT SUBS r1, r1, #1 ; SUBTRACTION

CMP r1, #1 ; COMPARISON
BEQ STOP
MUL r3,r0,r1; ; MULTIPLICATION
MOV r0,r3 ; Result
BNE FACT ; BRANCH TO THE LOOP IF NOT EQUAL

STOP

NOP
NOP
NOP

END ;Mark end of file    
-------------------------------------------------------------------------------

4. Add an array of 16-bit numbers

AREA ADDITION , CODE, READONLY
ENTRY ;Mark first instruction to execute
START
MOV R5,#6 ; INTIALISE COUNTER TO 6(i.e. N=6)
MOV R0,#0 ; INTIALISE SUM TO ZERO
LDR R1,=VALUE1 ; LOADS THE ADDRESS OF FIRST VALUE
LOOP
LDR R2,[R1],#2 ; WORD ALIGN T0 ARRAY ELEMENT
LDR R3,MASK ; MASK TO GET 16 BIT
AND R2,R2,R3 ; MASK MSB
ADD R0,R0,R2 ; ADD THE ELEMENTS
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ;
BNE LOOP ; LOOK BACK TILL ARRAY ENDS

LDR R4,=RESULT ; LOADS THE ADDRESS OF RESULT
STR R0,[R4] ; STORES THE RESULT IN R1

BACK B BACK
 MASK DCD 0X0000FFFF ; MASK MSB

VALUE1 DCW 0X1111,0X2222,0X3333,0XAAAA,0XBBBB,0XCCCC
; ARRAY OF 16 BIT NUMBERS(N=6)

AREA DATA2, DATA, READWRITE ; TO STORE RESULT IN GIVEN ADDRESS

RESULT DCD 0X0

END ; Mark end of file   
-----------------------------------------------------------------------------------

5. Square of a number using look-up table

AREA SQUARE , CODE, READONLY
ENTRY ;Mark first instruction to execute

START
LDR R0, = TABLE1 ; Load start address of Lookup table
LDR R1,= 9 ; Load no whose square is to be find
MOV R1, R1, LSL#0x2 ; Generate address corresponding to square of given no
ADD R0, R0, R1 ; Load address of element in Lookup table
LDR R3, [R0] ; Get square of given no in R3

NOP
NOP
BACK B BACK

;Lookup table contains Squares of numbers from 0 to 10 (in hex)
TABLE1 DCD 0X00000000; SQUARE OF 0=0
DCD 0X00000001; SQUARE OF 1=1
DCD 0X00000004; SQUARE OF 2=4
DCD 0X00000009; SQUARE OF 3=9
DCD 0X00000010; SQUARE OF 4=16
DCD 0X00000019; SQUARE OF 5=25
DCD 0X00000024; SQUARE OF 6=36
DCD 0X00000031; SQUARE OF 7=49
DCD 0X00000040; SQUARE OF 8=64
DCD 0X00000051; SQUARE OF 9=81
DCD 0X00000064; SQUARE OF 10=100

END ; Mark end of file    
---------------------------------------------------------------------------------------

6. Find the largest/smallest number in an array

AREA LARGEST , CODE, READONLY

ENTRY ;Mark first instruction to execute
START
MOV R5,#6 ; INTIALISE COUNTER TO 6(i.e. N=7)
LDR R1,=VALUE1 ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
LOOP
LDR R4,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
CMP R2,R4 ; COMPARE NUMBERS
BHI LOOP1 ; IF THE FIRST NUMBER IS > THEN GOTO LOOP1
MOV R2,R4 ; IF THE FIRST NUMBER IS < THEN MOV CONTENT R4 TO R2
LOOP1
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS

LDR R4,=RESULT ; LOADS THE ADDRESS OF RESULT
STR R2,[R4] ; STORES THE RESULT IN R2 
BACK B BACK

; ARRAY OF 32 BIT NUMBERS(N=7)
VALUE1

DCD 0X44444444 ;
DCD 0X22222222 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XAAAAAAAA ;
DCD 0X88888888 ;
DCD 0X99999999 ;

AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVEN ADDRESS

RESULT DCD 0X0

END ; Mark end of file 

-----------------------------------------------
AREA SMALLEST , CODE, READONLY

ENTRY ;Mark first instruction to execute

START
MOV R5,#6 ; INTIALISE COUNTER TO 6(i.e. N=7)
LDR R1,=VALUE1 ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
LOOP
LDR R4,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
CMP R2,R4 ; COMPARE NUMBERS
BLS LOOP1 ; IF THE FIRST NUMBER IS < THEN GOTO LOOP1

MOV R2,R4 ; IF THE FIRST NUMBER IS > THEN MOV CONTENT R4 TO R2
LOOP1
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS 
LDR R4,=RESULT ; LOADS THE ADDRESS OF RESULT
STR R2,[R4] ; STORES THE RESULT IN R1
BACK B BACK

; ARRAY OF 32 BIT NUMBERS(N=7)

VALUE1

DCD 0X44444444 ;
DCD 0X22222222 ;
DCD 0X11111111 ;
DCD 0X22222222 ;
DCD 0XAAAAAAAA ;
DCD 0X88888888 ;
DCD 0X99999999 ;

AREA DATA2, DATA, READWRITE ; TO STORE RESULT IN GIVEN ADDRESS

RESULT DCD 0X0

END ; Mark end of file 
----------------------------------------------------------------------------------------------

7. Arrange a series of 32-bit numbers

AREA ASCENDING , CODE, READONLY
ENTRY ;Mark first instruction to execute
START

MOV R8,#4 ; INTIALISE COUNTER TO 4(i.e. N=4)
LDR R2,=CVALUE ; ADDRESS OF CODE REGION
LDR R3,=DVALUE ; ADDRESS OF DATA REGION

LOOP0

LDR R1,[R2],#4 ; LOADING VALUES FROM CODE REGION
STR R1,[R3],#4 ; STORING VALUES TO DATA REGION

SUBS R8,R8,#1 ; DECREMENT COUNTER
CMP R8,#0 ; COMPARE COUNTER TO 0
BNE LOOP0 ; LOOP BACK TILL ARRAY ENDS

OUTLOOP MOV R9,#3 ; INTIALISE OUTER LOOP COUNTER TO 3(i.e. N=4)
MOV R5,#3 ; INITIALIZE INNER LOOP COUNTER TO 3(i.e. N=4)
LDR R1,=DVALUE ; LOADS THE ADDRESS OF FIRST VALUE
INLOOP LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT

LDR R3,[R1] ; LOAD SECOND NUMBER
CMP R2,R3 ; COMPARE NUMBERS
BLT LOOP2 ; IF THE FIRST NUMBER IS < THEN GOTO LOOP2

STR R2,[R1],#-4 ; INTERCHANGE NUMBER R2 & R3
STR R3,[R1] ; INTERCHANGE NUMBER R2 & R3
ADD R1,#4 ; RESTORE THE PTR

LOOP2

SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE INLOOP ; LOOP BACK TILL ARRAY ENDS

SUB R9,R9,#1 ;DECREMEMT COUNTER
CMP R9,#0 ;COMPARE COUNTER TO 0
BNE OUTLOOP ; IF FLAG IS NOT ZERO THEN GO TO START1

OUTLOOP

BACK B BACK 
; ARRAY OF 32 BIT NUMBERS(N=4) IN CODE REGION
CVALUE
DCD 0X44444444 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0X22222222 ;


AREA DATA1,DATA,READWRITE ;
DVALUE
DCD 0X00000000 ;
END ; Mark end of file 


----------------------------------------------------

AREA DECENDING , CODE, READONLY
ENTRY ;Mark first instruction to execute
START

MOV R8,#4 ; INTIALISE COUNTER TO 4(i.e. N=4)
LDR R2,=CVALUE ; ADDRESS OF CODE REGION
LDR R3,=DVALUE ; ADDRESS OF DATA REGION

LOOP0

LDR R1,[R2],#4 ; LOADING VALUES FROM CODE REGION
STR R1,[R3],#4 ; STORING VALUES TO DATA REGION

SUBS R8,R8,#1 ; DECREMENT COUNTER
CMP R8,#0 ; COMPARE COUNTER TO 0
BNE LOOP0 ; LOOP BACK TILL ARRAY ENDS

OUTLOOP MOV R9,#3 ; INTIALISE OUTER LOOP COUNTER TO 3(i.e. N=4)
MOV R5,#3 ; INITIALIZE INNER LOOP COUNTER TO 3(i.e. N=4)
LDR R1,=DVALUE ; LOADS THE ADDRESS OF FIRST VALUE
INLOOP LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT

LDR R3,[R1] ; LOAD SECOND NUMBER
CMP R2,R3 ; COMPARE NUMBERS
BGT LOOP2 ; IF THE FIRST NUMBER IS > THEN GOTO LOOP2

STR R2,[R1],#-4 ; INTERCHANGE NUMBER R2 & R3
STR R3,[R1] ; INTERCHANGE NUMBER R2 & R3
ADD R1,#4 ; RESTORE THE PTR

LOOP2

SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE INLOOP ; LOOP BACK TILL ARRAY ENDS

SUB R9,R9,#1 ;DECREMEMT COUNTER
CMP R9,#0 ;COMPARE COUNTER TO 0
BNE OUTLOOP ; IF FLAG IS NOT ZERO THEN GO TO START1

OUTLOOP

BACK B BACK
; ARRAY OF 32 BIT NUMBERS(N=4) IN CODE REGION
CVALUE
DCD 0X44444444 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0X22222222 ;
888


AREA DATA1,DATA,READWRITE ;
DVALUE
DCD 0X00000000 ;
END ; Mark end of file  
-----------------------------------------------------------------------------------------

8. Count ones and zeros in memory locations

AREA ONEZERO , CODE, READONLY
ENTRY ;Mark first instruction to execute
START
MOV R2,#0 ; COUNTER FOR ONES
MOV R3,#0 ; COUNTER FOR ZEROS
MOV R7,#2 ; COUNTER TO GET TWO WORDS
LDR R6,=VALUE ; LOADS THE ADDRESS OF VALUE

LOOP MOV R1,#32 ; 32 BITS COUNTER
LDR R0,[R6],#4 ; GET THE 32 BIT VALUE

LOOP0 MOVS R0,R0,ROR #1 ; RIGHT SHIFT TO CHECK CARRY BIT (1's/0's)
BHI ONES ; IF CARRY BIT IS 1 GOTO ONES BRANCH

OTHERWISE NEXT

ZEROS ADD R3,R3,#1 ; IF CARRY BIT IS 0 THEN INCREMENT THE COUNTER BY 1(R3)

B LOOP1 ; BRANCH TO LOOP1 
ONES ADD R2,R2,#1 ; IF CARRY BIT IS 1 THEN INCREMENT THE COUNTER BY 1(R2)

LOOP1 SUBS R1,R1,#1 ; COUNTER VALUE DECREMENTED BY 1
BNE LOOP0 ; IF NOT EQUAL GOTO TO LOOP0 CHECKS 32BIT

SUBS R7,R7,#1 ; COUNTER VALUE DECREMENTED BY 1
CMP R7,#0 ; COMPARE COUNTER R7 TO 0
BNE LOOP ; IF NOT EQUAL GOTO TO LOOP

STOP B STOP
VALUE DCD 0X11111111,0XAA55AA55 ; TWO VALUES IN AN ARRAY
END ; Mark end of file   
-------------------------------------------------------------------------------------------------

9. Display "Hello World" message using Internal UART

#include LPC214x.h
char *msg="Hello World";
int main()
{
PINSEL0=0X5; //P0.0 & P0.1 are configured as TXD0 and RXD0
U0LCR = 0X83; //8-bits, no parity, 1 stop bit,

//DLAB=1 (Enable access to Divisor Latches.)

U0DLM = 0X00;
U0DLL = 0X61; //U0DLM-U0DLL=0X0061 9600 bits/sec
U0LCR = 0X03; //DLAB=0 (Disable access to Divisor Latches.)
while(*msg != 0x00)
{
while(!(U0LSR & 0X20));
U0THR=*msg;
msg++;
}
}    
------------------------------------------------------------------------------------------------------

10. Interface and Control a DC Motor

#include LPC214x.h

void clock_wise(void);
void anti_clock_wise(void);
unsigned int j=0;

int main()
{
IO0DIR= 0X00000900;
IO0SET= 0X00000100; //P0.8 should always high.

while(1)
{
clock_wise();
for(j=0;j<400000;j++); //delay
anti_clock_wise();
for(j=0;j<400000;j++); //delay
} //End of while(1)
} //End of Main

void clock_wise(void)
{
IO0CLR = 0x00000900; //stop motor and also turn off relay
for(j=0;j<10000;j++); //small delay to allow motor to turn off
IO0SET = 0X00000900; //Selecting the P0.11 line for clockwise and turn on motor  
}

void anti_clock_wise(void)
{
IO0CLR = 0X00000900; //stop motor and also turn off relay
for(j=0;j<10000;j++); //small delay to allow motor to turn off
IO0SET = 0X00000100; //not selecting the P0.11 line for Anti clockwise
}  
---------------------------------------------------------------------------------------------------------

11. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.

#include  LPC214x.h
void clock_wise(void);
void anti_clock_wise(void);

unsigned long int var1,var2;
unsigned int i=0,j=0,k=0;

int main(void)
{
PINSEL0 = 0x00000000; //P0.12 to P0.15 GPIo
IO0DIR |= 0x0000F000; //P0.12 to P0.15 output

while(1)
{
for(j=0;j<50;j++) // 50 times in Clock wise Rotation(360 degree)
clock_wise();

for(k=0;k<65000;k++); // Delay to show anti_clock Rotation

for(j=0;j<50;j++) // 50 times in Anti Clock wise Rotation(360 degree)
anti_clock_wise();

for(k=0;k<65000;k++); // Delay to show clock Rotation

} // End of while(1) 
} // End of main

void clock_wise(void)
{
var1 = 0x00000800; //For Clockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
var1 = var1<<1; //For Clockwise

IO0PIN = var1;

for(k=0;k<3000;k++); //forstep speed variation

}
}

void anti_clock_wise(void)
{
var1 = 0x00010000; //For Anticlockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{

var1 = var1>>1; //For Anticlockwise

IO0PIN = var1;

for(k=0;k<3000;k++); //forstep speed variation

}
}   
-------------------------------------------------------------------------------------------------------

12. Interface a DAC and generate Triangular and Square waveforms.

// program to generate square wave with DAC interface
#include  LPC214x.h
void delay(void);
int main ( )
{
PINSEL1 = 0xFFFF0000 ; // Configure P0.16 to P0.23 as GPIO
IO0DIR = 0x00FF0000 ;
while(1)
{
IO0PIN = 0x00000000; //This register is used to read/write the value on Port
delay( );
IO0PIN = 0x00FF0000;
delay( );
}
}
void delay(void)
{
unsigned int i=0;
for(i=0;i<=95000;i++);
}   

// program to generate triangular wave with DAC interface
#include LPC214x.h
int main ( )
{
unsigned long int temp=0x00000000;
unsigned int i=0;
PINSEL1 = 0xFFFF0000 ; // Configure P0.16 to P0.23 as GPIO
IO0DIR=0x00FF0000;
while(1)
{
// output 0 to FE
for(i=0;i!=0xFF;i++)
{
temp=i;
temp = temp << 16;
IO0PIN=temp;
}
// output FF to 1
for(i=0xFF; i!=0;i--)
{
temp=i;
temp = temp << 16;
IO0PIN=temp;
}
} //End of while(1)
} //End of main() 
----------------------------------------------------------------------------------------------------------

14. Demonstrate the use of an external interrupt to toggle an LED On/Off.

#include LPC214x.h
void Extint1_Isr(void) irq; //declaration of ISR
unsigned char int_flag, flag;
int main(void)
{
IO1DIR |= 0x02000000; //P1.25 int led
IO1SET = 0x02000000;
PINSEL0=0x000000C0; //P0.3 EINT1
EXTMODE =0x01; //edge i.e falling edge trigger and active low
EXTPOLAR= 0x00;
VICVectAddr0 = (unsigned long) Extint1_Isr; //Assign the EINT0 ISR function
VICVectCntl0 = 0x20 | 15; //Assign the VIC channel EINT1 to interrupt priority 0
VICIntEnable |= 0x00008000; //Enable the EINT1 interrupt
while(1) //waiting for interrupt to occur
{
if(int_flag == 0x01)
{
if(flag == 0)
{
IO1CLR = 0x02000000;
flag = 1;
}
else if(flag == 1)
{
IO1SET = 0x02000000;
flag = 0;

}
int_flag = 0x00;
}
}
}
void Extint1_Isr(void) irq //whenever there is a low edge on EINT0
{
EXTINT = 0x02; //clear the interrupt
int_flag = 0x01;
VICVectAddr=0; //Acknowledge Interrupt
}    

15. Display Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between.

#include  LPC214x.h
unsigned int count=0, i,j;
unsigned int Disp[16]={ 0x003F0000, 0x00060000, 0x005B0000, 0x004F0000,
0x00660000,0x006D0000, 0x007D0000, 0x00070000, 0x007F0000, 0x006F0000,
0x00770000, 0x007C0000, 0x00390000, 0x005E0000, 0x00790000, 0x00710000 };
#define SELDISP1 0x10000000 //P0.28
#define SELDISP2 0x20000000 //P0.29
#define SELDISP3 0x40000000 //P0.30
#define SELDISP4 0x80000000 //P0.31
#define ALLDISP 0xF0000000 //Select all display
#define DATAPORT 0x00FF0000 //P0.16 to P0.23 Data lines connected to drive

Seven Segments

int main (void)
{
PINSEL1 = 0x00000000;
IO0DIR = 0xF0FF0000;
while(1)
{
IO0SET |= ALLDISP; //select all digits
IO0CLR = 0x00FF0000; // clear the data lines to 7-segment displays
IO0SET = Disp[count]; // get the 7-segment display value from the array
for(i=0;i<15;i++)
for (j=0;j<30000;j++);
count++;
if (count == 0x10) // 0 to F has been displayed ? go back to 0
{
count = 0;

IO0CLR =0xF0FF0000;
}
}
}    
------------------------------------------------------------------------------------------------------

13. Interface a 4x4 keyboard and display the key code on an LCD.

 #include LPC214x.h
#include stdio.h

/******* FUNCTION PROTOTYPE*******/

void lcd_init(void);
void clr_disp(void);
void lcd_com(void);
void lcd_data(void);
void wr_cn(void);
void wr_dn(void);
void scan(void);
void get_key(void);
void display(void);
void delay(unsigned int);
void init_port(void);

unsigned long int scan_code[16]= {0x00EE0000,0x00ED0000,0x00EB0000,0x00E70000,
0x00DE0000,0x00DD0000,0x00DB0000,0x00D70000,
0x00BE0000,0x00BD0000,0x00BB0000,0x00B70000,
0x007E0000,0x007D0000,0x007B0000,0x00770000};

unsigned char ASCII_CODE[16]= {'0','1','2','3',
				'4','5','6','7',
				'8','9','A','B',
				'C','D','E','F'}; 
unsigned char row,col;

unsigned char temp,flag,i,result,temp1;
unsigned int r,r1;
unsigned long int var,var1,var2,res1,temp2,temp3,temp4;
unsigned char *ptr,disp[] = "4X4 KEYPAD";
unsigned char disp0[] = "KEYPAD TESTING";
unsigned char disp1[] = "KEY = ";
int main()
{
// ARMLIB_enableIRQ();
init_port(); //port intialisation
delay(3200); //delay
lcd_init(); //lcd intialisation
delay(3200); //delay
clr_disp(); //clear display
delay(500); //delay

//........LCD DISPLAY TEST ........//
ptr = disp;
temp1 = 0x81; // Display starting address
lcd_com();
delay(800);
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}

//........KEYPAD Working........//
while(1)
{
get_key();
display();
}

} //end of main()

void get_key(void) //get the key from the keyboard
{
unsigned int i;
flag = 0x00;
IO1PIN=0x000f0000;
while(1)
{
for(row=0X00;row<0X04;row++) //Writing one for col's
{
if( row == 0X00)
{
temp3=0x00700000;
}
else if(row == 0X01)
{
temp3=0x00B00000;
}
else if(row == 0X02)
{

temp3=0x00D00000;
}
else if(row == 0X03)
{
temp3=0x00E00000;
}
var1 = temp3;

IO1PIN = var1; // each time var1 value is put to port1
IO1CLR =~var1; // Once again Conforming (clearing all other bits)
scan();
delay(100); //delay
if(flag == 0xff)
break;
} // end of for
if(flag == 0xff)
break;
} // end of while

for(i=0;i<16;i++)
{
if(scan_code[i] == res1) //equate the scan_code with res1
{

result = ASCII_CODE[i]; //same position value of ascii code
break; //is assigned to result

}
}
}// end of get_key();

void scan(void)

{
unsigned long int t;
temp2 = IO1PIN; // status of port1
temp2 = temp2 & 0x000F0000; // Verifying column key
if(temp2 != 0x000F0000) // Check for Key Press or Not
{
delay(1000); //delay(100)//give debounce delay check again
temp2 = IO1PIN;
temp2 = temp2 & 0x000F0000; //changed condition is same

if(temp2 != 0x000F0000) //store the value in res1
{
flag = 0xff;
res1 = temp2;
t = (temp3 & 0x00F00000); //Verfying Row Write
res1 = res1 | t; //final scan value is stored in res1
}
else
{
flag = 0x00;
}
}
} // end of scan()

void display(void)
{
ptr = disp0;
temp1 = 0x80; // Display starting address of first line
lcd_com();

while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;

}

ptr = disp1;
temp1 = 0xC0; // Display starting address of second line
lcd_com();

while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;

}
temp1 = 0xC6; //display address for key value
lcd_com();
temp1 = result;
lcd_data();
}

void lcd_init (void)
{
temp = 0x30;
wr_cn();
delay(3200);

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

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

temp = 0x20;
wr_cn();
delay(3200);

// load command for lcd function setting with lcd in 4 bit mode,
// 2 line and 5x7 matrix display

temp = 0x28;
lcd_com();
delay(3200);

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

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

temp1 = 0x80;
lcd_com();
delay(800);
}

void lcd_data(void)
{
temp = temp1 & 0xf0;
wr_dn();
temp= temp1 & 0x0f;
temp= temp << 4;
wr_dn();
delay(100);
}

void wr_dn(void) ////write 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;
}

void lcd_com(void)
{
temp = temp1 & 0xf0;

wr_cn();
temp = temp1 & 0x0f;
temp = temp << 4;
wr_cn();
delay(500);
}

void wr_cn(void) //write command reg
{

lines
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT

IO0CLR = 0x00000004; // clear bit RS = 0
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
}

void clr_disp(void)
{
// command to clear lcd display
temp1 = 0x01;
lcd_com();
delay(500);
}

void delay(unsigned int r1)
{
for(r=0;r