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

Embedded

The document describes writing assembly language programs for the 8051 microcontroller to perform arithmetic operations, logical operations, and data transfers. It includes algorithms and programs for 8-bit and 16-bit addition, subtraction, multiplication, and division. It also includes setting, masking, and complementing bits, and calculating squares and cubes.

Uploaded by

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

Embedded

The document describes writing assembly language programs for the 8051 microcontroller to perform arithmetic operations, logical operations, and data transfers. It includes algorithms and programs for 8-bit and 16-bit addition, subtraction, multiplication, and division. It also includes setting, masking, and complementing bits, and calculating squares and cubes.

Uploaded by

suvejah18
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Ex: no: 1 Programming Using Arithmetic Instructions of 8051 microcontroller

Date:

Aim:

To add, subtract, divide, multiply two 8 bit and 16 bit hexa numbers residing in memory and
store the result in memory.

Software Requried:

SNO NAME QUANTITY


1 MCU 8051 software 1
2 Window Xp operating system 1

I. 8-Bit addition and Subtraction:

Algorithm:
PROGRAM:
Addition without carry:

ORG 0000H
MOV A, #DATA1
ADD A, #DATA2
MOV 30H,A
END

Addition with carry:

ORG 0000H
MOV A,#DATA1
ADDC A,#DATA2
MOV 42H,A
END

Subtraction:

ORG 0000H
MOV A, #DATA 1
SUBB A, #DATA 2
MOV 30H,A
END
INPUT and OUTPUT:
Addition without carry
Input Output

INPUT and OUTPUT:


Addition with carry
Input Output

INPUT and OUPUT:


Subtraction:
Input Output
DATA =
DATA =
II. 8-Bit Multiplication and division:

ALGORITHM:
1. Start the program.
2. Get the Multiplier in A
3. Get the multiplicand in B
4. Multiply A With B
5. Store the result in memory
6. Stop the program.

Program:

ORG 0000H
MOV A,#DATA1
MOV B,#DATA2
MUL AB
MOV 30H,A
MOV 32H,B
END

INPUT and OUTPUT:

Input Output

Division:
ORG 0000H
MOV A,#DATA1
MOV B,#DATA2
DIV AB
MOV 30H,A
MOV 32H,B
END

Algorithm:
1. Start the program.
2. Get the dividend in A.
3. Get the divisor in B.
4. Divide A by B.
5. Store LSB & MSB of the result in the memory.
6. Stop the program.

INPUT and OUTPUT:


Input Output

III. 16 Bit Addition:


Algorithm:

1. Start.
2. Write the program in MCU 8051 ide.
3. Executed the program.
4. If no errors and warnings.
5. Note the address and opcode.
6. stop

Program:
Addition :

CLR C
MOV DPTR, #0010H
MOVX A, @DPTR
MOV R0,A
INC DPTR
MOVX A, @DPTR
ADD A,R0
MOV R1,A
INC DPTR
MOVX A, @DPTR
MOV R0,A
INC DPTR
MOVX A, @DPTR
ADD A,R0
INC DPTR
MOVX @DPTR,A
INC DPTR
MOV A, R1
MOVX @DPTR,A
END

Result:

Ex: no: 2 Programming Using logical Instructions, complements, square and cube of a number
Date:
Aim:

i) To set and mask specific bits of an 8 bit number using 8051 logical instructions.
ii) To write an assembly language program to find the 1’s complement and 2’s
complement of an 8- bit number using microcontroller instruction set.
iii) To write an assembly language program to find square and cube of an 8 bit number
using 8051 microcontroller.

I) SETTING BITS IN AN 8- BIT NUMBER

AIM:
To set specific bits of an 8 –bit number.

Software Requried:

SNO NAME QUANTITY


1 MCU 8051 software 1
2 Window Xp operating system 1

ALGORITHM:
1. Get the first data in A.
2. Get the second data and perform OR operation.
3. Store the result in memory.
4. Stop the program.
Program:

ORG 0000H
CLR A
MOV A, #DATA 1
ORL A, #DATA 2
MOV DPTR, #0010H
MOVX @DPTR,A
END

INPUT and OUTPUT:

Input Output
DATA1=
DATA2=
II.) MASKING BITS IN AN 8- BIT NUMBER

AIM :

To mask a bit of an 8 bit number and store the result in memory

Software Requried:

SNO NAME QUANTITY


1 MCU 8051 software 1
2 Window Xp operating system 1

ALGORITHM:
1. Start the program.
2. Get the first data in A.
3. Get the 2nd data and perform AND operation.
4. Store the result in memory.
5. Stop the program.
Program:
ORG 0000H
CLR A
MOV A, #DATA 1
ANL A, #DATA 2
MOV DPTR, #0010H
MOVX @DPTR,A
END

INPUT and OUTPUT:

Input Output
DATA1=
DATA2=

III.)ONE’S & TWO’S COMPLEMENT

AIM:
To obtain the one’s and two’s complement of an 8- bit number in register A.
Software Requried:

SNO NAME QUANTITY


1 MCU 8051 software 1
2 Window Xp operating system 1

ALGORITHM:
1. Get the data in accumulator.
2. Take the 1s complement of the data.
3. Increment to get the 2s complement.
4. Store the result in memory.
5. Stop the program.

Program:

ORG 0000H
MOV A,#DATA
CPL A
MOV DPTR,#0010H
MOVX @DPTR,A
INC A
INC DPTR
MOVX @DPTR,A
END

INPUT and OUTPUT:

Input Output
DATA=

IV.) SQUARE OF AN 8 BIT NUMBER

AIM:
To find square of an 8 bit number using 8051 microcontroller.
Software Requried:

SNO NAME QUANTITY


1 MCU 8051 software 1
2 Window Xp operating system 1

ALGORITHM:
1: Set the pointer for the memory location where the data available
2: Load the data to accumulator
3: Move the data from accumulator to B register.
4: Multiply B register with accumulator.
5: Store the result in next memory locations
6: Stop the process.

Program:

ORG 0000H
CLR A
MOV DPTR,#0010H
MOVX A, @DPTR
MOV B, A
MUL AB
INC DPTR
MOVX @DPTR,A
MOV A,B
INC DPTR
MOVX @DPTR,A
END

Output:

Input Output

Address Data Data

V.) CUBE OF AN 8 BIT NUMBER

AIM:
To find cube of an 8 bit number using 8051 microcontroller.

Software Requried:
SNO NAME QUANTITY
1 MCU 8051 software 1
2 Window Xp operating system 1

ALGORITHM:
1: Set the pointer for the memory location where the data available
2: Load the data to accumulator
3: Move the data from accumulator to B register.
4: Multiply B register with accumulator.
5: Multiply B register with accumulator.
6: Store the result in next memory locations
7: Stop the process.

Program:

ORG 0000H
CLR A
MOV DPTR,#0010H
MOVX A, @DPTR
MOV B, A
MOV R0,A
MUL AB
MOV B,R0
MUL AB
INC DPTR
MOVX @DPTR,A
MOV A,B
INC DPTR
MOVX @DPTR,A
END
Output:

Input Output

Address Data Data

Result:
Expt No. 3 Test Data transfer between register and memory

Date:

Aim:
a) To write an assembly language program to transfer N bytes of data from one location A to another
location B.
b) To write an assembly language program to exchange N bytes of data at location A and at location
B.

Software Requried:

SNO NAME QUANTITY


1 MCU 8051 software 1
2 Window Xp operating system 1

I) Data Transfer from one location to another:


Aim:
To write an assembly language program to transfer N bytes of data from one location A to another
location B.

Program:
ORG 0000H
MOV R0,#30H
MOV R1,#40H
MOV R7,#05H
BACK: MOVX A,@R0
MOVX @R1,A
INC R0
INC R1
DJNZ R7,BACK
END

Output:
Before Execution:
After Execution:

II) Data Exchange from one location to another:


Aim:
To write an assembly language program to exchange N bytes of data at location A and at location B.

Program:
ORG 0000H
MOV R0,#30H
MOV R1,#40H
MOV R7,#05H
BACK: MOVX A,@R0
MOV R4,A
MOVX A,@R1
MOVX @R0,A
MOV A,R4
MOVX @R1,A
INC R0
INC R1
DJNZ R7,BACK
END

Output:
Before Execution:

After Execution:
Result:

Expt No. 4 Embedded C Programming Using Arithmetic Instructions of 8051 microcontroller


Date:

AIM:
To write an Embedded C programming for performing addition, subtraction, division and
multiplication of two 16 bit hexa numbers residing in memory.
1. 16-bit addition:
Algorithm:
• Declare three unsigned long variables
• Assign the data to two variables
• Perform addition and store the result into variable
• Display the result on port0,
• Stop
Program:
#include<at89x52.h>
void main(void)
{
unsigned long a,b,sum;
a=0x1234; #Data1
b=0x1234 #Data2
sum=a+b;
P0=sum & 0xff;
P1=(sum & 0xff00)>>8;
P2=(sum & 0xff0000)>>16;
}
Output:
Input Output

Data Data

2. 16-bit subtraction:

Algorithm:
• Declare three unsigned long variables
• Assign the data to two variables
• Perform subtraction and store the result into variable
• Display the result on port0,port 1
• Stop
Program:

#include<at89x52.h>
void main(void)
{
unsigned long a,b,diff;

a=0x4466; #data 1
b=0x2222; #data 2
diff=a-b;
P0= diff & 0xff;
P1=(diff & 0xff00)>>8;
}
Output:
Input Output

Data Data

3. 8-bit multiplication:
Algorithm:
• Declare three unsigned long variables
• Assign the data to two variables
• Perform multiplication and store the result into variable
• Display the result on port0 and port 1
• Stop
Program:

#include<at89x52.h>
void main(void)
{
unsigned long a,b,mul;

a=0x12; #data1
b=0x12; #data2
mul=a*b;
P0= mul & 0xff;
P1=(mul & 0xff00)>>8;
P2=(mul & 0xff0000)>>16;
}
Output:
Input Output

Data Data

4. 8-bit division:

Algorithm:
• Declare four variables
• Assign the data to two variables
• Perform division and store the result into variable
• Display the quotient on port0 and remainder on port 1
• Stop

Program:
#include<at89x52.h>

void main(void)

unsigned char a,b;

unsigned int quo,rem;

a=0x08;

b=0x02;

quo=a/b;

rem=a%b;

P0= quo;

P1=rem;

Output:
Input Output

Data Data

Result:

Ex: no: 5 LED Control Using Arduino Board

Date:
Aim: To control LED Using Arduino Uno board.

Apparatus required:

S. No. Apparatus Range/Rating Quantity


1 Arduino UNO board Atmega 328P 1
2 Led 5mm 1
3 12V Adaptor 12 V 1
4 USB Cable 1
5 Jumper Wires Required

Theory:
Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic
resonator, a USB connection, a power jack, an ICSP header and a reset button. It contains everything
needed to support the microcontroller.

LEDs are the most efficient way to turn an electric current into illumination. When a
current flows through a diode in the forward direction, it consists of surplus electrons moving in one
direction in the lattice and “holes” (voids in the lattice) moving in the other. Occasionally, electrons can
recombine with holes. When they do, the process releases energy in the form of photons. This is true of
all semiconductor junctions, but LEDs use materials that maximize the effect. The color of the light
emitted (corresponding to the energy of the photon) is determined by the semiconductor materials that
form the diode junction.
The latest high-brightness (HB) white LEDs are made possible by the discovery of
semiconductor materials that produce blue or ultraviolet photons. In addition to the diode, an HB
package contains “yellow” phosphors on the inside of its lens. Some “blue” photons escape, but others
excite the phosphors, which then give off “yellow” photons. The result can be tuned in manufacturing to
produce “white” light.

Figure. LED symbol

Hardware Procedure:

• LED pin is connected to anyone of Arduino Uno digital pin.


• Power jack is connected to the Arduino Uno.

• USB connector is connected to Arduino Uno to monitor.

• Connect the 12V power supply to development board.

• Check the output from the development board.

Software Procedure:

1. Click on Arduino IDE

2. Click on file

3. Click on New

4. Write a Program as per circuit Pin connections

5. Click on Save

6. Click on Verify

7. Click on Upload the code into Arduino Uno by using USB cable.

Program:
LED Blink:
int led1 = 2;
int led2 = 3;
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop()
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
delay(1000);
}

RESULT:
Thus the LED was interfaced successfully and controlled by Arduino microcontroller Board.

Ex: no: 7 IR Sensor Interfacing with Arduino


Date:

Aim: To Interface IR Sensor Using Arduino Uno board

Apparatus required:

S. No. Apparatus Range/Rating Quantity


1 Arduino board Atmega 328P 1
2 IR Sensor
3 12V Adaptor 1
4 LED 5mm 1
5 USB Cable 1
6 Jumper Wires Required
Theory:
Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic
resonator, a USB connection, a power jack, an ICSP header and a reset button. It contains everything
needed to support the microcontroller.
IR sensor is an electronic device, that emits the light in order to sense some object of the
surroundings. An IR sensor can measure the heat of an object as well as detects the motion. Usually,
in the infrared spectrum, all the objects radiate some form of thermal radiation. These types of
radiations are invisible to our eyes, but infrared sensor can detect these radiations.
Hardware Procedure:
● LED pin is Connected to anyone of Arduino Uno digital pin.
● IR Sensor Pin is connected to anyone of Arduino Uno digital pin.
● Power jack is connected to the Arduino.
● USB connector is connected to Arduino Uno to monitor.
● Connect the 12V power supply to development board.
● Check the output from the development board.

Software Procedure:
1. Click on Arduino IDE
2. Click on file
3. Click on New
4. Write a Program as per circuit Pin connections
5. Click on Save
6. Click on Verify
7. Click on Upload the code into Arduino Uno by using USB cable.

Program:
IR Sensor Interfacing:

int LED = 11;


int IRSENSOR = 4;
void setup()
{
pinMode(IRSENSOR,INPUT);
pinMode(LED,OUTPUT);
}
void loop()
{
int x = digitalRead(IRSENSOR);
if(x==0)
{
digitalWrite(LED,HIGH);
}
else
{
digitalWrite(LED,LOW);
}
}

RESULT:
Thus the IR sensor was interfaced successfully and controlled by Arduino microcontroller Board.

Ex: no: 7 Explore different communication methods with IoT devices


Date:

Aim: To Interface Bluetooth module Using Arduino Uno board.

Apparatus required:

S. No. Apparatus Range/Rating Quantity


2 Arduino board Atmega 328P 1
3 Bluetooth module HC - 05
1
5 12V Adaptor 1
6 LED 5mm 4
7 USB Cable 1
8 Jumper Wires Required
Theory:
Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic
resonator, a USB connection, a power jack, an ICSP header and a reset button. It contains everything
needed to support the microcontroller.
HC-05 is a Bluetooth module which is designed for wireless communication. This module can
be used in a master or slave configuration. It is used for many applications like wireless headset, game
controllers, wireless mouse, wireless keyboard, and many more consumer applications. It has range
up to <100m which depends upon transmitter and receiver, atmosphere, geographic & urban
conditions.

Hardware Procedure:

● LED pin is Connected to anyone of Arduino Uno digital pin.


● TX pin of Bluetooth is connected to RX pin of Arduino UNO.
● RX pin of Bluetooth is connected to TX pin of Arduino UNO.
● Power jack is connected to the Arduino.
● USB connector is connected to Arduino Uno to monitor.
● Connect the 12V power supply to development board.
● Check the output from the development board.

Software Procedure:
1. Click on Arduino IDE
2. Click on file
3. Click on New
4. Write a Program as per circuit Pin connections
5. Click on Save
6. Click on Verify
7. Click on Upload the code into Arduino Uno by using USB cable.
Program:

#define ledPin 12
int data = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600); //default baud rate for bt 38400
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
data = Serial.read(); // Reads the data from the serial port

if (data == '0') {
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED: OFF");
}
else if (data == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");

}
}
}

RESULT: Thus the Bluetooth module is interfaced successfully by Arduino UNO.

You might also like