Anda di halaman 1dari 31

EXPERIMENT 1: TOGGLING OPERATION

OBJECTIVE: To interface the LEDs to the port and to perform Toggling operation
using AT89C51/8051 microcontroller.

CIRCUIT DIAGRAM:

Components required:
1. Bread board
2. AT89C51
3. Crystal 12 MHz
4. Capacitors-10 pF-1 no,30 pF -2 nos.
5. Resistors 470 ohms-8 nos, 8.2 k -1 no.
6. Single strand wires
7. 8 pin connectors -2 nos(optional)
8. LEDs -8 nos.
PROGRAM:

Programming in asm:

Loop: mov A,#0AAH;


mov P3,A;
ACALL DELAY;
mov A,#055H;
mov P3,A;
ACALL DELAY;
jmp Loop; To continuously toggle the output execute an infinite loop
DELAY: mov R3,#50;
HERE2 : mov R4,#255;
HERE : DJNZ R4,HERE;
DJNZ R3,HERE2;
RET;
END;

Programming in c :

#include <reg51.h>
#include <stdio.h>
void delayms(int );
int main(void)
{
for(;;) // To continuously toggle the output execute an infinite loop//
{
P3=0xAA;
delayms(250);
P3=0x55;
delayms(250);
}
}
void delayms(int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<1275;j++);
}
Programming in c for ATMEGA16 :

#include <avr/io.h>
void delayms(int );
int main(void)
{
DDRC=0XFF; //To make port c output
for(;;) // To continuously toggle the output execute an infinite loop//
{
PORTC=0xAA;
delayms(250);
PORTC=0x55;
delayms(250);
}
}
void delayms(int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<1275;j++);
}
EXPERIMENT 2: ARITHMETIC OPERATIONS

OBJECTIVE: To interface the LEDs to the port and to perform Arithmetic operations
using AT89C51/8051 Microcontroller.

Arithmetic operations that can be performed using this program: Addition, Subtraction,
Multiplication & Division.

CIRCUIT DIAGRAM:

Components required:
1. Bread board
2. AT89C51
3. Crystal 12 MHz
4. Capacitors-10 pF-1 no,30 pF -2 nos.
5. Resistors 470 ohms-8 nos, 8.2 k -1 no.
6. Single strand wires
7. 8 pin connectors -2 nos(optional)
8. LEDs -8 nos.
PROGRAM:

Programming in asm:

mov A,#0FFh;
mov P0,A; Port 0 is made input port
mov P1,A; Port 1 is made input port
mov P2,A; Port 2 is made input port
loop: mov A,P0;
CJNE A,#01h,SUB1; If Port 0=01h then execute Addition or check next condition
mov A,P1;
mov 0F0H,P2;
ADD A,0F0H;
mov P3,A;
sjmp loop1;
SUB1: mov A,P0;
CJNE A,#02h,MUL1; If Port 0=02h then execute Subtraction or check next condition
mov A,P1;
mov 0F0H,P2;
SUBB A,0F0H;
mov P3,A;
sjmp loop1;
MUL1: mov A,P0;
CJNE A,#03h,DIV1; If Port 0=03h then execute Multiplication or check next condition
mov A,P1;
mov 0F0H,P2;
MUL AB;
mov P3,A;
sjmp loop1;
DIV1: mov A,P0;
CJNE A,#04h,loop1; If Port 0=04h then execute Division or goto loop1
mov A,P1;
mov 0F0H,P2;
DIV AB;
mov P3,A;
loop1: JMP loop; To make the output remain constant execute an infinite loop
END;
Programming in c :

#include <reg51.h>
#include <stdio.h>
int main(void)
{
unsigned char w,x,y,z;
P0=0xFF;
P1=0xFF;
P2=0xFF;
for(;;) //to make the output remain constant//
{
w=P0;
x=P1;
y=P2;
if(w==0X01) //If P0 is given an input 1 then it will perform addition//
z=x+y;
else if(w==0X02) //If P0 is given an input 2 then it will perform Subtraction//
z=x-y;
else if(w==0X03) //If P0 is given an input 3 then it will perform Multiplication//
z=x*y;
else if(w==0X04) //If P0 is given an input 4 then it will perform Division//
z=x/y;
P3=z;
}
}
Programming in c for ATMEGA16:

#include <avr/io.h>
int main(void)
{
unsigned char w,x,y,z;
DDRB=0x00; //optional as ATMEGA16 is a default input microcontroller//
DDRD=0x00; //optional as ATMEGA16 is a default input microcontroller//
DDRA=0x00; //optional as ATMEGA16 is a default input microcontroller//
DDRC=0xFF; //To make port c output//
for(;;) //to make the output remain constant//
{
w=PINB;
x=PIND;
y=PINA;
if(w==0X01) //If Port B is given an input 1 then it will perform addition//
z=x+y;
else if(w==0X02) //If Port B is given an input 2 then it will perform Subtraction//
z=x-y;
else if(w==0X03) //If Port B is given an input 3 then it will perform Multiplication//
z=x*y;
else if(w==0X04) //If Port B is given an input 4 then it will perform Division//
z=x/y;
PORTC=z;
}
}
EXPERIMENT 3: LOGIC OPERATIONS

OBJECTIVE: To interface the LEDs to the port and to perform Logic operations using
AT89C51/8051 Microcontroller.

Logical operations that can be performed using this program: And, Or, Nand, Nor, Xor,
Xnor & Not.

CIRCUIT DIAGRAM:

Components required:
1. Bread board
2. AT89C51
3. Crystal 12 MHz
4. Capacitors-10 pF-1 no,30 pF -2 nos.
5. Resistors 470 ohms-8 nos, 8.2 k -1 no.
6. Single strand wires
7. 8 pin connectors -2 nos(optional)
8. LEDs -8 nos.
PROGRAM:

Programming in asm:

mov A,#0FFh;
mov P0,A; Port 0 is made input port
mov P1,A; Port 1 is made input port
mov P2,A; Port 2 is made input port
loop: mov A,P0;
CJNE A,#01h,OR1; If Port 0=01h then execute And operation or check next condition
mov A,P1;
mov 0F0H,P2;
ANL A,0F0H;
mov P3,A;
sjmp loop1;
OR1: mov A,P0;
CJNE A,#02h,NAND1; If Port 0=02h then execute Or operation or check next condition
mov A,P1;
mov 0F0H,P2;
ORL A,0F0H;
mov P3,A;
sjmp loop1;
NAND1: mov A,P0;
CJNE A,#03h,NOR1; If Port 0=03h then execute Nand operation or check next condition
mov A,P1;
mov 0F0H,P2;
ANL A,0F0H;
CPL A;
mov P3,A;
sjmp loop1;
NOR1: mov A,P0;
CJNE A,#04h,XOR1; If Port 0=04h then execute Nor operation or check next condition
mov A,P1;
mov 0F0H,P2;
ORL A,0F0H;
CPL A;
mov P3,A;
sjmp loop1;
XOR1: mov A,P0;
CJNE A,#05h,XNOR1; If Port 0=05h then execute Xor operation or check next condition
mov A,P1;
mov 0F0H,P2;
XRL A,0F0H;
mov P3,A;
sjmp loop1;
XNOR1: mov A,P0;
CJNE A,#06h,NOT1; If Port 0=06h then execute Xnor operation or check next condition
mov A,P1;
mov 0F0H,P2;
XRL A,0F0H;
CPL A;
mov P3,A;
sjmp loop1;
NOT1: mov A,P0;
CJNE A,#07h,NOT2; If Port 0=07h then execute Not operation of P1 or check next
condition
mov A,P1;
CPL A;
mov P3,A;
sjmp loop1;
NOT2: mov A,P0;
CJNE A,#08h,loop1; If Port 0=08h then execute Not operation of P2 or goto loop1
mov A,P2;
CPL A;
mov P3,A;
loop1: JMP loop; To make the output remain constant execute an infinite loop
END;
Programming in c:

#include <reg51.h>
#include <stdio.h>
int main(void)
{
unsigned char w,x,y,z;
for(;;) //to make the output remain constant//
{
w=P0;
x=P1;
y=P2;
if(w==0X01) //If P0 is given an input 1 then it will perform AND operation//
z=x & y;
else if(w==0X02) //If P0 is given an input 1 then it will perform OR operation//
z=x | y;
else if(w==0X03) //If P0 is given an input 1 then it will perform NAND operation//
z=~(x & y);
else if(w==0X04) //If P0 is given an input 1 then it will perform NOR operation//
z=~(x|y);
else if(w==0X05) //If P0 is given an input 1 then it will perform XOR operation//
z=x ^ y;
else if(w==0X06) //If P0 is given an input 1 then it will perform XNOR operation//
z=~(x ^ y);
else if(w==0X07) //If P0 is given an input 1 then it will perform NOT operation on x//
z= ~ x;
else if(w==0X08) //If P0 is given an input 1 then it will perform NOT operation on y//
z=~ y;
P3=z;
}
}
Programming in c for ATMEGA16:

#include <avr/io.h>
int main(void)
{
unsigned char w,x,y,z;
DDRB=0x00; //optional as ATMEGA16 is a default input microcontroller//
DDRD=0x00; //optional as ATMEGA16 is a default input microcontroller//
DDRA=0x00; //optional as ATMEGA16 is a default input microcontroller//
DDRC=0xFF; //To make port c output//
for(;;) //to make the output remain constant//
{
w=PINB;
x=PIND;
y=PINA;
if(w==0X01) //If Port B is given an input 1 then it will perform AND operation//
z=x & y;
else if(w==0X02) //If Port B is given an input 1 then it will perform OR operation//
z=x | y;
else if(w==0X03) //If Port B is given an input 1 then it will perform NANDoperation//
z=~(x & y);
else if(w==0X04) //If Port B is given an input 1 then it will perform NOR operation//
z=~(x|y);
else if(w==0X05) //If Port B is given an input 1 then it will perform XOR operation//
z=x ^ y;
else if(w==0X06) //If Port B is given an input 1 then it will perform XNORoperation//
z=~(x ^ y);
else if(w==0X07) //If Port B is given 1 then it will perform NOT operation on x//
z= ~ x;
else if(w==0X08) //If Port B is given 1 then it will perform NOT operation on y//
z=~ y;
PORTC=z;
}
}
EXPERIMENT 4: LOGIC OPERATIONS

OBJECTIVE: To interface the LEDs to the port and to perform Rotate and Swap
operations using AT89C51/8051 Microcontroller.

Operations that can be performed using this program: Rotate Left, Rotate Right &
Swap.

CIRCUIT DIAGRAM:

Components required:
1. Bread board
2. AT89C51
3. Crystal 12 MHz
4. Capacitors-10 pF-1 no,30 pF -2 nos.
5. Resistors 470 ohms-8 nos, 8.2 k -1 no.
6. Single strand wires
7. 8 pin connectors -2 nos(optional)
8. LEDs -8 nos.
PROGRAM:

Programming in asm:

mov A,#0FFh;
mov P0,A; Port 0 is made input port
mov P1,A; Port 1 is made input port
loop: mov A,P0;
CJNE A,#01h,RR1; If Port 0=01h then execute Rotate left or check next condition
mov A,P1;
RL A;
mov P3,A;
sjmp loop1;
RR1: mov A,P0;
CJNE A,#02h,SWAP1; If Port 0=02h then execute Rotate right or check next condition
mov A,P1;
RR A;
mov P3,A;
sjmp loop1;
SWAP1: mov A,P0;
CJNE A,#03h,loop1; If Port 0=03h then execute Swap or goto loop1
mov A,P1;
SWAP A;
mov P3,A;
loop1: JMP loop; To make the output remain constant execute an infinite loop
END;
EXPERIMENT 5: INTERFACING LCD

OBJECTIVE: To interface the LCD to AT89C51/8051 Microcontroller and display a


string in the first line.

Circuit Diagram

Components required:
1. Bread board
2. AT89C51
3. Crystal 12 MHz
4. Capacitors-10 pF-1 no,30 pF -2 nos.
5. Resistors 470 ohms-8 nos, 8.2 k -1 no.
6. Single strand wires
7. 8 pin connectors -2 nos(optional)
8. LCD-1 no.
PROGRAM:

Programming in asm:

ORG 0H;
mov A,#38H; init LCD 2 lines,5x7 matrix
ACALL COMNWRT;
ACALL DELAY;
mov A,#0EH; display On, cursor On
ACALL COMNWRT;
ACALL DELAY;
mov A,#01H; clear LCD
ACALL COMNWRT;
ACALL DELAY;
mov A,#06H; shift cursor right
ACALL COMNWRT;
ACALL DELAY;
mov A,#86H; cursor at line 1, position 6
ACALL COMNWRT;
ACALL DELAY;
mov A,#’H’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’E’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’L’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’L’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’O’;
ACALL DATAWRT;
AGAIN: SJMP AGAIN;
COMNWRT: mov P1,A; send command to LCD
CLR P2.0; RS=0
CLR P2.1; R/W=0
SETB P2.2; E=1 for high pulse
ACALL DELAY;
CLR P2.2; E=0 for H- to- L pulse
RET;
DATAWRT: mov P1,A; write data to LCD
SETB P2.0; RS=1
CLR P2.1; R/W=0
SETB P2.2; E=1 for high pulse
ACALL DELAY;
CLR P2.2; E=0 for H- to- L pulse
RET;
DELAY: mov R3,#50;
HERE2 : mov R4,#255;
HERE : DJNZ R4,HERE;
DJNZ R3,HERE2;
RET;
END;

Programming in c:

#include<reg51.h>
sfr ldata=0x90; //P1=LCD data pins
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2 ;
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void Msdelay(unsigned int);
void main()
{
lcdcmd(0x38) ; //init. LCD 2 lines,5x7 ;
Msdelay(250) ;
lcdcmd(0x0E) ; //LCD cursor on
Msdelay(250) ;
lcdcmd(0x01) ; //Clear LCD commmand
Msdelay(250) ;
lcdcmd(0x06) ; //Shift cursor right
Msdelay(250) ;
lcdcmd(0x86) ; //line 1,pos.6
Msdelay(250) ;
lcddata(‘H’) ;
Msdelay(250) ;
lcddata(‘E’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘O’) ;
}
void lcdcmd(unsigned char value)
{
ldata=value; //put the values on pins.//
rs=0;
rw=0;
en=1;
Msdelay(1);
en=0;
return;
}
void lcddata(unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
Msdelay(1);
en=0;
return;
}
void Msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}

Programming in c for ATMEGA16:

#include<avr/io.h>
void lcdcmd(unsigned char );
void lcddata(unsigned char );
void Msdelay(unsigned int );
void main()
{
DDRA=0xFF ;
DDRC=0xFF ;
lcdcmd(0x38) ; //init. LCD 2 lines,5x7 ;
Msdelay(250) ;
lcdcmd(0x0E) ; //LCD cursor on
Msdelay(250) ;
lcdcmd(0x01) ; //Clear LCD commmand
Msdelay(250) ;
lcdcmd(0x06) ; //Shift cursor right
Msdelay(250) ;
lcdcmd(0x86) ; //line 1,pos.6
Msdelay(250) ;
lcddata(‘H’) ;
Msdelay(250) ;
lcddata(‘E’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘O’) ;
}
void lcdcmd(unsigned char value)
{
PORTC=value; //put the value on pins.//
PORTA=0x04;
Msdelay(1);
PORTA=0x00;
return;
}
void lcddata(unsigned char value)
{
PORTC=value;
PORTA=0x05;
Msdelay(1);
PORTA=0x01;
return;
}
void Msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
EXPERIMENT 6: INTERFACING LCD

OBJECTIVE: To interface the LCD to AT89C51/8051 Microcontroller and display a


string in the second line.

Circuit Diagram

Components required:
1. Bread board
2. AT89C51
3. Crystal 12 MHz
4. Capacitors-10 pF-1 no,30 pF -2 nos.
5. Resistors 470 ohms-8 nos, 8.2 k -1 no.
6. Single strand wires
7. 8 pin connectors -2 nos(optional)
8. LCD-1 no.
PROGRAM:

Programming in asm:

ORG 0H;
mov A,#38H; init LCD 2 lines,5x7 matrix
ACALL COMNWRT;
ACALL DELAY;
mov A,#0EH; display On, cursor On
ACALL COMNWRT;
ACALL DELAY;
mov A,#01H; clear LCD
ACALL COMNWRT;
ACALL DELAY;
mov A,#06H; shift cursor right
ACALL COMNWRT;
ACALL DELAY;
mov A,#0C6H; cursor at line 2, position 6
ACALL COMNWRT;
ACALL DELAY;
mov A,#’H’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’E’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’L’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’L’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’O’;
ACALL DATAWRT;
AGAIN: SJMP AGAIN;
COMNWRT: mov P1,A; send command to LCD
CLR P2.0; RS=0
CLR P2.1; R/W=0
SETB P2.2; E=1 for high pulse
ACALL DELAY;
CLR P2.2; E=0 for H- to- L pulse
RET;
DATAWRT: mov P1,A; write data to LCD
SETB P2.0; RS=1
CLR P2.1; R/W=0
SETB P2.2; E=1 for high pulse
ACALL DELAY;
CLR P2.2; E=0 for H- to- L pulse
RET;
DELAY: mov R3,#50;
HERE2 : mov R4,#255;
HERE : DJNZ R4,HERE;
DJNZ R3,HERE2;
RET;
END;

Programming in c:

#include<reg51.h>
sfr ldata=0x90; //P1=LCD data pins
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2 ;
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void Msdelay(unsigned int);
void main()
{
lcdcmd(0x38) ; //init. LCD 2 lines,5x7 ;
Msdelay(250) ;
lcdcmd(0x0E) ; //LCD cursor on
Msdelay(250) ;
lcdcmd(0x01) ; //Clear LCD commmand
Msdelay(250);
lcdcmd(0x06) ; //Shift cursor right
Msdelay(250) ;
lcdcmd(0xC6) ; //line 2,pos.6
Msdelay(250) ;
lcddata(‘H’) ;
Msdelay(250) ;
lcddata(‘E’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘O’) ;
}
void lcdcmd(unsigned char values)
{
ldata=value; //put the values on pins.
rs=0;
rw=0;
en=1;
Msdelay(1);
en=0;
return;
}
void lcddata(unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
Msdelay(1);
en=0;
return;
}
void Msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}

Programming in c for ATMEGA16:

#include<avr/io.h>
void lcdcmd(unsigned char );
void lcddata(unsigned char );
void Msdelay(unsigned int );
void main()
{
DDRA=0xFF ;
DDRC=0xFF ;
lcdcmd(0x38) ; //init. LCD 2 lines,5x7 ;
Msdelay(250) ;
lcdcmd(0x0E) ; //LCD cursor on
Msdelay(250) ;
lcdcmd(0x01) ; //Clear LCD commmand
Msdelay(250);
lcdcmd(0x06) ; //Shift cursor right
Msdelay(250) ;
lcdcmd(0xC6) ; //line 2,pos.6
Msdelay(250) ;
lcddata(‘H’) ;
Msdelay(250) ;
lcddata(‘E’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘O’) ;
}
void lcdcmd(unsigned char value)
{
PORTC=value; //put the value on pins.//
PORTA=0x04;
Msdelay(1);
PORTA=0x00;
return;
}
void lcddata(unsigned char value)
{
PORTC=value;
PORTA=0x05;
Msdelay(1);
PORTA=0x01;
return;
}
void Msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
EXPERIMENT 7: INTERFACING LCD

OBJECTIVE: To interface the LCD to AT89C51/8051 Microcontroller and display two


strings in the first and second line.

Circuit Diagram

Components required:
1. Bread board
2. AT89C51
3. Crystal 12 MHz
4. Capacitors-10 pF-1 no,30 pF -2 nos.
5. Resistors 470 ohms-8 nos, 8.2 k -1 no.
6. Single strand wires
7. 8 pin connectors -2 nos(optional)
8. LCD-1 no.
PROGRAM:

Programming in asm:

ORG 0H;
mov A,#38H; init LCD 2 lines,5x7 matrix
ACALL COMNWRT;
ACALL DELAY;
mov A,#0EH; display On, cursor On
ACALL COMNWRT;
ACALL DELAY;
mov A,#01H; clear LCD
ACALL COMNWRT;
ACALL DELAY;
mov A,#06H; shift cursor right
ACALL COMNWRT;
ACALL DELAY;
mov A,#86H; cursor at line 1, position 6
ACALL COMNWRT;
ACALL DELAY;
mov A,#’H’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’E’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’L’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’L’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’O’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#0C6H; cursor at line 2, position 6
ACALL COMNWRT;
ACALL DELAY;
mov A,#’W’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’O’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’R’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’L’;
ACALL DATAWRT;
ACALL DELAY;
mov A,#’D’;
ACALL DATAWRT;
AGAIN: SJMP AGAIN;
COMNWRT: mov P1,A; send command to LCD
CLR P2.0; RS=0
CLR P2.1; R/W=0
SETB P2.2; E=1 for high pulse
ACALL DELAY;
CLR P2.2; E=0 for H- to- L pulse
RET;
DATAWRT: mov P1,A; write data to LCD
SETB P2.0; RS=1
CLR P2.1; R/W=0
SETB P2.2; E=1 for high pulse
ACALL DELAY;
CLR P2.2; E=0 for H- to- L pulse
RET;
DELAY: mov R3,#50;
HERE2 : mov R4,#255;
HERE : DJNZ R4,HERE;
DJNZ R3,HERE2;
RET;
END;
Programming in c:

#include<reg51.h>
sfr ldata=0x90; //P1=LCD data pins
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2 ;
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void Msdelay(unsigned int);
void main()
{
lcdcmd(0x38) ; //init. LCD 2 lines,5x7 ;
Msdelay(250) ;
lcdcmd(0x0E) ; //LCD cursor on
Msdelay(250) ;
lcdcmd(0x01) ; //Clear LCD commmand
Msdelay(250);
lcdcmd(0x06) ; //Shift cursor right
Msdelay(250) ;
lcdcmd(0x86) ; //line 1,pos.6
Msdelay(250) ;
lcddata(‘H’) ;
Msdelay(250) ;
lcddata(‘E’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘O’) ;
Msdelay(250);
lcdcmd(0xC6) ; //line 2,pos.6
Msdelay(250) ;
lcddata(‘W’) ;
Msdelay(250) ;
lcddata(‘O’) ;
Msdelay(250) ;
lcddata(‘R’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘D’) ;
}
void lcdcmd(unsigned char values)
{
ldata=value; //put the values on pins.
rs=0;
rw=0;
en=1;
Msdelay(1);
en=0;
return;
}
void lcddata(unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
Msdelay(1);
en=0;
return;
}
void Msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}

Programming in c for ATMEGA16:

#include<avr/io.h>
void lcdcmd(unsigned char );
void lcddata(unsigned char );
void Msdelay(unsigned int );
void main()
{
DDRA=0xFF ;
DDRC=0xFF ;
lcdcmd(0x38) ; //init. LCD 2 lines,5x7 ;
Msdelay(250) ;
lcdcmd(0x0E) ; //LCD cursor on
Msdelay(250) ;
lcdcmd(0x01) ; //Clear LCD commmand
Msdelay(250);
lcdcmd(0x06) ; //Shift cursor right
Msdelay(250) ;
lcdcmd(0x86) ; //line 1,pos.6
Msdelay(250) ;
lcddata(‘H’) ;
Msdelay(250) ;
lcddata(‘E’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘O’) ;
Msdelay(250);
lcdcmd(0xC6) ; //line 2,pos.6
Msdelay(250) ;
lcddata(‘W’) ;
Msdelay(250) ;
lcddata(‘O’) ;
Msdelay(250) ;
lcddata(‘R’) ;
Msdelay(250) ;
lcddata(‘L’) ;
Msdelay(250) ;
lcddata(‘D’) ;
}
void lcdcmd(unsigned char value)
{
PORTC=value; //put the value on pins.//
PORTA=0x04;
Msdelay(1);
PORTA=0x00;
return;
}
void lcddata(unsigned char value)
{
PORTC=value;
PORTA=0x05;
Msdelay(1);
PORTA=0x01;
return;
}
void Msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}