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

Embedded Controller 8051 C Lab Manual

8051 lab programs

Uploaded by

Beeresha R S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Embedded Controller 8051 C Lab Manual

8051 lab programs

Uploaded by

Beeresha R S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

KUVEMPU UNIVERITY

GOVERNMENT FIRST GRADE COLLEGE


SHIKARIPURA
DEPARTMENT OF ELECTRONICS

B. Sc Vth Semester

Paper Title: Embedded Controllers


Course Code: DSC-ELE5
LAB MANUAL

Student Name: ……………………………..


Register No………………………………….
Year ………………………………………..

GFGC Shikaripura Department of Electronics


Introduction & Installation to Keil Software

8051 Programming Using Keil µVision IDE


Step 1: Downloading Keil µVision IDE

Keil provides a code limited (2K bytes) evaluation version for 8051
architecture (C51) which is sufficient for learning purposes.

The main limitations of the evaluation version are the following.

• 8051 compiler, assembler, linker, and debugger are limited to 2 Kbytes of


object code
• Programs that generate more than 2 Kbytes of object code will not compile
• The debugger supports programs that are 2 Kbytes or smaller
• No hardware support for multiple DPTR registers is provided

Keil uVision IDE (Evaluation Version) can be downloaded using this link.

On Clicking the above link you will be redirected to Keil Website Download
section.

GFGC Shikaripura Department of Electronics


Please click on the C51 icon to download 8051 development tools (above
Figure) .
and download your Windows Executable.

Step 2: Creating a 8051/8052 Project Using Keil Uvision IDE

After you have installed the Keil uVision tools for 8051, Double click on the
Keil icon on your Windows Desktop to launch the IDE.

To create a new 8051 project using Keil IDE, Click on the ' Project ' item on
the IDE Menu bar and select ' New uVision Project... 'as shown in the above
image.

Now create a Folder to store your project and give a name to your Project
files (*.uvproj), for eg Test (Test.uvproj).

Step 3: Selecting an 8051 Device in Keil

GFGC Shikaripura Department of Electronics


You will then be taken to the device selection dialog, where you can select
the 8051 derivative for which you want to develop software.

Keil has support for a wide variety of 8051 derivatives on its IDE.The 8051
derivatives are organised according to their manufacturer's.

On selecting the particular microcontroller the Keil IDE also displays the
features of the selected microcontroller on its left pane .You can Click OK to
confirm your choice.

Step 4:

GFGC Shikaripura Department of Electronics


After selecting your 8051 derivative,

You will get another dialog as shown Above.Asking to copy STARTUP.A51


Click ' Yes '
Step 5:

Now your Project pane on the Kiel IDE would look something like this
(above image)

GFGC Shikaripura Department of Electronics


Step 6: Adding C Files to Keil Project

Now you can add C files to you Project.

Right Click on the Source Group 1 folder on your Project pane and
select Add New Item to Group 'Source Group1'...

Step 7:
Now you can select the type to add to your project. Select C File(.c) and
give it a name (here main.c) and Click Add.

GFGC Shikaripura Department of Electronics


Step 8: Building a C Project Using Keil UVision IDE

After you have typed out the above c program to your main.c file,You can
compile the C file by pressing F7 key or by going to ' Project -> Build
Target ' on the IDE menu bar.

Step 9: If there are no errors the code will compile and you can view the output
on the Build Output panel.

GFGC Shikaripura Department of Electronics


Step 10: Select Debug and start/stop Debug session

Step 11: Goto Peripherals and Select the output ports

GFGC Shikaripura Department of Electronics


Step 12: After selecting suitable output ports goto debug and
press run

After selecting run button verify the results in port pins.

GFGC Shikaripura Department of Electronics


1. An embedded C program to load a number into Accumulator.

# include<reg51.h>

void main(void)

Acc = 0x25;

2. Write an 8051 c program to send values 00H-0AAH to port P1.

#include<reg51.h>

void main(void)

unsigned char z;

for (z=0; z<=170; z++)

P1=z;

GFGC Shikaripura Department of Electronics


3. Write an 8051 C program to toggle all the bits of P1 continuously.

#include<reg51.h>

void main ( )

for ( ; ; )

P1=0x55;

P1=0xAA;

4. Write a program to load three numbers into Accumulator and send them to port

# include <reg51.h>

void main( )

ACC = 0x25;

P1 = ACC;

ACC = 0x46;

P1 = ACC;

ACC = 0x92;

P1 = ACC;

}
GFGC Shikaripura Department of Electronics
5. Write a 8051 c program to add array of 16bit numbers and store the 16bit result in the
internal RAM

#include <reg51.h>

#include<stdio.h>

void main(void)

unsigned int i, array[5] = {10,20,30,40,50};

unsigned long sum=0;

for(i=0;i<=5;i++)

sum=sum+array[i];

P1 = sum;

GFGC Shikaripura Department of Electronics


6. Write a 8051 c program to To read 10 data from port P0 and store in internal RAM.

#include <reg51.h>

#include<stdio.h>

void main(void)

unsigned int i, array[10] = {1,2,3,4,5,6,7,8,9,10};

for(i=0;i<=5;i++)

P0=array[i];

GFGC Shikaripura Department of Electronics


7. Write a 8051 c program to find the square of a numbers (1to10) using look-up table

#include <reg51.h>

void main(void)

unsigned char LUT[] = {1,4,9,16,25,36,49,64,81,100};

unsigned char num, square;

for(num=0;num<=10;num++)

square= LUT [num-1];

P0=square;

while(1);

GFGC Shikaripura Department of Electronics


8. Write a 8051 c program to display "Hi Microcontroller" message

#include <reg51.h>

#include <stdio.h>

void main(void)

SCON = 0x50;

TMOD = 0x20;

TH1 = 0xFD;

TR1 = 1;

TI = 1;

while(1)

printf("Hi Microcontroller");

GFGC Shikaripura Department of Electronics


9. Write a 8051 c program to To read data from port P0 convert it to decimal and send to P1
and P2.

#include <reg51.h>

void main(void)

unsigned char hexa=0xCF;

unsigned char hundreds, tens, units;

hexa = hexa/10;

P0 = B;

units = B;

hexa = hexa/10;

hundreds = ACC;

tens = B;

P1 = B;

P2 = ACC;

while(1);

GFGC Shikaripura Department of Electronics


10. Write a 8051 c program to blink LED at port 3 of 5th pin.

#include<reg51.h> // special function register declarations

sbit LED = P3^5; // Defining LED pin

void Delay(void); // Function prototype declaration

void main (void)

while(1) // infinite loop

LED = 0; // LED ON

Delay();

LED = 1; // LED OFF

Delay();

void Delay(void)

int j;

int i;

for(i=0;i<10;i++)
{
for(j=0;j<10000;j++)
}
}
GFGC Shikaripura Department of Electronics
GFGC Shikaripura Department of Electronics

You might also like