Sei sulla pagina 1di 90

LITAM LOYOLA INSTITUTE OF TECHNOLOGY AND MANAGEMENT

(Approved by AICTE & Affiliated to JNTU K, Kakinada) Loyola Nagar, Dhulipalla (Village), Sattenapalli (Mandal) Guntur (Dist). Pin: 522 412

MICROPROCESSORS & INTERFACING LAB MANUAL

Micro Processors & Interfacing Lab

Department of E.C.E

III YEAR B.Tech ECE II Semester MICROPROCESSORS AND INTERFACING LAB I. Microprocessor 8086:
1 .Introduction to MASM / TASM. 2 .Arithmetic operation Multibyte addition and subtraction, Multiplication and Division signed and unsigned Arithmetic operation, ASCII - .Arithmetic operation. 3. Logical operations - Shift and rotate Converting packed BCD to unpacked BCD , BCD to ASCII conversion. 4. By using string operations and Instruction prefix. Move Block , Reverse string, sorting, Inserting ,Deleting, Length of the String, String comparison.

5. Modular Program: Procedure, Near and Far implementation, Recursion. 6. DOS /BIOS programming, Reading keyboard (buffered with and without echo) Display characters , strings.

II. Interfacing:
1. 8259 Intrupt controller. 2. 8279 - Keyboard Display. 3. 8255 PPI 4. 8251 USART.

III. Microcontroller 8051:


1 Reading and Writing on a parallel port. 2. Timer in different modes. 3. Serial communication implementation. 4. Understanding three memory area of 00 FF (Programs using above area). 5. Using External interrupts. 6 Programs using special instructions like swap, bit / byte, set / reset etc. 7 Programs based on short , page , absolute addressing.

LITAM

Page 2

Micro Processors & Interfacing Lab

Department of E.C.E

LIST OF PROGRAMS I. MICROPROCESSOR 8086 programs:

1. PROCEDURE FOR SOFTWARE PROGRAMMING.6


2. PROCEDURE FOR HARDWARE PROGRAMMING.7 3. ADDITION OF TWO 16-BIT NUMBERS (SOFTWARE) ......9 4. ADDITION OF TWO 16-BIT NUMBERS (HARDWARE) ....10 5. SUBTRACTION OF TWO 16-BIT NUMBERS (SOFTWARE)..12 6. SUBTRACTION OF TWO 16-BIT NUMBERS (HARDWARE)........13 7. MULTIPLICATION OF TWO 16-BIT NUMBERS (SOFTWARE).....15 8. MULTIPLICATION OF TWO 16-BIT NUMBERS (HARDWARE)...16 9. DIVISION OF TWO 16-BIT NUMBERS (SOFTWARE)....18 10. DIVISION OF TWO 16-BIT NUMBERS (HARDWARE).19 11. ASCII ADDITION OF TWO 16-BIT NUMBERS (SOFTWARE)..21 12. ASCII ADDITION OF TWO 16-BIT NUMBERS (HARDWARE)..22 13. ASCII SUBTRACTION OF TWO 16-BIT NUMBERS (SOFTWARE)..24 14. ASCII SUBTRACTION OF TWO 16-BIT NUMBERS (HARDWARE)..25 15. ASCII MULTIPLICATION OF TWO 16-BIT NUMBERS (SOFTWARE)....27 16. ASCII MULTIPLICATION OF TWO 16-BIT NUMBERS (HARDWARE)28 17. ASCII DIVISION OF TWO 16-BIT NUMBERS (SOFTWARE)30 18. ASCII DIVISION OF TWO 16-BIT NUMBERS (HARDWARE)..31 19.MULTI BYTE ADDITION (SOFTWARE)...33 20.MULTIBYTE SUBTRACTION (SOFTWARE)35 21.MULTIBYTE MULTIPLICATION (SOFTWARE)......37 22.MULTI BYTE DIVISION (SOFTWARE).39 23.PACKEDTO UNPACKED BCD (SOFTWARE)..41 24.PACKED TO UNPACKED BCD (HARDWARE)42 25.BCD To ASCII CONVERSION(SOFTWARE).44 26.BCD To ASCII CONVERSION (HARDWARE).....45 27. REVERSE STRING (SOFTWARE)......47 28. REVERSE STRING (HARDWARE)....48 29. COMPARISION OF STRINGS (SOFTWARE)...50 30. COMPARISION OF STRINGS (HARDWARE)....51 31. SORTING ASCENDING ORDER (IN TERMS OF BYTES) (SOFTWARE).........53 LITAM Page 3

Micro Processors & Interfacing Lab

Department of E.C.E

32. ASCENDING ORDER PROGRAMMING (HARDWARE)...54 33. SORTING DESCENDING ORDER (IN TERMS OF BYTES)(SOFTWARE)...56 34. DESCENDING ORDER PROGRAMMING (HARDWARE).....57 35. DOS PROGRAMMING (SOFTWARE)...59 36. DOS PROGRAMMING (HARDWARE).....60 37. FACTORIAL OF A GIVEN NUMBER N USING RECURSIVE PROCEDURE (SOFTWARE)............................................................................................................62

II.

INTERFACING PROGRAMS:

1.PROCEDURE FOR INTERFACING .64 2.KEYBOARD INTERFACING THROUGH 8086 MICROPROCESSOR..65 3.TRAFFIC LIGHT CONTROLLER INTERFACE THROUGH 8086 MICROPROCESSOR68 4.DUAL DIGITAL TO ANALOG CONVERTER INERFACING WITH 8086 MICROPROCESSOR..70 5.REAL TIME CLOCK INTERFACE THROUGH 8086 MICROPROCESSOR.72 6.ELEVATOR INTERFACE THROUGH 8086 MICROPROCESSOR....78 7.STEPPER MOTOR INTERFACE THROUGH 8086 MICROPROCESSOR.80

III.

MICROCONTROLLER- 8051 programs :

1.PROCEDURE FOR PROGRAMMING..83 2. ADDITION OF TWO NUMBERS (HARDWARE)...84 3. SUBTRACTION OF TWO NUMBERS (HARDWARE)...85 4. MULTIPLICATION OF TWO NUMBERS (HARDWARE).86 5. DIVISION OF TWO NUMBERS (HARDWARE).87 6. HEX TO ASCII CONVERSION(HARDWARE)...88 7. LARGEST AMONG N NUMBERS (HARDWARE)..89 8. CHECKING THE 5th BIT POSITION(HARDWARE)...90

LITAM

Page 4

Micro Processors & Interfacing Lab

Department of E.C.E

Microprocessor 8086

LITAM

Page 5

Micro Processors & Interfacing Lab

Department of E.C.E

Procedure for software programming:


1. Open the command prompt. 2. cd\ 3. c:\cd tasm 4. c:\tasm> 5. c:\tasm>edit filename.asm 6. Then type the program. 7. To save the program, go to file and then save. 8. Then press alt+F and go to EXIT 9. Type Filename.asm 10. If errors are there in program,it shows the errors; otherwise it shows zero errors. 11. Then type tlink filename. 12. Then type td filename. 13. Press enter key and press F7 up to HLT. 14. Then press alt+V (view) and in that select dump. 15. It displays the result.

LITAM

Page 6

Micro Processors & Interfacing Lab

Department of E.C.E

Procedure for hardware programming:


1. 2. 3. 4. 5. Connect the RPS and keyboard to the trainer kit Check whether the 3rd and 7th pins are ON Switch ON the supply Press the RESET pin provided on the kit Give the starting address location to the processor by typing A 2000(starting addr location). 6. 7. Type the program To give the inputs type S DS: i/p addr location and then press ENTER Eg: S DS: 3000 8. 9. 10. After giving first byte of input, to move to the next addr location give ,(comma) and then enter next inputs. To execute the program type G 2000(starting addr location) To check the output values type D DS: o/p addr location and to check next byte of o/p increment the addr location. Eg: D DS: 4000 D DS: 4001

LITAM

Page 7

Micro Processors & Interfacing Lab Addition of two 16-bit numbers Start

Department of E.C.E

Move the content of data into ax

Move the content of data into ds

Move the content of n1 into ax

Move the content of n2 into bx

Add the content of bx to ax

Move the content of ax to n3

Stop

LITAM

Page 8

Micro Processors & Interfacing Lab

Department of E.C.E

1.ADDITION OF TWO 16-BIT NUMBERS (SOFTWARE) Aim: To write an assembly language program for the addition, Subtraction, Multiplication and Division of two 16-bit numbers in software and hardware. Apparatus: Software
TASM software PC Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,n1 Mov bx,n2 Add ax,bx Mov n3,ax Hlt Code ends Data segment N1 dw 0202h N2 dw 0305h N3 dw ? Data ends End

Hardware
8086 Microprocessor kit Keyboard

Input: N1= 0202h N2= 0305h Output: N3= 0507 AX= 0507 ; BX 0305

LITAM

Page 9

Micro Processors & Interfacing Lab

Department of E.C.E

2.ADDITION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS 2000 2003 2006 2008 200A 200C 200F 2011 2013 2015 2017 2019 Input: S DS: 3000 3001 3002 3003 Output: D DS: 4000 : 99 4001 : 88 MNEMONICS MOVW MOVW MOVB INCW MOVB INCW MOVB INCW MOVB ADDW MOVW INT : 44, : 22, : 55, : 66 OPERANDS SI,3000 DI,4000 AL,[SI] SI AH,[SI] SI BL,[SI] SI BH,[SI] AX,BX [DI],AX 03 OPCODES BE 00 30 BF 00 40 8A 04 47 8A 24 47 8A 1C 47 8A 3C 03 C3 89 05 CC

LITAM

Page 10

Micro Processors & Interfacing Lab Subtraction of two 16-bit numbers Start

Department of E.C.E

Move the content of data into ax

Move the content of data into ds

Move the content of n1 into ax

Move the content of n2 into bx

subtract the content of bx from ax

Move the content of ax to n3

Stop

LITAM

Page 11

Micro Processors & Interfacing Lab

Department of E.C.E

3.SUBTRACTION OF TWO 16-BIT NUMBERS (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,n1 Mov bx,n2 sub ax,bx Mov n3,ax Hlt Code ends N1 dw 0505h N2 dw 0305h N3 dw ? Data ends End

Input: N1= 0505h N2= 0305h

Output: N3=0200

LITAM

Page 12

Micro Processors & Interfacing Lab

Department of E.C.E

4.SUBTRACTION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS 2000 2003 2006 2008 200A 200C 200F 2011 2013 2015 2017 2019 MNEMONICS MOVW MOVW MOVB INCW MOVB INCW MOVB INCW MOVB SUBW MOVW INT OPERANDS SI,3000 DI,4000 AL,[SI] SI AH,[SI] SI BL,[SI] SI BH,[SI] AX,BX [DI],AX 03 OPCODES BE 00 30 BF 00 40 8A 04 47 8A 24 47 8A 1C 47 8A 3C 1B C3 89 05 CC

Input: S DS: 3000 3004 3005 3006 Output: D DS: 4000 : 22 4001 : 11 : 44, : 22, : 22, : 11

LITAM

Page 13

Micro Processors & Interfacing Lab Multiplication of two 16-bit numbers Start

Department of E.C.E

Move the content of data into ax

Move the content of data into ds

Move the content of n1 into ax

Move the content of n2 into bx

Multiply by bx

Move the content of ax to n3

Move the content of dx to n4

Stop

LITAM

Page 14

Micro Processors & Interfacing Lab

Department of E.C.E

5.MULTIPLICATION OF TWO 16-BIT NUMBERS (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,N1 Mov bx,N2 Mul bx Mov N3,ax Mov N4,dx Hlt Code ends Data segment N1 dw 0004h N2 dw 0003h N3 dw ? N4 dw ? Data ends End

Output: N3=2814 N4=0014 Ax=0200 bx=0404 Cx=0000 dx=0014

LITAM

Page 15

Micro Processors & Interfacing Lab

Department of E.C.E

6.MULTIPLICATION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS MNEMONICS OPERANDS OPCODES

2000 2003 2006 2008 200A 200C 200F 2011 2013 2015 2017 2018 2019 2020 2022 Input: S DS: 3000 3001 3002 3003 Output: D DS: 4000 4001 4002 4003 : : : : : : : :

MOVW MOVW MOVB INCW MOVB INCW MOVB INCW MOVB MULW MOVW INCW INCW MOVW INT

SI,3000 DI,4000 AL,[SI] SI AH,[SI] SI BL,[SI] SI BH,[SI] BX [DI],AX DI DI [DI],DX 03

BE 00 30 BF 00 40 8A 04 47 8A 24 47 8A 1C 47 8A 3C F7 E3 89 05 47 47 89 15 CC

02, 02, 02, 02

04 08 04 00

LITAM

Page 16

Micro Processors & Interfacing Lab Division of two 16-bit numbers Start

Department of E.C.E

Move the content of data into ax

Move the content of data into ds

Move the content of n1 into ax

Move the content of n2 into bx

Divide by bx

Move the content of ax to n3

Move the content of dx to n4

Stop

LITAM

Page 17

Micro Processors & Interfacing Lab

Department of E.C.E

7.DIVISION OF TWO 16-BIT NUMBERS (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,N1 Mov bx,N2 DIV bx Mov N3,ax Mov N4,dx Hlt Code ends Data segment N1 dw 0505h N2 dw 0404h N3 dw ? N4 dw ? Data ends End

Output: N3= 0001 N4= 0101

LITAM

Page 18

Micro Processors & Interfacing Lab

Department of E.C.E

8.DIVISION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS 2000 2003 2006 2008 200A 200C 200F 2011 2013 2015 2017 2018 2019 2020 2022 MNEMONICS MOVW MOVW MOVB INCW MOVB INCW MOVB INCW MOVB DIVW MOVW INCW INCW MOVW INT OPERANDS SI,3000 DI,4000 AL,[SI] SI AH,[SI] SI BL,[SI] SI BH,[SI] BX [DI],AX DI DI [DI],DX 03 OPCODES BE 00 30 BF 00 40 8A 04 47 8A 24 47 8A 1C 47 8A 3C F7 F3 89 05 47 47 89 15 CC

Input: S DS: 3000 3004 3005 3006 Output: D DS: 4000 4001 4002 4003 : 00 : 02 : 02 : 02 : 08, : 08, : 03, : 03

Result: Hence the arithmetic operations addition, Subtraction, Multiplication and Division of two 16-bit numbers are performed in software and hardware.

LITAM

Page 19

Micro Processors & Interfacing Lab ASCII Addition Start

Department of E.C.E

Move the content of data into ax

Move the content of ax into ds

Move the content of n1 into ax

Move the content of n2 into bx

Add the content of ax and bx

Ascii adjust after addition

Move the content of ax to n3

Stop

LITAM

Page 20

Micro Processors & Interfacing Lab

Department of E.C.E

9.ASCII ADDITION OF TWO 16-BIT NUMBERS (SOFTWARE)


AIM: To write an assembly language program for the addition, Subtraction, Multiplication and Division of two 16-bit numbers in software and hardware. Apparatus : Software TASM software PC Hardware 8086 Microprocessor kit Keyboard

Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,N1 Mov bx,N2 Add ax,bx AAA Mov N3,ax Hlt Code ends Data segment N1 dw 02 N2 dw 03 N3 dw ? Data ends End

Output : N3=05

LITAM

Page 21

Micro Processors & Interfacing Lab

Department of E.C.E

10.ASCII ADDITION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS MNEMONICS OPERANDS OPCODES

2000 2003 2006 2008 2009 200A 200C 200E 200F 2012 2014

MOVW MOVW MOVW INCW INCW MOVW ADDW AAA ADDW MOVW INT

SI,3000 DI,4000 AX,[SI] SI SI BX,[SI] AX,BX AX,3030 [DI],AX 03

BE 00 30 BF 00 40 8B 04 46 46 8B 1C 03 C3 C3 05 30 30 89 05 CC

Input: S DS: 3000 3007 3008 3009 Output: D DS: 4000 : 39 4001 : 30 : : : : 06, 00, 03, 00

LITAM

Page 22

Micro Processors & Interfacing Lab ASCII Subtraction Start

Department of E.C.E

Move the content of data into ax

Move the content of ax into ds

Move the content of n1 into ax

Move the content of n2 into bx

Add the content of ax and bx

Ascii adjust after subtraction

Move the content of ax to n3

Stop

LITAM

Page 23

Micro Processors & Interfacing Lab

Department of E.C.E

11.ASCII SUBTRACTION OF TWO 16-BIT NUMBERS (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,n1 Mov bx,n2 SUB ax,bx AAS Mov n3,ax Hlt Code ends Data segment N1 dw 08 N2 dw 04 N3 dw ? Data ends End

Output: N3=0004

LITAM

Page 24

Micro Processors & Interfacing Lab

Department of E.C.E

12.ASCII SUBTRACTION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS MNEMONICS OPERANDS OPCODES

2000 2003 2006 2008 2009 200A 200C 200E 200F 2012 2014

MOVW MOVW MOVW INCW INCW MOVW SUBW AAS ADDW MOVW INT

SI,3000 DI,4000 AX,[SI] SI SI BX,[SI] AX,BX AX,3030 [DI],AX 03

BE 00 30 BF 00 40 8B 04 46 46 8B 1C 2B C3 3F 05 30 30 89 05 CC

Input: S DS: 3000 3010 3011 3012 Output: : : : : 08, 00, 04, 00

D DS: 4000 : 34 4001 : 30

LITAM

Page 25

Micro Processors & Interfacing Lab ASCII Multiplication Start

Department of E.C.E

Initialize data segment

Move n1 value into ax register Move n2 value into bx register

Move 0f0f into cx register

AND operation of ax and cx contents

AND operation of bx and cx contents

Multipliation of ax and bx contents

Ascii adjust after multiplication

Move ax value into n3

Move dx value into n4

Stop

LITAM

Page 26

Micro Processors & Interfacing Lab

Department of E.C.E

13.ASCII MULTIPLICATION OF TWO 16-BIT NUMBERS (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,N1 Mov bx,N2 Mov cx,0f0fh And ax,cx And bx,cx mul bx AAM Mov N3,ax Mov N4,dx Hlt Code ends Data segment N1 dw 03 N2 dw 02 N3 dw ? N4 dw ? Data ends End

Output: N3=0006 N4=0000

LITAM

Page 27

Micro Processors & Interfacing Lab

Department of E.C.E

14.ASCII MULTIPLICATION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS MNEMONICS OPERANDS OPCODES

2000 2003 2006 2008 2009 200A 200C 200E 2010 2013 2015

MOVW MOVW MOVW INCW INCW MOVW MULW AAM ADDW MOVW INT

SI,3000 DI,4000 AX,[SI] SI SI BX,[SI] BX AX,3030 [DI],AX 03

BE 00 30 BF 00 40 8B 04 46 46 8B 1C F7 E3 04 0A 05 30 30 89 05 CC

Input: S DS: 3000 3013 3014 3015 Output: D DS: 4000 : 36 4001 : 30 : : : : 03, 00, 02, 00

LITAM

Page 28

Micro Processors & Interfacing Lab ASCII Division Start

Department of E.C.E

Initialize data segment

Move n1 value into ax register Move n2 value into bx register

Move 0f0f into cx register

AND operation of ax and cx contents

AND operation of bx and cx contents

Division of ax and bx contents

Ascii adjust after division

Move ax value into n3

Move dx value into n4

Stop

LITAM

Page 29

Micro Processors & Interfacing Lab

Department of E.C.E

15.ASCII DIVISION OF TWO 16-BIT NUMBERS (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov ax,N1 Mov bx,N2 Mov cx,0f0fh And ax,cx And bx,cx Div bx AAD Mov N3,ax Mov N4,dx Hlt Code ends Data segment N1 dw 08 N2 dw 02 N3 dw ? N4 dw ? Data ends End

Output: N3=0004 N4=0000

LITAM

Page 30

Micro Processors & Interfacing Lab

Department of E.C.E

16.ASCII DIVISION OF TWO 16-BIT NUMBERS (HARDWARE)


ADDRESS MNEMONICS OPERANDS OPCODES

2000 2003 2006 2008 2009 200A 200C 200E 2010 2013 2015

MOVW MOVW MOVW INCW INCW MOVW DIVW AAD ADDW MOVW INT

SI,3000 DI,4000 AX,[SI] SI SI BX,[SI] BX AX,3030 [DI],AX 03

BE 00 30 BF 00 40 8B 04 46 46 8B 1C F7 F3 05 0A 05 30 30 89 05 CC

Input: S DS: 3000 3016 3017 3018 OUTPUT: : : : : 06, 00, 03, 00

D DS: 4000 : 32 4001 : 30 Result: Hence the ASCII arithmetic operations addition, Subtraction, Multiplication and Division of two 16-bit numbers are performed in software and hardware

LITAM

Page 31

Micro Processors & Interfacing Lab Multi byte Addition Start

Department of E.C.E

Initialize data segment

Move n1 into cx and Load effective address of array1, array2, array3 into si, bx, di

Move content of si into al

ADD contents of bx with al

Move the content of al to di

Increment si, bx, di and decrement cx

If Count=0 YES Stop

NO

LITAM

Page 32

Micro Processors & Interfacing Lab

Department of E.C.E

17.MULTI BYTE ARITHMETIC OPERATIONS


Aim: To write an assembly language program for the multi byte addition, Subtraction, Multiplication and Division in software Apparatus: Software TASM software PC

Multibyte Addition: (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov cx,n1 Lea si,array1 Lea bx,array2 Lea di,array3 Back: mov al,[si] Adc al,[bx] Mov [di],al Inc si Inc bx Inc di Dec cx Jnz Back Hlt Code ends Data segment N1 dw 0005 Array1 dq 1234354556h Array2 dq 1234354556h Array3 dq ? Data ends End Result: 24686A8AAC

LITAM

Page 33

Micro Processors & Interfacing Lab Multi byte Subtraction Start

Department of E.C.E

Initialize data segment

Move n1 into cx and Load effective address of array1, array2, array3 into si, bx, di

Move content of si into al

Subtract contents of bx with al

Move the content of al to di

Increment si, bx, di and decrement cx

If Count=0 YES Stop

NO

LITAM

Page 34

Micro Processors & Interfacing Lab

Department of E.C.E

18.MULTIBYTE SUBTRACTION (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov cx,n1 Lea si,array1 Lea bx,array2 Lea di,array3 Back: mov al,[si] SBB al,[bx] Mov [di],al Inc si Inc bx Inc di Dec cx Jnz back Hlt Code ends Data segment N1 dw 0005h Array1 dq 1234354556h Array2 dq 1234354556h Array3 dq ? Data ends End

Result: 0000000000

LITAM

Page 35

Micro Processors & Interfacing Lab Multi byte Multiplication Start

Department of E.C.E

Initialize data segment

Move n1 into cx and Load effective address of array1, array2, array3 into si, bx, di

Move content of si into al

Multiply contents of bl with al

Move the content of al to di

Increment si, bx, di and decrement cx

If Count=0 YES Stop

NO

LITAM

Page 36

Micro Processors & Interfacing Lab

Department of E.C.E

19.MULTIBYTE MULTIPLICATION (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov cx,n1 Mov bl,n2 Mov dx,0000h Lea si,array1 Lea di,array2 Back:Mov al,[si] Cbw Mul bl Add ax,dx Mov dl,ah Mov [di],al Inc si Inc di Dec cx Jnz back Hlt Code ends Data segment N1 dw 0004h N2 db 05h Array1 dq 45335753h Array2 dq ? Data ends End

Result: array2: 5A00B49F

LITAM

Page 37

Micro Processors & Interfacing Lab Multi byte Division Start

Department of E.C.E

Initialize data segment

Move n1 into bl and Load effective address of array1, into si, di and move count into cx

Move content of si into al

Divide contents of al with bl

Move the content of al to di

Decrement si, di and cx

If Count=0 YES Stop

NO

LITAM

Page 38

Micro Processors & Interfacing Lab

Department of E.C.E

20.MULTI BYTE DIVISION (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov cl,n1 Mov bl,n2 Mov ax,0000 Mov dx,0000 Mov ah,00 Lea si,array1 Lea di,array2 Back:mov al,[si+3] Div bl Mov [di+3],al Dec si Dec di Dec cl Jnz back Hlt Code ends Data segment N1 db 04 N2 db 04 Array1 dq 88888888h Array2 dq ? Data ends End Result: Array2: 22222222h

Result: Hence the Multi byte arithmetic operations addition, Subtraction, Multiplication and Division are performed in software

LITAM

Page 39

Micro Processors & Interfacing Lab Packed BCD to Un packed BCD Start

Department of E.C.E

Initialize data segment

Move n1 to al, al to bl, move count 04 to cl

AND al with 0f

Move al result in to N2

Rotate right the content of bl by 04

AND bl with 0f

Move the bl result in to N3

NO

Stop

LITAM

Page 40

Micro Processors & Interfacing Lab

Department of E.C.E

LOGICAL OPERATIONS
Aim: To write an assembly language program to perform logical operations in software and hardware. Apparatus: Software TASM software PC Hardware 8086 Microprocessor kit Keyboard

21.PACKED TO UNPACKED BCD (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov al,n1 Mov bl,al Mov cl,04 And al,0fh Mov res1,al Ror bl,cl And bl,0fh Mov res2,bl Hlt Code ends Data segment N1 db 75h Res1 db ? Res2 db ? Data ends End Output: Res1 db 05 Res2 db 07

LITAM

Page 41

Micro Processors & Interfacing Lab

Department of E.C.E

22.PACKED TO UNPACKED BCD (HARDWARE)


ADDRESS 2000 2003 2006 2008 200A 200C 200E 2010 2012 2015 2016 2018 MNEMONICS MOVW MOVW MOVB MOVB MOVB ANDB MOVB RORB ANDB INCW MOVB INT OPERANDS SI,3000 DI,4000 AL,[SI] BL,AL CL,04 AL,0F [DI],AL BL,CL BL,0F DI [DI],BL 03 OPCODES BE 00 30 BF 00 40 8A 04 8A 08 B1 04 24 0F 89 05 D2 CB E3 0F 47 89 1D CC

Input: S DS: 3000 : 26

Output: D DS: 4000 : 06 4001 : 02

LITAM

Page 42

Micro Processors & Interfacing Lab Conversion of BCD to ASCII Start

Department of E.C.E

Initialize data segment

Move n1 to al, al to bl, move count 04 to cl

AND al with 0f

ADD 30 to al and Move al result in to N2

Rotate right the content of bl by 04

AND bl with 0f

ADD 30 to bl and Move the bl result NO in to N3 Stop

LITAM

Page 43

Micro Processors & Interfacing Lab

Department of E.C.E

23.BCD TO ASCII CONVERSION (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov al,n1 Mov bl,al Mov cl,04h And al,0fh Add al,30h Mov res1,al Ror bl,cl And bl,0fh Add bl,30h Mov res2,bl Hlt Code ends Data segment N1 db 65h Res1 db ? Res2 db ? Data ends End Output: Res1: 35 Res2: 36

LITAM

Page 44

Micro Processors & Interfacing Lab

Department of E.C.E

24.BCD TO ASCII CONVERSION (HARDWARE)


ADDRESS 2000 2003 2006 2008 200A 200C 200E 2010 2012 2014 2017 201A 201B 201D MNEMONICS MOVW MOVW MOVB MOVB MOVB ANDB ADDB MOVB RORB ANDB ADDB INCW MOVB INT OPERANDS SI,3000 DI,4000 CL,04 AL,[SI] BL,AL AL,0F AL,30 [DI],AL BL,CL BL,0F BL,30 DI [DI],BL 03 OPCODES BE 00 30 BF 00 40 B1 04 8A 04 8A 08 24 0F 04 30 88 05 D2 CB 80 E3 0F 80 C3 30 47 88 1D CC

Input: S DS: 3000 Output: D DS: 4000 : 35 4001 : 36 Result: Hence the Logical operations Packed to unpacked BCD and BCD to ASCII conversions are performed in both software and hardware : 65

LITAM

Page 45

Micro Processors & Interfacing Lab STRING REVERSING Start

Department of E.C.E

Initialize data segment

Move string length to cl, load effective address of arra1 to SI

Move SI to al

Rotate right al by cl times

Exchange contents of (di+string length ) and al

Stop

LITAM

Page 46

Micro Processors & Interfacing Lab

Department of E.C.E

STRING OPERATIONS
Aim: To write an assembly language program to perform comparison, reversing and sorting of the given strings in software and hardware. Apparatus: Software TASM software PC Hardware 8086 Microprocessor kit Keyboard

25.REVERSE STRING (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data,es:data Mov ax,data Mov ds,ax Mov es,ax Lea si,N1 Mov cl,string_length Mov al,[si] Ror al,cl Xchg [di+string_length],al Hlt Code ends Data segment N1 dq intel String_length equ($-n1) Data ends End

Output: letni

LITAM

Page 47

Micro Processors & Interfacing Lab

Department of E.C.E

26.REVERSE STRING (HARDWARE)


ADDRESS 2000 MNEMONICS MOVW MOVW MOVB MOVB RORB MOVB INT OPERANDS SI,3000 DI,4000 AL,[SI] CL,04 AL,CL [DI],AL 03 OPCODES

Input: S DS: 3000 : 45 Output: D DS: 4000 : 54

LITAM

Page 48

Micro Processors & Interfacing Lab STRING COMPARISION Start

Department of E.C.E

Initialize data segment

Load effective address of array1 in to SI and array2 to DI

Move string length to cx

Clear the direction flag, repeat the comparision of string bytes

yes

Jump if not equal no

Move the 0fffh value in to ax

Jump to next

Move 0000 in to ax, Next : move the content of ax to res

Stop

LITAM

Page 49

Micro Processors & Interfacing Lab

Department of E.C.E

27.COMPARISION OF STRINGS (SOFTWARE)


Source code: Code segment Assume cs:code,ds:data,es:data Mov ax,data Mov ds,ax Mov es,ax Lea si,array1 Lea di,array2 Mov cx,str_length Cld Rep cmpsb Jne ahead Mov ax,0000h Mov res,ax Jmp next ahead:mov ax,0fffh Mov res,ax Next:hlt Code ends Data segment array1 db micro str_length equ ($-array1) array2 db micro res dw ? Data ends End INPUT: 1) array1 db micro array2 db micro 2) array1 db micro array2 db intel OUTPUT: 1) res 2) res

: 0000 : 0fff

LITAM

Page 50

Micro Processors & Interfacing Lab

Department of E.C.E

28.COMPARISION OF STRINGS (HARDWARE)

ADDRESS 2000 2003 2006 2009 200A 200B 200C 200E 2011 2014 2016 2017 201A 201D 201F INPUT:

LABEL MNEMONICS MOVW MOVW MOVW CLD REP CMPSB JNE MOVW MOVW MOVW INT MOVW MOVW MOVW INT

OPERANDS SI,2500 DI,3000 CX,0004

OPCODES BE 0020 BF 00 30 B9 04 00 FC F3 A6 75 09 BF 00 50 B8 00 00 89 05 CC BF 00 50 B8 FF FF 89 05 CC

L1:

2017 (L1) DI,5000 AX,0000 [DI],AX 03 DI,5000 AX,FFFF [DI],AX 03

(i) S DS: 2500 : 08, 2501 : 08, 2502 : 03, 2503 : 03, S DS: 3000 3001 3002 3003 OUTPUT: (i) D DS: 5000 : FF 5001 : FF : 02, : 02, : 02, : 02

(ii) 08, 08, 03, 03 08, 08, 03, 03 (ii) 00 00

LITAM

Page 51

Micro Processors & Interfacing Lab ASCENDING ORDER

Department of E.C.E

Start

Initialize data segment

Move the content of count-1 to dx,

move the content of dx to cx, Move array1 to SI

Move SI to al and compare al and SI+1

yes

If [SI+1] <al no

Exchange content of SI+1, al and Exchange content of SI, al ADD 01 to SI , decrement cx yes If Cx0 no decrement content of dx yes If dx0 no Stop

LITAM

Page 52

Micro Processors & Interfacing Lab

Department of E.C.E

SORTING 29.ASCENDING ORDER (IN TERMS OF BYTES) (SOFTWARE)


Source code:

Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov dx,count-1 Again0:mov cx,dx Mov si,offset array Again1:mov al,[si] Cmp al,[si+1] Jl back Xchg [si+1],al Xchg [si],al Back:add si,01 Loop again1 Dec dx Jnz again0 Hlt Code ends Data segment Array db 53h,19h,25h,02h Count equ 04h Data ends End

Output: 02,19,25,53

LITAM

Page 53

Micro Processors & Interfacing Lab

Department of E.C.E

30.ASCENDING ORDER PROGRAMMING (HARDWARE)


ADDRESS LABEL 2000 2002 2004 2006 2009 200B 200D 200E 2010 2012 2014 2016 2018 2019 201B 201C 201E 2020 2022 2024 INPUT: S DS: 3000 3001 3002 3003 : 53, : 63, : 07, : 06 MNEMONICS MOVB MOVB MOVB MOVW MOVB MOVB INCW MOVB CMPB JL XCHGB MOVB DECW MOVB INCW DECB JNE DECB JNE INT OPERANDS CL,03 AH,00 BH,00 SI,3000 CH,04 AH,[SI] SI BH,[SI] AH,BH 2016 (L1) AH,BH [SI],BH SI [SI],AH SI CH 200B (L2) CL 2006 (L3) 03 OPCODES B1 03 B4 00 B7 00 BE 00 30 B5 04 BA 24 46 8A 3C 3A E7 7C 02 86 E7 88 3C 4E 88 24 46 FE CD 75 EB FE C9 75 E2 CC

L3: L2:

L1:

D DS: 3000 : 06 3001 : 07 3002 : 53 3003 : 63

LITAM

Page 54

Micro Processors & Interfacing Lab DESCENDING ORDER Start

Department of E.C.E

Initialize data segment

Move the content of count-1 to dx,

move the content of dx to cx, Move array1 to SI

Move SI to al and compare al and SI+1

yes

If [SI+1] >al no

Exchange content of SI+1, al and Exchange content of SI, al

ADD 01 to SI , decrement cx yes If Cx0 no decrement content of dx yes If dx0 no Stop

LITAM

Page 55

Micro Processors & Interfacing Lab

Department of E.C.E

SORTING 31.DESCENDING ORDER (IN TERMS OF BYTES) (SOFTWARE)


Source code:

Code segment Assume cs:code,ds:data Mov ax,data Mov ds,ax Mov dx,count-1 Again0:mov cx,dx Mov si,offset array Again1:mov al,[si] Cmp al,[si+1] JG back Xchg [si+1],al Xchg [si],al Back:add si,01 Loop again1 Dec dx Jnz again0 Hlt Code ends Data segment Array db 53h,19h,25h,02h Count equ 04h Data ends End

Output: 53,25,19,02

LITAM

Page 56

Micro Processors & Interfacing Lab

Department of E.C.E

32.DESCENDING ORDER PROGRAMMING (HARDWARE)


ADDRESS LABEL 2000 2002 2004 2006 2009 200B 200D 200E 2010 2012 2014 2016 2018 2019 201B 201C 201E 2020 2022 2024 INPUT: S DS: 3000 3004 3005 3006 OUTPUT: D DS: 3000 3001 3002 3003 : 52 : 51 : 49 : 10 : 51, : 49, : 52, : 10 MNEMONICS MOVB MOVB MOVB MOVW MOVB MOVB INCW MOVB CMPB JG XCHGB MOVB DECW MOVB INCW DECB JNE DECB JNE INT OPERANDS CL,03 AH,00 BH,00 SI,3000 CH,04 AH,[SI] SI BH,[SI] AH,BH 2016 (L1) AH,BH [SI],BH SI [SI],AH SI CH 200B(L2) CL 2006 (L3) 03 OPCODES B1 03 B4 00 B7 00 BE 00 30 B5 04 BA 24 46 8A 3C 3A E7 7F 02 86 E7 88 3C 4E 88 24 46 FE CD 75 EB FE C9 75 E2 CC

L3: L2:

L1:

Result: Hence the String operations are performed in both software and hardware and the output is verified

LITAM

Page 57

Micro Processors & Interfacing Lab Dos programming Start

Department of E.C.E

Initialize data segment

Display the content of DS

Load the effective address of message1 in to dx Read the string input, move content of al in to char

Display the content of char

Load effective address of message2 in to dx

Move the value 02 in to ah

Move the content of char in to al

Stop

LITAM

Page 58

Micro Processors & Interfacing Lab

Department of E.C.E

33.DOS PROGRAMMING (SOFTWARE)


Source code: Data segment Cr equ 0ah Lf equ 0dh Msg1 db cr,lf, type any key:$ Msg2 db cr,lf, typed key is:$ Char db ? Data ends Code segment Assume cs:code,ds:data Start:mov ax,data Mov ds,ax Mov ah,09h Lea dx,msg1 Int 21h Mov ah,01h Int 21h Mov char,al Mov ah,09h Lea dx,msg2 Int 21h Mov ah,02 Mov dl,char Int 21h Mov ah,4ch Int 21h Code ends End start Output: Type any key :a Typed key is :a

LITAM

Page 59

Micro Processors & Interfacing Lab

Department of E.C.E

34.DOS PROGRAMMING (HARDWARE)


ADDRESS 2000 2003 2005 2007 2009 200B 200D 200F L1: L2: LABEL MNEMONICS MOVW MOVW MOVB CMPB JE JMP MOVB INT OPERANDS AX,8000 DS,AX AH,01 AL,00 200D (L1) 2005 (L2) AH,4C 03 OPCODES B8 00 80 BE D8 B4 01 3C 00 74 02 EB F8 B4 4C CC

Input: S DS: 8000 Output: D DS: 8000 :E :E

Result: Hence, the DOS programming is performed and output is verified.

LITAM

Page 60

Micro Processors & Interfacing Lab Factorial of a given number Start

Department of E.C.E

Initialize data segment

Reset ax register, and move the content of n1 in to al

If al=00

Move the value 0001 in to ax

Move the content of ax in to result RES

Stop

Move the content of n1 in to al and move the content of al in to bl

If bl=00

Move the content of ax in to RES

Stop

LITAM

Page 61

Micro Processors & Interfacing Lab

Department of E.C.E

35.FACTORIAL OF A GIVEN NUMBER N USING RECURSIVE PROCEDURE


(N values from 0 to 8 only) Source code: Code segment Assume CS:code,DS: data Mov ax,data Mov DS,ax Mov ax,0000 Mov bx,0000 Mov ax,N1 Cmp ax,00 Je ahead Call facto Jmp next Ahead: Mov ax,0001 Mov res,ax Next: Hlt Facto proc near Mov ax,N1 Mov bx,ax Dec bx Back: mul bx Dec bx Cmp bx,00 Jne back Mov res,ax Ret Facto endp Code ends Data segment N1 dw 00h Res dw ? Data ends End Input: N1= 04h Output: res= 0018h Result: Hence the factorial of a given number using Recursive procedure is verified

LITAM

Page 62

Micro Processors & Interfacing Lab

Department of E.C.E

INTERFACING THROUGH 8086 MICROPROCESSOR

LITAM

Page 63

Micro Processors & Interfacing Lab

Department of E.C.E

INTERFACING PROCEDURE:1. For interfacing program in 8086, we should select the 3, 4, 7 pins in 8086 kit. For hardware program 3, 7 pins should select. 2. Connect RS-232 cable between CPU to 8086 Kit.

3. Select my computer\D drive\AHALYA (folder)\ESA863 (folder) \XT863 (folder)\XT863 (Window). 4. Press enter key and reset the kit. 5. For down load the program, the command is ctrl+D and enter the file name. (For example: tra863 [it is for traffic light controller]). 6. After completion of down loading the program, reset the kit.

7. Then type G 2000. 8. Then press enter key. 9. Get the output according to the interfacing kits connected.

LITAM

Page 64

Micro Processors & Interfacing Lab

Department of E.C.E

1.KEYBOARD INTERFACING Aim: To interface a keyboard to microprocessor 8086 Apparatus: Keyboard interface kit
8086 Microprocessor Trainer kit PC RS 232 Cable Power supply

Source code:
; KEYBOARD INTERFACE ; Assumes the interface is connected over J4 of trainer ; This program displays the value of the pressed key on the PC console ; in serial mode or LCD in stand-alone mode of operation. ; This program starts at 0:2000H location OUTPUT 2500AD ORG 2000H MOV AX,0000H MOV ES,AX MOV DX,0FFE6H ; Configure 8255 in Mode0 MOV AL,92H ; PortA as i/p , PortC as o/p` OUT DX,AL JMP SHORT START MES: DB 'KEY PRESSED = ',0H START: CALL FAR 0FE00:0031H ;Newline LEA DX,MES MOV AX,DX CALL FAR 0FE00:0013H ;Call for displaying the message CALL KSCAN CALL DELAY JMP SHORT START KSCAN: MOV CL,01H NEXT: MOV AL,CL MOV DX,0FFE4H OUT DX,AL MOV DX,0FFE0H IN AL,DX MOV AH,AL OR AL,AL JNZ KEYCODE CONT: ROL CL,1 CMP CL,08H JE KSCAN JMP NEXT LITAM Page 65

Micro Processors & Interfacing Lab KEYCODE:MOV BL,0H MOV AL,AH SHIFT: SHR AL,1 CMP AL,00H JZ ROW INC BL JMP SHIFT ROW: MOV AL,CL MOV CL,02H ROL AL,CL AND AL,0FBH OR AL,BL CALL FAR 0FE00:0052H RET DELAY: PUSH CX MOV CX,00H DLY: LOOP DLY POP CX RET END

Department of E.C.E

; Delay routine

LITAM

Page 66

Micro Processors & Interfacing Lab Output: Keys Values

Department of E.C.E

1 2 3 4 5 6 7 8 9 AC CE CHK != MC MR MM+ . + * / %

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 0A 0B 0C 0D 0E 0F

Result : Hence the keyboard interfacing is performed and the output is observed

LITAM

Page 67

Micro Processors & Interfacing Lab

Department of E.C.E

2. TRAFFIC LIGHT INTERFACING Aim: To interface a traffic light controller to microprocessor 8086 Apparatus: traffic light controller interface kit
8086 Microprocessor Trainer kit PC RS 232 Cable Power supply

Source code:
; TRAFFIC LIGHT CONTROLLER INTERFACE ; The interface is connected over J4 of of trainer ; Traffic system moves from one state to other after a fixed delay ; This program starts at 2000H location OUTPUT 2500AD ORG 2000H START: MOV AL,80H MOV DX,0FFE6H OUT DX,AL AGAIN: MOV SI,2038H NEXTST: MOV AL,[SI] MOV DX,0FFE0H OUT DX,AL INC SI ADD DX,2 MOV AL,[SI] OUT DX,AL INC SI ADD DX,2 MOV AL,[SI] OUT DX,AL INC SI CALL DELAY CMP SI,2056H JNZ NEXTST JMP AGAIN DELAY: MOV CX,0FFH DLY5: PUSH CX MOV CX,03FFH DLY10: NOP LOOP DLY10 POP CX LOOP DLY5 RET LITAM

; Initialisation of 8255 Mode 0 ; All ports as o/p ports ; Table of port values

; PortA value

; PortB value

; PortC value ; Calling Delay routine ; Checking for the end of the data values

; Delay routine

Page 68

Micro Processors & Interfacing Lab ORG 2038H PORTVALUES: DB 10H,81H,7AH ; State 1 DB 44H,44H,0F0H ; All ambers ON DB 08H,11H,0E5H ; State 2 DB 44H,44H,0F0H ; All ambers ON DB 81H,10H,0DAH ; State 3 DB 44H,44H,0F0H ; All ambers ON DB 11H,08H,0B5H ; State 4 DB 44H,44H,0F0H ; All ambers ON DB 88H,88H,00H ; State 5 DB 44H,44H,0F0H ; All ambers ON DB 00H ; Dummy

Department of E.C.E

Result: Hence, the traffic light controller interfacing is performed and the output is observed.

LITAM

Page 69

Micro Processors & Interfacing Lab

Department of E.C.E

3. DIGITAL TO ANALOG CONVERTER INTERFACING Aim: To interface a digital to analog converter to microprocessor 8086 Apparatus: digital to analog converter interface kit
8086 Microprocessor Trainer kit PC RS 232 Cable Power supply

Source code:
; Assume the interface is connected over J4 of trainer ; This program generates a Square or Triangular wave at Xout or Yout ; The program can be executed in Stand alone or Serial mode ; Execute the program from memory location 2000H OUTPUT 2500AD ORG 2000H MOV AX,0000H MOV CS,AX MOV ES,AX MOV DX,0FFE6H ;Initialise all 8255 MOV AL,80H ;ports as O/P ports OUT DX,AL CALL FAR 0FE00:01EDH ;newline routine JMP SHORT START ;display message string MES: DB 0AH, 0DH, 'DUAL DAC INTERFACE ' DB 0AH, 0DH, 'S - SQUARE WAVE' DB 0AH, 0DH, 'T - TRIAGLUAR WAVE', 0H START: LEA DX,MES ;display message on LCD MOV AX,DX ;or console CALL FAR 0FE00:0013H GETKEY: CALL FAR 0FE00:00A9H ;wait fo user entry CMP AL,53H ;if S,jump to square JE SQUARE ;wave routine CMP AL,54H ;if T, jump to triangle JE TRIANGLE ;wave routine JMP SHORT GETKEY ;wait for valid key ;Triangular wave generation routine TRIANGLE: CALL FAR 0FE00:0031H RPT1: MOV CX,0FFH ;set count MOV AL,00H ;start from 0 UP: INC AL ;increment data for LITAM Page 70

Micro Processors & Interfacing Lab MOV DX,0FFE0H ;+ive going slope and OUT DX,AL ;output at port A & B MOV DX,0FFE2H OUT DX,AL LOOP UP MOV CX,FFH ;set count MOV AX,CX ;start from FFh DOWN: DEC AL ;decrement data for MOV DX,0FFE0H ;-ive going slope at OUT DX,AL ;port A & B MOV DX,0FFE2H OUT DX,AL LOOP DOWN JMP SHORT RPT1 ;repeat continuously SQUARE: CALL FAR 0FE00:0031H RPT2: MOV AL,0FFH ;O/P FFh at ports MOV DX,0FFE0H OUT DX,AL MOV DX,0FFE2H OUT DX,AL MOV CX,FFH ;delay DLY1: LOOP DLY1 MOV AL,00H ;O/P 0 at ports MOV DX,0FFE0H OUT DX,AL MOV DX,0FFE2H OUT DX,AL MOV CX,FFH DLY2: LOOP DLY2 ;delay JMP SHORT RPT2 ;repeat continuously END

Department of E.C.E

Result: Hence, the digital to analog converter interfacing is performed and the output is observed on CRO.

LITAM

Page 71

Micro Processors & Interfacing Lab

Department of E.C.E

4.REAL TIME CLOCK INTERFACING Aim: To interface a real time clock to microprocessor 8086 Apparatus: real time clock interface kit
8086 Microprocessor Trainer kit PC RS 232 Cable Power supply

Source code:
SET RTC: ; Assume the interface is connected over J4 of the trainer ; this program is to set the rtc parametrs ; For RTC interface first execute this program from 2400H and then ; execute read rtc program from 2000H ; this program can be in serial mode only OUTPUT 2500AD ORG 2400H MOV AX,0000H MOV ES,AX MOV BL,0H MOV SI,2300H MOV DX,0FFE6H MOV AL,80H OUT DX,AL MOV DX,FFE4H MOV AL,10H OUT DX,AL MOV AL,28H HDLY: DEC AL JNE HDLY

;set address counter ;initialise pointer ;initialise all 8255 ports ;as output ;hold line high

;hold setup time delay

SET: MOV DX,0FFE2H ;output address to RTC MOV AL,BL OUT DX,AL NOP NOP MOV DX,0FFE0H ;get rtc parameter from MOV AL,[SI] ;memory and output OUT DX,AL ;to rtc MOV DX,0FFE4H ;make write and hold state MOV AL,50H ;high OUT DX,AL NOP NOP MOV AL,10H ;make write signal low LITAM

Page 72

Micro Processors & Interfacing Lab OUT DX,AL ;keeping hold high INC BL ;increment address count CMP BL,0DH ;all parameters over? JE STOP ;if yes , stop INC SI ;else point to next parameter JMP SHORT SET ;and repeat STOP: MOV AL,00H OUT DX,AL INT 3 END READ RTC: ; This program continuously reads RTC values and output the same ; on the PC console ; first execute the setrtc program then execute this program ; to get rtc values. ; This program can be in Serial mode only OUTPUT 2500AD ORG 2000H MOV AX,0000H MOV CS,AX MOV ES,AX MOV DS,AX JMP START ;Display Message Strings MES: DB 0AH,0AH,0DH,48H,52H,53H,20H,20H,20H,20H DB 4DH,49H,4EH,20H,20H,20H,20H,53H,45H,43H DB 20H,20H,20H,20H,41H,2FH,50H,20H,20H,20H DB 20H,20H,44H,41H,59H,20H,20H,20H,20H,20H DB 44H,44H,2DH,4DH,4DH,2DH,59H,59H LINE: DB 0AH,0DH,2DH,2DH,2DH,20H,20H,20H,20H,2DH DB 2DH,2DH,20H,20H,20H,20H,2DH,2DH,2DH,20H DB 20H,20H,20H,2DH,2DH,2DH,20H,20H,20H,20H DB 20H,2DH,2DH,2DH,20H,20H,20H,20H,20H,2DH DB 2DH,2DH,2DH,2DH,2DH,2DH,2DH,0AH,0DH,00H SPACE: DB 20H,20H,20H,20H,20H,00H HYP: DB 2DH,00H AM: DB 41H,4DH,20H,00H,00H PM: DB 50H,4DH,20H,00H LITAM ;hold and write low

Department of E.C.E

Page 73

Micro Processors & Interfacing Lab WEEK: DB 53H,55H,4EH,00H DB 4DH,4FH,4EH,00H DB 54H,55H,45H,00H DB 57H,45H,44H,00H DB 54H,48H,52H,00H DB 46H,52H,49H,00H DB 53H,41H,54H,00H DB 20H,20H,20H,00H BAK: DB 08H,00H NEW: DB 0DH,00H START: MOV SI,2300H ;initialise pointer CALL READ ;get rtc values MOV DX,0FFE6H ;initialise 8255 port A MOV AL,90H ;as I/P , port B as O/P OUT DX,AL CS: LEA DX,MES ;display message for rtc MOV SI,DX ;parameters CALL FAR 0FE00:01AFH ;Display message and line REPT: LEA DX,NEW MOV SI,DX CALL FAR 0FE00:01AFH MOV BX,2304H ;get hours value CALL DAT AND AL,3FH CALL FAR 0FE00:0052H ;Display Hours LEA DX,SPACE MOV SI,DX CALL FAR 0FE00:01AFH MOV BX,2302H ;get min. value CALL DAT CALL FAR 0FE00:0052H ;Display Minutes MOV SI,DX CALL FAR 0FE00:01AFH MOV BX,2300H ;get seconds CALL DAT CALL FAR 0FE00:0052H ;Display seconds MOV SI,DX CALL FAR 0FE00:01AFH MOV BX,2305H ;check for 12/24 MOV AL,[BX] ;hrs format AND AL,08H LITAM

Department of E.C.E

Page 74

Micro Processors & Interfacing Lab JNE DD MOV AL,[BX] ;check for AM or PM AND AL,04H ;if bit2=1 display PM JNE PM1 LEA DX,AM MOV SI,DX CALL FAR 0FE00:01AFH JMP SHORT MM PM1: LEA DX,PM ;routine to display PM MOV SI,DX CALL FAR 0FE00:01AFH JMP SHORT MM DD: LEA DX,HYP ;if 24 hour format MOV SI,DX ;display PM CALL FAR 0FE00:01AFH MOV SI,DX CALL FAR 0FE00:01AFH MOV SI,DX CALL FAR 0FE00:01AFH MM: LEA DX,SPACE MOV SI,DX CALL FAR 0FE00:01AFH MOV AX,00H MOV BX,2306H ;get day of week MOV AL,[BX] AND AL,07H LEA DX,WEEK ;display day of week CHK: CMP AL,00H JE DISP MOV CX,04H INCR: INC DX LOOP INCR DEC AX JMP SHORT CHK DISP: MOV SI,DX CALL FAR 0FE00:01AFH LEA DX,SPACE MOV SI,DX CALL FAR 0FE00:01AFH MOV BX,2307H ;get date value LITAM

Department of E.C.E

Page 75

Micro Processors & Interfacing Lab CALL DAT CALL FAR 0FE00:0052H ;display date LEA DX,HYP MOV SI,DX CALL FAR 0FE00:01AFH MOV BX,2309H ;get month value CALL DAT CALL FAR 0FE00:0052H ;display month MOV SI,DX CALL FAR 0FE00:01AFH MOV BX,230BH ;get year value CALL DAT CALL FAR 0FE00:0052H ;display year CALL REWRT ;check for update seconds CLEAR: PUSH CX MOV CX,0029H BACK: LEA DX,BAK MOV SI,DX CALL FAR 0FE00:01AFH LOOP BACK POP CX JMP REPT REWRT: MOV BX,2300H MOV AL,[BX] PUSH AX MOV SI,2300H CALL READ POP AX MOV BX,2300H CMP AL,[BX] JE REWRT RET READ: MOV DX,FFE4H MOV AL,10H OUT DX,AL MOV AL,28H HDLY: DEC AL JNE HDLY MOV AL,30H OUT DX,AL LITAM ;routine to check updating ;of seconds value in ;location 2300H ;repeat read and display ;operation ;routine to clear old values

Department of E.C.E

;hold line high

;hold setup time delay

;read and hold line high

Page 76

Micro Processors & Interfacing Lab MOV CL,00H ;clear rtc reg. counter NEXT: MOV DX,FFE2H ;output address to rtc MOV AL,CL OUT DX,AL MOV AL,04H ;read access time delay RDLY: DEC AL JNE RDLY MOV DX,FFE0H ;read data from rtc IN AL,DX AND AL,0FH ;AND with 0Fh and store MOV [SI],AL ;in memory INC SI ;increment address and rtc reg. INC CL CMP CL,0DH ;are all reg. addressed? JNE NEXT ;no, get next parameter MOV DX,0FFE4H ;else make hold and read lines low MOV AL,00H OUT DX,AL RET DAT: MOV AL,[BX] ;routine to club the lower

Department of E.C.E

AND AL,0FH ;nibbles of the memory MOV AH,AL ;locations INC BX MOV AL,[BX] AND AL,0FH ROL AL,1 ROL AL,1 ROL AL,1 ROL AL,1 OR AL,AH RET END CALL FAR 0FE00:0052H

Result: Hence, the real time clock interfacing is performed and the output is observed. .

LITAM

Page 77

Micro Processors & Interfacing Lab

Department of E.C.E

5.ELEVATOR INTERFACING Aim: To interface a Elevator to microprocessor 8086 Apparatus: Elevator interface kit
8086 Microprocessor Trainer kit PC RS 232 Cable Power supply

Source code:
; ELEVATOR INTERFACE ; Assumes the interface is connected over J4 of trainer ; The elvator will work in both Upward and Downward directions ; This program starts at 2000H location OUTPUT 2500AD ORG 2000H MOV DX,0FFE6H ; Configure 8255 MOV AL,82H ; PortA as o/p,PortB as i/p OUT DX,AL XOR AX,AX ; Initial stage is ground floor LOOP1: MOV AL,AH OR AL,0F0H MOV DX,0FFE0H OUT DX,AL MOV DX,0FFE2H LOOP2: IN AL,DX AND AL,0FH CMP AL,0FH JZ LOOP2 ; AH is the floor position

; Get request

MOV SI,00H FINDF: ROR AL,01H JNC FOUND ;If requested floor found INC SI JMP SHORT FINDF ; Otherwise,continue search FOUND: MOV AL,[SI]2100H ; Get requesting floor code CMP AL,AH ; Compare with current floor JA GOUP ; If it need to go UP JB GODN ; If it need to g DOWN CLEAR: MOV AL,[SI]2104H MOV DX,0FFE0H OUT DX,AL LITAM

Page 78

Micro Processors & Interfacing Lab JMP SHORT LOOP1 GOUP: CALL DELAY INC AH ; Elevator goes UP by one LED XCHG AL,AH OR AL,0F0H MOV DX,0FFE0H OUT DX,AL AND AL,0FH XCHG AH,AL CMP AL,AH JNZ GOUP JMP SHORT CLEAR GODN: CALL DELAY DEC AH ; Elevator goes DOWN by one LED XCHG AH,AL OR AL,0F0H MOV DX,0FFE0H OUT DX,AL AND AL,0FH XCHG AL,AH CMP AL,AH JNZ GODN JMP SHORT CLEAR DELAY: MOV CX,0800H ; Delay between glow of successive LEDs HR1: LOOP HR1 HR2: LOOP HR2 RET

Department of E.C.E

ORG 2100H VALUE1: DB 00H,03H,06H,09H ; Position codes for floors VALUE2: DB 0E0H,0D3H,0B6H,79H ; clear code+position dode for all floors

Result: Hence, the elevator interfacing is performed and the output is observed.

LITAM

Page 79

Micro Processors & Interfacing Lab

Department of E.C.E

6.STEPPER MOTOR INTERFACING Aim: To interface a Stepper motor to microprocessor 8086 Apparatus: Stepper motor interface kit
8086 Microprocessor Trainer kit PC RS 232 Cable Power supply

Source code:
; Assume the interface is connected over J4 of the trainer. ; This program illustrates the control of direction of ; rotation of the Stepper motor depending upon user choice. ; The program executes in a continuous loop. ; The program can be executed in STAND-ALONE MODE or SERIAL ; MODE of operation. ; The program starts at memory location 0:2000H ; Please refer ESA 86/88E user's manual for mnemonic ; syntax suitable to trainer OUTPUT 2500AD ORG 2000H MOV AX,0000H ;Initialise Segment MOV CS,AX MOV ES,AX ;Registers MOV DX,0FFE6H ;Initialise MOV AL,80H ;all 8255 Ports as o/p OUT DX,AL CALL FAR 0FE00:01EDH JMP SHORT START ; Display Message String MES1: DB 0AH,0DH,'ENTER DIRECTION' DB 0AH,0DH,'A-ANTICLOCKWISE C-CLOCKWISE',00H LEA DX,@MES1 ;Display message MOV AX,DX ;on LCD or Console CALL FAR 0FE00:0013H CALL FAR 0FE00:00A9H ;Wait for user entry CMP AL,41H ;If key ='A', JE ANTI ;rotate anti-clockwise CMP AL,43H ;If key = 'C' JE CLO JMP GET LITAM ;rotate clockwise ;Accept valid key only Page 80

START:

GET:

Micro Processors & Interfacing Lab ; Routine for Clockwise rotation of motor CLO: R1: CALL COMMON OUT DX,AL CALL DELAY ;Introduce delay RCR AL,1 ;Rotate bits in JMP SHORT R1 ;data byte right & repeat

Department of E.C.E

; Routine for Anti-clockwise rotation of motor ANTI: R2: CALL COMMON OUT DX,AL CALL DELAY RCL AL,1 ;Rotate bits JMP SHORT R2 ;left & repeat

COMMON: CALL FAR 0FE00:0031H CALL FAR 0FE00:00H MOV AL,11H ;Output value MOV DX,0FFE0H ;to Port A RET DELAY: MOV CX,800H SS: LOOP SS RET END ;Delay routine

Result: Hence, the Stepper motor interfacing is performed and the output is observed.

LITAM

Page 81

Micro Processors & Interfacing Lab

Department of E.C.E

Micro Controller - 8051

LITAM

Page 82

Micro Processors & Interfacing Lab

Department of E.C.E

Procedure for programming:


1. Connect the ESA 51/E kit with keyboard and RPS and switch on the supply 2. Press the reset button 3. Load the program by giving the starting address location as A starting address Eg: A 8000 4. After entering the program press the reset button 5. Enter the input values by typing MD: Input address location Eg: MD: 9000 and press enter 6. Execute the program using go command G starting address Eg: G 8000 7. To check the output type MD: output address location

LITAM

Page 83

Micro Processors & Interfacing Lab

Department of E.C.E

ARITHMETIC OPERATIONS 1.ADDITION OF TWO NUMBERS (HARDWARE)

ADDRESS 8000 8003 8004 8006 8009 800A 800C 800F 8010

LABEL

MNEMONICS MOV MOVX MOV MOV MOVX ADD MOV MOVX

OPERANDS DPTR,#9000 A,@DPTR 0F0,A DPTR,#9001 A,@DPTR A,0F0 DPTR,#9002 @DPTR,A 8010 (L1)

OPCODES 90 90 00 E0 F5 F0 90 90 01 E0 25 F0 90 90 02 F0 8D F3

L1:

SJMP

INPUT: MD 9000 9001 OUTPUT: G 8000 MD 9002 08

05 03

LITAM

Page 84

Micro Processors & Interfacing Lab

Department of E.C.E

2.SUBTRACTION OF TWO NUMBERS (HARDWARE)


ADDRESS 8000 8003 8004 8006 8009 800A 800C 800F 8010 L1: LABEL MNEMONICS MOV MOVX MOV MOV MOVX SUBB MOV MOVX SJMP OPERANDS DPTR,#9001 A,@DPTR 0F0,A DPTR,#9000 A,@DPTR A,0F0 DPTR,#9002 @DPTR,A 8010 (L1) OPCODES 90 90 01 E0 F5 F0 90 90 00 E0 95 F0 90 90 02 F0 8D F3

Input: MD 9000 9002 05 03

Output: G 8000 MD 9002 02

LITAM

Page 85

Micro Processors & Interfacing Lab

Department of E.C.E

3.MULTIPLICATION OF TWO NUMBERS (HARDWARE)


ADDRESS 8000 8003 8004 8006 8009 800A 800C 800D 8010 8011 8012 8014 8015 MNEMONICS MOV MOVX MOV MOV MOVX MOV MUL MOV MOVX INC MOV MOVX LJMP OPERANDS DPTR,#9001 A,@DPTR 0F0,A DPTR,#9000 A,@DPTR B,A AB DPTR,#9002 @DPTR,A DPTR A,0F0 @DPTR,A 0 OPCODES 90 90 01 E0 F5 F0 90 90 00 E0 F5 0B A4 90 90 02 F0 A3 E5 F0 F0 02 00 00

Input: MD 9000 02 9001 02 Output: G 8000 MD 9002 04 9003 00

LITAM

Page 86

Micro Processors & Interfacing Lab

Department of E.C.E

4.DIVISION OF TWO NUMBERS (HARDWARE)


ADDRESS 8000 8003 8004 8006 8009 800A 800C 800D 8010 8011 8012 8014 8015 MNEMONICS MOV MOVX MOV MOV MOVX MOV DIV MOV MOVX INC MOV MOVX LJMP OPERANDS DPTR,#9001 A,@DPTR 0F0,A DPTR,#9000 A,@DPTR B,A AB DPTR,#9002 @DPTR,A DPTR A,0F0 @DPTR,A 0 OPCODES 90 90 01 E0 F5 F0 90 90 00 E0 F5 0B 84 90 90 02 F0 A3 E5 F0 F0 02 00 00

Input: MD 9000 04 9002 02 Output: G 8000 MD 9002 02 9003 00

Result: Hence the arithmetic addition, subtraction, multiplication and division operations were
performed.

LITAM

Page 87

Micro Processors & Interfacing Lab

Department of E.C.E

LOGICAL OPERATIONS 5.HEX TO ASCII CONVERSION (HARDWARE)


ADDRESS 8000 8003 8004 8005 8006 8007 8009 800B 800C 800E 800F 8011 8012 8013 8015 L3: L2: L1: LABEL MNEMONICS MOV MOVX INC MOV CLR SUBB JC MOV ADD MOVX SJMP MOV CLR ADD LJMP OPERANDS DPTR,#9000 A,@DPTR DPTR R1,A C A,#0A 8011 (L1) A,R1 A,#37 @DPTR,A 800F(L2) A,R1 C A,#30 800E (L3) OPCODES 90 90 00 E0 A3 F9 C3 94 09 40 06 E9 24 37 F0 80 FE E9 C3 24 30 02 80 0E

INPUT: (i) (ii) OUTPUT: G 8000 (i) (ii)

MD 9000 05 MD 9000 A

MD 9001 35 MD 9001 41

LITAM

Page 88

Micro Processors & Interfacing Lab

Department of E.C.E

6.LARGEST AMONG N NUMBERS (HARDWARE)


ADDRESS 8000 8003 8004 8005 8008 8009 800A 800B 800C 800D 800E 800F 8011 8013 8014 8015 8016 8018 8019 801A 801D L3: L1: L4: L2: LABEL L5: MNEMONICS MOV MOVX MOV MOV MOVX DEC MOV INC MOVX MOV SUBB JNC JNZ MOV INC MOVX SJMP MOV MOV LJMP LJMP OPERANDS DPTR,#8900 A,@DPTR R2,A DPTR,#8901 A,@DPTR R2 R1,A DPTR A,@DPTR R3,A A,R1 8018 (L1) R2,800B (L2) A,R1 DPTR @DPTR,A 8016 (L3) A,R3 R1,A 8011 (L4) 8000 (L5) OPCODES 90 89 00 E0 FA 90 89 01 E0 1A F9 A3 E0 FB 99 05 18 DA F8 E9 A3 F0 80 FE EB F9 02 80 11 02 80 00

Input: MD 8900 8901 8902 8903 8904

04(given the count) 01 04 03 06

Output: G 8000 MD 8905 06

LITAM

Page 89

Micro Processors & Interfacing Lab

Department of E.C.E

7.CHECKING THE 5th BIT POSITION (HARDWARE)

ADDRESS 8000 8003 8004 8005 8006 8007 8008 800A 800C 800D 8010 8012 8013

LABEL

MNEMONICS MOV MOVX INC RLC RLC RLC JC MOV MOVX LJMP

OPERANDS DPTR,#8900 A,@DPTR DPTR A A A 8010 (L1) A,#0FF @DPTR,A 0030 A,#00 @DPTR,A 0

OPCODES 90 89 00 E0 A3 33 33 33 40 06 74 FF F0 02 00 63 74 00 F0 02 00 00

L1:

MOV MOVX LJMP

Input: 1)MD 8900 05 2)MD 8900 25 Output: G 8000 1)MD 8901 FF 2)MD 8901 00 Result: Hence the logical operations on 8051 microcontroller were performed and output is verified.

LITAM

Page 90

Potrebbero piacerti anche