LAB Manual - Microprocessor Lab - Draft
LAB Manual - Microprocessor Lab - Draft
(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
2
Expt No 1.a:
Date:
Program:
void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
Result
<Result should be in concurrence with the aim>
3
Expt No 1.a:
Date:
Program:
int LED = 8;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED, OUTPUT);
}
Result
<Result should be in concurrence with the aim>
4
Expt No 2.a:
Date:
/*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:
Theory:
A voltage divider circuit consisting of two resistors in series will divide the input voltage to bring it
<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);
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
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:
8
I=10 mA, therefore 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)
Program:
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:
9
Expt No: 4
Date:
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:
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:
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
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
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:
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
15
Program – Binary to BCD conversion
Result:
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
8-bit Addition:
Execution:Addition:
ML Input ML Output
8101 8500
8103
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
Execution: Multiplication:
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:
Result:
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:
Result:
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:
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:
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:
23
Expt No: 10
Date:
ALP for number system conversion
Aim
To develop and execute programs to perform the following number system conversions
Program
Input
Address Data
8500
Output
Address Data
8501
8502
24
2. ASCII to Packed BCD
Input Output
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
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.
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
Program
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
Result:
27