Você está na página 1de 241

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.

Tech II Semester
Dept of ECE, Aditya Engineering College 1

INTRODUCTION 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.
There are different softwares developed by different companies for assembly language
programming .They are
MASM - Microsoft Company.
TASM - Bore Land Company.

MERITS 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 it Shows inbox

Then type Command (CMD) which enters you into DOS prompt

Path setting

Suppose it display path as C:\ DOCUME-\ADMIN>

Then type CD\

i.e.; C:\DOCUME\\ADMIN>CD\

Then the path is C :\>

Then type CD MASM
Then the path is C: MASM>

Then type edit i.e.; C: MASM>edit

Then you enter into MASM text editor.


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 2


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 3

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 debug to create exe file
C:MASM>debug filename. EXE
Then it display -- on the screen
After that type R displays the registers contents and starting step of the program.
T Tracing at contents of program step by step.
Suppose you need to go for break point debugging. Then type that instruction no where you need to
check your register. For example T
10
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
DEBUG COMMANDS:

ASSEMBLE A [address] ; Assembly the instructions at a particular address
COMPARE C range address ; Compare two memory ranges

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 4


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 5

DUMP D [range] ; Display contents of memory
ENTER E address [list] ; Enter new or modifies memory contents beginning
at specific Location
FILL F range list ; Fill in a range of memory
GO G [=address] [addresses] ; Execute a program in memory
HEX H value1 value2 ; Add and subtract two Hex values
INPUT I port
LOAD L [address] [drive] [first sector] [number]
MOVE M range address
NAME N [pathname] [arg list]
OUTPUT O port byte
PROCEED P [=address] [number]
QUIT Q
REGISTER R [register]
SEARCH S range list
TRACE T [=address] [value]
UNASSEMBLE U [range]
WRITE W [address] [drive] [first sector] [number]
ALLOCATE expanded memory XA [#pages]
DEALLOCATE expanded memory XD [handle]
MAP expanded memory pages XM [Lpage] [Ppage] [handle]
DISPLAY expanded memory status XS



MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 6

FLOW CHART:

























START
Initialize DS
AL Data1
BL Data2


AL AL+BL
Data Memory AL
AL Data1


AX AL*BL
Data Memory AX
AX AX / BL
Data Memory AX
AL Data1
AH 00H

AL Data1


STOP
AL AL-BL
Data Memory AL
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 7

Exp No:
Date:
ARITHMETIC OPERATIONS ON 8- BIT DATA

ABSTRACT: Assembly language program to perform all arithmetic operations on 8-bit data
PORTS USED: None
REGISTERS USED: AX, BL
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load the given data to registers AL& BL
Step4: Perform addition and Store the result
Step 5: Repeat step 3
Step6: Perform subtraction and Store the result
Step7: Repeat step 3
Step8: Perform multiplication and Store the result
Step9: Repeat step 3
Step10: Perform division and Store the result
Step11: stop.


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 8

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 9

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 EQU 04H
N2 EQU 06H
RESULT DB 06H DUP (00)
DATA ENDS
CODE SEGMENT
START:
MOV AX , DATA
MOV DS , AX
MOV AL , N1
MOV BL, N2
ADD AL, BL
MOV [RESULT], AL
MOV AL, N1
SUB AL, BL
MOV [RESULT+1], AL
MOV AL, N1
MUL BL
MOV [RESULT+2], AL
MOV [RESULT+3], AH
MOV AL, N1
MOV AH, 00H
DIV BL
MOV [RESULT+4], AL
MOV [RESULT+5], AH
MOV AH, 4CH
INT 21H
CODE ENDS
END START

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 10


CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address





























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 11

RESULT:



























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 12

FLOW CHART:


























START
Initialize DS
SI 1000H
AX Data1
BX Data2


AX AX+BX
[SI] AX
AX Data1


AX, DX AX*BX
[SI+4] AX, DX
AX, DX DX AX / BX
[SI+8] AX,DX
AX Data1
DX 0000H

AX Data1


STOP
AX AX-BX
[SI+2] AX
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 13


Exp No:
Date:
ARITHMETIC OPERATIONS ON 16BIT DATA

ABSTRACT: Assembly language program to perform all arithmetic operations on 16bit data
PORTS USED: None
REGISTERS USED: AX, BX, SI
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Initialize SI with some memory location
Step4: Load the given data to registers AX & BX
Step5: Perform addition and Store the result
Step6: Repeat step 4
Step7: Perform subtraction and Store the result
Step8: Repeat step 4
Step9: Perform multiplication and Store the result
Step10: Repeat step 4
Step11: Perform division and Store the result
Step12: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 14

MANUAL CALCULATIONS:


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 15

PROGRAM:

ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 EQU 8888H
N2 EQU 4444H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV SI, 5000H
MOV AX, N1
MOV BX, N2
ADD AX, BX
MOV [SI], AX
MOV AX, N1
SUB AX, BX
MOV [SI+2], AX
MOV AX, N1
MUL BX
MOV [SI+4], AX
MOV [SI+6], DX
MOV AX, N1
MOV DX, 0000
DIV BX
MOV [SI+8], AX
MOV [SI+0AH], DX
MOV AH, 4CH
INT 21H
CODE ENDS
END START

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 16

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address





























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 17

RESULT:























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 18

FLOW CHART:











NO

YES









NO
YES


START
Initialize DS
Initialize Data1, Data2
CX COUNT
BX COUNT-1


AL Data1 [bx]
BX BX-1
CX CX-1
STOP
AL Data1 [bx] +Data2 [bx]+CF
Data memory AL
CX=0
CX COUNT
BX COUNT-1

AL Data1 [bx]
AL Data1 [bx]-Data2 [bx]-CF
Data memory AL
BX BX-1
CX CX-1
CX=0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 19

Exp No:
Date:

MULTIBYTE ADDITIONS AND SUBTRACTION

ABSTRACT: Assembly language program to perform multibyte addition and subtraction
PORT USED: None
REGISTERS USED: AL, BX, CX
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load CX register with count
Step4: Load BX register with No. of bytes
Step5: Copy the contents from the memory location n1 [BX] to AL
Step6: Perform addition with second number n2 [BX]
Step7: Store 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
Step11: Load BX register with no: of bytes
Step12: Store the contents from memory location n1 [BX] to AL
Step13: Perform subtraction with second number n2 [BX]
Step14: Store the result to the memory location sum [BX]
Step15: Decrement BX
Step16: Decrement CX, if CX not equal to Zero jump to step12
Step17: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 20

MANUAL CALCULATIONS:


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 21

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
MOV CX, COUNT
MOV BX, 0002H
CLC
BACK: MOV AL, N1 [BX]
ADC AL, N2 [BX]
MOV SUM [BX], AL
DEC BX
LOOP BACK
MOV CX, COUNT
MOV BX, 0002H
CLC
BACK1: MOV AL, N1 [BX]
SBB AL, N2 [BX]
MOV DIFF [BX], AL
DEC BX
LOOP BACK1
MOV AH, 4CH
INT 21H
CODE ENDS
END START
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 22


CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address






























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 23

RESULT:







MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 24

FLOW CHART:



















START
Initialize DS
AL Data1
BL Data2


AL Data1


AL 2`S Complement of AL
AX signed AL
AX AX/BL
Data memory AX

AL 2`S Complement of AL

AX AL*BL
Data memory AX
STOP
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 25

Exp No:
Date:
SIGNED OPERATIONS ON 8 BIT DATA

ABSTRACT: Assembly language program to perform signed operations
PORT USED: None
REGISTERS USED: AL, BL
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load AL with first number
Step4: Do 2s compliment of AL
Step5: Load BL with second number
Step6: Perform signed Multiplication
Step7: Store the result in data memory
Step8: Load AL with first number
Step9: Repeat step 4
Step10: Convert AL to AX
Step11: Perform signed division
Step12: Store the result in data memory
Step13: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 26

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 27

PROGRAM:
ASSUME CS: CODE , DS: DATA
DATA SEGMENT
N1 DB 08H
N2 DB 04H
RESULT DW 02 DUP (00)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AL, N1
NEG AL
MOV BL, N2
IMUL BL
MOV [RESULT], AX
MOV AL, N1
NEG AL
CBW
IDIV BL
MOV [RESULT+2], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START


Decrement
CX, if CX not
equal to
Zero jump
to step12
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 28


CODE TABLE:

Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address





























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 29

RESULT:






































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 30

FLOW CHART:























Initialize DS
AL ASCII 1
BL ASCII 2


AL AL+BL
Ascii Adjustment after addition
Data Memory AX
AL Ascii 1


START
AX AL*BL
Ascii Adjustment after Multiplication
Data Memory AX
Ascii Adjustment before division
AX AX / BL
Data Memory AX
AL Data1
BL Data2


AL AL-BL
Ascii Adjustment after subtraction
Data Memory AX
STOP
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 31

Exp No:
Date:
ASCII ARITHMETIC OPERATIONS

ABSTRACT: Assembly language program to perform ASCII arithmetic operations
PORT USED: None
REGISTERS USED: AL, BL, SI
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load SI with Memory location
Step4: Load AL with first number in ASCII form
Step5: Load BL with Second number in ASCII form
Step6: Perform addition
Step7: Perform ASCII adjustment after addition
Step8: Store the result to the data memory
Step9: Load AL with first number in ASCII form
Step10: Perform subtraction
Step11: Perform ASCII adjustment after subtraction
Step12: Store the result to the data memory
Step13: Load AL with first number
Step14: Perform multiplication
Step15: Perform ASCII adjustment after multiplication
Step16: Store the result to the data memory
Step17: Load AL with first number
Step18: Perform ASCII adjustment before division
Step19: Perform division
Step20: Store the result to the data memory
Step21: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 32

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 33

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 DB 8
N2 DB 4
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA
MOV DS, AX
MOV SI, 5000H
XOR AX, AX
MOV AL,N1
MOV BL,N2
ADD AL ,BL
AAA
MOV[ SI], AX
MOV AL, N1
SUB AL, BL
AAS
MOV [SI+2], AX
MOV AL, 08H
MOV BL, 04H
MUL BL
AAM
MOV [SI+4], AX
AAD
DIV BL
MOV [SI+6], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 34


CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address





























Decrement
CX, if CX not
equal to
Zero jump
to step12
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 35

RESULT:


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 36

FLOW CHART:
Al AH
AL AL .0FH
AH AH .F0H

Initialize DS
AL BCD Num
CL 04H

AH Cir AH by CL times
AL AL+30h

AH AH+30h

Data Memory AX
STOP
START
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 37

Exp No:
Date:
BCD TO ASCII CONVERSION

ABSTRACT: Assembly language program to convert BCD number to ASCII number
PORT USED: None
REGISTERS USED: AL, AH, CX
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load AL with BCD number
Step4: Copy the contents from AL to AH
Step5: Perform AND operation on AL with 0Fh
Step6: Perform AND operation on AL with F0h
Step7: Rotate the AH contents by four times
Step8: Perform OR operation on AL with 30h
Step10: Perform OR operation on AH with 30h
Step11: Store the result to the memory location
Step12: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 38

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 39

PROGRAM:
ASSUME CS: CODE,DS: DATA
DATA SEGMENT
BCD DB 17H
ASCII DW ?
DATA ENDS
CODE SEGMENT
ORG 1000H
START: 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
CODE ENDS
END START


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 40

CODE TABLE:
Physical Address
Label

Hex
Code

Mnemonic
operand

Comments
Segment
Address
Offset
Address

























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 41

RESULT:















































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 42

FLOW CHART:

AL AL .0FH
BL BL .0FH

Initialize DS
AL Ascii 1
BL Ascii 2
CL 04H

AL Cir AL by CL times

AL AL+BL

Data Memory AL
STOP
START
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 43

Exp No:
Date:
ASCII TO BCD CONVERSION

ABSTRACT: Assembly language program convert ASCII number to BCD number
PORT USED: None
REGISTERS USED: AL, BL, CX
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load AL with ASCII number
Step4: Copy the contents from AL to BL
Step5: Perform AND operation on AL with 0Fh
Step6: Perform AND operation on BL with 0Fh
Step7: Rotate the AL contents by four times
Step8: Perform OR operation on AL with BL
Step9: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 44

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 45

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ASCII
1
DB 1
ASCII
2
DB 7
BCD DB ?
DATA ENDS
CODE SEGMENT
ORG 1000H
START:MOV AX, DATA
MOV DS, AX
MOV CL, 04H
MOV AL, ASCII
1
MOV BL, ASCII
2
AND AL, 0FH
AND BL, 0FH
ROR AL, CL
OR AL, BL
MOV BCD, AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 46

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address



























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 47

RESULT:

















































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 48

FLOW CHART:

















YES





AL [SI]
AL Cir left AL
CF=1
CX CX-1
START
Initialize DS
CX COUNT
SI Offset LIST
DX 0000h

CX=0
Data memory DX
STOP
DH DH+1
SI SI+1
DL DL+1
SI SI +1
NO
YES
YES
NO
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 49

Exp No:
Date:
POSITIVE AND NEGATIVE COUNT IN AN ARRAY NUMBERS

ABSTRACT: Assembly language program to count number of positive and negative numbers
PORT USED: None
REGISTERS USED: SI, DX, CX, AL
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load CX register with count value
Step4: Initialize DX with 0000h
Step5: Load SI with offset list
Step6: Copy the contents from memory location SI to AL
Step7: Rotate left the content 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
Step15: Decrement CX and jump to step6 if no zero
Step16: Store the result to the data memory
Step17: Stop

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 50

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 51

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DB 0FFH, 0DDH, 04H, 05H, 98H
RESULT DW ?
DATA ENDS
CODE SEGMENT
ORG 1000H
START:MOV AX, DATA
MOV DS, AX
LEA SI, LIST
MOV CX, 0005H
MOV DX, 0000H
BACK:MOV AL, [SI]
ROL AL, 01H
JC NEGATIVE
INC DL
INC SI
LOOP BACK
JMP EXIT
NEGATIVE: INC DH
INC SI
LOOP BACK
EXIT: MOV [RESULT], DX
MOV AH, 4CH
INT 21H
CODE ENDS
END START






MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 52

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address






























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 53

RESULT:

















































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 54

FLOW CHART:
DH DH+1
SI SI+1
DL DL+1
SI SI +1
AL [SI]
AL Cir right AL
CF=1
CX CX-1
START
Initialize DS
CX COUNT
SI Offset LIST
DX 0000h

CX=0
Data memory DX
STOP
NO
NO
YES
YES
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 55

Exp No:
Date:
ODD AND EVEN COUNT IN AN ARRAY NUMBERS

ABSTRACT: Assembly language program to count number of odd and even numbers
PORT USED: None
REGISTERS USED: AL, CX, DL, DH, SI
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load CX register with count
Step4: Initialize DX with 0000
Step5: Load SI with offset list
Step6: Copy the contents from memory location SI to AL
Step7: Rotate right the content 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
Step15: Decrement CX and jump to step6 if no zero
Step16: Store the result to the data memory
Step17: Stop

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 56


MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 57

PROGRAM:
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
BACK: MOV AL, [SI]
ROR AL, 01H
JC ODD
INC DL
INC SI
LOOP BACK
JMP EXIT
ODD: INC DH
INC SI
LOOP BACK
EXIT: MOV [RESULT], DX
MOV AH, 4CH
INT 21H
CODE ENDS
END START













MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 58

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address





























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 59

RESULT:

















































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 60

FLOW CHART:

BL AL
AL AL .0FH
BL BL .F0H

Initialize DS
AL Packed BCD Num
CL 04H

BL Cir BL by CL times
Data Memory AL, BL
STOP
START
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 61

Exp No:
Date:
PACKED BCD TO UNPACKED BCD CONVERSION

ABSTRACT: Write a program to convert packed BCD number into Unpacked BCD number.
REGISTERS USED: AL, BL
PORTS USED: None.
ALOGARITHM:
Step1: Start
Step2: Initialize the data segment
Step3: Copy packed number into AL register
Step4: Copy packed number into BL register
Step5: Initialize the count CX with 04h
Step6: Perform AND operation on AL with 0Fh
Step7: Perform AND operation on BL with 0F0h
Step8: Rotate right without carry operation on BL by CL times
Step9: Move the result data memory
Step10: Stop

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 62

MANUAL CALCULATIONS:


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 63

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N EQU 29H
RESULT DB 02H DUP (0)
DATA ENDS
CODE SEGMENT
ORG 2000h
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
CODE ENDS
END START














MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 64

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address






























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 65

RESULT:
















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 66

FLOW CHART:











NO

YES



START
ES: DI DS: SI
CX CX-1
SI SI+1
DI DI+1


Initialize DS, ES
SI Offset string
DI Memory location
CX Count

STOP
CX=0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 67

Exp No:
Date:
MOVE BLOCK OF DATA

ABSTRACT: Assembly language program to transfer a block of data.
PORT USED: None.
REGISTERS USED: AX, BL.
ALGORITHM:
Step1: Start
Step2: Initialize data segment & extra segment
Step3: Define the String
Step4: Load CX register with length of the String
Step5: Initialize DI with memory location
Step6: Load SI with offset list
Step7: Repeat the process of moving string byte from SI to DI until CX equals to zero
Step8: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 68

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 69

PROGRAM:
ASSUME CS: CODE, DS: DATA, ES: DATA
DATA SEGMENT
LIST DB ADITYA
COUNT EQU 06H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV CX, COUNT
MOV DI, 5000H
LEA SI, LIST
CLD
REP MOVSB
MOV AH, 4CH
INT 21H
CODE ENDS
END START


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 70

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address






























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 71

RESULT:





















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 72

FLOWCHART:











NO




NO

YES





START
AL [SI]
AL [DI]
[SI] AL
Initialize DS, ES
SI Offset string
BX 0002h
CX Count
DI Count-1

STOP
CX=0
CX AX
AX, DX AX/BX
CX AX


SI SI+1
DI DI+1
CX CX-1
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 73

Exp No:
Date:
REVERSAL OF GIVEN STRING
ABSTRACT: Assembly language program to reverse a given string
PORT USED: None
REGISTERS USED: AX, BL
ALGORITHM:
Step1: Start
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
Step6: Initialize DI with (count-1)
Step7: Initialize BX with 02
Step8: Perform division with BX
Step9: Copy the contents from AX to CX
Step10: Move the contents from memory location SI to AL
Step11: Exchange the contents of AL with [DI]
Step12: Move the contents from memory location AL to SI
Step13: Increment SI
Step14: Decrement DI
Step15: Decrement CX and jump to step10 if no zero
Step16: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 74

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 75

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DB MICRO PROCESSOR
COUNT EQU ($-LIST)
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV CX, COUNT
MOV AX, CX
MOV SI, OFFSET LIST
MOV DI, (COUNT-1)
MOV BX, 02
DIV BX
MOV CX, AX
BACK: MOV AL,[SI]
XCHG AL,[DI]
MOV [SI], AL
INC SI
DEC DI
LOOP BACK
MOV AH, 4CH
INT 21H
CODE ENDS
END START


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 76

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address





























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 77

RESULT:

































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 78

FLOW CHART:










YES
NO





NO
YES


NO
YES

START
CX CX-1
Initialize DS
CX Count
DX Count

STOP
CX=0
AL [SI]
SI SI+1
Compare AL, [SI]
[SI ] AL
SI SI-1
[SI] AL
SI Offset list
CX DX

CF=1
DX DX-1
DX=0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 79


Exp No:
Date:
SORTING OF N NUMBERS

ABSTRACT: Assembly language program to do sorting of numbers in a given series
PORT USED: None
REGISTERS USED: CX, DX, AL, SI
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load CX register with count
Step4: Copy the contents from CX to DX
Step5: Load SI with offset list
Step6: Copy the contents from DX to CX
Step7: Move the contents from memory location SI to AL
Step8: Increment SI
Step9: Compare AL contents with [SI]
Step10: Jump to step15 if carry
Step11: Exchange the contents of AL with [SI]
Step12: Decrement SI
Step13: Move the contents from AL to memory location SI
Step14: Increment SI
Step15: Decrement CX and jump to step7 if no zero
Step16: Decrement DX and jump to step5 if no zero
Step17: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 80

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 81

PROGRAM:
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
NEXT: LOOP BACK
DEC DX
JNZ AGAIN
MOV AH, 4CH
INT 21H
CODE ENDS
END START

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 82

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address






















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 83

RESULT:
















































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 84

FLOW CHART:









YES

NO







START
Initialize DS, ES
DI Offset string
DX 0000h
AL NULL Character

STOP
ZF=0
Compare AL, ES:[DI]


DX DX+1
DI DI+1
Data memory DX
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 85

Exp No:
Date:

LENGTH OF THE GIVEN STRING
ABSTRACT: Assembly language program to find the Length of a string
PORT USED: None
REGISTERS USED: AX, BL
ALGORITHM:
Step1: Start
Step2: Initialize data segment & extra segment
Step3: Load AL with $
Step4: Load SI with offset list
Step5: Initialize DX with 0000
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
Step10: Store the result to the memory location
Step11: Stop

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 86


MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 87

PROGRAM:
ASSUME CS: CODE, DS: DATA, ES: DATA
DATA SEGMENT
LIST DB ADITYA$
LEN DW ?
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV AL,$
LEA DI, LIST
MOV DX, 0000H
CLD
BACK: SCASB
JE EXIT
INC DX
JMP BACK
EXIT: MOV LEN, DX
MOV AH, 4CH
INT 21H
CODE ENDS
END START




MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 88

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address






























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 89

RESULT:

















































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 90


FLOW CHART:










NO
YES



NO

YES






START
Repeat Compare ES: DI,DS:SI

Initialize DS, ES
SI Offset string1
DI Offset String2
AX Length1
BX Length2

STOP
ZF=0
Compare AX, BX
ZF=0
Data memory NO

Data memory Yes
CX AX
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 91

Exp No:
Date:
COMPARISON OF TWO STRINGS
ABSTRACT: Assembly language program to compare two strings.
PORT USED: None
REGISTERS USED: AX, BL
ALGORITHM:
Step1: Start
Step2: Initialize data segment & extra segment
Step3: Load AX with length of String 1
Step4: Load BX with length of String 2
Step5: Compare AX with BX
Step6: Jump step14 if not equal
Step7: Copy the contents from AX to CX
Step8: Load SI with first location of string 1
Step9: Load DI with first location of string 2
Step10: Repeat comparing string byte until count equals to zero
Step11: jump to step 14 if not equal
Step12: Store the result to the data memory
Step13: Jump to step 15
Step14: Store another result to the data memory
Step15: Stop


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 92

MANUAL CALCULATIONS:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 93

PROGRAM:
ASSUME CS: CODE, DS: DATA, ES: DATA
DATA SEGMENT
LIST1 DB ADITYA
LEN1 EQU ($-LIST1)
LIST2 DB ADITYA
LEN2 EQU ($-LIST2)
RESULT DW ?
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV AX.LEN1
MOV BX, LEN2
CMP AX, BX
JNE EXIT
MOV CX, AX
MOV SI, OFFSET LIST1
MOV DI, OFFSET LIST2
CLD
REP CMPSB
JNE EXIT
MOV RESULT, 5555H
JMP NEXT
EXIT: MOV RESULT, 0FFFFH
NEXT: MOV AH, 4CH
INT 21H
CODE ENDS
END START
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 94

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address






























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 95

RESULT:































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 96

FLOW CHART:









YES

NO






START
AL 13h
AH 00H
Interrupt 10H
STOP
ZF=0
Compare AL, q


AH 00H
Interrupt 10H
BL 0Fh
AH 14
Interrupt 10H
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 97

Exp No:
Date:
READING KEYBOARD BUFFERED WITH ECHO
ABSTRACT: To Read the Keyboard Buffered with Echo.
REGISTERS USED: AH, AL, SI.
PORTS USED: None.
ALGORITHM:
Step1: Start.
Step2: Load the number 13h into AL register.
Step3: Initialize the AH register with 00h
Step4: Display interrupt
Step5: Initialize the AH register with 00h
Step6: Key board Interrupt
Step7: Compare the data in AL register with character q.
Step8: If equal to zero go to step 12.
Step9: Move the number 0Fh into BL register.
Step10: Move the number 14 into AH register.
Step11: Keyboard Interrupt.
Step12: Load the number 4C in AH register.
Step13: Stop.

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 98


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 99

PROGRAM:
ASSUME CS: CODE
CODE SEGMENT
ORG 1000h
START: MOV AH, 00H
MOV Al, 13H
INT 10H
BACK: MOV AH, 00h
INT 16H
CMP AL, q
JE EXIT
MOV BL, 0FH
MOV AH, 14
INT 10H
JMP BACK
EXIT: MOV AH, 4CH
INT 21H
CODE ENDS
END START




MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 100

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic
operand

Comments
Segment
Address
Offset
Address





























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 101

RESULT:










MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 102

FLOW CHART:









YES

NO





START
Initialize DS, CS
SI 2000H



STOP
ZF=0
Compare AL, q


AH 00H
Interrupt 16H
[SI] AL
SI SI+1


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 103

Exp No:
Date:
READING KEYBOARD BUFFERED WITHOUT ECHO
ABSTRACT: To read the string or character from keyboard without ECHO by using BIOS
Commands.
REGISTERS USED: AH, AL, SI
PORTS USED: None.
ALGORITHM:
Step1: Start
Step2: Initialize SI with Offset Result.
Step3: Initialize AH with 00h
Step4: Keyboard Interrupt
Step5: Compare AL with character q.
Step6: Copy the contents AL into SI register.
Step7: If equal to zero go to step 10
Step8: Increment SI.
Step9: Go to step 3 without condition.
Step10: Terminate the program.
Step11: Stop.

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 104


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 105

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 3000h
RESULT DB 50h DUP (0)
DATA ENDS
CODE SEGMENT
ORG 1000h
START: MOV SI, OFFSET RESULT
BACK: MOV AH, 00h
INT 16h
CMP AL, q
MOV [SI], AL
JE EXIT
INC SI
JMP BACK
EXIT: MOV AH, 4Ch
INT 21h
CODE ENDS
END START





MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 106

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address





























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 107

RESULT:
































MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 108


FLOW CHART:









YES

NO








START
AL 13h
AH 00H
Interrupt 10H
STOP
ZF=0
AL Text [SI]
Compare AL, q


Initialize DS
SI Offset Text

BL 0Fh
AH 14
Interrupt 10H
SI SI+1

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 109

Exp No:
Date:
DISPLAY STRING BY USING DOS & BIOS COMMANDS
ABSTRACT: To display the string character by using BIOS 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.
Step6: Copy the contents SI into AL register.
Step7: Compare AL register with null character !
Step8: If equal go to step 11.
Step9: Move the number 14 into AH register.
Step10: Move the number 05h into BL register.
Step11: Set keyboard display mode.
Step12: Go to step 6.
Step 13: Terminate the program.
Step14: Stop.


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 110


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 111

PROGRAM:

ASSUME CS: CODE, DS: DATA
DATA SEGMENT
TEXT DB ADITYA MICROPROCESSORS LAB!'
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV AH, 00H
MOV AL, 13H
INT 10H
MOV SI, 00H
BACK: MOV AL, TEXT [SI]
CMP AL,'!'
JE EXIT
MOV AH, 14
MOV BL, 05H
INT 10H
INC SI
JMP BACK
EXIT: MOV AH, 4CH
INT 21H
CODE ENDS
END START



MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 112

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address



















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 113

RESULT:












MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 114


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 115

Exp No:
Date:
DIGITAL TO ANALOG CONVERTER

GENERATION OF WAVE FORMS:
AIM: program to generate the following wave forms:
Triangular wave forms
Saw tooth wave forms
Square wave

REGISTERS USED: general purpose registers: AL, DX, and CX
PORTS USED: Out (port-B)
CONNECTION: J
4
of ESA 86/88 to J
1
DAC interface.
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 X
out
and Y
out
at which the wave forms are observed on a CRO. (port A is used to
control X
out
port B is used to control Y
out
).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 op-amps is done by making use of the two 10k pots provided. The output
wave forms are observed at X
out
and Y
out
on an oscillator.
THEORY:
BASIC DAC TECHNIQUE:
V
o
= K V
FS
(d1 .2
-1
+ d
2
. 2
-2
+ . . . . . . . .+d
n .
2
-n
)
Where d
1
= MSB, d
2
= LSB
V
FS
= 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 V
R

to give an analog output. The out put can be either voltage or current
Out put voltage V
o
= K V
FS
(d
1
.2
-1
+ d
2.
2
-2
+ . . . . . . . . +d
n.
2
-n
)
MSB weight = V
FS
if d
1
= 1 and all are zeros, K = 1.
LSB weight = V
FS
/2
n
if dn = 1 and all are zeros, K = 1
DUAL DAC INTERFACE:
This program generates a square wave or a Triangular wave at points X
out
or Y
out
of
interface. The waveforms may be observed on an oscilloscope.

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 116

FLOW CHART:













NO
YES





NO
YES



START
DX Addr. Of CWR
AL 80

CX=0
[DX] AL
AL AL+1
CX CX-1

CX=0
[DX] AL
CX FFH

DX Addr. Of Port-A
AL 00
CX FFH

[DX] AL
AL AL-1
CX CX-1

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 117


This program can be executed in STAND-ALONE MODE or SERIAL MODE of
operation.
The program starts at memory location 3000H
ALGORITHM: (FOR TRIANGULAR WAVE):
Step 1: Start
Step 2: Initialize the control word register with all ports as simple I/O mode
Step 3: Load Maximum Amplitude value to CX register.
Step 4: Load 00 to AL register.
Step 5: Initialize the port A address.
Step 6 : Locate the contents of AL to DX register.
Step 7: Increment the value in AL by one.
Step 8: Locate AL contents to DX register.
Step 9: Decrement the value of CX register by one and go to step 6 if CX not equal to zero.
Step 10: Load 00FF to CX register.
Step 11: Decrement the value of AL by one.
Step 12: Locate the contents in AL register to DX register.
Step 13: Decrement the value of CX by one and go to step 12 if CX not equal to zero.
Step 14: Otherwise move to step 3
Step 15: Stop.


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 118


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 119

PROGRAM (FOR TRIANGULAR WAVE):

MOV DX, 0FFE6
MOV AL, 80
OUT DX, AL
MOV DX, 0FFE0
MOV AL, 00
RPT: MOV CX, 0FF
L
1
: OUT DX, AL
INC AL
LOOP L
1
MOV CX, 0FF
L
2
: OUT DX,AL
DEC AL
LOOP L
2
JMP RPT

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 120

CODE TABLE:

Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address


















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 121

RESULT:

















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 122

FLOW CHART:











NO
YES

START
DX Addr. Of CWR
AL 80

[DX] AL
AL AL+1
CX CX-1

CX=0
[DX] AL
DX Addr. Of Port-A
AL 00
CX FFH

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 123

ALGORITHM (FOR SAW TOOTH WAVE):

Step 1: Start
Step 2: Initialize the control word register with all ports as simple I/O mode
Step 3: Load Maximum Amplitude value to CX register.
Step 4: Load 00 to AL register.
Step 5: Initialize the port A address.
Step 6 : Locate the contents of AL to DX register.
Step 7: Increment the value in AL by one.
Step 8: Locate AL contents to DX register.
Step 9: Decrement the value of CX register by one and go to step 6 if CX not equal to zero.
Step 10: Go to step 4 and Repeat


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 124


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 125

PROGRAM (FOR SAW TOOTH WAVE):

MOV DX, 0FFE6
MOV AL, 80
OUT DX,AL
MOV DX, 0FFE0
MOV AX, 00
RPT: MOV CX, 0FF
L
1
: OUT DX, AX
INC AX
LOOP L
1
MOV AX, 00
OUT DX, AX
JMP RPT


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 126

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address



















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 127

RESULT:

















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 128


FLOW CHART:











NO
YES





NO
YES


START
DX Addr. Of CWR
AL 80

CX=0
[DX] AL


CX=0
[DX] AL
CX COUNT
AL FFH


DX Addr. Of Port-A
AL 00
CX COUNT

CX CX-1

CX CX-1


[DX] AL


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 129

ALGORITHM (FOR SQUARE WAVE):

Step 1: Start
Step 2: Initialize the control word register with all ports as simple I/O mode
Step 3: Load Maximum Amplitude value to AX register.
Step4: Initialize the port A address.
Step 5 : Transmit the contents of AX to port A
Step 6: Create Delay
Step 7: Load Minimum Amplitude value to AX register.
Step 8: Transmit the contents of AX to port A
Step 9: Create Delay
Step 10: Go to Step 3 and Repeat

ALGORITHM FOR DELAY
Step 1: Load the CX register with 93h
Step 2: Decrement CX
Step 3: Repeat Step 2 till CX is zero
Step4: Return to main program








MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 130


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 131

PROGRAM (FOR SQUARE WAVE):

MOV DX, 0FFE6
MOV AL, 80
OUT DX, AL
MOV DX, 0FFE0
RPT: MOV AX, 0FF
OUT DX, AX
CALL DELAY
MOV AX, 00
OUT DX, AX
CALL DELAY
JMP RPT
DELAY PROGRAM:
MOV CX, 1E
L1: NOP
NOP
LOOP L1
RET

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 132

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address
























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 133

RESULT:






MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 134



FLOW CHART:

















NO

YES

EFFECTIVE
ADDRESS
HEX CODES
4000 7F 8A 95 A0

4004 AA B5 BF C8
4008 D1 D9 E0 E7
400C ED F2 F7 FA
4010 FC FE FF FE
4014 FC FA F7 F2
4018 ED E7 E0 D9
401C D1 C8 BF B5
4020 AA A0 95 8A
4024 7F 74 69 5F
4028 53 49 3F 36
402C 2D 25 1D 17
4030 10 0B 07 04
4034 01 00 01 04
4038 07 0B 10 17
403C 1D 25 2D 36
4040 3F 49 53 5F
4044 69 74
START
DX Addr. Of CWR
AL 80

AL [SI]
[DX] AL
SI SI+1
CX CX-1

CX=0
[DX] AL
DX Addr. Of Port-A
SI Memory location
CX Count

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 135


ALGORITHM (FOR SINE WAVE):
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: 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 8: Move the contents SI into AL register.
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.





MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 136


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 137

PROGRAM FOR SINE WAVE:

MOV DX, 0FFE6
MOV AL, 80
OUT DX, AL
RPT: MOV SI, 4000
MOV CL, 46
MOV DX, 0FFE0
L1: MOV AL, [SI]
OUT DX, AL
INC SI
LOOP L1
JMP RPT




MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 138

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address
























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 139

RESULT:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 140


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 141

Exp No:
Date:
KEYBOARD INTERFACING
AIM: To display a string through interfacing 8279.
REGISTERS USED: AX, BX, CX, DX, SI
PORTS USED: command port, data port
CONNECTIONS: 8279 study card P
1
to J
2
of ESA 86/88 study card adapter.
DESCRIPTION:8279 study card provides keyboard as well as display section. The display
section features size 8 digit seven segment displays while the keyboard connections
comprises a 4x 4 matrix hex key pad and associated circuitry. The options for using shift and
controls keys during key scanning are also provided. The interface has 3 connectors, P
1,
J
1
, &
J
4
to interface the card with ESA 86/88E trainers. Connect the 50 pin FRC connectors P
1
to
connector J
2
to ESA 86/88E study card adapter.
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 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
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 142


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 143



PIN OUT DEFINITION 8279
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.
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 144


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 145


8279 Interfaced to the 8088

Keyboard Interface of 8279

KEYBOARD INTERFACE OF 8279:
The keyboard matrix can be any size from 2x2 to 8x8.
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.
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 146


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 147


D7 D6 D5 Function Purpose
0 0 0 Mode set
Selects the number of display positions, type of key
scan
0 0 1 Clock Programs internal clk, sets scan and debounce times.
0 1 0 Read FIFO Selects type of FIFO read and address of the read.
0 1 1 Read Display Selects type of display read and address of the read.
1 0 0 Write Display Selects type of write and the address of the write.
1 0 1
Display write
inhibit
Allows half-bytes to be blanked.
1 1 0 Clear Clears the display or FIFO
1 1 1 End interrupt Clears the IRQ signal to the microprocessor.

o The first 3 bits of # sent to control port selects one of 8 control words.
Keyboard Interface of 8279
First three bits given below select one of 8 control registers (opcode).
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.
DD Function
00 8-digit display with left entry
01 16-digit display with left entry
10 8-digit display with right entry
11 16-digit display with right entry

Keyboard Interface of 8279
o 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
011 Decoded keyboard with N-key rollover
100 Encoded sensor matrix
101 Decoded sensor matrix
110 Strobed keyboard, encoded display scan
111 Strobed keyboard, decoded display scan
o Encoded: SL outputs are active-high, follow binary bit pattern 0-7 or 0-15.
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 148


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 149

o Decoded: SL outputs are active-low (only one low at any time).
Pattern output: 1110, 1101, 1011, 0111.
o 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.
o 2-key lockout/N-key rollover: Prevents 2 keys from being recognized if
pressed simultaneously/Accepts all keys pressed from 1
st
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.

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
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.
2) Keyboard type is programmed next.
o The previous example illustrates an encoded keyboard, external decoder used
to drive matrix.
3) Program the FIFO.
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:
Code given in text for reading keyboard.
Data returned from 8279 contains raw data that need to be translated to ASCII:
o Row and column number are given the rightmost 6 bits (scan/return).
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 150


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 151

o This can be converted to ASCII using the XLAT instruction with an ASCII
code lookup table.
o The CT and SH indicate whether the control or shift keys were pressed.
o The Strobed Keyboard code is just the state of the RLx bits at the time a 1 was
strobed on the strobed input pin.


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 152


FLOW CHART:



















NO
YES


NO

YES
SI Memory Location
DX Addr. Of Command word of 8279
CX COUNT, AL 10H

[DX] AL
AL D3H

AL [SI]
SI SI+1
[DX] AL

CX CX-1
DX Addr. Of Data register of 8279

[DX] AL
START
[DX] AL
AL 90H

DX DELAY

DX DX-1
DX=0
CX=0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 153

ALGORITHM:
Step 1: Start
Step 2: Load SI with memory location.
Step 3: Move 10 to AL register.
Step 4: Load CX with count.
Step 5: Initialize the Command word register i.e., 0FF42
Step 6: Locate the contents in AL register to DX register using port out.
Step 7: Move D3 to AL register.
Step 8: Locate the contents in AL register to DX register using port out.
Step 9: Move 90 to AL register.
Step 10: Locate the contents in AL register to DX register using port out
Step 11: Initialize the Data Register address ie. 0FF40
Step 12: Move the contents SI into AL register.
Step 13: Locate the contents in AL register to DX register using port out.
Step 14: Create Delay.
Step 15: Increment the value of SI.
Step 16: Decrement the counter and go to Step 11 until CX =0
Step 17: Jump to location step 5.

ALGORITHM FOR DELAY
Step 1: Load the DX register with 0FFFFh
Step 2: Decrement DX
Step 3: Repeat Step 2 till DX is zero
Step4: Return to main program


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 154


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 155

PROGRAM:
START: MOV SI, 2000H
MOV CX, 0008H
MOV AL, 10
MOV DX, 0FF42
OUT DX, AL
MOV AL, 0D3
OUT DX, AL
MOV AL, 90
OUT DX, AL
NEXT: MOV DX, 0FF40
MOV AL, [SI]
OUT DX, AL
CALL DELAY
INC SI
LOOP NEXT
JMP START
DELAY PROGRAM:
MOV DX, 0FFFFH
BACK: DEC DX
JNZ BACK
RET

INPUT DATA:
Segment address Offset address DATA INPUT
2000 00 77 F3 60 87 E6 77



MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 156


CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address


























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 157

RESULT:
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 158


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 159

Exp No:
Date:

.STEPPER MOTOR INTERFACING
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 J
1
of stepper motor.
OPERATING PRINCIPLE OF PERMANENT MAGNET STEPPER MOTOR:



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 F
a
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 F
a
. the resulting
magnetic field F makes an angle of 45
0
. the rotor consequently moves through 45
0
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 45
0
in anti-clockwise direction to aligne itself with stator
field F
b
. with voltage +V on winding B, a voltage V is applied to winding A. then the stator
magnetic field has two components F
a
, F
b
and their resultant F makes an angle of 135
0

position.

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 160


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 161

In this way it can be seen that ,as the pattern of excitation of the state of winding is changed,
the rotor moves successively through45
0
steps. And completes one full revolution in anti
clock-wise direction. A practical PM stepper motor will have 1.8
0
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
A = 360 / (N * K) degrees
Where N = number of rotor tooth.
K = execution sequence factor.
PM stepper motors have three modes of excitation i,e..
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 90
0
.
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 90
0
. However, the rotor positions in the two
phase mode are 45
0
way from those in single phase mode.
Hybrid mode: this is a combination of single and two phase modes. There are 8 steps in
excitation sequence=2 and step angle = 45
0
. 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 PA
0
, PA
1
, PA
2
, PA
3
are the four lines brought out to the 26 pin
FRC male connector(J
1
) 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 360
0
/N
T
. where
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 162


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 163

N
T
is the number of teeth on rotor. Generally the stepper motor is available with 10
to 30
0
rotation. They are available with two phases 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.9
0
to 30
0
. 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.
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 R
1
and R
2
are current limiting resistors.
Typical parameters of stepper motor:
1. Operating voltage - 12 volts
2. Current rating - 1.2 Amp
3. Step angle - 1.8
0

4. Step for revolution - 200(No. of teeth on rotor)
5. Torque - 3 kg/cm
Working of stepper motor:
Suppose that SW
1
and SW
2
are turned ON. Turning OFF SW
2
and turning ON SW
4

cause the motor to rotate one step of 1.8
0
clockwise. Changing to SW
4
and SW
3
ON will
cause the motor to rotate 1.8
0
clockwise another. Changing SW
3
and SW
2
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


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 164

FLOW CHART











NO

YES




NO

YES










NO


YES




NO YES
START
DX Addr. Of CWR
AL 80

[DX] AL

CX=0
[DX] AL
DX Addr. Of Port-A
AL Data
BX STEPS

CX CX-1
AL Cir left AL
BX BX-1
CX COUNT
BX=0
BX STEPS
[DX] AL

CX COUNT
CX=0
CX CX-1
AL Cir Right AL
BX BX-1
BX=0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 165

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:Intialize BX with 07d0
Step 6: move port A address ie.,,0FFE0 to DX register.
Step 7: move 11 to AL register.
Step 8: locate the contents in AL register to DX register using port out.
Step 9: move 300 to CX register.
Step 10: repeat step 8 until the content in CX register becomes equal to zero.
Step 11: Rotate carry left through bit.
Step 12: Decrement BX by one
Step 13: repeat steps from 8 until the content in BX register becomes equal to zero.
Step 14:Intialize BX with 07d0
Step 15: locate the contents in AL register to DX register using port out.
Step 16: move 300 to CX register.
Step 17: repeat step 15 until the content in CX register becomes equal to zero.
Step 18: Rotate carry left through bit.
Step 19: Decrement BX by one
Step 20: repeat steps from 15 until the content in BX register becomes equal to zero.
Step 21: jump to location / step 8.


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 166


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 167

PROGRAM:
MOV DX, 0FFE6
MOV AL, 80
OUT DX, AL
RPT: MOV BX,07D0
MOV DX, 0FFE0
MOV AL, 11
BACK: OUT DX, AL
MOV CX, 0300
L1: LOOP L1
ROL AL, 1
DEC BX
JNZ BACK
MOV BX,07D0
MOV AL, 11
BACK1:OUT DX, AL
MOV CX, 0300
L2: LOOP L2
ROR AL, 1
DEC BX
JNZ BACK1
JMP RPT

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 168

CODE TABLE:
Physical Address
Label

Hex Code

Mnemonic operand

Comments
Segment
Address
Offset
Address
























MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 169

RESULT:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 170


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 171

BASIC TUTORIAL FOR KEIL SOFTWARE
This tutorial will assist you in writing your first 8051 Assembly language program using the
popular Keil
Compiler. Keil offers an evaluation package that will allow the assembly and debugging of
files 2K or less.
1. Open Keil from the Start menu

2. Select New project from the project menu


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 172


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 173

3. Give the Project name


4. Click on the save button
5. The device window will be displayed. Select the part you will be using to test with.
For now we will use Generic. Double Click on the Generic


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 174


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 175

6. Scroll down and select the 8051(all Variants)part
7. Click OK



8. The dialog box will appear as below press YES

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 176


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 177

9. Click File menu and select NEW


10. A new window will open up in the Keil IDE

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 178


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 179

11. Write asm program on the editor


12. Click file menu and save

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 180


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 181

13. Name the file blinking.asm and click the save button


14. Expand Target 1 in the tree menu

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 182


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 183

15. Right click on source group and click on add files to group Source Group 1


16. Change file type to asm source file(*.a*;*.src) and click on blinking.asm
17. Click add button and click close button

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 184


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 185

18. Expand the source group 1 in the tree menu to ensure that the file was added t project


19. Click the project menu and click translate current active file

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 186


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 187

20. After click the translate in the build window shows the errors and warnings if any.


21. Click on target 1 in tree menu
22. Click on the project menu and select the options for Target1


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 188


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 189

23. Select Target tab and change Xtal (Mhz) from 12.0 to 11.0592


24. Select Output Tab and Click on create Hex file Check Box
25. Click ok button

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 190


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 191

26. Click on the project menu select build target in the build window it should report
errors and warnings, if any.


27. Click on the debug menu and select start/stop debug session

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 192


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 193

28. The keil debugger should be now be running


29. Click on peripherals. Select I/O ports

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 194


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 195

30. A new window should port will pop up. This represent the port and pins


31. Press F5 on the keyboard to run the program.


32. To exit out, Click on debug menu and select start/stop debug session.

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 196

FLOW CHART:

Write data to port
PA
Initialization ports as i/p
& o/p
Read data from port
AP
Start
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 197

Exp No:
Date:
PARALLEL PORT READ & WRITE OPERATION

ABSTRACT: Write an ALP to write and read data on a parallel port.
TOOLS USED: Keil Software
PORTS USED: P1, P2
REGISTERS USED: A (Accumulator)
ALGORITHM:
1. Write 0FFh to port selected to make it as input port.
2. Write 00h to port selected to make it as output port.
3. Read the content from port and store in to accumulator.
4. Write the content from accumulator to port.
5. Repeat Step 2
PROGRAM:
ORG 0000h // orgin of program (Starting address of program)
MOV A, #0ffh //Load ffh to Accumulator
MOV P1, a // Content of Accumulator write to P1(Port 1) to make as a i/p port
MOV A, #00h // Load 00h to Accumulator
MOV P2, A //Content of Accumulator write to P2(Port 2) to make as a o/p port
BACK:
MOV A, P1 //Read the from P1 and Store into A(Accumulator)
MOV P2, A // write from A(Accumulator) to P2
SJMP BACK //Short jump to back
END

RESULT:
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 198

FLOWCHART:
Start
Configure TMOD
Register
THX----|
|->Load Value
TLX-----|







Start Timer
TF
Clear TF
Stop Timer
1
0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 199

Exp No:
Date:
TIMER MODES OPERATION

ABSTRACT: Write on ALP to create a square wave of 50% duty cycle on P1.5
TOOLS USED: Keil Software
PORTS USED: P1
REGISTERS USED: TMOD, TLX, THX
TMOD is an 8-bit register

ALGORITHM:
1. Configure TMOD register( Select Timer and Mode of operation)
2. Load registers THX, TLX with initial count.
3. Start the Timer
4. Monitor TF for high
5. Stop the Timer
6. Clear TF
7. Repeat Step 2
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 200

















MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 201

PROGRAM:
MOV TMOD, #01 ;Timer 0, mode 1(16-bit mode)
HERE:
MOV TL0, #0F2H ;TL0=F2H, the low byte
MOV TH0, #0FFH ;TH0=FFH, the high byte
CPL P1.5 ;toggle P1.5
ACALL DELAY
SJMP HERE
DELAY:
SETB TR0 ;start the timer 0
AGAIN:
JNB TF0, AGAIN ;monitor timer flag 0 -until it rolls over
CLR TR0 ;stop timer 0
CLR TF0 ;clear timer 0 flag
RET
END



RESULT:
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 202

FLOW CHART:

START
Configure TMOD
Register
THxLoad Value
Start Timer
TF
Clear TF
1
0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 203

ABSTRACT: Write an ALP to generate a square wave on P1.0 with frequency of 2KHz.
TOOLS USED: Keil Software
PORTS USED: P1
REGISTERS USED: TMOD, THx
ALGORITHM:
1. Configure TMOD Register
2. Load Register THx with initial count
3. Start Timer
4. Monitor TF for high
5. Clear TF
6. Repeat Step 4

PROGRAM:
MOV TMOD, #20H ;T1/8-bit/auto reload
MOV TH1, #26 ;TH1 = 26
SETB TR1 ;start the timer 1
BACK:
JNB TF1,BACK ;till timer rolls over
CPL P1.0 ;P1.0 to hi, lo
CLR TF1 ;clear Timer 1 flag
SJMP BACK
END

RESULT:
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 204

FLOW CHART:
Start
Configure TMOD
Register
Set Baud Rate
THxBR
Configure SCON
Register

Start the Timer
TRx1

Clear TI
SBUFTransfer
Data
TI
1
0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 205

Exp No:
Date:
SERIAL PORT OPERATION

ABSTRACT: Write a ALP for the 8051 to transfer letter A serially at 9600 baud rate,
continuously
TOOLS USED: Keil Software
PORTS USED: None
REGISTERS USED: TMOD, THx, SCON, SBUF
TMOD:


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 206


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 207

SCON:

ALGORITHM:
1. Configure TMOD Register ( Select Timer and Mode of Operation)
2. Load THx with value to set baud rate
3. Configure SCON register according to framing of data
4. Start the timer
5. Load the transfer data in to SBUF
6. Monitor the TI bit till last bit transmitted
7. Clear the TI for next character
8. Repeat step 5
PROGRAM:
ORG 0000H
MOV TMOD, #20H ;timer 1,mode 2(auto reload)
MOV TH1, #-3 ;9600 baud rate
MOV SCON, #50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN:
MOV SBUF, #'A' ;letter A to transfer
HERE:
JNB TI, HERE ;wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN
END
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 208





MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 209

RESULT:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 210

FLOW CHART:

Start
Configure TMOD
Register
Set Baud Rate
Configure SCON
Register
Start Timer
TRx1
RI
ABUF
P1A
Clear RI
0
1
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 211

ABSTRACT: Write an ALP to receive bytes of data serially and put them in port 1, set the
baud rate suitably
TOOLS USED: Keil Software
PORTS USED: P1
REGISTERS USED: TMOD, THx, SCON, SBUF, A (Accumulator)

ALGORITHM:
1. Configure TMOD Register (Select Timer and Mode of Operation)
2. Load THx with value to set baud rate.
3. Configure SCN register according to framing the data.
4. Start timer
5. Monitor the RI bit till last bit received
6. Load the Content present in SBUF to Accumulator.
7. Write the content of Accumulator to port1
8. Clear the RI for next character.

PROGRAM:
ORG 0000H
MOV TMOD, #20H ;timer 1,mode 2(auto reload)
MOV TH1, #-6 ;4800 baud rate
MOV SCON, #50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
HERE:
JNB RI, HERE ;wait for char to come in
MOV A, SBUF ;saving incoming byte in A
MOV P1, A ;send to port 1
CLR RI ;get ready to receive next byte
SJMP HERE ;keep getting data
END



RESULT:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 212


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 213

AIM: Write a C program for Alphanumeric LCD panel and Hex keypad input interface to
8051
PORTS USED: P1, P2 & P3
SOFTWARE USED: KEIL SOFTWARE
REGISTERS USED: NO
MODULES USED: AT89C51, LCD, 4X4 HEXA KEYPAD
AT89C51
Features
Compatible with MCS-51 Products
4K Bytes of In-System Reprogrammable Flash Memory
Endurance: 1,000 Write/Erase Cycles
Fully Static Operation: 0 Hz to 24 MHz
Three-level Program Memory Lock
128 x 8-bit Internal RAM
32 Programmable I/O Lines
Two 16-bit Timer/Counters
Six Interrupt Sources
Programmable Serial Channel
Low-power Idle and Power-down Modes
Description
The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 4K bytes
of Flash programmable and erasable read only memory (PEROM). The device is
manufactured using Atmels high-density nonvolatile memory technology and is compatible
with the industry-standard MCS-51 instruction set and pin out. The on-chip Flash allows the
program memory to be reprogrammed in-system or by a conventional nonvolatile memory
programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel
AT89C51 is a powerful microcomputer which provides a highly-flexible and cost-effective
solution to many embedded control applications.
Pin Configuration


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 214


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 215

Block Diagram

Pin Description
VCC
Supply voltage.
GND
Ground.
Port 0
Port 0 is an 8-bit open-drain bi-directional I/O port. As an output port, each pin can sink eight
TTL inputs. When 1s are written to port 0 pins, the pins can be used as high impedance
inputs. Port 0 may also be configured to be the multiplexed low order address/data bus during
accesses to external program and data memory. In this mode P0 has internal pullups. Port 0
also receives the code bytes during Flash programming, and outputs the code bytes during
program verification. External pullups are required during program verification.
Port 1
Port 1 is an 8-bit bi-directional I/O port with internal pullups. The Port 1 output buffers can
sink/source four TTL inputs. When 1s are written to Port 1 pins they are pulled high by the
internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 216


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 217

pulled low will source current (IIL) because of the internal pullups. Port 1 also receives the
low-order address bytes during Flash programming and verification.
Port 2
Port 2 is an 8-bit bi-directional I/O port with internal pullups. The Port 2 output buffers can
sink/source four TTL inputs. When 1s are written to Port 2 pins they are pulled high by the
internal pullups and can be used as inputs. As inputs, Port 2 pins that are externally being
pulled low will source current (IIL) because of the internal pullups. Port 2 emits the high-
order address byte during fetches from external program memory and during accesses to
external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, it
uses strong internal pull-ups when emitting 1s. During accesses to external data memory that
use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function
Register. Port 2 also receives the high-order address bits and some control signals during
Flash programming and verification.
Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pullups. The Port 3 output buffers can
sink/source four TTL inputs. When 1s are written to Port 3 pins they are pulled high by the
internal pullups and can be used as inputs. As inputs, Port 3 pins that are externally being
pulled low will source current (IIL) because of the pullups. Port 3 also serves the functions of
various special features of the AT89C51 as listed below:

Port 3 also receives some control signals for Flash programming and verification.
RST
Reset input. A high on this pin for two machine cycles while the oscillator is running resets
the device.
ALE/PROG
Address Latch Enable output pulse for latching the low byte of the address during accesses to
external memory. This pin is also the program pulse input (PROG) during Flash
programming.
In normal operation ALE is emitted at a constant rate of 1/6 the oscillator frequency, and may
be used for external timing or clocking purposes. Note, however, that one ALE pulse is
skipped during each access to external Data Memory. If desired, ALE operation can be
disabled by setting bit 0 of
SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC
instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no
effect if the microcontroller is in external execution mode.


Program Store Enable is the read strobe to external program memory. When the AT89C51 is
executing code from external program memory,

is activated twice each machine cycle,


except that two

activations are skipped during each access to external data memory.



MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 218


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 219

/VPP
External Access Enable.

must be strapped to GND in order to enable the device to fetch


code from external program memory locations starting at 0000H up to FFFFH.
Note, however, that if lock bit 1 is programmed,

will be internally latched on reset.

should be strapped to VCC for internal program executions. This pin also receives the 12-
volt programming enable voltage (VPP) during Flash programming, for parts that require 12-
volt VPP.

XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.\

XTAL2
Output from the inverting oscillator amplifier.

Matrix Keypad
Introduction:
Keypads are a part of HMI or Human Machine Interface and play really important role in a
small embedded system where human interaction or human input is needed. Matrix keypads
are well known for their simple architecture and ease of interfacing with any microcontroller.
In this part of tutorial we will learn how to interface a 4x4 matrix keypad with AVR and 8051
microcontroller. Also we will see how to program then in Assembly and C.
Constructing a Matrix Keypad:
Construction of a keypad is really simple. As per the outline shown in the figure below we
have four rows and four columns. In between each overlapping row and column line there is
a key.

So keeping this outline we can construct a keypad using simple SPST Switches as shown
below:

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 220


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 221

Now our keypad is ready, all we have to do is connect the rows and columns to a port of
microcontroller and program the controller to read the input.
Scanning a Matrix Keypad:
There are many methods depending on how you connect your keypad with your controller,
but the basic logic is same. We make the columns as i/p and we drive the rows making them
o/p, this whole procedure of reading the keyboard is called scanning.
In order to detect which key is pressed from the matrix, we make row lines low one by one
and read the columns. Lets say we first make Row1 low, then read the columns. If any of the
key in row1 is pressed will make the corresponding column as low i.e if second key is
pressed in Row1, then column2 will give low. So we come to know that key 2 of Row1 is
pressed. This is how scanning is done.
So to scan the keypad completely, we need to make rows low one by one and read the
columns. If any of the button is pressed in a row, it will take the corresponding column to a
low state which tells us that a key is pressed in that row. If button 1 of a row is pressed then
Column 1 will become low, if button 2 then column2 and so on...

LCD
Introduction:
The most commonly used Character based LCDs are based on Hitachi's HD44780 controller
or other which are compatible with HD44580. In this tutorial, we will discuss about character
based LCDs, their interfacing with various microcontrollers, various interfaces (8-bit/4-bit),
programming, special stuff and tricks you can do with these simple looking LCDs which can
give a new look to your application.

PIN Configuration:
The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs
which have only 1 controller and support at most of 80 characters, whereas LCDs supporting
more than 80 characters make use of 2 HD44780 controllers.
Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two pins
are extra in both for back-light LED connections). Pin description is shown in the table
below.
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 222


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 223



Commands:
Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by
the MCU. Before starting the internal operation of the LCD, control information is
temporarily stored into these registers to allow interfacing with various MCUs, which operate
at different speeds, or various peripheral control devices. The internal operation of the LCD is
determined by signals sent from the MCU. These signals, which include register selection
signal (RS), read/write signal (R/W), and the data bus (DB0 to DB7), make up the LCD
instructions There are four categories of instructions that:
Designate LCD functions, such as display format, data length, etc.
Set internal RAM addresses
Perform data transfer with internal RAM
Perform miscellaneous functions

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 224


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 225



Although looking at the table you can make your own commands and test them. Below is a
brief list of useful commands which are used frequently while working on the LCD.



MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 226


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 227

LCD Initialization:
Before using the LCD for display purpose, LCD has to be initialized either by the internal
reset circuit or sending set of commands to initialize the LCD. It is the user who has to decide
whether an LCD has to be initialized by instructions or by internal reset circuit.
Initialization by internal Reset Circuit
An internal reset circuit automatically initializes the HD44780U when the power is turned on.
The following instructions are executed during the initialization. The busy flag (BF) is kept in
the busy state until the initialization ends (BF = 1). The busy state lasts for 10 ms after VCC
rises to 4.5 V.
Display clear
Function set:
DL = 1; 8-bit interface data
N = 0; 1-line display
F = 0; 5 x 8 dot character font
Display on/off control:
D = 0; Display off
C = 0; Cursor off
B = 0; Blinking off
Entry mode set:
I/D = 1; Increment by 1
S = 0; No shift

Now the problem with the internal reset circuit is, it is highly dependent on power supply, to
meet this critical power supply conditions is not hard but are difficult to achieve when you
are making a simple application. So usually the second method i.e. Initialization by
instruction is used and is recommended most of the time.

Initialization by instructions
Initializing LCD with instructions is really simple. Given below is a flowchart that describes
the step to follow, to initialize the LCD.

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 228


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 229




As you can see from the flow chart, the LCD is initialized in the following sequence...
1) Send command 0x30 - Using 8-bit interface
2) Delay 20ms
3) Send command 0x30 - 8-bit interface
4) Delay 20ms
5) Send command 0x30 - 8-bit interface
6) Delay 20ms
7) Send Function set - see Table 4 for more information
8) Display Clear command
9) Set entry mode command - explained below
The first 3 commands are usually not required but are recommended when you are using 4-bit
interface. So you can program the LCD starting from step 7 when working with 8-bit
interface. Function set command depends on what kind of LCD you are using and what kind
of interface you are using
LCD Entry mode
a) I/D - Increment/Decrement bit
b) S - Display shift.
With these two bits we get four combinations of entry mode which are 0x04, 0x05, 0x06 and
0x07 So we get different results with these different entry modes. Normally entry mode 0x06
is used which is No shift and auto increment.
Programming example for LCD Initialization
#include <AT89X51.H>.
#define LCD_data P2
#define LCD_D7 P2_7
#define LCD_rs P1_0
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 230


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 231

#define LCD_rw P1_1
#define LCD_en P1_2
void LCD_init()
{
LCD_data = 0x38; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x0F; //Display on, Curson blinking command
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x01; //Clear LCD
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x06; //Entry mode, auto increment with no shift
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_busy();
}

Reading the busy flag:
As discussed in the previous section, there must be some delay which is needed to be there
for LCD to successfully process the command or data. So this delay can be made either with
a delay loop of specified time more than that of LCD process time or we can read the busy
flag, which is recommended. The reason to use busy flag is that delay produced is almost for
the exact amount of time for which LCD need to process the time. So is best suited for every
application.
Steps to read busy flag
When we send the command, the BF or D7th bit of the LCD becomes 1 and as soon as the
command is processed the BF = 0.
Following are the steps to be kept in mind while reading the busy flag.
Select command register
Select read operation
Send enable signal
Read the flag
CODE
void LCD_busy()
{
LCD_D7 = 1; //Make D7th bit of LCD as i/p
LCD_en = 1; //Make port pin as o/p
LCD_rs = 0; //Selected command register
LCD_rw = 1; //We are reading
while(LCD_D7)
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 232


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 233

{ //read busy flag again and again till it becomes 0
LCD_en = 0; //Enable H->L
LCD_en = 1;
}
}
or
void LCD_busy()
{
unsigned char i,j;
for(i=0;i<50;i++) //A simple for loop for delay
for(j=0;j<255;j++);
}
Sending Command to LCD:
To send commands we simply need to select the command register. Everything is same as we
have done in the initialization routine. But we will summarize the common steps and put
them in a single subroutine. Following are the steps:
Move data to LCD port
select command register
select write operation
send enable signal
wait for LCD to process the command

void LCD_command(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in instruction register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
Sending Data to LCD:
To send data we simply need to select the data register. Everything is same as the command
routine. Following are the steps:
Move data to LCD port
select data register
select write operation
send enable signal
wait for LCD to process the data

void LCD_senddata(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 1; //Selected data register
LCD_rw = 0; //We are writing
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}

MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 234

FLOW CHART:
START
INITIALIZE INPUT
AND OUTPUT PORTS
INITIALIZE LCD
READ KEY FROM
KEYPAD
WRITE DATA FROM
KEYPAD TO LCD
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 235

ALGORITHM:
1. Configure P1 port as generating outputs and taking inputs from Keypad and P2&P3 ports are
output of LCD.
2. Initialize the LCD.
3. Scan the key from keypad.
4. Read the key from keypad and write in to LCD.
5. Repeat the step 3.
Program:
// ***********************************************************
// Keypad Interfacing with 8051
//// Module description: Get input from keypad and display it on LCD
// ***********************************************************

#include<reg51.h>

//Function declarations
void cct_init(void);
void delay(int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void Return(void);
char READ_SWITCHES(void);
char get_key(void);
void lcdstring(unsigned char *value);

//*******************
//Pin description
/*
P2 is data bus
P3.7 is RS
P3.6 is E
P1.0 to P1.3 are keypad row outputs
P1.4 to P1.7 are keypad column inputs
*/
//********************
// Define Pins
//********************
sbit RowA = P1^1; //RowA
sbit RowB = P1^2; //RowB
sbit RowC = P1^3; //RowC
sbit RowD = P1^4; //RowD

sbit C1 = P1^5; //Column1
sbit C2 = P1^6; //Column2
sbit C3 = P1^7; //Column3
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 236

SCHEMATIC:




MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 237

sbit E = P3^7; //E pin for LCD
sbit RS = P3^5; //RS pin for LCD
sbit RW = P3^6; // RW pin for LCD

// ***********************************************************
// Main program
//
int main(void)
{
char key; // key char for keeping record of pressed key

cct_init(); // Make input and output pins as required
lcdinit(); // Initilize LCD

while(1)
{
key = get_key(); // Get pressed key
writecmd(0x01); // Clear screen
lcdstring("KEY PRESSED:");
writedata(key); // Echo the key pressed to LCD
}
}


void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0xf0; //used for generating outputs and taking inputs from Keypad
P2 = 0x00; //used as data port for LCD
P3 = 0x00; //used for RS and E, RW
}

void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}

void writedata(char t)
{
RS = 1; // This is data
P2 = t;
RW=0; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 238


MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 239

void writecmd(int z)
{
RS = 0;
RW=0; // This is command
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}

void lcdinit(void)
{
///////////// Reset process from datasheet /////////
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
/////////////////////////////////////////////////////
writecmd(0x38); //function set
writecmd(0x0c); //display on,cursor off,blink off
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}
void lcdstring(unsigned char *value)
{
while(*value)
{
writedata(*value++);
}

}
void Return(void) //Return to 0 location on LCD
{
writecmd(0x02);
delay(1500);
}

char READ_SWITCHES(void)
{
RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A

if (C1 == 0) { delay(10000); while (C1==0); return '1'; }
if (C2 == 0) { delay(10000); while (C2==0); return '2'; }
if (C3 == 0) { delay(10000); while (C3==0); return '3'; }
MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 240



MICROPROCESSORS AND MICROCONTROLLERS LAB III B.Tech II Semester
Dept of ECE, Aditya Engineering College 241

RowA = 1; RowB = 0; RowC = 1; RowD = 1; //Test Row B

if (C1 == 0) { delay(10000); while (C1==0); return '4'; }
if (C2 == 0) { delay(10000); while (C2==0); return '5'; }
if (C3 == 0) { delay(10000); while (C3==0); return '6'; }


RowA = 1; RowB = 1; RowC = 0; RowD = 1; //Test Row C

if (C1 == 0) { delay(10000); while (C1==0); return '7'; }
if (C2 == 0) { delay(10000); while (C2==0); return '8'; }
if (C3 == 0) { delay(10000); while (C3==0); return '9'; }


RowA = 1; RowB = 1; RowC = 1; RowD = 0; //Test Row D

if (C1 == 0) { delay(10000); while (C1==0); return '*'; }
if (C2 == 0) { delay(10000); while (C2==0); return '0'; }
if (C3 == 0) { delay(10000); while (C3==0); return '#'; }

return 'n'; // Means no key has been pressed
}

char get_key(void) //get key from user
{
char key = 'n'; //assume no key pressed

while(key=='n') //wait untill a key is pressed
key = READ_SWITCHES(); //scan the keys again and again

return key; //when key pressed then return its value
}


RESULT:

Você também pode gostar