0% found this document useful (0 votes)
1 views

Lab- 8051 Embedded C

The document outlines a step-by-step procedure for creating and debugging a project using Keil IDE for the AT89C51 microcontroller. It includes instructions for writing code, building the project, creating a hex file, and simulating the project in Proteus software. Additionally, it provides example codes for LED blinking, shifting, and using timers and interrupts with the microcontroller.

Uploaded by

crystal2moon2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Lab- 8051 Embedded C

The document outlines a step-by-step procedure for creating and debugging a project using Keil IDE for the AT89C51 microcontroller. It includes instructions for writing code, building the project, creating a hex file, and simulating the project in Proteus software. Additionally, it provides example codes for LED blinking, shifting, and using timers and interrupts with the microcontroller.

Uploaded by

crystal2moon2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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 ca-
ble 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 Blinking

# 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 LED Shifting


# include <reg51.h>
void main( )
void delay();
{
while(1)
{
int k;
for(k=0x01;k<=0x80;k<<=1)
{
P1=k;
delay ( );
}
}

void delay( )
{
int i,j;
for(i=0;i<=2000;i++)
{
for(j=0;j<=2000;j++);
}
Exp: 3 LED BLINKING USING TIMERS

# include <reg51.h>
void main( )
void delay();
{
while(1)
{
P1=0x00;
delay ( );
P1=0xFF;
delay ( );

}
}

void delay( )
{
TMOD=0x01;
TL0=0x00;
TH0=0x05;
TR0=1;
while(TF==0);
TF0=0;
TR0=0;

}
Note:

1. Choose Peripheral-> Timer

Screen shot should contain all the windows

Exp: 4 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

You might also like