MICROCONTROLLERS & EMBEDDED SYSTEMS LAB Faculty

advertisement
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Subject: MICROCONTROLLERS & EMBEDDED SYSTEMS LAB
Faculty: V.YASWANTH RAGHAVA
Branch: Electronics & Telecommunication, EEE
Class: B.E.7th Semester,
List of Experiments:
1. Write an assembly language program for addition of two 8 bit numbers
2. Write an assembly language program for subtraction of two 8 bit numbers
3. Write an assembly language program for addition of two 16 bit numbers
4. Write an assembly language program for Multiplication of two numbers
5. Write an assembly language program for Division of two numbers
6. Write an assembly language program to find the average of two numbers
7. Write a 8051 ALP to copy a block of 10 bytes from RAM location starting at
37h to RAM location starting at 59h.
8. Write a 8051 ALP using Timer 0 to create a 10khz square wave on P1.0
9. Write a 8051 assembly language program to find sum of elements in an
array
10. Write a 8051 assembly language program to perform Hexa decimal to
decimal conversion
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Program 1
Aim: To perform 8-bit addition using 8051 microcontroller
Apparatus: KEIL Software , Pc, Keyboard
Program:
Address
Ahead
Program
Explanation
MOV a,#23
Move data 1 to a
MOV r1,#11
Move data 2 to register 1
MOV r2, #00
Set r2 for carry
ADD a,r1
Add a, r1
JNC ahead
Jump on no carry to ahead
INC r2
If carry is '1' increment r2
MOV DPTR,#9200
Set datapointer to location 9200
MOVX @ DPTR,a
move a contents to location pointed by data
pointer (DPTR)
INC DPTR
Increment pointer
MOV a,r2
Move r2 to a
MOVX @ DPTR,a
move a contents to location pointed by data
pointer (DPTR)
LCALL 00BB
End
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Result: Thus the program 8 bit addition is performed using Keil software
Program 2
Aim: Write an assembly language program to perform 8-bit subtraction using 8051
microcontroller
Apparatus required: KEIL Software , Pc, Keyboard
Program:
ADDRESS PROGRAM
MOV a,#23
Ahead
EXPLANATION
Move data 1 to a
MOV r1,#11
Move data 2 to register 1
MOV r2, #00
Set r2 for carry
SUBB a,r1
Subtract r1 from a and store in a
JNC ahead
Jump on no carry to ahead
INC r2
If carry is '1' increment r2
MOV DPTR,#9200
Set datapointer to location 9200
MOVX @ DPTR,a
move a contents to location pointed by data
pointer (DPTR)
INC DPTR
Increment pointer
MOV a,r2
Move r2 to a
MOVX @ DPTR,a
move a contents to location pointed by data
pointer (DPTR)
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
LCALL 00BB
End
Result: Thus program for subtracting two 8 bit numbers had been executed..
.
Program 3
Aim: Write an 8051 Assembly language program for addition of two 16-bit
numbers
Apparatus required: KEIL Software , Pc, Keyboard
Program :
ADDRESS PROGRAM
MOV A,R7
EXPLANATION
Move the low‐byte into the accumulator
ADD A,R5
MOV R3,A
Add the second low‐byte to the accumulator
Move the answer to the low‐byte of the result
MOV A,R6
Move the high‐byte into the accumulator
ADDC A,R4
Add the second high‐byte to the accumulator, plus
carry.
MOV R2,A
MOV A,#00h
ADDC A,#00h
MOV MOV
R1,A
Move the answer to the high‐byte of the result
By default, the highest byte will be zero.
Add zero, plus carry from step 2
Move the answer to the highest byte of the result
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Result: Thus program for addition two 16 bit numbers had been
executed..
.
Program 4
Aim: write an assembly language program for multiplication of two 8 bit numbers
Apparatus Required: KEIL Software , Pc, Keyboard
Program :
Address
Program
MOV A, # data 1
Explanation
Move immediate data to accumulator
MOV B, # data 2
Move 2nd data to B register
MUL A B
Get the product in A & B
MOV DPTR, #
4500
Load data in 4500 location
MOV X @DPTR, Move A to ext RAM
A
MOV A,B
Move 2nd data in A
Same the ext RAM
MOV A @ DPTR
SJMP 410E
Remain idle in infinite loop
Result: Thus the program of multiplication of 8 bit numbers is performed.
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Program 5
Aim: write an assembly language program for division of two 8 bit numbers
Apparatus Required: KEIL Software , Pc, Keyboard
Program :
Address
Program
MOV A, # data 1
Explanation
Move immediate data to accumulator
MOV B, @ data
2
Move immediate data to B register
DIV A B
Divide content of A & B
MOV DPTR, #
4500
Load data pointer in 4500 location
MOV X @DPTR, Move A to ext RAM
A
INC DPTR
MOV A,B
Increment Data pointer
Move remainder to A
Same the ext RAM
MOV @ DPTR
,A
SJMP 410E
Remain idle in infinite loop
Result: Thus the program of Division of 8bit numbers is performed.
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Program 6
Aim: write an alp for finding the average of two numbers .
Apparatus Required: KEIL Software , Pc, Keyboard
Program :
Address
Program
MOV A,#04 H
MOV F0, #06 H
ADD A,F0 H
MOV F0,#02H
DIV A,B
RET
Explanation
Move data 04 H to A
Move data 06 H to B
ADD content of A&B
Move data 02H to B
Divide result in A with content of B
Stop
Result: Thus the program for average of 8bit numbers is performed.
Program 7
Aim: Write a 8051 ALP to copy a block of 10 bytes from RAM location starting at
37h to RAM location starting at 59h.
Apparatus required: KEIL Software , Pc, Keyboard
Program:
ADDRESS
PROGRAM
ORG 00H
MOV R0,#37H
MOV R1,#59H
EXPLANATION
Source pointer
Destination pointer
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
LOOP1:
MOV R2,#10
MOVA, @R0
MOV @R0,A
INC R0
INC R1
DJNZ R2,LOOP1
END
Counter
Result: Thus the program to copy a block of 10 bytes from Ram location is
performed.
Program 8
Aim: Write a 8051 ALP using Timer 0 to create a 10khz square wave on P1.0
Apparatus required: KEIL Software , Pc, Keyboard
Program:
ADDRESS
LOOP :
PROGRAM
ORG 00H
MOV TMOD,#02H
EXPLANATION
MOV TH0,#‐50
‐50 reload value in TH0
SETB TR0
JNB TF0, LOOP
CLR TF0
start timer0
wait for overflow
clear timer0 overflow flag
CPL P1.0
SJMP LOOP
END
toggle port bit
Repeat
8‐bit auto‐reload mode
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Result: Thus 10khz square wave on port P1.0 is created is created using Timer 0.
Program 9
Aim: Write a 8051 assembly language program to find sum of elements in an array
Apparatus required: KEIL Software , Pc, Keyboard
Program:
ADDRESS
PROGRAM
EXPLANATION
MOV DPTR, #4200
MOVX A, @DPTR
MOV R0, A
MOV B, #00
MOV R1, B
INC DPTR
LOOP2:
CLR C
MOVX A, @DPTR
ADD A, B
MOV B, A
JNC LOOP
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
INC R1
LOOP:
INC DPTR
DJNZ R0, LOOP2
MOV DPTR, #4500
MOVX @DPTR, A
MOV A, R1
INC DPTR
MOV A, B
MOVX @DPTR, A
HLT:
SJMP HLT
Result: Thus the program to find the sum of elements in an array is executed
Program 10
Aim: Write a 8051 assembly language program to perform Hexa decimal to
decimal conversion
Apparatus required: KEIL Software , Pc, Keyboard
Program:
ADDRESS
PROGRAM
EXPLANATION
MOV DPTR, #4500
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
MOVX A, @DPTR
MOV B, #64
DIV A, B
MOV DPTR, #4501
MOVX @DPTR, A
MOV A, B
MOV B, #0A
DIV A, B
INC DPTR
INC DPTR
MOVX @DPTR, A
MOV A, B
MOVX @DPTR, A
HLT:
SJMP HLT
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
COLUMBIA INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAIPUR
DEPARTMENT OF ELECTRONICS & TELE COMMUNICATION ENGINEERING
Result: Thus the program to perform Hexa decimal to decimal conversion is
executed
MICROCONTROLLERS & EMBEDDED SYSTEMS LAB MANUAL
Prepared by V.YASWANTH RAGHAVA
Download