Embedded
Embedded
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:
Algorithm:
PROGRAM:
Addition without carry:
ORG 0000H
MOV A, #DATA1
ADD A, #DATA2
MOV 30H,A
END
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
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 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.
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.
AIM:
To set specific bits of an 8 –bit number.
Software Requried:
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 Output
DATA1=
DATA2=
II.) MASKING BITS IN AN 8- BIT NUMBER
AIM :
Software Requried:
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 Output
DATA1=
DATA2=
AIM:
To obtain the one’s and two’s complement of an 8- bit number in register A.
Software Requried:
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 Output
DATA=
AIM:
To find square of an 8 bit number using 8051 microcontroller.
Software Requried:
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
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
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:
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:
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:
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)
a=0x08;
b=0x02;
quo=a/b;
rem=a%b;
P0= quo;
P1=rem;
Output:
Input Output
Data Data
Result:
Date:
Aim: To control LED Using Arduino Uno board.
Apparatus 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.
Hardware Procedure:
Software Procedure:
2. Click on file
3. Click on New
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.
Apparatus required:
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:
RESULT:
Thus the IR sensor was interfaced successfully and controlled by Arduino microcontroller Board.
Apparatus required:
Hardware Procedure:
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");
}
}
}