0% found this document useful (0 votes)
31 views10 pages

Embedded System Lab Report 1

The document provides a comprehensive guide on familiarizing with the 8051/8052 microcontroller, focusing on writing assembly language code for various operations including data manipulation, arithmetic, and subroutine calls. It outlines the necessary equipment, theoretical background, and includes multiple programming problems with solutions in C, covering tasks such as addition, multiplication, sorting, and finding prime numbers. The document serves as a practical resource for understanding and implementing microcontroller programming techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views10 pages

Embedded System Lab Report 1

The document provides a comprehensive guide on familiarizing with the 8051/8052 microcontroller, focusing on writing assembly language code for various operations including data manipulation, arithmetic, and subroutine calls. It outlines the necessary equipment, theoretical background, and includes multiple programming problems with solutions in C, covering tasks such as addition, multiplication, sorting, and finding prime numbers. The document serves as a practical resource for understanding and implementing microcontroller programming techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

TITLE

Familiarization with 8051/8052 Microcontroller

OBJECTIVES
To enable us to write assembly language code for the 8051/8052 microcontroller
capable of:

1. Data Manipulation
2. Arithmetic and logic operations
3. Looping and branching techniques
4. Subroutine calls

Equipment Required
 Simulation Software: KEIL, Vision-Embedded development tool, Proteus Design
Suite – Professional PCB layout, circuit design and simulation tool.
 In-System Programming (ISP) Software: ProgISP – An in-system-programmable
tool to load HEX files in to micro-controller.

Theory
 8051 Microcontroller

 Features of 8051

 Instruction set

o Arithmetic Instructions

o Logical Instructions

o Data transfer Instructions

o Boolean Variable Instructions


o Program Branching Instructions

 Architecture of 8051 Microcontroller

 Circuit Diagram (in Proteus)

PROBLEMS
1. Write code to add the numbers 897F9AH and 34BC48H and save the result in internal
RAM starting at 40H. The result should be displayed continuously on the LEDs of
the development board starting from least significant byte with an appropriate timing
interval between each byte. Use port zero (P0) of the micro-controller to interface
with LEDs.

2. Implement a subroutine that replaces the SWAP instruction using rotate right
instructions. Test your program on the contents of the accumulator when it contains
the number 6BH.

3. Multiply, by using looping and successive addition technique, the data in RAM location
22H by the data in RAM location 15H and put the result in RAM locations 19H (low
byte) and 1AH (high byte). Data in 22H should be FFH and data in 15H should be DEH.
4. Divide, by using looping and successive subtraction technique, the data in RAM
location 3EH by the number 12H; put the quotient in R4 and remainder in R5. Data in
3EH should be AF.

#include<regx51.h>
unsigned int dividend _at_ 0x3E;
void delay(int i)
{
unsigned int j,k;
for(j=0;j<i;j++)
for(k=0;k<1000;k++);
}
void main(void)
{
unsigned int divisor = 0x12;
unsigned int quotient = 0x00;
dividend = 0xAF;
while(dividend >= divisor)
{
dividend-=divisor;
quotient++;
}
while(1)
{
P0 = quotient;
delay(10000);
P0 = dividend;
delay(10000);
}
}

5. Store ten hexadecimal numbers in internal RAM starting from memory location 50H.
The list of numbers to be used is: D6H, F2H, E4H, A8H, CEH, B9H, FAH, AEH,
BAH, CCH. Implement a subroutine that extracts both the smallest and largest
numbers from the stored numbers.
Code in C:
#include<regx51.h>
unsigned int nums[10] _at_ 0x50;
void delay(int i)
{
unsigned int j,k;
for(j=0;j<i;j++)
for(k=0;k<1000;k++);
}

void main( )
{
int largest,smallest,i;
nums[0]=0xD6;
nums[1]=0xF2;
nums[2]=0xE4;
nums[3]=0xA8;
nums[4]=0xCE;
nums[5]=0xB9;
nums[6]=0xFA;
nums[7]=0xAE;
nums[8]=0xBA;
nums[9]=0xCC;
largest = nums[0];
smallest = nums[0];

for(i=1;i<10;i++)
{
if(nums[i]<smallest)
{
smallest = nums[i];
}
}
for(i=1;i<10;i++)
{
if(nums[i]>largest)
{
largest = nums[i];
}
}
while(1)
{
P0=smallest;
delay(10000);
P0=largest;
delay(10000);
}
}
6. Store ten hexadecimal numbers in internal RAM starting from memory location 60H.
The list of numbers to be used is: A5H, FDH, 67H, 42H, DFH, 9AH, 84H, 1BH, C7H,
31H. Implement a subroutine that orders the numbers in ascending order using bubble
or any other sort algorithm and implement s subroutine that order the numbers in
descending order using selection sort algorithm.

Code (i) in C:

#include<regx51.h>
unsigned nums[10] _at_ 0x60;
void delay(int i)
{
unsigned int j,k;
for(j=0;j<i;j++)
for(k=0;k<1000;k++);
}

void main( )
{
int i,j,temp;
nums[0]=0xA5; nums[1]=0xFD; nums[2]=0x67; nums[3]=0x42; nums[4]=0xDF;
nums[5]=0x9A; nums[6]=0x84; nums[7]=0x1B; nums[8]=0xC7; nums[9]=0x31;
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
if(nums[j]>nums[j+1])
{
nums[j+1]; temp;
}
}
}
temp = nums[j];
nums[j] =
nums[j+1] =
while(1)
{
for(i=0;i<10;i++)
{
P0 = nums[i];
delay(10000);
}
}
}
Code (ii) in C:

#include<regx51.h>
unsigned int nums[10] _at_ 0x60;
void delay(int i){
unsigned int j,k;
for(j=0;j<i;j++)
for(k=0;k<1000;k++);
}

void main( ){
int i,j,largest,laarge,datnum;
nums[0]=0xA5; nums[1]=0xFD; nums[2]=0x67; nums[3]=0x42; nums[4]=0xDF; nums[5]=0x9A; nums[6]=0x84;
nums[7]=0x1B; nums[8]=0xC7; nums[9]=0x31;

largest = nums[i];
laarge = nums[i];
for(j=i+1;j<=9;j++)
{
if(largest<nums[j])
{
largest = nums[j]; datnum = j;
}
}
nums[i]=nums[datnum];
nums[datnum]=laarge;
while(1)
{
for(i=0;i<10;i++)
{
P0 = nums[i];
delay(10000);
}
}
}
7. Store numbers from 00H to 20H in internal RAM starting from memory location 40H.
Implement a subroutine that extracts only the prime numbers.
Code in C:
#include <reg51.h>
unsigned char data d[21] _at_ 0x40;

void delay(int time)


{
unsigned int i,j;
for (i=0; i<time; i++)
for (j=0; j<125; j++);
}

int isprime(unsigned char val)


{
unsigned char j;
for(j=0x2; j<val; j++)
if(val % j == 0x0) break;
if(j==val)
return 1;
return 0;
}
void main( )
{
unsigned char a[20];
unsigned char i,
count=0;
for(i=0x0; i<0x21; i++)
d[i] = i; a[counfor(i=0x3; i<0x21; i++)

if(isprime(d[i]))

a[count++] = d[i];

while(1)

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

P0 = a[i];

delay(1000);

}}

}
8. Find the factorial of a number stored in R3. The value in R3 could be any number in
the range from 00H to 05H. Implement a subroutine that calculates the factorial. The
factorial needs to be represented in both hexadecimal and decimal formats.

#include<reg51.h>

void delay(int time)


{
unsigned int i,j;
for (i=0; i<time; i++)
for (j=0; j<125; j++);
}

void main()
{
unsigned int val = 0x5; unsigned int fact = 0x1;
unsigned char i;
unsigned char x, d1, d2, d3;

for(i=0x1; i<=val; i++)


fact *= i;

x = fact / 0xa;

d1 = fact % 0xa;

d2 = x % 0xa;

d3 = x / 0xa;

while(1)
{
P0 = fact;
delay(1000); P0 = d1;
delay(1000); P0 = d2;
delay(1000); P0 = d3;
delay(1000);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy