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

LAB Manual - Microprocessor Lab - Draft

The document contains a laboratory manual for the subject Microprocessors & Microcontrollers Lab. It lists 12 experiments to be performed including blinking LEDs using Arduino, measuring DC voltage with Arduino, controlling speed of a DC motor using MOSFET and Arduino, and implementing arithmetic operations in binary and BCD using 8085 microprocessor. For experiment 4, it provides algorithms and programs for binary addition and BCD addition to be coded on 8085 microprocessor.

Uploaded by

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

LAB Manual - Microprocessor Lab - Draft

The document contains a laboratory manual for the subject Microprocessors & Microcontrollers Lab. It lists 12 experiments to be performed including blinking LEDs using Arduino, measuring DC voltage with Arduino, controlling speed of a DC motor using MOSFET and Arduino, and implementing arithmetic operations in binary and BCD using 8085 microprocessor. For experiment 4, it provides algorithms and programs for binary addition and BCD addition to be coded on 8085 microprocessor.

Uploaded by

Vipin V A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Government Engineering College Idukki

Department of Electrical & Electronics Engineering

EEL 331 – Microprocessors & Microcontrollers Lab

(2019 Scheme)

Laboratory Manual
List of Experiments
Expt Name of experiment Page No
No
1 Blinking LED using Arduino UNO 03-04
2 Measurement of DC voltage using Arduino UNO (0-5V and 0- 05-07
12V)
3 DC motor speed control using MOSFET driver and Arduino 08-09
UNO module
4 Programs to implement Arithmetic operations in binary and 10-13
BCD: addition, subtraction, multiplication and division using
8085
5 Program to sort an array using bubble sort using 8085 14

6 Program for Binary to BCD conversion and vice versa using 15-16
8085

7 Arithmetic operations using 8051 with external memory 17-19


interfacing

8 ALP to find biggest number in an array using 8051 20

9 Implementation of bubble sort using 8051 21-23

10 ALP for number system conversion using 8051 24-25

11 ALP to generate square wave using 8051 26

12 ALP for driving stepper motor using 8085 27

2
Expt No 1.a:
Date:

Blinking internal LED of Arduino UNO module


Aim:
To blink internally connected LED of Arduino UNO

Program:
void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Result
<Result should be in concurrence with the aim>

3
Expt No 1.a:
Date:

Blinking external LED using Arduino UNO module


Aim:
To blink an externally connected LED using Arduino UNO

Program:

int LED = 8;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second


digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Result
<Result should be in concurrence with the aim>

4
Expt No 2.a:
Date:

Arduino based voltage measurement - Analog input range 0-5 V


Aim:
To measure a DC voltage in range 0-5V using Arduino UNO
Program:

/*AnalogReadSerial
Reads an analog input (potentiometer) on pin 0,
prints the result to the serial monitor.
<<OPEN THE SERIAL MONITOR TO VIEW THE OUTPUT FROM
THE POTENTIOMETER >>
Attach the center pin of a potentiometer to pin
A0, and the outside pins to +5V and ground.*/
int sensorValue = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(10); // Delay a little bit to improve simulation performance
}

Circuit Diagram

Result
<Result should be in concurrence with the aim>

5
Expt No 2.b:
Date:

Arduino based voltage measurement - Analog input range 0-12 V


Aim:
To measure a DC voltage in range 0-12V using Arduino UNO

Theory:

A voltage divider circuit consisting of two resistors in series will divide the input voltage to bring it

within the range of the Arduino analog inputs.

<Design the suitable values of R1 & R2, such that maximum voltage across R2 will be 5V, when actual
maximum input voltage is applied across series combination, in this case, 12V>

Program:

int value = 0;

float voltage;

float R1 = 47000.0;

float R2 = 33000.0;

void setup(){

pinMode(A0, INPUT);

Serial.begin(9600);

void loop(){

value = analogRead(A0);

voltage = value * (5.0/1024)*((R1 + R2)/R2);

Serial.print("Voltage =");

6
Serial.println(voltage);

delay(500);

Circuit Diagram

Result
<Result should be in concurrence with the aim>

7
Expt No 3:
Date:

DC motor speed control using MOSFET driver and Arduino UNO module
Aim:

To setup an experiment for controlling the speed of DC motor using MOSFET driven by PWM
signal from Arduino module

Connection diagram and Interfacing Circuit:

Figure shows a typical circuit for using the TLP250 as a MOSFET driver. VIN is the input drive
signal that dictates the output state. the TLP250 ground and load ground are referenced to the
power ground, ie Vsupply and VMOS share the same reference ground as can clearly be seen from
the circuit diagram and this ground is separate from Signal Ground. This clearly illustrates the
isolation in MOSFET drive as the driving signal is isolated from the load supply.

When VIN = 1, Q1 is driven from the supply voltage (Vsupply) – the gate is pulled up to Vsupply
level. Q1 turns on and current flows through the load – the load is driven from VMOS via the
MOSFET.

When VIN = 0, Q1 is driven low – the gate is pulled down to its source level. Q1 turns off and the
load is off.

Vsupply could be between 10V and 15V – 12V being a very common level used.

Design:

R1 should be calculated by you depending on the amplitude of the input signal.


A 10 mA current is sufficient to turn on the LED at the input side of TLP 250. When output is
HIGH from microcontroller, VIN will be 5V, The forward voltage for the LED would typically be
between 1.6V and 1.8V

So, IR1 = (VIN-VLED) = 5-1.8V=3.2 V

8
I=10 mA, therefore R1 =

So, select a resistance less than or equal to 320Ω as R1.

R2 is the gate resistor. R3 is gate-to-source resistor, which prevents accidental turn on of the
MOSFET by external noise usually at startup when the gate is floating. The MOSFET may
sometimes turn on with a floating gate because of the internal drain to gate "Miller" capacitance.
A gate to source resistor acts as a pull-down to ensure a low level for the MOSFET. I have had
MOSFETs blowing up in high voltage circuits, without the resistor in place. In most of the
commercial power supplies / inverters, there is a 1k resistor used. (Note: You may skip the
portion highlighted in yellow while copying to the record)

C1 is the decoupling capacitor. C2 is for filtering/smoothing, as a bulk capacitor.

Program:

int pwmPin = 6; // PWM output connected to digital pin 9


int val = 0; // variable to store the read value

void setup() {
pinMode(pwmPin, OUTPUT); // sets the pin as output
pinMode(A3, INPUT);
}

void loop() {
val = analogRead(A3); // read the input pin, potentiometer connected to analog pin 3
analogWrite(pwmPin, val / 4);
/* analogRead values go from 0 to 1023,
analogWrite values from 0 to 255*/
}

Procedure:
1. Connect the potentiometer end connections across 5V supply of Arduino Uno, and
central lead to analog input A3.
2. Connect the digital pin D6 to pin 2 of TLP 250, and GND to pin 3 of TLP250
3. Make the remaining connections, set potentiometer to minimum position, and turn on the
power supply for Arduino, MOSFET controller and load.
4. With change the potentiometer position, and observe the change in speed of the DC
motor

Result:

<Result must be in concurrence with the aim>

9
Expt No: 4
Date:

Programs to implement Arithmetic operations in binary and BCD: addition, subtraction,


multiplication and division
Aim:

To code and execute programs to implement following arithmetic operations in binary and BCD:
1. addition
2. subtraction
3. multiplication
4. division

Binary Addition
Algorithm:

1. Load the first number from memory location 2050 to accumulator.


2. Move the content of accumulator to register H.
3. Load the second number from memory location 2051 to accumaltor.
4. Then add the content of register H and accumulator using “ADD” instruction and storing result at
3050
5. The carry generated is recovered using “ADC” command and is stored at memory location 3051

Program:
Address HEX Code Mnemonics Comment
2000 3A,50,20 LDA 2050 A<-[2050]
2003 67 MOV H, A H<-A
2004 3A,51,20 LDA 2051 A<-[2051]
2007 84 ADD H A<-A+H
2008 6F MOV L, A L←A
2009 3E,00 MVI A, 00 A←00
200B 8F ADC A A←A+A+carry
200C 67 MOV H, A H←A
200D 22,50,30 SHLD 3050 H→3051, L→3050
2010 76 HLT

BCD Addition:
Algorithm:
1. Load 00H in a register (for carry)
2. Load content from memory into register pair
3. Move content from L register to accumulator
4. Add content of H register with accumulator
5. Add 06H if sum is greater than 9 or Auxiliary Carry is not zero
6. If carry flag is not equal to 1, go to step 8
7. Increment carry register by 1
8. Store content of accumulator into memory
9. Move content from carry register to accumulator
10. Store content of accumulator into memory
11. Stop

Program:

10
Memory HEX Code Mnemonics Comment
2000 0E,00 MVI C, 00 [C] <- 00H, carry
2002 2A,00,25 LHLD 2500 [H-L] <- [2500]
2005 7D MOV A,L [A] <- [L]
2006 84 ADD H [A] <- [A] + [H]
2007 27 DAA Add 06 if sum > 9 or AC = 1
2008 D2,0C,20 JNC 200C Jump if no carry
200B 0C INR C [C] <- [C] + 1
200C 32,02,25 STA 2502 [A] -> [2502], sum
200F 79 MOV A,C [A] <- [C]
2010 32,03,25 STA 2503 [A] -> [2503], carry
2013 76 HLT Stop

Binary Subtraction:
Algorithm:

1. Load 00 in a register C (for borrow)


2. Load two 8-bit number from memory into registers
3. Move one number to accumulator
4. Subtract the second number with accumulator
5. If borrow is not equal to 1, go to step 7
6. Increment register for borrow by 1
7. Store accumulator content in memory
8. Move content of register into accumulator
9. Store content of accumulator in other memory location
10. Stop

Program:
Memory HEX Codes Mnemonics Comment
2000 0E,00 MVI C,00 [C] <- 00
2002 2A,00,25 LHLD 2500 [H-L] <- [2500]
2005 7C MOV A,H [A] <- [H]
2006 95 SUB L [A] <- [A] – [L]
2007 D2,0B,20 JNC 200B Jump If no borrow
200A 0C INR C [C] <- [C] + 1
200B 32,02,25 STA 2502 [A] -> [2502], Result
200E 79 MOV A,C [A] <- [C]
2010 32,03,25 STA 2503 [A] -> [2503], Borrow
2013 76 HLT Stop

BCD Subtraction:
Algorithm:
1. Load the data from address 2051 in A
2. Move the data from A to C
3. Move the data 99 in A
4. Subtract the contents of registers A and C
5. Increment the content of A by 1
6. Move the data from A to B
7. Load the data from address 2050 in A
8. Add the contents of A and C and adjust it in BCD format by using DAA instruction
9. Store the result at memory address 3050
10. Stop

11
Program:
Address HEX Codes Mnemonics Comment
2000 3A,51,20 LDA 2051 A <- 2051
2003 4F MOV C, A C <- A
2004 3E,99 MVI A, 99 A <- 99
2006 91 SUB C A=A–C
2007 3C INR A A=A+1
2008 47 MOV B, A B <- A
2009 3A,50,20 LDA 2050 A <- 2050
200C 80 ADD B A=A+B
200D 27 DAA Convert the hexadecimal value to BCD value
200E 32,50,30 STA 3050 3050 <- A
2011 76 HLT STOP

Binary Multiplication:
Program:
Address HEX Codes Label Mnemonics Comment
2000 2A,50,20 LHLD 2050 H←2051, L←2050
2003 EB XCHG H↔D, L↔E
2004 4A MOV C, D C←D
2005 16,00 MVI D 00 D←00
2007 21,00,00 LXI H 0000 H←00, L←00
200A 19 L1 DAD D HL←HL+DE
200B 0D DCR C C←C-1
C2,04,20 JNZ L1
200C (JNZ 200A) If Zero Flag=0, goto Label L1
200F 22,50,30 SHLD 3050 H→3051, L→3050
2012 76 HLT

BCD Multiplication:

Program:
Address HEX Codes Labels Mnemonics Comments

2000 21, 00, 80 LXI H,8000H Load first operand address


2003 46 MOV B, M Store first operand to B
2004 23 INX H Increase HL pair
2005 4E MOV C, M Store second operand to register C
2006 1E, 00 MVI E, 00H Clear register E
2008 63 MOV H, E Clear H register
2009 7B MOV A, E Clear A register
200A B9 CMP C Compare C with A
200B CA, 23, 20 JZ DONE When Z = 0,jump to DONE
200E 80 LOOP ADD B Add B with A
200F 27 DAA Decimal Adjust
2010 57 MOV D, A Store A to D
2011 D2, 19, 20 JNC NINC Jump to NINC
2014 7C MOV A, H Store H to A
2015 C6, 01 ADI 01H Increase A by1
2017 27 DAA DecimalAdjust
2018 67 MOV H, A Restore H from A
2019 7B NINC MOV A, E Load E to A
12
201A C6, 01 ADI 01H Increase A by1
201C 27 DAA Decimal adjust
201D 5F MOV E, A Restore E from A
201E B9 CMP C Compare C with A
201F 7A MOV A,D Load D to A
2020 C2, 0E, 20 JNZ LOOP Jump to LOOP
2023 6F DONE MOV L, A Load A to L
2024 22, 50, 80 SHLD 8050H Store HL pair at location 8050 & 8051
2027 76 HLT Terminate the program

Binary Division
Algorithm:
1. Start the program by loading the HL pair registers with address of memory location.
2. Move the data to B Register.
3. Load the second data into accumulator.
4. Compare the two numbers to check carry.
5. Subtract two numbers.
6. Increment the value of carry.
7. Check whether the repeated subtraction is over.
8. Then store the results(quotient and remainder) in given memory location.
9. Terminate the program

Program:
ADDRESS Hex code MNEMONICS COMMENT
2000 21,50,20 LXI H, 2050
2003 46 MOV B, M B<-M
2004 0E,00 MVI C, 00 C<-00H
2006 23 INX H
2007 7E MOV A, M A<-M
2008 B8 CMP B
2009 DA,11,20 JC 2011 check for carry
200C 90 SUB B A<-A-B
200D 0C INR C C<-C+1
200E C3,08,20 JMP 2008
2011 32,50,30 STA 3050 3050<-A
2014 79 MOV A, C A<-C
2015 32,51,30 STA 3051 3051<-A
2018 76 HLT terminate the program

Result :
<Result should be in correlation with the aim>
<Note: Algorithm, flowchart, input and output to be recorded in the left hand side page, program to be
mentioned in right hand side page>

13
Expt No: 5
Date:
Program to sort an array using bubble sort
Aim

To code and execute the program to sort an array using bubble sort in
1. ascending order
2. descending order

Algorithm – Ascending Order

1. Load size of list in C register and set D register to be 0


2. Decrement C as for n elements n-1 comparisons occur
3. Load the starting element of the list in Accumulator
4. Compare Accumulator and next element
5. If accumulator is less than or equal to the next element jump to step 8
6. Swap the two elements
7. Set D register to 1
8. Decrement C
9. If C>0 take next element in Accumulator and go to point 4
10.If D=0, this means in the iteration, no exchange takes place consequently we know that it won’t
take place in further iterations so the loop in exited and program is stopped
11. Jump to step 1 for further iterations
Program-Ascending Order

HEX
Addr Codes Label Instruction Comment
2000 21,40,20 START LXI H 2040 Load size of array
2003 16,00 MVI D 00 Clear D register to set up a flag
2005 4E MOV C, M Set C register with number of elements in list
2006 OD DCR C Decrement C
2007 23 INX H Increment memory to access list
2008 7E CHECK MOV A, M Retrieve list element in Accumulator
2009 23 INX H Increment memory to access next element
200A BE CMP M Compare Accumulator with next element
200B DA,18,20 JC NEXTBYTE If accumulator is less then jump to NEXTBYTE
200E CA,18,20 JZ NEXTBYTE If accumulator is equal then jump to NEXTBYTE
2011 46 MOV B, M Swap the two elements
2012 77 MOV M, A
2013 2B DCX H
2014 70 MOV M, B
2015 23 INX H
2016 16,01 MVI D 01 If exchange occurs save 01 in D register
2018 OD NEXTBYTE DCR C Decrement C for next iteration
2019 C2,08,20 JNZ CHECK Jump to CHECK if C>0
201C 7A MOV A, D Transfer contents of D to Accumulator
201D FE,01 CPI 01 Compare accumulator contents with 01
201F CA,00,20 JZ START Jump to START if D=01
2022 76 HLT HALT
Note: For sorting in descending order, prepare the program on your own
Result:
<Result should be in concurrence with the aim>

14
Expt No 6:
Date:
Program for Binary to BCD conversion and vice versa
Aim:

To code and execute the program to convert


1. from BCD to binary
2. from binary to BCD

Algorithm – BCD to Binary conversion

1. Load the BCD number from the memory location (201FH, arbitrary choice) into the
accumulator
2. Temporarily store the accumulator’s value in B
3. Obtain BCD2 by ANDing the accumulator with 0FH and store it in C
4. Restore the original value of the accumulator by moving the value in B to A. AND the
accumulator with F0H
5. If the value in the accumulator equals 0, then BCD 2 is the final answer and store it in the
memory location, 2020H (arbitrary)
6. Else, shift the accumulator to right 4 times to obtain BCD 1. Next step is to multiply
BCD1 by 0AH
7. Multiplication: Move BCD1 to D and initialise E with 0AH as the counter. Clear the
accumulator to 0 and add D to it E number of times
8. Finally, add C to the accumulator and store the result in 2020H

Program – BCD to Binary Conversion

ADDRESS HEX Codes LABEL MNEMONIC


2000 3A,1F,20 LDA 201F
2003 47 MOV B, A
2004 E6,0F ANI 0F
2006 4F MOV C, A
2007 78 MOV A, B
2008 E6,F0 ANI F0
200A CA,1A,20 JZ SKIPMULTIPLY
200D OF RRC
200E OF RRC
200F OF RRC
2010 OF RRC
2011 57 MOV D, A
2012 AF XRA A
2013 1E,0A MVI E 0A
2015 82 SUM ADD D
2016 1D DCR E
2017 C1,15,20 JNZ SUM
201A 81 SKIPMULTIPLY ADD C
201B 32,20,20 STA 2020
201E 76 HLT

15
Program – Binary to BCD conversion

Address HEX Codes Labels Mnemonics Comments


2000 21, 00, 80 LXI H,8000H Initialize memory pointer
2003 16, 00 MVI D,00H Clear D- reg for Most significant Byte
2005 AF XRA A Clear Accumulator
2006 4E MOV C, M Get HEX data
2007 C6, 01 LOOP ADI 01H Count the number one by one
2009 27 DAA Adjust for BCD count
200A D2, 0E, 20 JNC SKIP Jump to SKIP
200D 14 INR D Increase D
200E 0D SKIP DCR C Decrease C register
200F C2, 07, 20 JNZ LOOP Jump to LOOP
2012 6F MOV L, A Load the Least Significant Byte
2013 62 MOV H, D Load the Most Significant Byte
2014 22, 50, 80 SHLD 8050H Store the BCD
2017 76 HLT Terminate the program

Result:

<Result should be in concurrence with the aim>

16
Expt No:7
Date:
Arithmetic operations using 8051 with external memory interfacing
Aim

To formulate and execute ALP to implement basic arithmetic operations using 8051 with external
memory interfacing

Algorithm:

Addition / Subtraction

Step 1 : Move 1st data to memory


Step 2 : Add or subtract 1st data with/from 2nd data
Step 3 : Initialize data pointer.
Step 4 : Move result to memory pointed by DPTR.
Multiplication / Division

Step 1 : Get 1st data and 2nd data to memory


Step 2 : Multiply or divide 1st data with 2nd data
Step 3 : Initialize data pointer.
Step 4 : Move result to memory pointed by DPTR (first part)
Step 5 : Increment DPTR
Step 6 : Move 2nd part of result to register A
Step 7 : Move result to 2nd memory location pointer by DPTR
Program:

8-bit Addition:

Memory Label Opcode Mnemonics Comments


Location
8100 74 01 MOV A, #01 Moves data 1 to
register A
8102 24 02 ADD A, #02 Add content of A and
data 2 and store in A
8104 90 85 00 MOV DPTR,#8500 Moves data 4500 to
DPTR
8107 F0 MOVX @DPTR,A Moves control of A to
location pointed DTPR
8108 80 FE SJMP 8108 Short jump to 4108

Execution:Addition:

ML Input ML Output
8101 8500
8103

Program: 8-bit Subtraction:

Memory Label Opcode Mnemonics Comments


Location
8100 74 05 MOV A,#05 Moves data 1 to
register A

17
8102 CLR C Clearing existing borrow
8103 94 02 SUBB A,#02 Subtract data 2 from
content of A and store
result in A
8105 90 85 00 MOV DPTR,#8500 Moves 8500 to DPTR
8108 F0 MOVX @DPTR,A Moves result by
location by DTPR
8109 80 FE SJMP 8109 Short jump to 8109

Execution: Subtraction:

ML Input ML Output
8101 8500
8103

Program: 8-bit Multiplication:


Memory Label Opcode Mnemonics Comments
Location
8100 Start 74 03 MOV A,#03 Move immediate data
to accumulator
8101 75 F0 02 MOV B,#02 Move 2nd data to B
register
8105 A4 MUL AB Get the product in A &
B
8106 90 85 00 MOV DPTR, # 8500 Load data in 8500
location
8109 F0 MOVX @DPTR,A Move A t ext RAM

810A A3 INC DPTR


810B E5 F0 MOV A,B Move 2nd data in A
810D F0 MOVX @DPTR,A Same the ext RAM
810E 80 FE SJMP 810E Remain idle in infinite
loop

Execution: Multiplication:

ML Input Output Address Value


8101 8500
8103

Program: 8-bit Division:

Memory Label Opcode Mnemonics Comments


Location
8100 Start 74 04 MOV A,#04 Move immediate data
to accumulator
8102 75 F0 02 MOV B,#02 Move immediate to B
reg.
8105 84 DIV AB Divide content of A &
B
8106 90 85 00 MOV DPTR, # 8500 Load data pointer with
8500 location
8109 F0 MOVX @DPTR,A Move A to ext RAM

18
810A A3 INC DPTR Increment data pointer
810B E5 F0 MOV A,B Move remainder to A
810D F0 MOVX @DPTR,A Move A to ext RAM
810E 80 FE SJMP 810E Remain idle in infinite
loop

Execution: Division:

ML Input Output Address Value


8101 8500
8103

Result:

<Result should be in concurrence with the aim>

19
Expt No:8
Date:
ALP to find biggest number in an array
Aim:

To write and execute an ALP to find the biggest number in an array of 8-bit
unsigned numbers of predetermined length.

Algorithm:

1. Initialize pointer and counter.


2. Load internal memory location 40H as zero.
3. Move the first element of an array to r5 register.
4. Compare the data stored in memory location 40H is equal to or less than thevalue of
first element of an array.
5. If it is lesser, then move the data of first element to 40H memory
locationELSE increment pointer and decrement counterCheck the
counter. If counter is not equal to zero, repeat from the 2nd
step else Move the R5 register to 40H memory location.
6. Stop the program.
Program:
Memory Label Opcode Mnemonics Comments
Location
8100 90 82 00 MOV DPTR,#8200H
8103 75 40 00 MOV 40H,#00H
8106 7D 0A MOV R5,#05H Give the number of inputs for
finding the largest number.
8108 E0 MOVX A,@DPTR Moves into accumulator a bytefrom
LOOP2: external memory
8109 B5 40 08 CJNE A,40H,LOOP1 Compare and jump not equal to‘A’
810C LOOP 3 A3 INC DPTR
810D DD F9 DJNZ R5,LOOP2 Decrement and Jump not equal to Zero
810F E5 40 MOV A,40H
8111 F0 MOVX @DPTR,A
8112 HLT 80 FE SJMP HLT
8114 LOOP1 40 F6 JC LOOP3
8116 F5 40 MOV 40H,A
8118 80 F2 SJMP LOOP3
SAMPLE INPUT AND OUTPUT:
INPUT:
Memory address Data
Output
8200 Memory address Data

Result:

<Result should be in concurrence with the aim>

20
Expt No: 9
Date:
Implementation of bubble sort using 8051

Aim:

To sort a given set of numbers stored in external memory using bubble sort in 8051 in:

(1) ascending order


(2) descending order

Algorithm for sorting in ascending order:

1. Initialize the register and data pointer.


2. Get first two elements in registers A &B.
3. Compare the two elements of data. If value of B register is high then
exchange A& B data else increment pointer and decrement register R3.
4. Check R3 is zero, and then move the register R5 & R6.
5. Again increment pointer and decrement R4,
6. Check R4 is zero. If no repeat the process from step 2.
7. Otherwise stop the program.

Program for sorting in ascending order:


Memory Label Opcode Mnemonics
Location
MOV R3,#4
8100 7B 04
MOV R4,#4
8102 7C 04
8104 90 85 00 MOV DPTR,#8500
8107 REPT 1: AD 82 MOV R5,DPL
8109 AE 83 MOV R6, DPH
810B E0 MOVX A,@DPTR
810C F5 FO MOV B,A
810E REPT A3 INC DPTR
810F E0 MOVX A,@DPTR
8110 F8 MOV R0,A
8111 C3 CLR C
8112 95 F0 SUBB A,B
8114 50 13 JNC CHKNXT
8116 EXCH C0 82 PUSH DPL
8118 C0 83 PUSH DPH
811A 8D 82 MOV DPL,R5
811C 8E 83 MOV DPH,R6

21
811E E8 MOV A,R0
811F F0 MOVX @DPTR,A
8120 D0 83 POP DPH
8122 D0 82 POP DPL
8124 E5 F0 MOV A,B
8126 F0 MOVX @DPTR,A
8127 88 F0 MOV B,R0
8129 CHKNXT: DBE3 DJNZ R3,REPT
812B 1C DEC R4
812C EC MOV A,R4
812D FB MOV R3,A

812E OC INC R 4
812F 8D 82 MOV DPL,R5
8131 8E 83 MOV DPH,R6
8133 A3 INC DPTR
8134 DC D1 DJNZ R4,REPT1
8136 80 FE SJMP HLT
Algorithm for sorting in descending order:

1. Initialize the register and data pointer.


2. Get first two elements in registers A &B.
3. Compare the two elements of data. If value of B register is low then
exchange A &B data else increment pointer and decrement register R3.
4. Check R3 is zero, and then move the register R5 & R6.
5. Again increment pointer and decrement R4,
6. Check R4 is zero. If no repeat the process from step 2.
7. Otherwise stop the program.
Program for sorting in descending order:

Memory Label Opcode Mnemonics


Location
MOV R3,#4
8100 7B 04
MOV R4,#4
8102 7C 04
8104 90 85 00 MOV DPTR,#8500
8107 REPT 1: AD 82 MOV R5,DPL
8109 AE 83 MOV R6, DPH
810B E0 MOVX A,@DPTR
810C F5 FO MOV B,A
810E REPT A3 INC DPTR

22
810F E0 MOVX A,@DPTR
8110 F8 MOV R0,A
8111 C3 CLR C
8112 95 F0 SUBB A,B
8114 40 13 JC CHKNXT
8116 EXCH C0 82 PUSH DPL
8118 C0 83 PUSH DPH
811A 8D 83 MOV DPL,R5
811C 8E 83 MOV DPH,R6
811E E8 MOV A,R0
811F F0 MOVX @DPTR,A
8120 D0 83 POP DPH
8122 D0 82 POP DPL
8124 E5 F0 MOV A,B
8126 F0 MOVX @DPTR,A
8127 88 F0 MOV B,R0
8129 CHKNXT: DBE3 DJNZ R3,REPT
812B 1C DEC R4
812C EC MOV A,R4
MOV R3,A
812D FB
812E OC INC R4
812F 8D 82 MOV DPL,R5
8131 8E 83 MOV DPH,R6
8133 A3 INC DPTR
8134 DC D1 DJNZ R4,REPT1
8136 80 FE SJMP HLT

Result:

<Result should be in concurrence with the aim>

23
Expt No: 10
Date:
ALP for number system conversion
Aim

To develop and execute programs to perform the following number system conversions

1. Packed BCD to ASCII


2. ASCII to Packed BCD

Program

1. Packed BCD to ASCII

Address Label Hex Code Mnemonics Description


8100 START: 90 45 00 MOV DPTR, #8500H Address at which BCD number is
stored
8103 E0 MOVX A, @DPTR BCD moved to A
8104 FA MOV R2,A
8105 54 F0 ANL A,#F0H Mask lower order nibble
8017 C4 SWAP A Swaps lower and higher order
nibbles of A, higher order nibble
unpacked
8108 44 30 ORL A,#30H Converted higher order nibble
810A A3 INC DPTR
810B F0 MOVX @DPTR,A Moved value back to location 4501H
810C EA MOV A,R2
810D 54 0F ANL A,#0FH Masked higher order nibble, lower
order nibble unpacked
810F 44 30 ORL A,#30H Converted higher order nibble
8111 A3 INC DPTR
8112 F0 MOVX @DPTR,A
8113 STOP 80 FE SJMP STOP

Input

Address Data
8500

Output

Address Data
8501
8502

24
2. ASCII to Packed BCD

Address Label Hex Code Mnemonics Description


8100 START: 90 85 00 MOV DPTR,#8500H Gets first number from memory
8103 E0 MOVX A, @DPTR
8104 54 F0 ANL A,#F0H Masks upper nibble
8106 C4 SWAP A Swaps upper and lower nibbles of A
8107 F5 F0 MOV B,A
8109 A3 INC DPTR
810A E0 MOVX A, @DPTR Gets next number from memory
810B 54 F0 ANL A,#F0H Masks upper nibble
810D AF F0 ORL A,B
810F A3 INC DPTR
8110 F0 MOVX @DPTR,A Move packed BCD to next location
8111 STOP: 80 FE SJMP STOP

Input Output

Address Data Address Data


8500 8502
8501

Result

25
Expt No: 11
Date:
ALP to generate square wave using 8051
Aim

To develop and execute an ALP to generate a 10Hz square wave using 8051

Design

Frequency of square wave to be generated = 10Hz

Time period of square wave= 1/10 = 0.1s = 100 mS (50mS HIGH, 50mS LOW)

In external memory of the 8051 kit, from 6060H location, delay subroutine is already burned into ROM,
with inputs as R6 and R7=n, where n is the counter maximum value in hex format, which includes an inner
loop timer which has 512 number of states.

Clock frequency =11.0592 MHz

One clock time period = 1/11.0592 μs

Time period for one instruction cycle = 12 x 1/11.0592 = 12/11.0592 μs

In the delay subroutine available in 6060H, one run of inner loop timer will run 512 times, produce approx
delay of 12/11.0592 x 512 D = 534.261 μs=0.5343 ms

Therefore, n (in decimal)=50/0.5555 = 90 D = 5A H

Program

Address Label Hex Code Mnemonics Description


8000 90 20 03 MOV DPTR,#2003 Address of control word of 8255-1
8003 74 80 MOV A,#80 Set control word for all ports
8005 F0 MOVX @DPTR,A Write Control word
8006 74 FF MOV A,#FF To set all pins to 1
8008 90 20 00 MOV DPTR,#2000 Address of 8255-1 Port-A
800B LOOP: F0 MOVX @DPTR,A Write to Port A
800C 64 FF XRL A,#FF To invert all bits
800E 7E 00 MOV R6,#00 Set delay time
8010 7F 5A MOV R7,#5A Value to initiate time delay subroutine of
required time period
8012 C0 E0 PUSH A Store Accumulator contents temporarily to stack
8014 12 60 60 LCALL DELAY Call Delay subroutine(Already stored in ROM,
R6, and R7=n are inputs)
8017 D0 E0 POP A Restore Accumulator
8019 02 80 0B LJMP LOOP To execute the whole process in continuous loop

Result

26
Expt No: 12
Date:
ALP for driving stepper motor using 8085
Aim:

To develop and execute an ALP for driving a stepper motor in single phase full step operation using
8085 and 8255 PPI interface

Theory of operation:

The stepper motor will rotate in anti-clockwise direction if the output from PPI is given in
F8,F1,F4,F2 sequence, and anticlockwise if the output from PPI is given in F2,F4,F1,F8 sequence

Program (for anti-clockwise rotation):

Address Label Hex code Mnemonics Description


2000 3E 80 MVI A 80 Initialise Port A of 8255 as Output Port
2002 D3 03 OUT 03 Writing to Control register (Addr : 03H)
2004 LOOP: 3E F2 MVI A F2 Bit sequence for step 1
2006 D3 00 OUT 00 Output to Port A (Addr: 00H)
2008 CD 23 20 CALL DELAY1 Delay between two consecutive steps
200B 3E F4 MVI A F4 Bit sequence for step 2
200D D3 00 OUT 00 Output to Port A (Addr: 00H)
200F CD 23 20 CALL DELAY1 Delay between two consecutive steps
2012 3E F1 MVI A F1 Bit sequence for step 3
2014 D3 00 OUT 00 Output to Port A (Addr: 00H)
2016 CD 23 20 CALL DELAY1 Delay between two consecutive steps
2019 3E F8 MVI A F8 Bit sequence for step 4
201B D3 00 OUT 00 Output to Port A (Addr: 00H)
201D CD 23 20 CALL DELAY1 Delay between two consecutive steps
2020 C3 04 20 JMP LOOP
2023 DELAY1: 11 00 00 LXI H 0000 Delay routine for controlling speed
2026 CD BC 03 CALL 03BC Delay function written in ROM location 03BC
2029 C9 RET
202A 76 HLT

Result:

<Result should be in concurrence with the aim>

27

You might also like