Sie sind auf Seite 1von 42

MANIPAL UNIVERSITY JAIPUR

Department of Electrical Engineering

APPENDIX - C

PROGRAMMING SOLUTIONS
OF
LAB EXERCISES

MICROCONTROLLER & EMBEDDED SYSTEMS LAB


( EE1531 )

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 2:
DATA TRANSFER & ADDRESSING MODE
Exercise (To be executed in the Lab)
[1] WAP to load the register R0, R1, R2, R3 with the value 32 H, E4 H, 8D H, 83 H respectively.
CODE:
ORG 00H
MOV R0,#32H
MOV R1,#0E4H
MOV R2,#8DH
MOV R3,#83H
END
[2] WAP to transfer data from accumulator to external memory address 078E H.
CODE:
ORG 00H
MOV DPTR,#078EH
MOV A,#3EH
MOVX @DPTR,A
END
[3] WAP to load 4AH data in code memory at location 0700H.
CODE:
ORG 0700H
START: DB 4AH
END
[4] WAP to transfer the content of Code memory address 018A H, in to A register.
CODE:
ORG 00H
MOV DPTR,#018AHH
CLR A
Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOVC A,@A+DPTR
ORG 018AH
DB 34H
END

Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 3:
DATA BLOCK TRANSFER
Exercise (To be executed in the Lab)
[1] WAP to transfer the data block (array) of 8 elements (available at RAM location 30H to 37H)
at new location of starting address 50H in sequence.
CODE:
ORG 00H
MOV 30H,#10H
MOV 31H,#11H
MOV 32H,#13H
MOV 33H,#15H
MOV 34H,#45H
MOV 35H,#46H
MOV 36H,#0E4H
MOV 37H,#34H
MOV R0,#30H
MOV R1,#50H
MOV R4,#08H
LOOP1: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R4,LOOP1
END
[2] WAP to transfer the data block (array) of 8 elements (available at RAM location 30H to 37H)
at new location of starting address 50H in reverse sequence.
CODE:
ORG 00H
MOV 30H,#10H
MOV 31H,#11H
Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV 32H,#13H
MOV 33H,#15H
MOV 34H,#45H
MOV 35H,#46H
MOV 36H,#0E4H
MOV 37H,#34H
MOV R0,#30H
MOV R1,#57H
MOV R4,#08H
LOOP1: MOV A,@R0
MOV @R1,A
INC R0
DEC R1
DJNZ R4,LOOP1
END
[3] WAP to exchange the data block (array) of 8 elements (available at RAM location 30H to
37H) at new location of starting address 50H in sequence. (Without exchange instruction)
CODE:
ORG 00H
MOV 30H,#10H
MOV 31H,#11H
MOV 32H,#13H
MOV 33H,#15H
MOV 34H,#45H
MOV 35H,#46H
MOV 36H,#0E4H
MOV 37H,#34H
MOV 50H,#49H
MOV 51H,#50H
MOV 52H,#0A2H
MOV 53H,#33H
Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV 54H,#66H
MOV 55H,#77H
MOV 56H,#0E7H
MOV 57H,#88H
MOV R0,#30H
MOV R1,#50H
MOV R4,#08H
LOOP1: MOV A,@R0
MOV B,@R1
MOV @R1,A
MOV @R0,B
INC R0
INC R1
DJNZ R4,LOOP1
END
[4] WAP to exchange the data block (array) of 8 elements (available at RAM location 30H to
37H) at new location of starting address 50H in reverse sequence. (Without exchange
instruction)
CODE:
ORG 00H
MOV 30H,#10H
MOV 31H,#11H
MOV 32H,#13H
MOV 33H,#15H
MOV 34H,#45H
MOV 35H,#46H
MOV 36H,#0E4H
MOV 37H,#34H
MOV 50H,#49H
MOV 51H,#50H
MOV 52H,#0A2H
Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV 53H,#33H
MOV 54H,#66H
MOV 55H,#77H
MOV 56H,#0E7H
MOV 57H,#88H
MOV R0,#30H
MOV R1,#57H
MOV R4,#08H
LOOP1: MOV A,@R0
MOV B,@R1
MOV @R1,A
MOV @R0,B
INC R0
DEC R1
DJNZ R4,LOOP1
END

Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 4:
SEARCHING OF DATA IN ARRAY
Exercise (To be executed in the Lab)
[1] Write an ALP to find the data 89H is available or not in the array available at ten successive
location starting at 40H, load 00H in R0 if the data is not available in the array, otherwise load
01H in R0.
CODE:
ORG 00H
MOV 40H,#10H
MOV 41H,#11H
MOV 42H,#13H
MOV 43H,#15H
MOV 44H,#45H
MOV 45H,#46H
MOV 46H,#0E4H
MOV 47H,#34H
MOV 48H,#49H
MOV 49H,#50H
MOV R5,#0AH
MOV R1,#40H
LOOP1: CJNE @R1,#89H,HERE
MOV R0,#01H
HERE: INC R1
DJNZ R5,LOOP1
END
[2] Write an ALP to find the number of repetition occur of data 89H in array available at ten
successive location starting at 30H, store the result in the register R1.
CODE:
ORG 00H
MOV 30H,#10H
Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV 31H,#11H
MOV 32H,#13H
MOV 33H,#15H
MOV 34H,#45H
MOV 35H,#46H
MOV 36H,#0E4H
MOV 37H,#34H
MOV 38H,#49H
MOV 39H,#50H
MOV R5,#0AH
MOV R0,#30H
MOV R1,#00H
LOOP1: CJNE @R0,#89H,HERE
INC R1
HERE: INC R0
DJNZ R5,LOOP1
END
[3] Write an ALP to find the maximum number of the array available at ten successive location
starting at 30H, store the result in the register R0.
CODE:
ORG 00H
MOV 30H,#10H
MOV 31H,#11H
MOV 32H,#13H
MOV 33H,#15H
MOV 34H,#45H
MOV 35H,#46H
MOV 36H,#0E4H
MOV 37H,#34H
MOV 38H,#49H
MOV 39H,#50H
Department Of Electrical Engineering

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV A,30H
MOV R1,#31H
LOOP1:MOV B,@R1
CJNE A,B,HERE
HERE: JNC HERE2
MOV A,B
HERE2: INC R1
DJNZ R5,LOOP1
MOV R0,A
END

Department Of Electrical Engineering

10

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 5:
SORTING OF DATA ARRAY
Exercise (TO BE PERFORMED IN LAB):
[1] Write an ALP to sort the array in ascending manner, available at ten successive location
starting at 40H, store the sorted values in new array of starting address of 50H.
CODE:
ORG 00H
MOV 40H,#10H
MOV 41H,#11H
MOV 42H,#13H
MOV 43H,#15H
MOV 44H,#45H
MOV 45H,#46H
MOV 46H,#0E4H
MOV 47H,#34H
MOV 48H,#49H
MOV 49H,#50H
MOV R5,#09H
LOOP1: MOV R4,#09H
MOV R0,#40H
MOV R1,#41H
LOOP2:MOV A,@R0
MOV B,@R1
CJNE A,B,HERE
HERE: JC HERE2
MOV @R0,B
MOV @R1,A
HERE2: INC R1
INC R0
DJNZ R4,LOOP2
DJNZ R5,LOOP1
Department Of Electrical Engineering

11

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV R3,#0AH
MOV R4,#40H
MOV R5,#50H
LOOP3: MOV A,@R4
MOV B,@R5
MOV @R1,A
MOV @R0,B
INC R4
INC R5
DJNZ R4,LOOP3
END
[2] Write an ALP to sort the array in descending manner, available at ten successive location
starting at 40H, store the sorted values in new array of starting address of 50H.
CODE:
MOV 40H,#10H
MOV 41H,#11H
MOV 42H,#13H
MOV 43H,#15H
MOV 44H,#45H
MOV 45H,#46H
MOV 46H,#0E4H
MOV 47H,#34H
MOV 48H,#49H
MOV 49H,#50H
MOV R5,#09H
LOOP1: MOV R4,#09H
MOV R0,#40H
MOV R1,#41H
LOOP2:MOV A,@R0
MOV B,@R1
Department Of Electrical Engineering

12

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

CJNE A,B,HERE
HERE: JC HERE2
MOV @R0,B
MOV @R1,A
HERE2: INC R1
INC R0
DJNZ R4,LOOP2
DJNZ R5,LOOP1
MOV R3,#0AH
MOV R4,#40H
MOV R5,#59H
LOOP3: MOV A,@R4
MOV B,@R5
MOV @R1,A
MOV @R0,B
INC R4
DEC R5
DJNZ R4,LOOP3
END

Department Of Electrical Engineering

13

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 6:
ARITHMETIC AND LOGICAL OPERATIONS-1
Exercise (TO BE PERFORMED IN LAB)
[1] Write an 8051 program to add the contents of register R5 to that of register R6. Store the
result in RAM location 30H. Verify PSW register content and comment. Use immediate
addressing to load the values to R5 and R6.
CODE:
ORG 00H
MOV R5,#98H
MOV R6,#28H
MOV A,R5
ADD A,R6
JNC HERE
MOV 29H,#01H
HERE: MOV 30H,A
END
[2] Write an 8051 program to subtract the contents of register R5 to that of register R6. Store the
result in RAM location 30H. Verify PSW register content and comment. Use immediate
addressing to load the values to R5 and R6.
CODE:
ORG 00H
MOV R5,#28H
MOV R6,#98H
MOV A,R5
SUBB A,R6
JNC HERE
CPL A
INC A
HERE: MOV 30H,A
END
Department Of Electrical Engineering

14

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

[3] A set of one byte unsigned binary numbers is stored from memory location 51H onwards, the
size of the set is available at 50H.Write an 8051 program to add these numbers and store the 16bit result in 70H and 71H.
CODE:
ORG 00H
MOV 50H,#05H
MOV 51H,#11H
MOV 52H,#13H
MOV 53H,#15H
MOV 54H,#45H
MOV 55H,#46H
MOV 70H,#00H
MOV R0,50H
MOV R1,#51H
CLR A
LOOP1: ADD A,R1
JNC HERE
INC 70H
HERE: INC R1
DJNZ R0,LOOP1
MOV 71H,A
END
[4] A set of one byte signed binary numbers is stored from memory location 40H onwards, the
size of the set is available at 50H.Write an 8051 program to add these numbers and store the 16bit result in 60H and 61H.
CODE:
ORG 00H
MOV 50H,#05H
MOV 51H,#11H
MOV 52H,#13H
Department Of Electrical Engineering

15

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV 53H,#15H
MOV 54H,#45H
MOV 55H,#46H
MOV R0,50H
MOV R1,#51H
CLR A
LOOP1: MOV A,@R1
JNB ACC.7,HERE
CPL A
INC A
HERE: MOV @R1,A
INC R1
DJNZ R0,LOOP1
MOV R4,50H
MOV R1,#51H
MOV 60H,#00H
CLR A
LOOP2: ADD A,@R1
JNB ACC.7,HERE2
CPL A
INC A
HERE2: JNC HERE3
INC 61H
HERE3: MOV 60H, A
INC R1
DJNZ R4,LOOP2
END
[5] Write an ALP to find whether the 8 bit binary number stored at external RAM location
1050H is of even parity or odd parity. If parity is odd, store the number in 1051H, otherwise,
store in 1052H.

Department Of Electrical Engineering

16

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

CODE:
ORG 00H
MOV DPTR,#1050H
MOV A,#65H
JB PSW.0,HERE
INC DPTR
HERE: INC DPTR
MOVX @DPTR,A
END
[6] Write an ALP to set bits D3 and D7 of RAM locations 2DH and 3EH without affecting other
bits, (Without using bit manipulation instructions)
CODE:
ORG 00H
MOV 2DH,#54H
MOV 3EH,#83H
MOV A,#88H
ORL A,2DH
MOV 2DH,A
MOV A,#88H
ORL A,3EH
MOV 3EH,A
END
(Using bit manipulation instructions)
CODE:
ORG 00H
MOV 2DH,#54H
MOV 3EH,#83H
SETB 6BH
SETB 6FH
MOV 20H,3EH
Department Of Electrical Engineering

17

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

SETB 03H
SETB 07H
MOV 3EH,20H
END

Department Of Electrical Engineering

18

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 7:
ARITHMETIC AND LOGICAL OPERATIONS-2
Exercise (TO BE PERFORMED IN LAB)
[1] Write an ALP to multiply two 8 bit unsigned numbers available at internal RAM locations
51H and 52H. Store the 16-bit result in the next two consecutive locations.
CODE:
ORG 00H
MOV 51H,#45H
MOV 52H,#49H
MOV A,51H
MOV B, 52H
MUL AB
MOV 53H,B
MOV 54H,A
END
[2] Write an ALP to multiply an 8 bit unsigned number at location 60H by another 8 bit signed
number at 61H and store the 16 bit result in the next two locations.
CODE:
ORG 00H
MOV 60H,#87H
MOV 61H,#91H
MOV A,61H
MOV B,60H
JNB ACC.7,HERE
CPL A
INC A
HERE: MUL AB
MOV 62H,B
MOV 63H,A
END
Department Of Electrical Engineering

19

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

[3] WAP to divide the content of R0 by R1. Store the result in R2 (answer) and R3 (reminder).
Then restore the original content of R0.
CODE:
ORG 00H
MOV R0,#76H
MOV R1,#65H
MOV A,R0
MOV B,R1
DIV AB
MOV R2,A
MOV R3,B
MOV B,R1
MUL AB
ADD A,R3
MOV R0,A
END
[4] Write an ALP to check whether the 8 bit unsigned number at 65H is divisible by 05H. If
divisible store the quotient at 66H. Otherwise store the quotient and remainder at 67H and 68H.
CODE:
ORG 00H
MOV 65H,#76H
MOV B,#05H
MOV A,65H
DIV AB
MOV R4,B
CJNE R4,#00H,HERE
MOV 66H,A
SJMP LABLE
HERE: MOV 67H,A
LABLE: MOV 68H,B
END
Department Of Electrical Engineering

20

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

[5] Write an ALP to add two signed numbers in 2s compliment form available at RAM locations
3DH and 3EH and store the result in 3FH. Check the overflow flag and comment on the result.
CODE:
ORG 00H
MOV 3DH,#0F7H
MOV 3EH,#0FFH
MOV A,3DH
CPL A
INC A
MOV 3DH,A
MOV A,3EH
CPL A
INC A
ADD A,3DH
END

Department Of Electrical Engineering

21

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 8:
BCD OPERATIONS
Exercise (TO BE PERFORMED IN LAB)
[1] Write an 8051 program to add n 8-bit BCD numbers available in RAM locations starting at
30H. Store the 16 bit BCD result in 41H and 42H. Use assembler directive EQU to indicate the
value of n.
CODE:
ORG 00H
BITS EQU 05H
MOV 30H,#34H
MOV 31H,#78H
MOV 32H,#67H
MOV 33H,#74H
MOV 34H,#99H
MOV R0,#BITS
MOV R1,#30H
CLR A
LOOP2: ADD A,@R1
JNC HERE
INC 41H
HERE: INC R1
DA A
DJNZ R0,LOOP2
MOV 42H,A
END
[2] Write an 8051 program to subtract an 8 bit packed BCD number available in the RAM
location 33H from another 8 bit packed BCD number available at 34H. If the result is positive,
store 00H in 35H and the BCD result in 36H. If the result is negative store 01H in 35H and the
magnitude of the actual difference in 36H.

Department Of Electrical Engineering

22

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

CODE:
ORG 00H
MOV 33H,#39H
MOV 34H,#23H
MOV A,34H
SUBB A,33H
JNC HERE
CPL A
INC A
MOV 35H,#01H
SJMP LAB
HERE: MOV 35H,#00H
LAB: MOV 36H,A
END

Department Of Electrical Engineering

23

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 9:
CODE CONVERSION TECHNIQUES
Excercise ( TO BE PERFORMED IN LAB)
[1] Write an ALP to convert a 2 digit Hex number available in RAM location 6BH to its
equivalent BCD number and display it in packed form in the next two RAM locations.
CODE:
ORG 00H
MOV 6BH,#54H
ADD A,6BH
DA A
MOV R2,A
ANL A,#0FH
MOV 6CH,A
MOV A,R2
SWAP A
ANL A,#0FH
MOV 60H,A
END
[2] Write an ALP to unpack a packed Hex number between 00 and FF stored at RAM location
50H and convert each of the unpacked number to its equivalent ASCII and display them in
port0 and port 1. Use look up table technique to find the ASCII code. Use assembler directive
DB to store the table of ASCII codes.
CODE:
ORG 00H
MOV 50H,#5AH
ADD A,50H
DA A
MOV R1,#51H
MOV R3,#02H
MOV R2,A
Department Of Electrical Engineering

24

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

LOOP1: MOV DPTR,#0300H


ANL A,#0FH
MOVC A,@A+DPTR
MOV @R1,A
MOV A,R2
SWAP A
INC R1
DJNZ R3,LOOP1
MOV P0,51H
MOV P1,52H
ORG 0300H
TABLE1: DB 0,1,2,3,4,5,6,7,8,9
END

Department Of Electrical Engineering

25

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 10:
DELAY GENERATION,TIMER AND COUNTER
Exercise
[1] Write an ALP for generate a square wave of 10KHz at Port pin P1.1 without timer.
CODE:
ORG 00H
CLR P1.1
NOP
HERE: CPL P1.1
ACALL DELAY
SJMP HERE
DELAY: MOV R0,#21
NOP
HERE2: DJNZ R0,HERE2
RET
END
[2] Write an ALP for generate a square wave of 10KHz at Port pin P1.1 with the help of timer.
CODE:
ORG 00H
CLR P1.1
MOV TMOD,#20H
MOV TH1,#0D8H
HERE: CPL P1.1
ACALL DELAY
SJMP HERE
ORG 0100H
DELAY: SETB TR1
JNB TF1,$
CLR TR1
CLR TF1
Department Of Electrical Engineering

26

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

RET
END
[3] Write an ALP to implement a decimal DOWN counter from 95 - 30 and display it
continuously in the external RAM location 1000H with a delay of 1.1 secs between each count.
Use eight bit registers of 8051 to generate delay.
CODE:
ORG 00H
MOV A,#95H
MOV DPTR,#0100H
LOL:MOV TMOD,#01H
MOV TLO,#00H
MOH TH0,#00H
MOV R1,#30
LOOP1: STEB TR0
JNB TF0,$
CLR TR0
CLR TF0
DJNZ R1,LOOP1
MOVX @DPTR,A
CJNE A,#30,HERE
SJMP $
HERE: DEC A
SJMP LOL
END

Department Of Electrical Engineering

27

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 11:
PROGRAMMING OF INTERRUPTS
Exercise
[1] Write a main program to enable external interrupts0 and 1, and keep waiting for the interrupt.
When 8051 is interrupted through INT0, write an ISR to obtain a rectangular wave of 1.5 KHz with
35% duty cycle at P1.6 pin of 8051 continuously and when interrupted through INT1, write an ISR to
obtain a rectangular wave of 600Hz with 70% duty cycle at P1.6 pin. Use 8 bit registers of 8051 to
obtain the delay
CODE:
ORG 00H
LJMP MAIN
ORG 0003H
MOV R0,#77H
RETI
ORG 000BH
MOV R0,#0FFH
RETI
ORG 030H
MAIN:
MOV IE,#85H
MOV R0,#00H
LOOP1: CJNE R0,#00H,L1
SJMP LOOP1
ORG 090H
L1:
CJNE R0,#77H,L2
ACALL WAVE1
Department Of Electrical Engineering

28

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

SJMP L1
WAVE1: SETB P1.6
ACALL DELAY1_ON
CLR P1.6
ACALL DELAY1_OFF
RET
L2: ACALL WAVE2
SJMP LX
WAVE2: SETB P1.6
ACALL DELAY2_ON
CLR P1.6
ACALL DELAY2_OFF
RET
ORG 300H
DELAY1_ON:
MOV R5,#117
HERE1: DJNZ R5,HERE1
RET
ORG 400H
DELAY2_OFF: MOV R5,#217
HERE2: DJNZ R5,HERE2
RET
ORG 500H
DELAY2_ON:
MOV R5,#255
HERE3: MOV R6,#5
HERE4: DJNZ R6,HERE4
DJNZ R5,HERE3

Department Of Electrical Engineering

29

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

ORG 600H
DELAY2_OFF:
MOV R5,#250
HERE5: DJNZ R5,HERE5
RET
END

Department Of Electrical Engineering

30

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 12:
LCD INTERFACING
Exercise
[1] Write an ALP to display the message WELCOME TO MANIPAL on the on board LCD display
unit. Display WELCOME at the centre of the first line and TO MANIPAL at the centre of the
second line. Do not use any standard LCD routines provided by ESA.
CODE:
ORG 00H
MOV DPTR,#COM
C1:CLR A
MOVC A,@A+DPTR
ACALL COMD
ACALL DELAY
JZ SEND_DATA1
JNC DPTR
SJMP C1
SEND_DATA1:
MOV DPTR,#MYDATA1
D1:CLR A
MOVC A,@A+DPTR
ACALL DATA
ACALL DELAY
INC DPTR
JZ SEND_COM
INC DPTR
SJMP D1
SEND_COM:
MOV DPTR,#COM2
Department Of Electrical Engineering

31

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

C2: CLR A
MOVC A,@A+DPTR
ACALL COMD
ACALL DELAY
JZ SEND_DATA2
INC DPTR
JZ AGAIN
SJMP D2
SJMP $
ORG 0800H
COMD: MOV P2,A
CLR P3.7
CLR P3.6
SETB P3.5
ACALL DELAY
CLR P3.5
RET
DATA: MOV P2,A
SETB P3.7
CLR P3.6
SETB P3.5
ACALL DELAY
CLR P3.5
RET
DELAY: MOV R3,#255
LOOP1: MOV R4,#250
LOOP2: DJNZ R4,LOOP2
DJNZ R3,LOOP1
RET
ORG 0A00H
Department Of Electrical Engineering

32

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

COM: DB 38H,0EH,01H,06H,84H,0
MYDATA1: DB WELCOME,0
ORG 0B00H
COM: DB C3H,0
MYDATA: DB TO MANIPAL,0
END

Department Of Electrical Engineering

33

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 13:
LOGIC CONTROLLER INTERFACE
Exercise
[1] Interface Logic Controller Interface to 8051 to perform the following logical operations.
Write an ALP to read the input status, compliment bits 3 and 5 without affecting the other bits
and display it through output LEDs.
CODE:
ORG 00H
MOV R1,#0FFH
MOV P0,#00H
MOV A,#0B6H
MOV P1,A
MOV A,P1
XRL A,#14H
MOV P0,A
END
[2]Write an 8051 program to blink the LEDs at the output port for 0.2secs one after the other
starting with the LED at the LS bit.
CODE:
ORG 00H
MOV P0,#00H
MOV A,#01H
HERE: ACALL DELAY
RL A
MOV P0.A
SJMP HERE
ORG 0100H
MOV TMOD,#20H
MOV TH1,#ODBH
DELAY: MOV R0,@20
Department Of Electrical Engineering

34

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

LOOP1: SETB TR1


JNB TF1,$
CLR TR1
CLR TF1
DJNZ R0,LOOP1
RET
END
[3]Write an 8051 ALP to perform the following logical operations. Take the input from the input
port and display the output at the output port.
(a) Y0 = X0 XOR X1
CODE:
ORG 00H
MOV P0,#00H
MOV P1,#0FFH
MOV A,#80H
MOV P1,A
MOV A,P1
MOV R0,A
MOV A,#36H
MOV P1,#36H
MOV A,P1
XRL A,R0
MOV P0,A
END
(b) Y2 = (X1 + X2). X3
CODE:
ORG 00H
MOV P0,#00H
MOV P1,#0FFH
MOV A,#80H
Department Of Electrical Engineering

35

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV P1,A
MOV A,P1
MOV B,A
MOV A,#3
MOV P1,A
MOV A,P1
ADD A,B
MOV B,A
MOV A,#10
MOV P1,A
MOV A,P1
MUL AB
MOV P0,A
END
(c) Y4 = (X0 + X1) + (X2.X3)
CODE:
ORG 00H
MOV A,#10
MOV P1,#0FFH
MOV P0,#00H
MOV P1,A
MOV A,P1
MOV R1,#15
MOV R2,A
MOV A,R1
MOV P1,A
MOV A,P1
ADD A,R2
MOV R3,A
MOV A,#4
MOV P1,A
Department Of Electrical Engineering

36

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

MOV A,P1
MOV B,A
MOV A,#6
MOV P1,A
MOV A,P1
MUL AB
MOV R4,A
ADD A,R3
MOV P0,A
END

Department Of Electrical Engineering

37

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

EXPERIMENT 14:
STEPPER MOTOR INTERFACE:
Exercise
[1] Write an ALP to run the stepper motor in clock-wise direction with the speed of
(a) 2 revolution per second.
CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H
HERE: MOV P0,A
RR A
ACALL DELAY
SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0F6H
MOV TLO,#3AH
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
RET
END

(b) 10 revolution per second


CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H
HERE: MOV P0,A
RR A
ACALL DELAY
Department Of Electrical Engineering

38

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0FEH
MOV TLO,#0AH
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
RET
END

(c) 50 revolution per second


CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H
HERE: MOV P0,A
RR A
ACALL DELAY
SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0FFH
MOV TLO,#9AH
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
RET
END
(d) 100 revolution per second
Department Of Electrical Engineering

39

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H
HERE: MOV P0,A
RR A
ACALL DELAY
SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0FFH
MOV TLO,#0CDH
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
RET
END
[2] Write an ALP to run the stepper motor in anti-clock-wise direction with the speed of
(a) 2 revolution per second
CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H
HERE: MOV P0,A
RL A
ACALL DELAY
SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0F6H
MOV TLO,#3AH
SETB TR0
Department Of Electrical Engineering

40

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

JNB TF0,$
CLR TR0
CLR TF0
RET
END
(b) 10 revolution per second
CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H
HERE: MOV P0,A
RL A
ACALL DELAY
SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0FEH
MOV TLO,#0AH
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
RET
END

(c) 50 revolution per second


CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H

Department Of Electrical Engineering

41

School of Electrical, Electronics & Communication Engineering,


Manipal University Jaipur

HERE: MOV P0,A


RL A
ACALL DELAY
SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0FFH
MOV TLO,#9AH
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
RET
END
(d) 100 revolution per second
CODE:
ORG 00H
MOV P0,#00H
MOV A,#66H
HERE: MOV P0,A
RL A
ACALL DELAY
SJMP HERE
DELAY: MOV TMOD,#01H
MOV THO,#0FFH
MOV TLO,#0CDH
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
RET
END

Department Of Electrical Engineering

42

Das könnte Ihnen auch gefallen