MP Lab Finalize
MP Lab Finalize
com
1. INTRODUCITION TO MASM/TASM
ASSEMBLY LANGUAGE PROGRAMMING USING MASM SOFTWARE:
This software used to write a program (8086, Pentium processors etc.) The programs are written using assembly language in editor then compile it. The complier converts assembly language statements into machine language statements/checks for errors. Then execute the compiled program. Programs for different processor instructions (Pentium, 8086) programming manner differ for each model. There are different soft wares developed by different companies for assembly language programming are: MASM - Microsoft Company. TASM - Bore Land Company.
MERIT OF MASM:
1. produces binary code 2. Referring data items by their names rather than by their address.
HOW TO ENTER INTO MASM EDITOR: Click Start on the desktop. Then select Run
Then type Command (CMD) which enters You into DOS prompt
sa
ia
Path setting Then type CD\ Then the path is C :\> Then type CD MASM Then the path is C: MASM> www.saiadityaece.com
i.e.; C:\DOCUME\\ADMIN>CD\
dit ya ec e
1
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com Then type edit i.e.; C: MASM>edit Then you enter into MASM text editor. Then enter to file and select New.
And name it and then write the ALP (Assembly Language Program) in this editor. After that save it as filenames Then exit from the editor and go to prompt. Then type MASM filename.ASM I.e. C: MASM>MASM filename.ASM or C: MASM filename.ASM, , ; Then link this file using C: MASM>LINK filename.OBJ or C: MASM>LINK filename.OBJ , , ; i.e link the program in assembly with DOS then to debug to create exe file
Then it display -- on the screen After that type R displays the registers contents steps and starting step of the program.
Suppose you need to go for break point debugging. Then type that instruction no where you need to check your register. For example T10 it will display the contents of register after executing 10 instructions. DEBUG: This command utility enables to write and modify simple assembly language programs in an easy fashion. It provides away to run and test any program in a controlled environment. We can change any part of the program and immediately execute the program with an having to resemble it. We can also run machine language(Object files) directly by using DEBUG
ia
DEBUG COMMANDS:
ASSEMBLE A [address] address COMPARE DUMP C range address D [range] ENTER E address [list] beginning at specific www.saiadityaece.com
sa
dit ya ec e
; Assembly the instructions at a particular ; Compare two memory ranges ; Display contents of memory ; Enter new or modifies memory contents Location 2
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com FILL F range list GO HEX INPUT LOAD ; Fill in a range of memory
ia
MAP expanded memory pages www.saiadityaece.com
sa
dit ya ec e
; Add and subtract two Hex values L [address] [drive] [first sector] [number] M range address N [pathname] [arg list] O port byte P [=address] [number] R [register] S range list T [=address] [value] W [address] [drive] [first sector] [number] XA [#pages] XD [handle] XM [Lpage] [Ppage] [handle] 3
ABSTRACT: Assembly language program to perform all arithmetic operations on 8bit data PORTS USED: None
Step3: Copy the contents from memory location [0000] to AL Step4: Copy the contents from memory location [0001] to BL Step 5: Perform addition
sa
ia
Step8: Perform subtraction Step11: Perform multiplication
Step9: Move the result to the memory location [0003] Step10: Copy the contents from memory location [0000] to AL
Step13: Copy the contents from memory location [0000] to AL www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 4
dit ya ec e
Step16: stop.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 5
dit ya ec e
sa
ia
www.saiadityaece.com
dit ya ec e
Initialize data segment Copy the contents from memory location [0000] to AL Perform addition Move the result to the memory location [0002] Perform subtraction Move the result to the memory location [0003] Perform multiplication 1 6
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 7
dit ya ec e
Move the result to the memory location [0004] Copy the contents from memory location [0000] to AL Perform division Move the result to the memory location [0006] Stop
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT N1 EQU N2 EQU RESULT DB DATA ENDS CODE SEGMENT START: MOV MOV MOV MOV ADD
sa
MOV MOV
ia
AL, N1 AH, 00H BL MOV INT www.saiadityaece.com 21H
dit ya ec e
04H 06H 04H DUP (00) AX DS , DATA , AX , N1 N2 AL BL, AL, BL [RESULT], AL AL, N1 AL, BL [RESULT+1], AL AL, N1 BL [RESULT+2], AL [RESULT+3], AH [RESULT+4], AL [RESULT+5], AH AH, 4CH 8
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com CODE ENDS END START
Physical address Segment Effective address address OD64 0000 0003 0005 0008 000C 000E 0011 0014 0016 0019 001C 001E 0021 0025 0028
ia
B400 002A 002C 002F 0033 0035 F6F3 A20600 88260700 B44C CD21 www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonics Opcode Operand MOV AX,0D63 MOV DS,AX Comments B8630D 8ED8 ;Initialize data segment A00000 MOV AL,[0000] MOV BL,[0001] ADD AL,BL ;Move the contents to AL ;Move the contents to BL 8A1E0100 02C3 ;Add BL contents with AL ;Move the contents to memory ;Move the contents to AL A20200 A00000 2AC3 MOV [0002],AL MOV AL,[0000] SUB AL,BL A20300 A00000 F6E3 MOV [0003],AL MOV AL,[0000] MUL BL ;Subtract BL contents with AL ;Move the contents to memory ;Move the contents to AL A20400 MOV [0004],AL ;Multiply the contents of BLwithAL ;Move the contents from AH ;Move the contents to AH ;Move the contents to AL 88260500 A00000 MOV [0005],AH MOV AL,[0000] MOV AH,00 DIV BL ;Move 00 into AH register ;Division the contents of BL with AL ;Move the contents to AL ;Move the contents from AH ;Terminate the Program ;Stop MOV [0006],AL MOV [0007],AH MOV AH,4C INT 21 9
CODE TABLE:
sa
ia
RESULT:
ABSTRACT: Assembly language program to perform all arithmetic operations on 16bit data www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 10
dit ya ec e
D 0000 04 06 0A FE 18 00 00 04
Step4: Move the contents from memory location [0000] to AX Step5: Move the contents from memory location [0001] to BX Step6: Perform addition
Step8: Copy the contents from the memory location [0000] to AX Step9: Perform subtraction
Step11: Copy the contents from the memory location [0000] to AX Step12: Perform multiplication
sa
ia
Step17: Stop. www.saiadityaece.com
dit ya ec e
11
sa
ia
www.saiadityaece.com :
dit ya ec e
Initialize data segment Load SI with memory location 5000 Move the contents from memory location [0000] to AX Move the contents from memory location [0001] to BX Perform addition Move the result to the memory location specified Copy the contents from the memory location [0000] to AX] Perform subtraction Move the result to the memory location [SI+02] 1 12
ia
www.saiadityaece.com
sa
dit ya ec e
1 Perform multiplication Perform division Stop 13
ASSUME
DATA SEGMENT N1 EQU 8888H N2 EQU 4444H DATA ENDS CODE SEGMENT
sa
INT CODE ENDS
ia
DX, 0000 BX MOV MOV MOV [SI+8], AX AH, 4CH 21H END START www.saiadityaece.com
dit ya ec e
CS: CODE, DS: DATA AX, DATA DS, AX SI, 5000H AX, N1 BX, N2 AX, BX [SI], AX AX, N1 AX, BX [SI+2], AX AX, N1 BX [SI+4], AX [SI+6], DX AX, N1 [SI+0AH], DX 14
PROGRAM:
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com CODE TABLE: Physical address Segment Effective address address 0D64 0000 0003 0005 0008
ia
0029 002C 002E 0031 0034 0036 www.saiadityaece.com
sa
dit ya ec e
B8 63 0D 8E D8 MOV MOV MOV MOV MOV ADD AX,0D63 DS,AX BE 00 50 A1 00 00 SI,5000 AX,[0000] BX,[0002] 000B 000F 0011 0013 0016 0018 8B 1E 02 00 03 C3 89 AX,BX 04 MOV MOV SUB [SI],AX A1 00 00 2B C3 AX,[0000] 89 44 02 MOV MOV MUL 001B 001E 0020 0023 0026 A1 00 00 F7 E3 89 44 04 89 54 06 MOV MOV MOV MOV DIV MOV MOV MOV INT A1 00 00 BA 00 00 F7 F3 89 44 08 89 54 0A B4 CD 4C 21 BX 21h 15
Label
Hex code
Mnemonic
Operand
Comments
;Initialize SI with 5000 ;copy the contents of 0000 ;Copy the contents of 0002 ;Add the contents of AX with BX ;Copy the result in [SI]
;copy the contents of 0000 AX,BX ;Subtract the contents of AX with BX [SI+02],AX ;Move the result into [SI+2] AX,[0000] ;Copy the contents of 0000 BX ;Multiply AX with BX [SI+04]AX ;Move the lower word of result into [SI+4] [SI+06],BX ;Move the higher word of result into [SI+6] AX,[0000] ;Copy the contents of 0000 DX,0000 ;Initialize DX with 0000
;Perform division with BX [SI+08],AX ;Move the quotient into [SI+8] [SI+0AH],AX ;Move the remainder into [SI+0A] AH,4C ;Terminate the program
sa
ia
RESULT: D 5000: 00 00 00 CC CC 44 44 20 64 68 24 02
dit ya ec e
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com ABSTRACT: Assembly language program to perform multibyte addition and subtraction PORT USED: None
Step5: Copy the contents from the memory location n1 [bx] to AL Step6: Perform addition with second number n2 [bx]
Step7: Move the result to the memory location sum [bx] Step8: Decrement BX
Step9: Decrement CX, if CX not equal to Zero jump to step5 Step10: Load CX register with count
sa
ia
Step15: Decrement BX Step17: Stop www.saiadityaece.com
dit ya ec e
17
ia
www.saiadityaece.com
sa
dit ya ec e
Initialize data segment Get count into CX register Load the BX register with no: of bytes Copy the contents from the memory location n1 [bx] to AL Perform addition with second number n2 [bx] Move the result to the memory location sum [bx] Decrement BX Decrement CX, & CX = 0 NO YES 1 18
ia
www.saiadityaece.com
sa
dit ya ec e
Get count into CX register & Load BX register with no of bytes Perform subtraction with second number n2 [bx] Move the result to the memory location sum [bx] Decrement BX Decrement CX, & If CX = 0 NO YES Stop 19
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT N1 DB 33H, 33H, 33H N2 DB 11H, 11H, 11H COUNT EQU 0003H SUM DB 03H DUP (00) DIFF DB 03H DUP (00) DATA ENDS CODE SEGMENT ORG 1000H START: MOV AX, DATA MOV DS, AX
BACK:
sa
ia
BACK1: MOV AL, N1 [BX] SBB DEC BX LOOP BACK1 MOV AH, 4CH INT 21H www.saiadityaece.com
dit ya ec e
MOV CX, COUNT MOV BX, 0002H CLC MOV AL, N1 [BX] ADC AL, N2 [BX] MOV SUM [BX], AL DEC BX LOOP BACK MOV CX, COUNT MOV BX, 0002H AL, N2 [BX] MOV DIFF [BX], AL 20
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com CODE ENDS END START CODE TABLE: Physical address Segment Effective address address 0D64 1000 1003 1005 1008 100B 100F 1013 1017 1018 101A 101D 1020 1024 1028 102C 102D 102F 1031
ia
4B E2 F1 B4 4C CD 21 RESULT: www.saiadityaece.com
sa
D 0000: 33 33 33 11 11 11 44 44 44 22 22 22
dit ya ec e
Lab el Hex code Mnemonic Operand comments B8 63 0D 8E D8 MOV MOV MOV MOV MOV ADC AX,0D63 ;Initialize the data segment DS,AX B9 03 00 CX,0003 BB 02 00 BX,0002 L1 8A 87 00 00 12 87 00 00 88 87 06 00 4B AL,[BX+0000] AL,[BX+0003] MOV DEC [BX+0006],AL BX E2 F1 LOOP MOV MOV MOV SBB L1 B9 03 00 CX,0003 BX,0002 BB 02 00 L2 8A 87 00 00 1A 87 03 00 88 87 09 00 AL,[BX+0000] AL,[BX+0003] MOV DEC LOOP MOV INT [BX+0009],AL BX 1020 AH,4C 21 ;Terminate the program 21
;Initialize the count CX with 0003 ;Move the value 02 in BX register ;Copy the contents of BX+0000 ;Perform ADC with[BX+0000] ;Move the result in BX+0006 location ;Decrement the contents of BX ;Decrement the counter and go to L1 until CX is zero ;Initialize the counter CX with 0003 ;Move the number 02 in BX register ;Copy the contents of BX+0000 ;Perform SBB with [BX+0003] ;Move the result in BX+0009 location ;Decrement the contents of BX ;Decrement the counter and go to L2 until CX is zero
ABSTRACT: Assembly language program to perform signed operations PORT USED: None
Step7: Move the result to the memory location [0000] Step8: Load AL with first number Step9: Negate the contents of AL Step11: Perform signed division
sa
ia
Step13: Stop www.saiadityaece.com
dit ya ec e
2 d) SIGNED OPERATIONS ON 8 BIT DATA
22
ia
www.saiadityaece.com
sa
dit ya ec e
Initialize data segment Get a first number in AL register Negate the contents of AL Load BL with second number Perform signed Multiplication Move the result to the memory location [0000] Get a first number in AL register Negate the contents of AL 1 23
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 24
dit ya ec e
Stop
ASSUME CS: CODE , DS: DATA DATA SEGMENT N1 DB 08H N2 DB 04H RESULT DW 02 DUP (00) DATA ENDS CODE SEGMENT START:
sa
ia
IDIV BL INT 21H CODE ENDS END START www.saiadityaece.com
dit ya ec e
MOV AX, DATA MOV DS, AX MOV AL, N1 NEG AL CBW MOV BL, N2 IMUL BL MOV [RESULT], AX MOV AL, N1 NEG AL CBW MOV [RESULT+2], AX MOV AH, 4CH 25
PROGRAM:
Effective address 0000 0003 0005 0008 000A 000B 000F 0011 0014 0017 0019 001A 001C 001F 0021
ia
CD 21 RESULT: D 0000: 08 04 E0 FF FE 00 www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonic Operand comments B8 63 0D 8E D8 MOV MOV MOV NEG AX,0D63 DS,AX A0 00 00 F6D8 98 AL,[0000] ;Copy the [0000] in AL AL ;Negate contents of AL ;Convert Byte to Word CBW 8A 1E 01 00 F6 EB MOV BL,[0001] BL ;Get second number in BL ;Perform IMUL with BL IMUL MOV MOV NEG A3 02 00 A0 00 00 F6 D8 98 [0002],AX AL,[0000] ;Get first number in AL AL ;Negate the contents of AL ;Convert Byte to Word CBW IDIV F6 FB BL ;Perform IDIV with BL A3 04 00 B4 4C MOV MOV INT [0004],AX AH,4C ;Terminate the program 21 26
CODE TABLE:
ABSTRACT: Assembly language program to perform ASCII arithmetic operations PORT USED: None
Step3: Load SI with Memory location Step4: Load AL with first number
Step8: Copy the result to the memory location [SI] Step9: Load AL with first number Step10: Perform subtraction
Step12: Copy the result to the memory location [SI+01] Step13: Load AL with first number Step14: Perform multiplication
sa
ia
Step17: Load AL with first number Step18: Perform division Step21: Stop www.saiadityaece.com
Step19: Perform ASCII adjustment before division Step20: Copy the result to the memory location [SI+03]
dit ya ec e
27
sa
ia
www.saiadityaece.com
dit ya ec e
Initialize data segment Initialize SI with memory location Get a first ASCII no in AL register Get second ASCII no in BL register Perform addition Perform ASCII adjustment after addition Copy the result to the memory location [SI] Get first ASCII no in AL register & second ASCII no in BL register Perform subtraction 1 28
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com 1 Perform ASCII adjustment after subtraction
sa
ia
www.saiadityaece.com
dit ya ec e
Get first ASCII no in AL register & second ASCII no in BL register Perform multiplication Get first ASCII no in AL register & second ASCII no in BL register Perform division Perform ASCII adjustment before division Stop 29
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT N1 DB 8 N2 DB 4 DATA ENDS CODE SEGMENT ORG 1000H START:
sa
ia
AAS AAM www.saiadityaece.com
dit ya ec e
MOV AX, DATA MOV DS, AX MOV SI, 1000H XOR AX, AX XOR BX, BX MOV AL, N1 MOV BL, N2 ADD AX, BX AAA MOV [SI], AX MOV AL, N1 MOV AH,00 SUB AL, BL MOV [SI+2], AX MOV AL, 08H MOV BL, 04H MUL BL MOV [SI+4], AX 30
CODE TABLE:
Effective address 1000 1003 1005 1008 100A 100C 100F 1013 1015 1016 1018
ia
02 C3 37 89 04 A0 00 00 2A C3 101B www.saiadityaece.com
sa
dit ya ec e
DIV BL MOV [SI+6], AX MOV AH, 4CH INT 21H CODE ENDS END START Label Hex code Mnemonic Operand comments B8 63 0D 8E D8 MOV MOV MOV XOR XOR AX,0D63 DS,AX ;Initialize data segment BE 00 10 33 C0 SI,1000 ;Initialize SI with 1000 AX,AX BX,BX 33 DB A0 00 00 MOV MOV ADD AAA MOV MOV SUB [SI],AX AL,[0000] AL,BL AL,[0000] ;Perform XOR operation on AX ;Perform XOR operation on BX ;Get first no. in AL ;Get second no. in BL ;Perform ADD AL , Bl ;Perform AAA ;Move the result in[SI] ;Get first no. in AL ;Perform SUB AL, BL ;Perform AAS 8A 1E 01 00 BL,[0001] AL,BL 31
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com 101D 101E 1021 1023 1025 1027 1029 102C 102E 1031 1033 1035 3F 89 44 02 B0 08 B3 04 AAS ;Move the result in [SI+2] MOV MOV MOV MUL [SI+02],AX ;Load AL with 08h ;Load BL with 04h AL,08
RESULT:
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 32
D 1000: 02 01 04 00 02 03 08 00
dit ya ec e
BL,04 BL ;Perform MUL with BL ; Perform AAM F6 E3 D4 0A AAM ;Move the result in [SI+4] ; Perform AAD 89 44 04 D5 0A F6 F3 MOV AAD DIV [SI+04],AX ;Perform division with BL ;Move the result in [SI+6] ;Terminate the program BL 89 44 06 B4 4C MOV MOV INT [SI+06],AX AH,4C CD 21 21
ABSTRACT: Assembly language program to convert BCD number to ASCII number PORT USED: None
Step6: Perform AND operation AL with 0F Step7: Perform AND operation AL with F0 Step8: Rotate the AH contents
sa
ia
Step12: Stop www.saiadityaece.com
dit ya ec e
3 a) BCD TO ASCII CONVERSION
33
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 34
dit ya ec e
sa
ia
www.saiadityaece.com
dit ya ec e
Initialize data segment Get BCD no in AL register Load the count 04 in CX register Copy the contents from AL to AH Perform AND operation AL with 0F Perform AND operation AL with F0 Rotate the AH contents Perform OR operation AL with 30 Perform OR operation AH with 30 Move the result to the memory location 35
ASSUME CS: CODE, DATA SEGMENT BCD DB 17H ASCII DW ? DATA ENDS
ia
CODE ENDS END START www.saiadityaece.com
sa
dit ya ec e
DS: DATA MOV AX, DATA MOV DS, AX MOV AL, BCD MOV CL, 04 MOV AH, AL AND AL, 0FH AND AH, 0F0H ROR AH, CL OR AL, 30H OR AH, 30H MOV ASCII, AX MOV AH, 4CH INT 21H 36
sa
ia
RESULT: D 0000: 17 37 31 www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 37
dit ya ec e
Effective address 1000 1003 1005 1007 1009 B8630D 8ED8 B017 B104 MOV MOV MOV MOV MOV AND AND AX,0D63 DS,AX AL,17 ;initialize data segment ;Get a number in AL CX,0004 8AE0 240F AH,AL 100B AL,0F 100D 1010 1012 1014 1017 80E4F0 D2CC 0C30 AH,F0 ROR OR OR AH,CL AL,30 ;Rotate right AH, CL 80CC30 A30100 B44C AH,30 MOV MOV INT [0001],AX AH,4C 21 101A 101C CD21
Physical address
Label
Hex code
Mnemonic Operand
comments
;Initialize CX with 0004 ;Copy the contents of AL ;Perform AND ALwith 0F ;Perform AND AHwith F0
;Perform OR AL with 30 ;Perform OR AH with 30 ;Move the result in [0001] ;Terminate the program
ABSTRACT: Assembly language program convert ASCII number to BCD number PORT USED: None
Step3: Load AL with first ASCII number Step4: Load CX register with count 04
Step5: Load BL with second ASCII number Step6: Perform AND operation AL with 0F Step7: Perform AND operation BL with 0F
Step8: Rotate the contents of AL with CL count Step9: Perform OR operation AL with BL
sa
ia
Step11: Stop www.saiadityaece.com
dit ya ec e
3 b) ASCII TO BCD CONVERSION
38
sa
ia
www.saiadityaece.com
dit ya ec e
Initialize data segment Get first ASCII no in AL register Load CX register with a count 04 Get second ASCII no in BL register Perform AND operation AL with 0F Perform AND operation BL with 0F Rotate the contents of AL with CL count Perform OR operation AL with BL Move the result to the memory location Stop 39
ASSUME
START:
sa
ia
OR AL, BL INT 21H CODE ENDS END START www.saiadityaece.com
dit ya ec e
CS: CODE, DS: DATA MOV AX, DATA MOV DS, AX MOV CL, 04H MOV AL, ASCII1 MOV BL, ASCII2 AND AL, 0FH AND BL, 0FH ROR AL, CL MOV BCD, AL MOV AH, 4CH 40
Effective address 1000 1003 1005 1007 100A 100E 1010 1013 1015 1017 101A 101C
ia
RESULT: D 0000: 31 37 www.saiadityaece.com
sa
dit ya ec e
B8 63 0D 8E D8 B1 04 MOV MOV MOV MOV MOV AND AND AX,0D63 ;Initialize data segment DS,AX CL,04 A0 00 00 AL,[0000] ;Get 1st no. in AL register 8A 1E 01 00 24 0F BL.[0001] ;Get 2nd no. in BL register AL,0F 80 E3 0F D2 C8 0A C3 BL,0F ROR OR AL,CL ;Rotate right AL , CL AL,BL ;Perform OR, AL with BL ;Move the result in [0002] ; Terminate the program A2 02 00 B4 4C MOV MOV INT [0002],AL AH,4C 21 CD 21 17 41
Physical address
Mnemonic
Operand
comments
ABSTRACT: Assembly language program to count number of positive and negative numbers PORT USED: None
Step3: Load CX register with count Step4: Initialize DX with 0000 Step5: Load SI with offset list
Step6: Move the contents from memory location SI to AL Step7: Rotate left the contents of AL Step8: Jump to step13 if carry Step9: Increment DL
Step10: Increment SI
sa
Step17: Stop
ia
Step12: Jump to step16 Step13: Increment DH Step14: Increment SI www.saiadityaece.com
Step15: Decrement CX and jump to step6 if no zero Step16: Move the result to the memory location
dit ya ec e
42
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 43
dit ya ec e
ia
2 3 www.saiadityaece.com
sa
dit ya ec e
Initialize data segment and Load SI with offset list & Get a count with CX register & Initialize DX with 0000 Move the contents from memory location SI to AL Rotate the contents of AL to left NO If carry equal to zero YES Increment DL and Increment SI Decrement CX& If CX=0 YES JMP NO 4 1 44
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 45
dit ya ec e
Increment DH & Increment SI Increment SI Decrement CX If CX=0 NO YES Move the result to the memory location Stop
DATA SEGMENT LIST DB 0FFH, 0DDH, 04H, 05H, 98H RESULT DW ? DATA ENDS CODE SEGMENT ORG 1000H START:
BACK:
sa
EXIT:
ia
JMP EXIT NEGATIVE: INC DH INC SI INT 21H www.saiadityaece.com
dit ya ec e
CS: CODE, DS: DATA MOV AX, DATA MOV DS, AX LEA SI, LIST MOV CX, 0005H MOV DX, 0000H MOV AL, [SI] ROL AL, 01H JC NEGATIVE INC DL INC SI LOOP BACK LOOP BACK MOV [RESULT], DX MOV AH, 4CH 46
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com CODE ENDS END START
CODE TABLE: Physical address Segment Effective address address 0D64 1000 1003 1005 1009 100C 100E 1010 1012 1014 1015 1017 1019 101A 101C 101D 101F 1023 1025
ia
46 E2ED L2 B44C CD21 RESULT: www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonic Operand Comments B8630D 8ED8 MOV MOV AX,0D63 ;Initialize the data segment ; DS,AX 8B360000 LEA B90500 8A04 SI,[0000] CX,0005 AL,[SI] AL,01 L1 MOV MOV ROL JB Back D0C0 7208 ; Load Effective addr. SI With 0000 ;Initialize the count CX with 0005 ;Copy the number of [SI] in AL ;Rotate Left AL , 01 ;If Barrow jump L1 FEC2 46 INC INC DL SI ; Increment value of DL ;Increment value of SI E2F5 LOOP JMP Back EB06 90 L2 ;Decrement count and go to Back until CX = 0 ;Go to L2 without condition ;No Operation NOP INC INC LOOP L1 FEC6 DH :Decrement value of DH ;Increment value of SI ;Decrement counter and go to Back until CX=0 ;Move the result in [0005] location ;Terminate the program 21 SI Back [0005],DX AH,4C 89160500 MOV MOV INT 47
ABSTRACT: Assembly language program to count number of odd and even numbers PORT USED: None
Step3: Load CX register with count Step4: Initialize DX with 0000 Step5: Load SI with offset list
Step6: Move the contents from memory location SI to AL Step7: Rotate right the contents of AL Step8: Jump to step13 if carry Step9: Increment DL Step10: Increment SI
Step11: Decrement CX and jump to step6 if no zero Step12: Jump to step16 Step13: Increment DH Step14: Increment SI
sa
ia
Step17: Stop www.saiadityaece.com
Step15: Decrement CX and jump to step6 if no zero Step16: Move the result to the memory location
dit ya ec e
3 d) NO OF ODD AND EVEN NUMBERS
48
ia
2 3 www.saiadityaece.com
sa
dit ya ec e
Initialize data segment and Load SI with offset list & Get a count with CX register & Initialize DX with 0000 Move the contents from memory location SI to AL Rotate the contents of AL to right NO If carry equal to zero YES Increment DL and Increment SI Decrement CX& If CX=0 YES JMP NO 4 1 49
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 50
dit ya ec e
Increment DH & Increment SI Increment SI Decrement CX If CX=0 NO YES Move the result to the memory location Start
sa
CODE ENDS END START
ia
ODD: EXIT: www.saiadityaece.com
dit ya ec e
ASSUME CS: CODE, DS: DATA DATA SEGMENT LIST DB 05H,01H,03H,04H,08H,02H COUNT DW 0006H RESULT DW ? DATA ENDS CODE SEGMENT ORG 1000H START: MOV AX, DATA MOV DS, AX MOV CX, COUNT MOV DX, 0000H MOV SI, OFFSET LIST MOV AL, [SI] ROR AL, 01H JC ODD INC DL INC SI BACK: LOOP BACK JMP EXIT INC DH INC SI LOOP BACK MOV [RESULT], DX MOV AH, 4CH INT 21H 51
ia
46 E2 ED L2 B4 4C CD 21 www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonic Operand comments B8 63 0D 8E D8 MOV MOV AX,0D63 DS,AX ;Initialize the data segment 8B 0E 06 00 MOV BA 00 00 BE 00 00 8A 04 MOV MOV MOV ROR JB CX,[0006] DX,0000 SI,0000 ;Load the 1st no. in AL ;Rotate right AL,01 ;If Barrow go to L1 Back AL,[SI] D0 C8 F2 08 AL,01 L1 FE C2 46 INC INC DL ;Increment the value of SI SI E2 F5 LOOP JMP Back L2 EB 06 90 NOP INC INC LOOP MOV MOV INT L1 FE C6 DH SI Back [0008],DX AH,4C 21 ;Increment the Value of SI 89 16 08 00 ;Terminate the program 52
CODE TABLE:
;Initialize counter with [0006] ;Initialize DX register with 0000 ;Initialize SI with 0000
;Decrement counter and go to Back until CX=0 ;Go to L2 without unconditional ;No Operation ;Increment the value of DH
;Decrement counter and go to Back until CX=0 ;Move the result in register DX
ABSTRACT: Write a program to convert packed BCD number into Unpacked BCD number. REGISTERS USED: AL, BL PORTS USED: None. ALOGARITHM: Step1: Start
Step3: Move packed number into AL register Step4: Move packed number into BL register Step5: Initialize the count CX with 04h. Step6: AND operation AL with 0Fh.
Step8: Rotate right without carry operation on BL by CL times. Step9: Move the result into location 0000 and 0001. Step10: Stop.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 53
dit ya ec e
FLOW CHART
sa
ia
www.saiadityaece.com
dit ya ec e
Start Initialize the data segment Move the number 29 into AL register & Move the value 29h into BL register Initialize the counter CX with 0004 Logical AND ed between AL & 0Fh and Logical AND ed between BL & 0F0h 1 54
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 55
dit ya ec e
1 Rotate right BL with 04h times Store the result in 0000 and 0001 location Stop
PROGRAM: ASSUME
sa
CODE ENDS
ia
END START www.saiadityaece.com
dit ya ec e
CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV AL, N MOV BL, N MOV CL, 04H AND AL, 0Fh AND BL, 0F0h ROR BL, CL MOV [RESULT], BL MOV [RESULT+1], AL MOV AH, 4Ch INT 21h 56
CODE TABLE:
ia
2019 201B RESULT: D 0B42:0000 29 www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonic Comments Effective address 2000 2003 2005 2007 2009 Op code operands AX,0B3B B8 3B 0B 8E D8 B1 04 B8 29 B3 29 24 0F MOV MOV MOV MOV MOV AND AND DS, AX CL,04h 200B 200D 2010 2012 2016 80 E3 F0 D2 CB ROR 88 1E 00 00 A2 01 00 8A 07 CD 21 MOV MOV MOV INT 02 09 57
; Initialize the count with 04h AL, N ;Packed number in AL BL, N ;Packed number in BL AL,0Fh ;AND Operation AL with 0F BL, 0F0h ;AND Operation BL with F0 BL,CL ;Rotate right BL, Cl [0000],AL ; Move the result in [0000] [0001], BL ;Move the result in [0001] AH, 4Ch ;Terminate the program 21 ;Stop
ABSTRACT: Assembly language program to transfer a block of data. PORT USED: None.
Step2: Initialize data segment & extra segment Step3: Load CX register with count
Step4: Initialize DI with memory location Step5: Load SI with offset list
Step6: Repeat the process of moving string byte from SI to DI until count equals to zero Step7: Stop
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 58
dit ya ec e
4 a) TRANSFER BLOCK OF DATA
Repeat the process of moving string byte from SI to DI until count equals to zero
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 59
dit ya ec e
Initialize data segment and Initialize extra segment Load CX register with count Initialize DI with memory location & load SI with offset list Stop
DATA SEGMENT
sa
ia
CODE ENDS END START www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 60
dit ya ec e
CS: CODE, DS: DATA, ES: DATA MOV AX, DATA MOV DS, AX MOV ES, AX MOV CX, COUNT MOV DI, 5000H LEA SI, LIST REP MOVSB MOV AH, 4CH INT 21H
RESULT: D 0000:
ia
S I I 79 Y 14 $ A D 5000: 73 S 69 I 79 www.saiadityaece.com 72 74 R T 61 69 I 14
sa
dit ya ec e
Label Hex code Mnemonic Operand Comments B8 63 0D 8E D8 MOV MOV MOV MOV MOV LEA AX,0D63 DS,AX ;Initialize the data segment BE C0 ES,AX B9 06 00 BF 00 50 CX,0014 DI,5000 8D 36 00 00 F3 A4 SI,[0000] REPZ MOV INT B4 4C CD 21 21 ;Stop 73 69 72 74 R T 61 69 20 73 61 69 I 20 61 64 S A A D 20 73 S 61 A 69 I 20 61 A 64 D 61
ABSTRACT: Assembly language program to reverse a given string PORT USED: None
Step2: Initialize data segment & extra segment Step3: Load CX register with count
Step4: Copy the contents from CX to AX Step5: Load SI with offset list
sa
Step16: Stop
ia
Step13: Increment SI Step14: Decrement DI www.saiadityaece.com
Step11: Exchange the contents of AL with [DI] Step12: Move the contents from memory location AL to SI
dit ya ec e
4 b) REVERSAL OF GIVEN STRING
62
FLOW CHART
ia
www.saiadityaece.com
sa
dit ya ec e
Start Initialize data segment and Initialize extra segment load CX with count and SI with offset list Initialize DI with count-1 and Initialize BX with 02h 1 63
ia
www.saiadityaece.com
sa
dit ya ec e
1 Copy the contents from AX to CX and move the contents from SI to AL Exchange the contents of AL to [DI] and move the contents from AL to SI Increment SI and Decrement DI Decrement CX and if CX=0 YES NO Stop 64
PROGRAM: ASSUME
DATA SEGMENT
sa
ia
INC SI DEC DI INT 21H CODE ENDS END START www.saiadityaece.com
BACK:
dit ya ec e
CS: CODE, DS: DATA MOV AX, DATA MOV DS, AX MOV ES, AX MOV CX, COUNT MOV AX, CX MOV SI, OFFSET LIST MOV DI, (COUNT-1) MOV BX, 02 DIV BXS MOV CX, AX MOV AL,[SI] XCHG AL,[DI] MOV [SI], AL LOOP BACK MOV AH, 4CH 65
CODE TABLE: Physical address Segment Effective address address 0D64 1000 1003 1005 1007 100A 100C 100F 1012 1015 1017 101A 101B
ia
86 05 88 04 46 101D 101F 1020 1021 1023 1025 4F E2 F6 B4 4C CD 21 www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonic Operand Comments B8 63 0D 8E D8 8E C0 MOV MOV MOV MOV MOV MOV MOV MOV DIV AX,0D63 DS,AX ES,AX ;Initialize the data segment ;Initialize the extra segment ;Initialize the counter with 000F ;Load AX with CX value ;Initialize SI with 0000 B9 0F 00 8B C1 CX,000F AX,CX BE 00 00 SI,0000 BF 0E 00 BB 02 00 F7 F3 8B C8 8A 04 DI,000E ;Initialize DI with 000e BX,0002 ;Move the value 02 in BX BX ;Division operation with BX ;Move AX value in CX ;Load the 1st no. in AL ;Exchange AL,[DI] ;Move the no in AL into [SI] ;Increment the value of SI ;Decrement the value of DI ;Decrement the counter and go to Back until CX=0 ;Terminate the program ;Stop MOV MOV CX,AX Back AL,[SI] XCHG MOV INC DEC LOOP MOV INT AL,[DI] [SI],AL SI DI Back AH,4C 21 66
ia
RESULT: D 0000: 72 6D R 6F 73 73 O S S E M
sa
ABSTRACT: Assembly language program to do sorting of numbers in a given series www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 67
dit ya ec e
65 63 6F 72 70 20 6F 72 63 69 C O R P O R C I
4 C) SORTING OF N NUMBERS
Step4: Copy the contents from CX to DX Step5: Load SI with offset list
sa
ia
Step17: Stop www.saiadityaece.com
dit ya ec e
68
ia
4 2 www.saiadityaece.com
sa
dit ya ec e
Initialize data segment and Load SI with offset list & Get a count with CX register Copy the contents from CX to DX Copy to contents from SI to AL register Increment SI Compare the contents of AL and SI YES If carry equal to zero NO Exchange the contents of AL & SI 3 1 69
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 70
dit ya ec e
Decrement SI & move the contents of AL into SI Increment SI Decrement CX If CX =0 NO YES NO Decrement DX If DX=0 YES Start
sa
ia
NEXT: www.saiadityaece.com
dit ya ec e
ASSUME CS: CODE, DS: DATA DATA SEGMENT LIST DB 56H, 12H, 72H,32H COUNT EQU 0003H DATA ENDS CODE SEGMENT ORG 1000H START: MOV AX, DATA MOV DS, AX MOV CX, COUNT MOV DX, CX AGAIN: MOV SI, OFFSET LIST MOV CX, DX BACK: MOV AL, [SI] INC SI CMP AL, [SI] JC NEXT XCHG [SI], AL DEC SI MOV [SI], AL INC SI LOOP BACK DEC DX JNZ AGAIN MOV AH, 4CH INT 21H 71
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com CODE ENDS END START
ia
101C 101E 101F 1021 1023 L1 4A www.saiadityaece.com
101B
sa
dit ya ec e
Label Hex code Mnemonic Operands Comments B8 63 0D 8E D8 MOV MOV MOV MOV MOV MOV MOV INC AX,0D63 DS,AX B9 03 00 8B D1 CX,0003 DX,CX L2 BE 00 00 8B CA 8A 04 46 SI,0000 ;Initialize SI with 0000 CX,DX Back AL,[SI] SI ;Get 1st no. in AL ;Increment value of SI ;Compare AL,[SI] 3A 04 72 06 86 04 4E CMP JB AL,[SI] L1 ;If barrow go to L1 XCHG DEC AL,[SI] SI 88 04 46 MOV INC [SI],AL SI ;Copy the AL reg into [SI] ;Increment the value of SI E2 F1 LOOP DEC JNZ MOV INT Back DX L2 AH,4C 21 75 E9 ;Jump no zero go to L2 ;Terminate the program B4 4C CD 21 72
CODE TABLE:
ABSTRACT: Assembly language program to find the Length of a string PORT USED: None
Step2: Initialize data segment & extra segment Step3: Load AL with $
Step6: Scan string byte from DI memory location until AL =ES: DI Step7: Jump to step10 if equal Step8: Increment DX Step9: Jump to step6
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 73
dit ya ec e
sa
ia
www.saiadityaece.com
dit ya ec e
Initialize data segment and Initialize extra segment Load AL with $ and SI with offset list Initialize DX with 0000h YES If equal NO Increment DX and jump to back Move the result to the memory location Stop 74
sa
ia
CODE ENDS END START www.saiadityaece.com
dit ya ec e
ASSUME CS: CODE, DS: DATA, ES: DATA DATA SEGMENT LIST DB SRI SAI ADITYA$ LEN DW ? DATA ENDS CODE SEGMENT ORG 1000H START: MOV AX, DATA MOV DS, AX MOV ES, AX MOV AL,$ LEA SI, LIST MOV DX, 0000H SCASB BACK: JE EXIT INC DX JMP BACK EXIT: MOV LEN, DX MOV AH, 4CH INT 21H 75
PROGRAM:
101A 101C
ia
RESULT: D 0000: 73 S 69 I 79 Y 72 74 R T 61 A 69 I 14 $ www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonic Operands Comments B8 63 0D 8E D8 8E C0 B0 24 MOV MOV MOV MOV LEA AX,0D63 DS,AX ES,AX AL,24 8D3600 00 BA0000 AE SI,[0000] DX,0000 MOV L2 SCASB JZ 74 03 42 L1 INC DX L2 EBFA JMP L1 8916 0700 B44C MOV MOV INT [0007],DX AH,4C 21 CD21 20 73 S 61 A 69 I 20 61 A 64 D 76
CODE TABLE:
;Load SI Effective address ;Initialize the DX with ;Scan string byte with SI ;If equal to zero go to L
ABSTRACT: Assembly language program to compare two strings. PORT USED: None
Step2: Initialize data segment & extra segment Step3: Load AX with length1 Step4: Load BX with length2
Step7: Copy the contents from AX to CX Step8: Load SI with first string
sa
ia
Step13: Jump to step 15 Step15: Stop www.saiadityaece.com
Step11: jump to step 14 if not equal Step12: Move the result to the memory location
dit ya ec e
4 e) COMPARISON OF TWO STRINGS
77
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 78
dit ya ec e
sa
2
ia
www.saiadityaece.com
dit ya ec e
Initialize data segment and Initialize extra segment Load AX with length 1 and Load BX with length 2 Compare AX with BX NO If equal YES Copy the contents from AX to CX Load SI with first string & Load DI with second string 1 79
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 80
dit ya ec e
NO If equal YES Move the result to the memory location Move another result to the memory location Stop
DATA ENDS
sa
CODE ENDS END START
ia
MOV JMP EXIT: MOV MOV INT NEXT: 21H www.saiadityaece.com
dit ya ec e
CS: CODE, DS: DATA, ES: DATA DB SRI SAI ADITYA EQU ($-LIST1) DB SRI SAI ADITYA EQU ($-LIST2) DW ? MOV MOV MOV MOV MOV CMP JNE AX, DATA DS, AX ES, AX AX.LEN1 BX, LEN2 AX, BX EXIT MOV MOV MOV REP JNE CX, AX SI, OFFSET LIST1 DI, OFFSET LIST2 CMPSB EXIT RESULT, 5555H NEXT RESULT, 0FFFFH AH, 4CH 81
PROGRAMS:
101B
ia
90 L1 L2 102C 102E www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonics Operands Comments B8 63 0D 8E D8 8E C0 MOV MOV MOV MOV MOV CMP JNZ AX,0D63 DS,AX ES,AX segment B8 06 00 AX,0006 BB 06 00 3B C3 75 15 BX,0006 AX,BX L1 ;If no 0 go to L1 8B C8 MOV MOV MOV CX,AX BE 00 00 BF 06 00 F3 A6 75 09 SI,0000 DI,0006 REPZ JNZ CMPSB L1 ;If no 0 go to L1 C7060C005555 EB07 MOV JMP PTR[000C],5555 L2 NOP MOV MOV INT PTR[000C],FFFF AH,4C 21 ;No Operation C7060C00FFFF B44C CD21 82
;Compare AX with B
;Copy the contents o AX into CX ;Initialize SI with 00 ;Load DI with 0006 ;Compare with SI
sa
ia
REGISTERS USED: AH, AL, SI. PORTS USED: None. www.saiadityaece.com
dit ya ec e
5 a) READING KEYBOARD (WITH Echo)
83
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com ALGORITHM: Step1: Start. Step2: Load the number 13h into AL register. Step3: Initialize the AH register with 00 Step4: Key board Interrupt
Step7: Compare the data in AL register and character q. Step8: If equal to zero go to step 12.
Step10: Move the number 14h into AH register. Step11: Keyboard Interrupt.
sa
ia
PROGRAM: ORG 1000h START: www.saiadityaece.com
dit ya ec e
ASSUME CS: CODE, DS: DATA CODE SEGMENT MOV AL, 13h 84
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com MOV AH, 00 INT 10h BACK:
EXIT:
sa
ia
CODE TABLE: Segment Effective Label Hex base address code address 0B3D 1000 B0 13 www.saiadityaece.com Mnemonics Operands Comment MOV AL, 13 ;Move the 13 into AL register SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 85
dit ya ec e
MOV AH, 00h INT 16h CMP AL, q JE EXIT MOV BL, 0Fh MOV AH, 14h INT 10h JMP BACK MOV AH, 4Ch INT 21h
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com 1002 B4 00 MOV AH, 00 ;Initialize the AH register with 00 ;Keyboard Interrupt ; Initialize the AH register with 00 ; Keyboard Interrupt ;Compare the data 71 with AL register ;If equal to zero go to L1 ;Move 0F into the BL register ;Move 0F into the AH register ;Keyboard Interrupt ;Jump to L2 ;Move 4C into AH register ;Go to DOS commands
1006
1008
100A
RESULT:
sa
ia
5 b) READING KEYBOARD (without echo)
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 86
dit ya ec e
B4 00 MOV AH, 00 CD 16 3C 71 INT 21 CMP AL, 71 74 08 JZ L1 B3 0F B4 0F MOV MOV INT BL, 0F AH, 0F 10 CD 10 EB F0 B4 4C JMP L2 MOV INT AH, 4C 21 CD 21
1004
CD 10
INT
10
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com ABSTRACT: To Display the string or character (without ECHO) by using DOS Command
Step4: Set the wait for KEY press.. Step5: Compare AL with q.
Step6: Copy the contents AL into SI register. Step7: If equal to zero go to step 10 Step8: Increment the value of SI.
Step9: Go to step 3 without condition. Step10: Terminate the program. Step11: Stop.
sa
PROGRAM:
ia
ASSUME CS: CODE, DS: DATA www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 87
dit ya ec e
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com DATA SEGMENT ORG 3000h
START: BACK:
EXIT:
sa
CODE TABLE:
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 88
dit ya ec e
RESULT DB 50h DUP (0) DATA ENDS CODE SEGMENT ORG 1000h MOV SI, OFFSET RESULT MOV AH, 00h INT 16h CMP AL, q MOV [SI], AL JE EXIT INC SI JMP BACK MOV AH, 4Ch INT 21h
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com Segment Effective Label Hex base address code address 0E42 1000 BE 00 30 1003 L2 B4 00 Mnemonics Operands Comment
1005 1007
1009
100B
ia
RESULT: D 3000 6D 69 63 72 6F 70 72 M I C R O P www.saiadityaece.com
sa
dit ya ec e
MOV MOV SI, 3000 AH, 00 CD 16 3C 71 INT 16 CMP AL, 71 88 04 MOV [SI] , AL 74 03 46 JZ L1 SI ;Initialize the SI with 3000h ;Initialize the AH register with 00 ;Bios keyboard Interrupt ;Compare 71 with AL register ;Move the data in AL register into [SI] ;If zero go to L1 ;Increment the value of SI ;Go to L2 with out condition ;Terminate the program ;Stop INC EB F3 B4 4C JMP L2 L1 MOV INT AH, 4Ch 21 CD 21 6F 63 65 73 73 6F 72 73 20 6C 61 62 C E S S O R S L A B R O 89
ABSTRACT: To display the string character by using DOS commands. REGISTER USED: AL, AH, SI. PORTS USED: None ALGORITHM: Step1: Start
Step2: Set the screen in Graphic mode Step3: Initialize AH with 00h
Step4: Set the keyboard display mode. Step5: Initialize SI with 0000h.
Step7: Compare AL register with null character ! Step8: If equal go to step 11.
Step10: Move the number 05h into BL register. Step11: Set keyboard display mode.
sa
ia
Step 13: Terminate the program. Step14: Stop. www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 90
Step12: Go to step 6.
dit ya ec e
MOV DS, AX
MOV AL, 13H; SET the screen in graphics mode MOV AH, 00 INT 10H
sa
INT 21H
ia
MOV BL, 05H INT 10H INC SI JMP BACK EXIT: MOV AH, 4CH www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 91
MOV AH, 14
dit ya ec e
PROGRAM:
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com CODE ENDS END START
CODE TABLE:
Segme Effectiv Labe nt base e l addres address s 0B41 1000 1003 1005
1007
1009
100B
100E
1012
1014 1016
ia
1018 B3 05 101A CD 10 101C 101D 46 EB FF 101F L1 B4 4C www.saiadityaece.com
sa
dit ya ec e
Hex code Mnemonics Operands Comment B8 3F 0B 8E D8 B0 13 MOV MOV MOV B4 00 MOV CD 10 INT BE 00 00 MOV L2 8A 80 40 00 3C 21 MOV CMP 74 09 JZ B4 0E MOV MOV INT INC JMP MOV AX, 0B3F ;Initialize data segment DS, AX AL,13 ;Move the13 into AL register. AH, 00 ;Initialize the AH register with 0000 10 ;Set the keyboard display mode SI, 0000 ;Initialize SI with 0000 location AL, ;Copy the [SI+00] contents of SI into AL AL, 21 ;Compare the value 21 with AL register L1 ;If equal to zero go to L1 AH, 0E ;Load AH register with 0Eh BL, 05 ;Load BL register with 05h 10 ;Set the keyboard display mode SI ;Increment value of SI L2 ;Jump go to L2 with out condition AH, 4Ch ;Terminate the program 92
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com 1021 CD 21 INT 21 ;Dos command interrupt
RESULT:
sa
DESCRIPTION: The 8255 is a general purpose programmable I/O device with 24 I/O lines. These I/O Lines are grouped as shown below: Group A . Port A (8 bits PA0 to PA7) and Port C (4 bits PC7 to PC4). 16 Group B . Port B (8 bits PB0 to PB7) and Port C (4 bits PC3 to PC0). These groups can be operated in 3 different modes: mode 0, mode 1, and mode 2. In Mode 0 the three ports, A, B, and C, may be programmed as input or output. In mode 1 Ports A and B may be programmed as input or output, but port C is used to generate Handshake and interrupt signals. In mode 2, port A becomes a bi-directional port and 5 I/O lines of port C are used for handshaking and interrupt signals. The pin-out of the 8255 is given on the picture shown below.
ia
www.saiadityaece.com
dit ya ec e
93
sa
Following is the description of the inputs and outputs used for interfacing to the 8255: CS A low on this input pin enables communication between the 8255 and the device Controlling it. 47 RD A low on this input pin enables the 8255 to send data or status information to the Device controlling the 8255. WR A low on this input pin enables the device controlling the 8255 to write data or Control words to the 8255. A0 and A1 These input address lines, in conjunction with the RD and WR signals, allow the selection of one of three ports or the control register, as defined by the table given below: A1 A0 Location 0 0 Port A 0 1 Port B 1 0 Port C 1 1 Control Register RESET A high on this input pin clears the control register and all ports are set to input Mode. To program the 8255 PPI, one must write a control word to the control register. This Control word will define how the 8255 is going to behave. The table shown below defines the value of each bit of the control word: Control word bit Function D0 1 = Port C (lower) is input, 0 = Port C (lower) is output D1 1 = Port A is input, 0 = Port A is output D2 1 = Port B mode 1, 0 = Port B mode 0 D3 1 = Port C (upper) is input, 0 = Port C (upper) is output www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY
ia
dit ya ec e
94
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com D4 1 = Port A is input, 0 = Port A is output D5 D6 Port A 00 = Mode 0, 01 = Mode 1, 1X = Mode 2 D7 1 = Mode set flag active 48 Procedure Write a program to:
1. Reset and initialize the 8255 to mode 0 with ports A, B, and C defined as outputs.
2. Create a menu of options to allow for the selection of which port is going to biased to simulate a three bits up-counter, and to quit the program. 3. When a port is selected from the menu, the screen should be cleared and message indicating which port is in use should be displayed.
The counting sequence should be displayed both on the screen and on the LED s associated with The selected port until a key is pressed on the keyboard, at which time you start back at step 2.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 95
dit ya ec e
1.
sa
ia
Step 3: move 80 to AL register. Step 5: move 55 to AL register. Step 6: Initialize port A address. Step 8: Call subroutine program.
Step 9: complement the contents of AL register. www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 96
dit ya ec e
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com Step 10: initialize port B address.
Step 12: Call subroutine program. Step 13: Go step 6. Step 14: Stop.
Step2: Decrement CX and go to step2 until the count CX equal to zero. Step3: Return to main program.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 97
dit ya ec e
Step 11: locate the contents in AL register to DX register using port out.
Move the data 80h into AL register & Locate the contents in AL to DX register using port out
ia
www.saiadityaece.com
sa
dit ya ec e
Initialize the control word register Move the value 55h into AL register Initialize port A address Move the value 00 into CX register, decrement CX register and jump to main program if CX is equal to zero Complement the contents of AL register 2 1 98
FLOW CHART
Move the value 00 into CX register, decrement CX register and jump to main program if CX is equal to zero
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 99
dit ya ec e
1 2 Initialize port B address Jump Stop
RPT:
DELAY PROGRAM:
sa
ia
RET www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 100
L1:
dit ya ec e
MOV DX, 0FF46 MOV AX, 80 OUT DX, AL MOV AX, 55 MOB DX, 0FF40 DX, AX OUT CALL NOT DELAY AX MOV DX, 0FF42 OUT DX, AX CALL DELAY JMP RPT MOV CX, 0000H LOOP L1
PROGRAM:
CODE TABLE:
sa
ia
RESULT: www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 101
dit ya ec e
Label Hex code Mnemonic Comments Effective address 5000 5003 5006 5007 Op code operands DX , BA 46 FF B8 80 00 EF MOV FF46 MOV OUT AX, 0080 Move FF46 to DX register Load AX with 80 DX , AX Move AX content to DX B8 55 00 MOV AX , 0055 Move 55 to AX register. 500A 500D 500E 5011 5013 5016 5017 Rpt BA 40 FF EF MOV 0FF40 OUT DX , DX,AX 6000 Move 0FF40 to DX register. Move AX content to DX Go to subroutine E8 EE 1F FD D0 CALL NOT AX BA 42 FF EF MOV ,0FF42 OUT DX DX , AX 6000 E8 E9 1F EB F1 CALL Complement the AX register Initialize the port B address. Move the contents of AX into DX. Go to 6000 location Go to 500A location. 501A JMP RPT
Step 2: Move the control word address 0FF40 to register DX Step 3: Move 90 to AL register.
Step 4: Locate the contents in AL register to DX register using port out. Step 5: Move 55 to AL register.
Step 7: Locate the contents in AL register to DX register using port IN. Step 8: Complement the contents of AL register.
Step 10: Locate the contents in AL register to DX register using port out. Step 11: Go step 5. Step 12: Stop.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 102
dit ya ec e
Move the data 90h into AL register & Locate the contents in AL to DX register using port out
ia
www.saiadityaece.com
sa
dit ya ec e
Initialize the control word register Move the value 55h into AL register Initialize port A address Complement the contents of AL register 2 1 103
FLOW CHART
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 104
dit ya ec e
1 Initialize port B address Jump Stop
RPT:
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 105
dit ya ec e
MOV DX, 0FF46 MOV AX, 90 OUT DX, AX MOV AL, 55 MOV DX, 0FF40 IN AX, DX AX NOT MOV DX, 0FF42 OUT JMP DX, AX RPT
PROGRAM:
CODE TABLE:
sa
ia
RESULT: www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 106
dit ya ec e
Label Hex code Mnemonic Comments Effective address 4000 5003 5006 5007 Op code operands DX , BA 46 FF B8 90 00 EF MOV FF46 MOV OUT Rpt B8 55 00 MOV 500A 500D 5011 5013 5016 BA 40 FF EF MOV 0FF40 IN NOT FD D0 BA 42 FF EF MOV ,0FF42 OUT 501A EB F1 JMP
Move FF46 to DX register AX, 0090 Load AX with 90 DX , AX Move AX content to DX AX , 0055 Move 55 to AX register. DX , Move 0FF40 to DX register. AX,DX Move DX content to AX AX Complement the AX register DX Initialize the port B address. DX , AX Move the contents of AX into DX. RPT Go to 500A location.
AIM: program to generate the following wave forms: Triangular wave forms Saw tooth wave forms Square wave Sine wave
REGISTERS USED: general purpose registers: AL, DX, and CX PORTS USED: out (port-B)
DESCRIPTIONS: As can be from the circuit only 17 lines from the connector are used totally. The port A and port B of 8255 programmable peripheral interface are used as output ports. The digital inputs to the DACs are provided through the port A and port B of 8255.the analog outputs of the DACs are connected to the inverting inputs of op-amps A741 which acts as current to voltage converters. The out puts from the op- amps are connected to points marked Xout and Yout at which the wave forms are observed on a CRO. (port A is used to control Xout port B is used to control Yout).the difference voltage for the DACs is derived from an on-board voltage regulator A 723 .it generates a voltage of about 8V.the offset balancing of the opamps is done by making use of the two 10k pots provided. The output wave forms are observed at Xout and Yout on an oscillator. THEORY: BASIC DAC TECHNIQUE:
sa
ia
Vo = K VFS (d1 .2-1 + d2 . 2-2 + . . . . . . . .+dn . 2-n ) Where d1 = MSB, d2 = LSB VFS = Full scale reading / out put voltage K --- Conversion factor is adjusted to unity. D/A converters consist of n bit binary word Dand is combined with a reference voltage VR to give an analog output. The out put can be either voltage or current Out put voltage Vo = K VFS (d1 .2-1 + d2. 2-2 + . . . . . . . . +dn. 2-n) MSB weight = VFS if d1 = 1 and all are zeros, K = 1. LSB weight = VFS/2n if dn = 1 and all are zeros, K = 1
DUAL DAC INTERFACE: This program generates a square wave or a Triangular wave at points Xout or Yout of interface. The waveforms may be observed on an oscilloscope. This program can be executed in STAND-ALONE MODE or SERIAL MODE of operation. www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 107
dit ya ec e
II b) DIGITAL TO ANALOG CONVERTER
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com The program starts at memory location 3000H
Step 4: Locate the contents in AL register to DX register using port out. Step 5: Move 00FF to CX register. Step 6: Move 00 to AL register.
Step 8 : Locate the contents of AL to DX register. Step 9: Increment the value in AL by one.
Step 11: Decrement the value of CX register by one and move to step 6 if CX not equal to zero.
sa
Step 16: Stop.
ia
zero. Step 15: Otherwise move to step 5. www.saiadityaece.com
Step 13: Locate the contents in AL register to DX register. Step 14: Decrement the value of CX by one and move to step 11 if CX not equal to
dit ya ec e
108
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 109
dit ya ec e
FLOW CHART
ia
NO www.saiadityaece.com
sa
dit ya ec e
Initialize the control word register Copy the contents from AX to 80 & Locate the contents in AL to DX register using port out Move 0FF to CX register and Move 00 to AL register Initialize port A address Locate the contents of AX to DX register & Increment the value in AX by one Locate AX contents to DX register Decrement CX & CX =0 YES 2 1 110
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 111
dit ya ec e
Move 0FF to CX register Decrement the value of AL Locate the contents in AL register to DX register Decrement CX & CX=0 NO YES Jump Stop
OUT DX, AL
LOOP L1
LOOP L2
JMP RPT
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 112
dit ya ec e
CODE TABLE (FOR TRIANGULAR WAVE): Physical address Segment address 0000 Label Hex code
ia
201B RESULT: www.saiadityaece.com
sa
dit ya ec e
Mnemonic Comments Effective address 2000 2003 2006 2007 Op code operands DX , BA E6 FF MOV FFE6 B8 80 00 MOV EF OUT AX, 0080 Move FFE6 to DX register Load AX with 80 DX , AX BA E0 FF MOV DX , FFE0 B8 00 00 MOV AX , 0000 200A 200D 2010 2011 2012 2014 2017 2018 2019 Move DX content to AX Move FFE0 to DX register Load AX with 0000 Move FF to CX register Move contents of AX to DX Increment the contents of AX Loop go to 2010 location Move 00FF to CX register Move the contents of AX into DX Decrement to AX register Loop go to 2017 location Jump to 200D location Rpt L1 B9 FF 00 EF 40 MOV CX , 00FF OUT DX , AX INC AX E2 FC LOOP L1 B9 FF 00 EF 48 MOV CX , 00FF OUT DEC DX, AX L2 AX E2 FC LOOP L2 JMP EB EA RPT 113
Step 2: Move the control word address 0FFE6 to register DX Step 3: Move 80 to AL register.
Step 4: Locate the contents in AL register to DX register using port out. Step 5: Move 00 to AL register.
Step 7: Locate or move 0FFE2 to DX register ie, port B address. Step 8: Locate AL contents to DX register.
Step 10: Decrement the value of CX register by one and move to step 8 if CX not equal to zero.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 114
dit ya ec e
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 115
dit ya ec e
FLOW CHART
ia
NO www.saiadityaece.com
sa
dit ya ec e
Initialize the control word register Copy the contents from AX to 80 & Locate the contents in AL to DX register using port out Move 00 to AX register Move 0FF to CX register Initialize port B address Locate the contents of AX to DX register Locate the contents of AX to DX register Decrement CX & CX =0 YES Stop 116
LOOP L1
MOV AX, 00
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 117
dit ya ec e
sa
ia
RESULT: www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY
dit ya ec e
Label Hex code Mnemonic Comments Effective address 3000 3003 3006 3007 Op code operands DX , FFE6 AX, 0080 BA E6 FF B8 80 00 EF MOV MOV OUT DX , AX BA E0 FF B8 00 00 MOV DX , FFE0 MOV AX , 0000 300A 300D 3010 3011 3012 3014 3017 Rpt L1 B9 FF 00 EF 40 MOV CX , 00FF OUT DX , AX INC AX E2 FC LOOP L1 B8 00 00 EF MOV AX , 0000 OUT DX, AX 3018 EB F3 JMP RPT 118
Move FFE6 to DX register Load AX with 80 Move DX content to AX Move FFE0 to DX register Load AX with 0000 Move FF to CX register Move contents of AX to DX Increment the contents of AX Loop go to 2010 location Move 0000 to AX register Move the contents of AX into DX Jump to 300D location
Step 2: Move the control word address 0FFE6 to register DX Step 3: Move 80 to AL register.
Step 4: Locate the contents in AL register to DX register using port out. Step 5: Move FF to AL register.
Step 6: Locate the contents in AL register to DX register using port out . Step 7: Move 91 into CX register.
Step 8: Decrement the value CX by one and jump to step 8 if CX not equal to zero. Step 9: Other wise move 00 to AL register.
Step 10: Locate the contents in AL register to DX register using port out . Step 11: Move 91 into CX register.
Step 12: Decrement the value CX by one and jump to step 12 if CX not equal to zero. Step 13: Jump to location step 5. Step 14: Stop.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 119
dit ya ec e
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 120
dit ya ec e
FLOW CHART
ia
www.saiadityaece.com
sa
dit ya ec e
Initialize the control word register Copy the contents from AX to 80 & Locate the contents in AL to DX register using port out Move 0FF to AX register Initialize port A address Locate the contents of AX to DX register Move the data 91h into CX register Decrement CX & CX =0 NO YES 1 2 121
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 122
dit ya ec e
Move 00h to AX register Locate the contents in AL register to DX register Move the data 91h into CX register Decrement CX & CX=0 YES NO Jump Stop
OUT DX, AL
OUT DX, AX
sa
ia
RET www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 123
LOOP L1
dit ya ec e
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com CODE TABLE (FOR SQUARE WAVE): Physical address Segment address 0000
DELAY PROGRAM:
ia
Label 6000 6003 6004 6005 www.saiadityaece.com
LOCATION 0000:6000
sa
dit ya ec e
Label Hex code Mnemonic Comments Effective address 5000 5003 5006 5007 Op code operands DX , BA E6 FF B8 80 00 EF MOV FFE6 MOV OUT BA E0 FF B8 FF 00 EF MOV MOV OUT 500A 500D 500E 5011 5014 Rpt E8 FF EF B8 00 00 EF CALL MOV OUT Move FFE6 to DX register AX, 0080 Load AX with 80 DX , AX Move AX content to DX DX , FFE0 Move FFE0 to DX register AX , 00FF Load AX with 00FF DX,AX Move AX content to DX 6000 5015 5018 E8 E8 FF E8 F0 CALL JMP RPT Jump to 500A location Hex codes Mnemonics Op code Operand MOV CX,001E NOP NOP C3 RET Return to main program comment B9 1E 00 Move 001E into CX register 124
Step 2: Move the control word address 0FFE6 to register DX Step 3: Move 80 to AL register.
Step 4: Locate the contents in AL register to DX register using port out. Step 5: Initialize the SI with 4000h location.
Step 6: Move the number 46 into the counter CX register. Step 7: Initialize the Port A address ie. 0FFE0
Step 9: Locate the contents in AL register to DX register using port out.. Step 10: Increment the value of SI.
Step 11: Decrement the counter and go to Step 8 until CX =0 Step 12: Jump to location step 5. Step 13: Stop.
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 125
dit ya ec e
RPT:
L1:
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 126
dit ya ec e
OUT DX, AL MOV SI, 4000 MOV CL, 46 MOV DX, 0FFE0 MOV AL, [SI] OUT DX, AL INC SI LOOP L1 JMP RPT
2007
2012
2013 2014
ia
2016 www.saiadityaece.com
sa
dit ya ec e
Mnemonics Operands Comments MOV MOV OUT DX, 0FFE6 AL, 80 DX, AL RPT BE 0040 MOV SI, 4000 8B 46 00 BA E0 FF B8 C6 MOV MOV MOV CX , 46 L1 DX, 0FFE0 AL, [SI] ;Initialize control word register ;Load AL with 80 ;Read the data from AL register using port out ;Initialize the SI with 4000 ie,LOOK-UP TABLE ;Initialize the counter with 46h Initialize port A EF OUT DX, AL 46 INC SI E2 F5 LOOP L1 EB EA JMP RPT ;move the number in [SI] into al register ;read the data from Al register using port out ;Increment the value of SI ;Decrement counter and go to L1 until CX=0 ;Jump go to rpt with out condition 127
LOOK UP TABLE:
4004
4008
400C
4010
4014
4018
ia
ED E7 D9 C8 B5 401C D1 4020 AA A0 8A 74 5F 49 36 4024 7F 4028 53 402C www.saiadityaece.com
sa
dit ya ec e
HEX CODES 8A A0 7F 95 AA B5 C8 D9 E7 BF D1 E0 ED F2 FA FE FE F7 FC FF FC FA F2 F7 E0 BF 95 69 3F 128
4034
4038
403C
4040
4044
RESULT:
AIM: To display a string through interfacing 8279. REGISTERS USED: AX, BX, CX, DX, SI PORTS USED: command port, data port
sa
ia
DESCRIPTION: INTRODUCTION:
In many microprocessors-based systems, calculator keypad is used as an input device. A calculator keypad can be interfaced to a microprocessor using a dedicated peripheral controller like INTEL 8279Akeyboard/display controller. In this case, the www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 129
dit ya ec e
01 01 07 0B 17 10 1D 25 36 2D 3F 49 5F 53 69 74
10
07
II C) KEYBOARD INTERFACING
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com controller can handle the interface problems like key debounce, 2-key lock-out, N-key roll-over etc,. Further such an alternative approach, the calculator keypad interface is passive and software is used for encoding the key positions and for handling problems like key debounce, roll-over etc. The present interface module provides a calculator style calculator keypad consisting of the key 0 to 9 , + ,- , ,= ,% , . , C, CE and two spare keys. These 20 keys are arranged in a 38 matrix (the third row has only four keys). The row lines can be driven through port C and the status of column lines can be read through port A. this interface allows the user to study a number of techniques generally used in calculator keypad interfacing. User can write programs for software debouncing of key closures, two key understanding of keyboard interface. Further , user can become familiar with the arithmetic group of processor instructions by implementing the calculator functions like addition, subtraction, multiplication , diversion, percentage etc..
THEORY:
A programmable keyboard and display interfacing chip. o Scans and encodes up to a 64-key keyboard. o Controls up to a 16-digit numerical display. Keyboard has a built-in FIFO 8 character buffer
The display is controlled from an internal 16x8 RAM that stores the coded display information
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 130
dit ya ec e
sa
ia
www.saiadityaece.com
A0: Selects data (0) or control/status (1) for reads and writes between micro and 8279. BD: Output that blanks the displays. CLK: Used internally for timing. Max is 3 MHz. CN/ST: Control/strobe, connected to the control key on the keyboard. CS: Chip select that enables programming, reading the keyboard, etc. DB7-DB0: Consists of bidirectional pins that connect to data bus on micro. IRQ: Interrupt request, becomes 1 when a key is pressed, data is available. OUT A3-A0/B3-B0: Outputs that sends data to the most significant/least significant nibble of display. RD (WR): Connects to micros IORC or RD signal, reads data/status registers. RESET: Connects to system RESET. RL7-RL0: Return lines are inputs used to sense key depression in the keyboard matrix. Shift: Shift connects to Shift key on keyboard. SL3-SL0: Scan line outputs scan both the keyboard and displays.
dit ya ec e
131
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 132
dit ya ec e
Pins SL2-SL0 sequentially scan each column through a counting operation. o The 74LS138 drives 0s on one line at a time. o The 8279 scans RL pins synchronously with the scan. o RL pins incorporate internal pull-ups, no need for external resistor pull-ups. Unlike the 82C55, the 8279 must be programmed first.
D7 D6 D5 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
ia
Clear End interrupt
o
sa
dit ya ec e
Function Mode set Clock Purpose Selects the number of display positions, type of key scan Programs internal clk, sets scan and debounce times. Selects type of FIFO read and address of the read. Read FIFO Read Display Selects type of display read and address of the read. Selects type of write and the address of the write. Allows half-bytes to be blanked. Clears the display or FIFO Clears the IRQ signal to the microprocessor. Write Display Display write inhibit The first 3 bits of # sent to control port selects one of 8 control words.
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com 000DDMMM o Mode set: Opcode 000. DD sets displays mode. MMM sets keyboard mode.
DD field selects either: 8- or 16-digit display Whether new data are entered to the rightmost or leftmost display position.
o
DD
sa
o
ia
o o
dit ya ec e
Function MMM field: DD Function 000 Encoded keyboard with 2-key lockout 001 Decoded keyboard with 2-key lockout 010 Encoded keyboard with N-key rollover 100 Encoded sensor matrix 011 Decoded keyboard with N-key rollover 101 Decoded sensor matrix 110 Strobed keyboard, encoded display scan 111 Strobed keyboard, decoded display scan Encoded: SL outputs are active-high, follow binary bit pattern 0-7 or 015. Decoded: SL outputs are active-low (only one low at any time). Pattern output: 1110, 1101, 1011, 0111. Strobed: An active high pulse on the CN/ST input pin strobes data from the RL pins into an internal FIFO for reading by micro later.
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com o 2-key lockout/N-key rollover: Prevents 2 keys from being recognized if pressed simultaneously/Accepts all keys pressed from 1st to last.
INTERFACE OF 8279
001PPPPP o The clock command word programs the internal clock driver. o The code PPPPP divides the clock input pin (CLK) to achieve the desired operating frequency, e.g. 100KHz requires 01010 for a 1 MHz CLK input.
010Z0AAA o The read FIFO control word selects the address (AAA) of a keystroke from the FIFO buffer (000 to 111). o Z selects auto-increment for the address.
011ZAAAA o The display read control word selects the read address of one of the display RAM positions for reading through the data port.
sa
ia
100ZAAAA o Selects write address Z selects auto-increment so subsequent writes go to subsequent display positions.
INTERFACE OF 8279
1010WWBB o The display write inhibit control word inhibits writing to either the leftmost 4 bits of the display (left W) or rightmost 4 bits. o BB works similarly except that they blank (turn off) half of the output pins. 1100CCFA o The clear control word clears the display, FIFO or both www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 135
dit ya ec e
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com o Bit F clears FIFO and the display RAM status, and sets address pointer to 000. If CC are 00 or 01, all display RAM locations become 00000000. If CC is 10, 00100000, if CC is 11, 11111111. 1110E000 o End of Interrupt control word is issued to clear IRQ pin in sensor matrix mode.
1) Clock must be programmed first. If 3.0 MHz drives CLK input, PPPPP is programmed to 30 or 11110.
INTERFACE OF 8279
2) Keyboard type is programmed next. o The previous example illustrates an encoded keyboard, external decoder used to drive matrix.
sa
ia
INTERFACE OF 8279
Once done, a procedure is needed to read data from the keyboard. o To determine if a character has been typed, the FIFO status register is checked. o When this control port is addressed by the IN instruction, the contents of the FIFO status word is copied into register AL:
Data returned from 8279 contains raw data that need to be translated to ASCII: www.saiadityaece.com
dit ya ec e
136
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com o Row and column number are given the rightmost 6 bits (scan/return).
o
o o
ALGORITHM:
sa
ia
www.saiadityaece.com
Step5: Initialize counters CX with the value 08h Step6: Move the 0ff40 to DX register and Load AL with 00 Step7: Write the value in AL register into DX register using port OUT. Step8: Go to step 6 until equal to zero. Step9: Move the address 2050 into SI register. Step10: Move the value 0FF42 to DX register. Step11: Read the value in DX register into AL register using port IN.
dit ya ec e
The CT and SH indicate whether the control or shift keys were pressed. The Strobed Keyboard code is just the state of the RLx bits at the time a 1 was `strobed on the strobe input pin. 137
This can be converted to ASCII using the XLAT instruction with an ASCII code lookup table.
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com Step12: Add the contents of AL register with the value 07h. Step 13: Go to step 8 if the result not equal to zero. Step14: Get the value 40 to AL register.
Step15: Write the value in AL register into DX register using port OUT. Step 16: move the 0ff40 to DX register.
Step 17: read the value in DX register into AL register using port IN. Step 18: Logical AND ed the contents of AL with 01F. Step19: Move the value of AL into BL register.
Step21: Initialize data port and move the value 94 into AL register.
Step22: Write the data in AL register into DX register using port OUT.
Step 23: Initialize Command port and move the value F3 into AL register.
Step24: Write the value in AL register into DX register using port OUT. Step25: Initialize the data port and move the value 95 into AL register.
Step 26: Write the value in AL register into DX register using port OUT. Step 27: Initialize the Command port.
sa
PROGRAM:
ia
Step 30: Go to step 8. Step31: Stop. MOV BX, 00H MOV DX, 0FF42 www.saiadityaece.com
Step 28: Move the contents of SI into AL register. Step29: Write the value in AL register into DX register using port OUT.
dit ya ec e
138
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com MOV AL, 00 OUT DX, AL
RPT:
BACK:
KEY:
sa
ia
MOV DX, 0FF40 IN AL, DX AND AL, 1F MOV BL, AL ADD SI, BX MOV DX, 0FF42 MOV AL, 94 www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 139
dit ya ec e
MOV AL, 90 OUT DX, AL MOV CX, 08 MOV AL, 00 MOV DX, 0FF40 OUT DX, AL LOOP RPT MOV SI, 2050 MOV IN DX, 0FF42 AL, DX AND AL, 07 JZ KEY MOV AL, 40 OUT DX, AL
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com OUT DX, AL MOV DX, 0FF40
CODE TABLE:
ia
2006 2008 2009 200B 200C 200F www.saiadityaece.com2011
sa
dit ya ec e
MOV AL, 0F3 OUT DX, AL MOV DX, 0FF42 MOV AL, 95 OUT DX, AL MOV DX, 0FF40 MOV AL, [SI] OUT DX, AL JMP BACK Label Hex code Mnemonic Comments Effective address 2000 2003 Op code operands MOV MOV MOV OUT MOV OUT MOV MOV MOV BX,00 BB 00 00 BA 42 FF B0 00 EE B0 90 EE B9 08 00 B0 00 BA 40 FF DX,0FF42 AL,00 DX,AL AL, 90 DX,AL CX,08 AL,00 DX,0FF40 Set the count Routine to clear All display LEDs Initialize data port 140
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com 2014 2015 2017 RPT EE E2 FD OUT LOOP MOV MOV DX,AL RPT
ia
202F 2032 2034 2035 2038 203A www.saiadityaece.com
sa
dit ya ec e
BAC K BE 50 20 SI, 2050 201A BA 42 FF DX,0FF42 201D KEY EC IN AL,DX 201E 24 07 AND AL,07 2020 2022 2024 2025 74 FB B0 40 EE JZ KEY Jump if condition MOV OUT AL,40 DX,AL BA 40 FF MOV DX,0FF40 Read FIFO RAM 2028 2029 EC IN AL,DX AL,1F Mask SIFT 24 1F AND AND AL with 1F 202B 8A D8 MOV BL,AL 202D 03 F3 ADD SI,BX Add SI with BX BA 42 FF B0 94 EE BA 40 FF B0 F3 MOV MOV OUT MOV DX,0FF42 AL,94 DX,AL DX,0FF40 MOV AL,F3 EE OUT DX,AL 141
Write the data from por IN Logical AND between [AL] and 07h
Address to display 0
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com203B 203E 2040 2041 2044 BA 42 FF B0 95 EE MOV MOV OUT DX,0FF42 AL,95 DX,AL Addressed data port Set 95 into AL register
INPUT DATA:
Segment address
ia
2058 205C RESULT: www.saiadityaece.com
sa
dit ya ec e
BA 40 FF 8A 04 MOV MOV DX,0FF40 AL,[SI] 2046 2047 EE OUT JMP DX,AL E9 CD FF BACK Offset address 2050 2054 DATA INPUT F3 60 B5 F4 66 D6 D7 70 F7 76 77 C7 93 E5 97 17 142
Read the data from port Initialize control port Move the contents of SI into the AL register
sa
INTRODUCTION: The analog to digital conversion can be done in many ways. One of the methods is the Dual Slope method, used to achieve high noise immunity. The input voltage is integrated for a fixed time T1. Also a known reference voltage VR is integrated for a time TX. Now the input voltage VX is given by V V X = 1 TX T1 V But 1 =K (a constant) T1 Hence VX = K . TX I.e. the input voltage is proportional to the measured time TX. If integrated time TC is chosen as 20 m sec.the microprocessor measures time as the number of counts, namely TX = NX. TC where www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY
ia
dit ya ec e
ADDITIONAL PROGARMS
143
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com NX is number of counts. TX is counter period. By proper choice of the counter period TC scaling can be incorporated into the counter such that a software multiplication can be avoided.
THEORY: Voltage,current,temperature,pressure,time,etc, are available in analog form.ot is difficult to process ,store or transmit the analog signal with out introducing considerable error because of the superimposition of noise as in the case of amplitude modulation. Therefore, for processing, transmission and storage purpose. It is often convenient to express these variables in digital form, it gives better accuracy system is based. The operation of any digital communication system is based upon analog to digital and digital to analog conversion. A/D converter requires sample and hold(S/H) circuit. The ADC output is a sequence of binary digit. D/A converter is to convert digital signal to analog signal and function of DAC is exactly opposite to that of ADC. The D/A converter is usually operated at the same frequency as the ADC.the output of D/A converter is commonly a stair case. This stair case like digital output is passed through a smoothing filter to reduce the effect of quantization noise. ADCs are classified broadly into two groups according to their conversion technique: 1. Direct type ADCs and 2. Integrating type ADCs.
Direct type ADCs compare a given analog signal with the internally generated equivalent signal. This group includes: 1. Flash (comparator) type converter 2. Counter type converter. 3. Tracking or servo converter 4. Successive approximation type converter.
sa
ia
www.saiadityaece.com
Integral type ADCs perform conversion in an indirect manner by first changing the analog input signal to a linear function of time or frequency and then to a digital code .the two most widely used integrating type converters are: 1. Charge balancing ADC. 2. Dual slope ADC The flash (comparator) type is expensive for high of accuracy the integrated type converter is used in application such as digital meter, panel meter and so on. PARALLEL COMPARATOR (FLASH) A/D CONVERTER: It is simplest possible converter and the fastest and most expensive technique.
3-BIT A/D CONVERTER: Circuit consists of resistive divider network, 8 op-amp comparators and 8-5line encoder. At each node of the resistive divider, a comparison voltage is available .since
dit ya ec e
144
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com all the resistors are of equal value, the voltage levels available at the nodes are equally divided between the reference voltage VR and the ground. The purpose of circuit is to compare the analog input voltage VA with each of the voltages. The circuit has the advantage of high speed as the conversion take place simultaneously rather than sequentially. Typical conversion time is loons or less. Conversion time is limited only by the speed of the comparator and of the priority encoder by using advanced micro devices AMA 686A comparator and a T1147 priority encoder ,conversion delays of the order of 20 nos can be obtained. This type of ADC has the disadvantage that the number of comparators required almost doubles for each added bit. A 2-bit ADC requires 3 comparators .in general, the number of comparators required are 2n-1 where n is the desired number of bits. Hence the number of comparators approximately doubles for each added bit. Also the larger the value of n the more complex is the priority encoder. INTEGRATING TYPE OF ADCS: the generating type of ADCs do not require a S/H circuit at the input. If the input changes during conversion, the ADCs output code will be proportional to the value of the input averaged over the integration period. DUAL SLOPE ADC:
sa
ALGORITHM:
ia
www.saiadityaece.com
The analog part of the circuit consists of a high input impedance buffer A1, precision integrator A2 and a voltage comparator. The converter fort integrates the analog input signal VA for a fixed duration of 2n clock periods. Then to integrate an internal reference voltage VR of opposite polarity until the integrator output is zero. The number N of clock cycles required to return the integrated period. Hence N represents the desired output code. Since VR and n are constant, the analog voltage VA is proportional to the count reading N and is independent of R,C and T. The dual-slope ADC integrates the input signal for a fixed time, hence to provides excellent noise rejection of ac signals whose periods are integral multiples of the integration time T1. The main disadvantage of the dual-slope ADC is the long conversion time. For instance, if 2n-T =1 / 50 is used to reject line pick-up , the conversion time will be 20 m sec. Dual-slope converters are particularly suitable for accurate measurement of slowly varying signal, such as thermo couples and weighing scales. Dual slope ADCs also form the basics of digital panel meters and millimeters. Dual slope converters are available in monolithic form and are available both in microprocessors compatible and in display oriented versions.
REGISTERS USED: AX, BX, CX, DX. PORTS USED: Port A and Port B.
dit ya ec e
145
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com Step1: Initialize 8255 Control Word Register and Port A as O/P port and Port B as I/P port.
Step3: Initialize Port A address and read the data from port out. Step4: Perform NOP five times.
Step5: Move the number 01h into AL register. Step6: Read the data from port out.
Step9: Load AL with 04 and read the data from port out.
Step10: Initialized port A with 0FFE0 and initialized BX register with 0000h.
Step11: Initialized port B with 0FFE2 and write the data from register AL using port
IN.
sa
ia
www.saiadityaece.com
Step13: Jump the corresponding condition to specify in instruction. Step14: After the increment the BL register jump step 11. Step15: Move the contents of BL register into the AL register.
dit ya ec e
146
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com Step16: Initialize SI with 3000h and move the value in AL register into the SI location.
Step 18: Initialize port A and read the data from port out. Step19: Get the value 03h into BX register.
Step20: Initialize CX with 0FFFFh and continue the loop until CX is equal to zero. Step21: Decrement the value of BX register and jump step 20 if BX equal to zero. Step22: Jump step 2 Unconditional Step23: Stop.
PROGRAM:
START:
sa
ia
OUT DX, AL NOP NOP NOP NOP NOP MOV AX, 01 www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 147
dit ya ec e
MOV DX, 0FFE6 MOV AL, 82 OUT DX, AL MOV AL, 02H MOV DX, 0FFE0
L2 :
L1 :
DISP:
sa
$:
ia
MOV [SI], AL MOV AL, 02H MOV DX, 0FFE0 OUT DX, AL MOV BX, 20 DELAY: MOV CX, 0FFFF LOOP $ www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 148
dit ya ec e
MOV CX, 1000H LOOP L1 MOV AL, 04H OUT DX, AL MOV DX, 0FFE0 MOV BL, 00H MOV DX, 0FFE2 IN AX, DX AND AL, 01 JE DISP INC BL JMP L1 MOV AL, BL MOV SI, 3000H
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com JNZ DELAY JMP START
CODE TABLE:
ia
401A 401C 401D 4020 4022 4025 L1 4026 www.saiadityaece.com
sa
dit ya ec e
Label Hex code Mnemonic Comments Effective address 4000 Op code operands DX,0FFE6 BA E6 FF MOV 4003 4004 4006 4008 B0 82 EE MOV OUT AL,82 DX,AL START B0 02 MOV MOV OUT NOP NOP NOP NOP NOP AL,02 BA E0 FF EE 90 90 90 90 90 DX,0FFE0 400B DX,AL 400C 4011 4014 4015 4018 B8 01 00 EE B9 00 10 E2 FE B0 04 EE BA E0 FF MOV OUT MOV LOOP MOV OUT MOV AX,01 DX,AL CX, 1000H L1 AL,04H DX,AL DX,0FFE0 149
Initialize the Control word register Port A as output & port B as input
Reset integrator
Addressed port A ie initializes. Read the data from port out No operation
Set the count with 1000h Continuous loop Load AL with 04number Read the data Initialized port A addressed
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com 4028 402A L2 B3 00 BA E2 FF MOV MOV BL,00 DX,0FFE2
ia
404B 404C 404E RESULT: www.saiadityaece.com
sa
dit ya ec e
402C EC IN AL,DX 402E 4030 4033 4035 4037 24 01 AND JE INC AL, 01H 74 04 FE C3 EB F4 DISP BL JMP L2 DSP 8A C3 MOV MOV MOV AL,BL 403A 403B B8 00 30 SI,3000 [SI],AL 403E 4041 4043 4044 4046 B0 02 MOV MOV OUT AL,02 BA E0 FF EE DX,0FFE0 DX,AL BB 20 00 MOV MOV BX,20 DY B9 FF FF CX,0FFFH 4049 L3 F2 EE 4B LOOP DEC L3 BX 75 F8 EB AD JNZ JMP DY START 150
AND ed operation between AL and 01 Jump conditionally Increment value of BL Jump Unconditionally Move the contents from AL into BL Initialize SI with 3000h Move the value in AL register into contents of SI Load AL with the value 02h Initialize port A
Read the data from port out Set the 20h in BX register Set the count with 0FFFFh value into CX register Continuous loop Decrement the value of BX register Jump Conditionally Jump Unconditionally.
AIM: program to design a stepper motor to rotate shaft of a 4 phase stepper motor in clockwise 15 rotations. REGISTERS USED: General purpose registers: AL , DX , CX PORTS USED: Port B, port C (out)
CONNECTIONS: J4 of ESA 86/88E to J1 of stepper motor. OPERATING PRINCIPLE OF PERMANENT MAGNET STEPPER MOTOR:
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 151
dit ya ec e
STEPPER MOTOR INTERFACING
sa
ia
A = 360 / (N * K) degrees Where N = number of rotor tooth.
It consists of two stator windings A,B and a motor having two magnetic poles N and S. when a voltage +v is applied to stator winding A, a magnetic field Fa is generated. The rotor positions itself such that its poles lock with corresponding stator poles. With the winding A excited as before ,winding b is now to Fa. the resulting magnetic field F makes an angle of 450. the rotor consequently moves through 450 in anti clockwise direction,again to cause locking of rotor poles with corresponding stator poles. While winding B has voltage +V applied to it, winding A is switched off. The rotor then moves through a further 450 in anti-clockwise direction to aligne itself with stator field Fb. with voltage +V on winding B, a voltage V is applied to winding A. then the stator magnetic field has two components Fa , Fb and their resultant F makes an angle of 1350 position. In this way it can be seen that ,as the pattern of excitation of the state of winding is changed, the rotor moves successively through450 steps. And completes one full revolution in anti clock-wise direction. A practical PM stepper motor will have 1.80 step angle and 50 tooth on its rotor;there are 8 main poles on the stator, each having five tooth in the pole face. The step angle is given by
PM stepper motors have three modes of excitation i,e.. www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 152
dit ya ec e
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com Single phase mode Two phase mode Hybrid mode
Single phase mode: in this mode only one of the motor winding is excited at a time. There are four steps in the sequence, the excitation sequence factor K=2 ,so that step angle is 900.
Two phase mode: Here both stators phase are excited at a time. There are four steps in the excitation sequence, K = 2 and the step angle is 900. However, the rotor positions in the two phase mode are 450 way from those in single phase mode.
sa
Hybrid mode: this is a combination of single and two phase modes. There are 8 steps in excitation sequence=2 and step angle = 450. a voltage +V is applied to a stator winding during some steps, which voltage V is applied during certain other steps. This requires a bipolar regulated power supply capable of yielding +V,-V and zero outputs and a air of SPDT switches, which is quite cumbersome. Consequently each of the two stator windings is split into two sections A1-A2 , B1-B2. these sections are wound differentially. These winding sections can now be excited from a univocal regulated power supply through switcher S1 to S4. this type of construction is called bipolar winding construction. Bipolar windingesults in reduced winding inductance and consequently improved torque stepping rate. Description: the stepper motor interfaces uses four transistor pairs (SL 100 and 2N 3055) in a Darlington pair configuration. Each Darlington pair is used to excite the particular winding of the motor connected to 4 pin connector on the interface. The inputs to these transistors are from the 8255 PPI I/O lines of the microprocessor kit or from digital I/O card plugged in the PC. port A lower nibble PA0 , PA1, PA2 , PA3 are the four lines brought out to the 26 pin FRC male connector(J1) on the interface module. The freewheeling diodes across each winding protect transistors from switching transients. Theory: A motor used for moving things in small increments is known as stepper motor. Stepper motor rotate from one fixed position to next position rather than continuous rotation as in case of other ac or dc motor stepper motors are used in printers to advance the paper from one position to advance the paper from one position to another in steps. They are also used to position the read/write head on the desired track of a floppy disk. To rotate the shaft the stepper motor a sequence of pulses are applied to the windings in a predefined sequence. The number of pulses required for one complete rotation per pulse is given by 3600/NT. where NT is the number of teeth on rotot. Generally the stepper motor is available with 10 to 300 rotation. They are available with two phase and four phase common field connections. Instead of rotating smoothly around and around as most motors, stepper motors rotate or step one fixed position to next. Common step size range from 0.90 to 300. it is stepped from one position to next by changing the currents through the fields in the motor. The two common field connections are referred to as two phase and four phase. The drive circuitry is simpler in 4 phase stepper. The figure shows a circuitry that can interface a small 4 stepper motor to four microcomputer port lines. www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY
ia
dit ya ec e
153
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com The 7406 buffers are inverting , so. A high on ah output port pin turns on current to a winding. The purpose of clamp diodes across each winging is to save transistors from inductive kick. Resistors R1 and R2 are current limiting resistors. Typical parameters of stepper motor: 1. Operating voltage 12 volts 2. Current rating 1.2 Amp 3. Step angle 1.80 4. Step for revolution 200(No. of teeth on rotor) 5. Torque 3 kg/cm Working of stepper motor: Suppose that SW1 and SW2 are turned ON. Turning OFF SW2 and turning ON SW4 cause the motor to rotate one step of 1.80 clockwise. Changing to SW4 and SW3 ON will cause the motor to rotate 1.80 clockwise another. Changing SW3 and SW2 ON will cause another step. To step the motor in counter clock wise direction simply work through the switch sequence in the reverse direction. The switch pattern for changing from one step to another step in clockwise direction is simply rotated right one position. For counter clockwise direction rotated left one position. ALGORITHM: Step 1: Start
Step 2: move the control word address 0FFE6 to register DX Step 3: move 80 to AL register.
Step 4: locate the contents in AL register to DX register using port out. Step 5: move port A address ie.,,0FFE0 to DX register. Step 6: move 11 to AL register.
sa
ia
Step 11: jump to location / step 7. Step 12: stop. www.saiadityaece.com
Step 9: repeat step 8 until the content in CX register becomes equal to zero. Step 10: Rotate carry left through bit.
dit ya ec e
154
ia
www.saiadityaece.com
sa
dit ya ec e
Start FLOW CHART Initialize the control word register Copy the contents from AX to 80 & Locate the contents in AL to DX register using port out Initialize port A address Move the data 11h into AL register & Locate the contents in AL to DX register using port out Load CX register with 300 2 1 155
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 156
dit ya ec e
Decrement CX & CX=0 NO YES Rotate carry left through bit Jump Stop
MICROPROCESSORS LAB MANUAL ECE Dept. www.saiadityaece.com PROGRAM: MOV MOV RPT: OUT
MOV L1:
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 157
dit ya ec e
DX, 0FFE6 AX, 80 DX, AX DX, 0FFE0 AX, 0011 DX, AX CX, 0300 L1 AL, 01H RPT
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 158
RESULT:
dit ya ec e
Label Hex code Mnemonic Comments Effective address 5000 5003 5006 5007 Op code operands DX , FFE6 AX, 0080 BA E6 FF B8 80 00 EF Mov Mov Out DX , AX BA E0 FF B8 FF 00 EF Mov Mov Out DX , FFE0 AX , 00FF 500A 500D 500E 5011 5014 Rpt DX,AX 6000 Move FFE6 to DX register Load AX with 80 Move AX content to DX Move FFE0 to DX register Load AX with 00FF Move AX content to DX E8 FF EF B8 00 00 EF Call Mov Out AX , 0000 DX , AX 5015 5018 E8 E8 FF E8 F0 Call 6000 Jmp Rpt Jump to 500A location
CODE TABLE:
sa
ia
www.saiadityaece.com SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY 159
dit ya ec e