PROCEDURE
Step1- Create a separate folder for the project.
Step2- Open Keil IDE version 2 or 5, if any project is already open then choose Project-
→Close project
Step3- Choose Project→ New project. Choose the folder which is already created and
give the name of the project.
Step4-A new window “Select Target” will appear, in this the target device has to be
choose - “AT89C51”.
Step5-Next a pop-up window will appear and it will ask whether to include the start up
file. Give yes for this.
Step6- Go to File→New File, a text editor will open for typing the program, then the
file is saved with .C extension in the same folder where the project is created.
Step7- After that, in the Project window, choose Source Group1 from the Target1 and
then right click on it, choose the option “Add existing file to source group1”.
Step8- Go to Project menu and choose “Build target”
Step 9- The project will be build. If there is any error correct it.
Step 10-Then go to Debug menu and start debug session by choosing Start/Stop debug
session.
Step 11-After starting Debug session, the Peripheral menu will be enabled and the
needed peripherals are chosen from the menu.
Step 12- Then in Debug menu choose “Go” option to run the program.
Step 13-In order to come out of the execution, choose “Stop” option in the Debug menu.
Step 14-To create Hex file Choose the magic stick icon or right click on Target1 and
choose “ Select options for Target” and then select “Output” tab then put a tick on
“Create Hex file” option.
Step 15- After creating Hex file, open Proteus 8 software and then simulate the project
in it.
Step 16- To perform the experiment in hardware, open the flasher Nuvoton, in that the
hex file has to be loaded.
Step 17- The hardware kit is connected to the computer (host system) with RS 232 cable
and connection is established between the target device and host system.
Step 18- Then the Hex file is flashed to the target device and the hardware output is
verified.
Exp: 1 LED Interfacing
# include <reg51.h>
void delay();
void main( )
{
while(1)
{
delay ( );
P1=0x00;
delay ( );
P1=0xFF;
}
}
void delay( )
{
int i,j;
for(i=0;i<=2000;i++)
{
for(j=0;j<=2000;j++);
}
Exp: 2 LCD Interfacing
#include <reg51.h>
void delay();
void command();
void write();
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
unsigned char a[]={0x38,0x0e,0x06,0x01,0x80};
unsigned char b[]={'V','I','T','B','H','O','P','A','L'};
int i,j,k,l;
void main()
{
while(1)
{
command();
write();
delay();
}
}
void command()
{
RS=0;
RW=0;
EN=1;
for(i=0;i<5;i++)
{
P1=a[i];
}
}
void write()
{
RS=1;
RW=0;
EN=1;
for(j=0;j<9;j++)
{
P1=b[j];
delay();
}
}
void delay( )
{
for(k=0;k<=200;k++)
{
for(l=0;l<=200;l++);
}}
Exp: 3 Assume that crystal frequency=11.0592MHz. What value do we need to load into
the timer’s register if we want a delay of 5ms. Show the program for Timer 0 to create a
pulse width of 5 ms on P2.3. Write an assembly program.
CLR P2.3
MOV TMOD,#01H
HERE: MOV TL0,#0EAH
MOV TH0,#0EDH
SETB P2.3
SETB TR0
AGAIN: JNB TF0,AGAIN
CLR P2.3
CLR TR0
CLR TF0
END
Note:
1. Choose Peripheral-> Timer
Screen shot should contain all the windows
Exp: 4 Assume that crystal frequency=11.0592MHz. Write a program to generate
square wave of 2kHz frequency on P1.5 using Timer 1
MOV TMOD,#10H
HERE: MOV TL1,#18H
MOV TH1,#0FFH
SETB TR1
AGAIN: JNB TF1,AGAIN
CLR TR1
CPL P1.5
SJMP HERE
END
Note:
1. Choose Peripheral-> Timer
Screen shot should contain all the windows
Exp: 5 DAC interfacing- generation of Sine wave
AGAIN: MOV DPTR,#TABLE
MOV R2,#0DH
BACK: CLR A
MOVC A,@A+DPTR
MOV P1,A
INC DPTR
DJNZ R2,BACK
SJMP AGAIN
TABLE: DB 128,192,238,255,238,192,128,64,17,0,17,64,128
Exp: 6 EXTERNAL HARDWARE INTERRUPT
#include <reg51.h>
void ISR_EX0 (void) interrupt 0
{
P1=~P1;
}
void main()
{
IT0=1;
EX0=1;
EA=1;
while(1);
}
Note:
1. Choose Peripheral-> Interrupt
2. Choose Port-> Port 3
3. By changing values in Port 3 pin no.2 – Interrupt will be generated
Screen shot should contain all the windows