Top Banner
1 DEPT.OF ECE,LITS ,KHAMMAM DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING MICROPROCESSSORS AND INTERFACING LAB IIIYEAR I SEMESTER (CSE) LAQSHYA INSTITUTE OF TECHNOLOGY AND SCIENCES TANIKELLA (V), KONIJERLA (M), KHAMMAM
65
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Mp Lab Manual

1

DEPT.OF ECE,LITS ,KHAMMAM

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

MICROPROCESSSORS AND INTERFACING LABIIIYEAR I SEMESTER (CSE)

LAQSHYA INSTITUTE OF TECHNOLOGY AND SCIENCES

TANIKELLA (V), KONIJERLA (M), KHAMMAM

Page 2: Mp Lab Manual

2

DEPT.OF ECE,LITS ,KHAMMAM

MICROPROCESSORS

AND INTERFACING LAB (III-I SEM)

Page 3: Mp Lab Manual

3

DEPT.OF ECE,LITS ,KHAMMAM

S.NO NAME OF THE EXPERIMENT PAGE NO

1 Assembly language Program (ALP) to 8086 processor to add, subtract and multiply two 16 bit unsigned numbers

9

2 Assembly language Program (ALP) to 8086 processor to divide a 32 bit unsigned number by a 16 bit unsigned number

12

3 Assembly language Program (ALP) to 8086 processor to sort the given array of 32 bit numbers in ascending and descending order

13

4 Assembly language Program (ALP) to 8086 processor to find the length of a given string

15

5 Assembly language Program (ALP) to 8086 processor to reverse the given string and verify whether it is a palindrome

16

6 Assembly language Program (ALP) to 8086 processor to verify the password

19

7 Assembly language Program (ALP) to 8086 processor to insert or delete a character/ number from the given string

21

8 Interface a keypad to 8086 microprocessor and display the key number pressed on the 7- segment display which is also interfaced to 8086

26

9 Write an interrupt service routine to 8086 when ever there is an interrupt request on interrupt pin, which displays “hello” on a LCD

29

10 Interface a stepper motor to 8086 and operate it in clockwise and anti-clock wise by choosing variable step-size

31

11 Interface an 8 bit ADC to 8086 and generate digital output and store it in memory for the given square/ ramp/ triangle wave form inputs

40

12 Interface an ADC to 8086 and generate step, ramp, triangle and square waveforms with different periods

45

Page 4: Mp Lab Manual

4

DEPT.OF ECE,LITS ,KHAMMAM

1. INTRODUCITION TO MASM/TASM

ASSEMBLY LANGUAGE PROGRAMMING USING MASM

SOFTWARE:

This software used to write a program (8086, Pentium processors etc.) The programs are written

using assembly language in editor then compile it. The complier converts assembly language

statements into machine language statements/checks for errors. Then execute the compiled

program. Programs for different processor instructions (Pentium, 8086) programming manner

differ for each model.

There are different software’s developed by different companies for assembly language

programming are:

· MASM - Microsoft Company.

· TASM - Bore Land Company.

MERIT OF MASM:

1. produces binary code

2. Referring data items by their names rather than by their address

HOW TO ENTER INTO MASM EDITOR:

Click “Start” on the desktop

Then select Run

Then it Shows inbox

Page 5: Mp Lab Manual

5

DEPT.OF ECE,LITS ,KHAMMAM

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

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.

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 filename’s

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, , ;

Page 6: Mp Lab Manual

6

DEPT.OF ECE,LITS ,KHAMMAM

Then link this file using C: MASM>LINK filename.OBJ

or C: MASM>LINK filename.OBJ , , ;

i.e link the program in assembly with DOS

then to debug to create exe file

C:MASM>debug filename. EXE

Then it display “--” on the screen

-g ; for at a time execution

-I ; for restarting the program execution

-d ; to see the data segment

-q ; to quit the execution

C:\masm\afdebug filename .exe

F1 ; for single step execution

g ; for at a time execution

L filename .exe ; to reload the program

Quit ; to come out of the execute screen

After that type ‘R’ displays the registers contents steps and starting step of the

program.

Page 7: Mp Lab Manual

7

DEPT.OF ECE,LITS ,KHAMMAM

‘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 T10

it will display the contents of register after executing 10 instructions.

DEBUG:

This command utility enables to write and modify simple assembly language programs in an easy

fashion. It provides away to run and test any program in a controlled environment. We can change

any part of the program and immediately execute the program with an having to resemble it. We

can also run machine language(Object files) directly by using DEBUG

DEBUG COMMANDS:

ASSEMBLE A [address] ; Assembly the instructions at a particular address

COMPARE C range address ; Compare two memory ranges

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

Page 8: Mp Lab Manual

8

DEPT.OF ECE,LITS ,KHAMMAM

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]

Page 9: Mp Lab Manual

9

DEPT.OF ECE,LITS ,KHAMMAM

Expt1a): Write and execute an Assembly Language Program to 8086 Processor to add two

16-bit unsigned numbers

data segment

num1 dw 1234h,2345h, 3467h

num2 dw 2345h,3456h, 4567h

res dw 0000h

count db 03h

data ends

code segment

assume cs:code, ds:data

start: mov ax,data

mov ds,ax

mov si,offset num1

mov di,offset num2

mov bx,offset res

mov cl,count

go1: mov ax,[si]

mov dx,[di]

add ax,dx

mov res,ax

inc si

inc di

inc bx

dec cl

jnz go1

int 03

code ends

end start

Page 10: Mp Lab Manual

10

DEPT.OF ECE,LITS ,KHAMMAM

Expt1b): Write and execute an Assembly Language Program to 8086 Processor to subtract

two 16-bit unsigned numbers

data segment

num1 dw 2345h, 3456h, 4567h

num2 dw 1234h, 2345h, 3456h

res dw 0000h

count db 03h

data ends

code segment

assume cs:code, ds:data

start: mov ax,data

mov ds,ax

mov si,offset num1

mov di,offset num2

mov bx,offset res

mov cl,count

go1: mov ax,[si]

mov dx,[di]

sub ax,dx

mov res,ax

inc si

inc di

inc bx

dec cl

jnz go1

int 03

code ends

end start

Page 11: Mp Lab Manual

11

DEPT.OF ECE,LITS ,KHAMMAM

Expt1c): Write and execute an Assembly Language Program to 8086 Processor to Multiply

two 16-bit un signed numbers

data segment

num1 dw 2345h, 3456h, 4567h

num2 dw 1234h, 2345h, 3456h

res dw ?

count db 03h

data ends

code segment

assume cs:code, ds:data

start: mov ax,data

mov ds,ax

mov si,offset num1

mov di,offset num2

mov bx,offset res

mov cl,count

go1: mov ax,[si]

mov dx,[di]

mul dx

mov res,al

inc si

inc di

inc bx

dec cl

jnz go1

int 03

code ends

end start

Page 12: Mp Lab Manual

12

DEPT.OF ECE,LITS ,KHAMMAM

Expt2): Write and execute an Assembly Language Program to 8086 Processor for Division

DATA SEGMENT

DIVIDEND DW 2 DUP(0)

DIVISOR DB ?

QUO DW 1 DUP(0)

REM DW 1 DUP(0)

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS : DATA

START:

MOV AX, DIVIDEND

MOV DX, DIVISOR+2

DIV DIVISOR

MOV QUO, AX

MOV REM, DX

CODE ENDS

END START

Expt3a): Write and execute an Assembly Language Program to 8086 Processor to sort the

given array of numbers in Ascending order

Page 13: Mp Lab Manual

13

DEPT.OF ECE,LITS ,KHAMMAM

DATA SEGMENT

X DW 42H,34H,26H,17H,09H

LEN EQU 05

ASCD DB 10 DUP(0)

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA

MOV DS,AX

MOV BX,LEN-1

MOV CX,BX

UP1: MOV BX,CX

LEA SI,X

UP: MOV AX,[SI]

MOV DX,[SI+2]

CMP AX,DX

JB DOWN

MOV [SI],DX

MOV [SI+2],AX

DOWN: INC SI

INC SI

DEC BX

JNZ UP

DEC CX

JNZ UP1

MOV AH,4CH

INT 03h

CODE ENDS

END START

Expt3b): Write and execute an Assembly Language Program to 8086 Processor to sort the

given array of numbers in Descending order

Page 14: Mp Lab Manual

14

DEPT.OF ECE,LITS ,KHAMMAM

DATA SEGMENT

X DW 42H,34H,26H,17H,09H

LEN EQU 05

ASCD DB 10 DUP(0)

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA

MOV DS,AX

MOV BX,LEN-1

MOV CX,BX

UP1: MOV BX,CX

LEA SI,X

UP: MOV AX,[SI]

MOV DX,[SI+2]

CMP AX,DX

JA DOWN

MOV [SI],DX

MOV [SI+2],AX

DOWN: INC SI

INC SI

DEC BX

JNZ UP

DEC CX

JNZ UP1

MOV AH,4CH

INT 03h

CODE ENDS

END START

Page 15: Mp Lab Manual

15

DEPT.OF ECE,LITS ,KHAMMAM

Expt4): Write and execute an Assembly Language Program to 8086 Processor to find the

length of a given string

data segment

str db “name”

len db ?

data ends

code segment

assume cs:code,ds:data

start: mov ax,data

mov ds,ax

mov si,offset str

mov bl, 00h

mov cl,bl

go2: mov al,[si]

cmp al,bl

je go1

inc si

inc cl

jmp go2

go1: mov len,cl

int 03h

code ends

end start

Page 16: Mp Lab Manual

16

DEPT.OF ECE,LITS ,KHAMMAM

Expt6a): Write and execute an Assembly Language Program to 8086 Processor to reverse

the given string

data segment

str db “name”

len db ?

data ends

code segment

assume cs:code,ds:data

start: mov ax,data

mov ds,ax

mov si,offset str

mov bl, 00h

mov cl,bl

go2: mov al,[si]

cmp al,bl

je go1

inc si

inc cl

jmp go2

go1: mov len,cl

int 03h

code ends

end start

Page 17: Mp Lab Manual

17

DEPT.OF ECE,LITS ,KHAMMAM

Expt6b): Write and execute an Assembly Language Program to 8086 Processor to check for

palindrome

DATA SEGMENT

STR1 DB 'LIRIL'

LEN EQU $-STR1

STR2 DB 20 DUP(0)

MES1 DB 10,13,'WORD IS PALINDROME$'

MES2 DB 10,13,'WORD IS NOT PALINDROME$'

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA,ES:DATA

START: MOV AX,DATA

MOV DS,AX

MOV ES,AX

LEA SI,STR1

LEA DI,STR2+LEN-1

MOV CX,LEN

UP: CLD

LODSB

STD

STOSB

LOOP UP

LEA SI,STR1

LEA DI,STR2

CLD

MOV CX,LEN

REPE CMPSB

CMP CX,0H

Page 18: Mp Lab Manual

18

DEPT.OF ECE,LITS ,KHAMMAM

JNZ NOTPALIN

LEA DX,MES1

MOV AH,09H

INT 21H

JMP EXIT

NOTPALIN: LEA DX,MES2

MOV AH,09H

INT 21H

EXIT: MOV AH,4CH

INT 21H

CODE ENDS

END START

Page 19: Mp Lab Manual

19

DEPT.OF ECE,LITS ,KHAMMAM

Expt6): Write and execute an Assembly Language Program to 8086 Processor to verify

password

.model small

.data

nam db ’KRISHNA$’

pass db 50

db ?

db 10 dup(?)

msg1 db 10,13,"enter the password: $",10,13

msg2 db 10,13,"password valid : Congrats!!!! $",10,13

msg3 db 10,13,"password invalid, Sorry Try again ## $",10,13

print macro msg ; macro definition to print a string on screen

lea dx,msg

mov ah,09

int 21h

endm

.code

start: mov ax,@data

mov ds,ax

mov es,ax

xor ax,ax

print msg1

lea dx,pass

mov ah,0ah ; read password from keyboard

int 21h

mov di,dx

inc di

Page 20: Mp Lab Manual

20

DEPT.OF ECE,LITS ,KHAMMAM

mov cl, byte ptr[di] ; length of the string in cl register

mov ch,00

inc di

lea si, nam

cld

back: cmpsb

jne xx

loop back

print msg2

jmp xxy

xx: print msg3

xxy: mov ah,4ch

int 21h

end start

Page 21: Mp Lab Manual

21

DEPT.OF ECE,LITS ,KHAMMAM

Expt8a): Write and execute an Assembly Language Program to 8086 Processor to insert a

character /number from the given string

data segment

str db “miro”

count db 05

pos db 03

ins db ‘c’

data ends

extra segment

srt1 db ?

extra ends

code segment

assume cs:code,ds:data,es:extra

start: mov ax,data

mov ds,ax

mov ax,extra

mov es,ax

xor ax,ax

mov dl,ins

mov bl,pos

mov cl,count

go2: mov al,06

sub al,cl

cmp al,bl

je go1

cld

movsb

Page 22: Mp Lab Manual

22

DEPT.OF ECE,LITS ,KHAMMAM

dec cl

jnz go2

jmp exit

go1: mov al,dl

stosb

dec cl

jnz go2

exit: int 03

code ends

end start

Page 23: Mp Lab Manual

23

DEPT.OF ECE,LITS ,KHAMMAM

Expt8b): Write and execute an Assembly Language Program to 8086 Processor to delete a

character /number from the given string

data segment

str db “micro”

count db 05

pos db 03

del db ‘c’

data ends

extra segment

srt1 db ?

extra ends

code segment

assume cs:code,ds:data,es:extra

start: mov ax,data

mov ds,ax

mov ax,extra

mov es,ax

xor ax,ax

mov dl,ins

mov bl,pos

mov cl,count

go2: mov al,06

sub al,cl

cmp al,bl

je go1

cld

movsb

Page 24: Mp Lab Manual

24

DEPT.OF ECE,LITS ,KHAMMAM

dec cl

jnz go2

jmp exit

go1: lodsb

mov dl,al

dec cl

jnz go2

exit: mov del,dl

int 03h

code ends

end start

Page 25: Mp Lab Manual

25

DEPT.OF ECE,LITS ,KHAMMAM

Interfacing the 8086 processor.

Run command prompt and go to Masm directory

i.e. C:\masm\

Type the program by opening an editor using Edit command

i.e. C:\masm\edit filename .asm

After typing the program assemble the program using masm command.

i.e. C:\masm\masm filename .asm;

After assembling, link the file using link command

i.e. C:\masm\ link filename .obj;

Convert the executable file to binary program.

i.e. C:\masm\ exe2bin filename .exe

Convert the binary file to hex program.

i.e. C:\masm\bin2hex filename .exe

Open the hex uploader program.

i.e. C:\masm\mmeterm

Set the Baud rate to 9600bits/second.

i.e. 5. Configuration> 1. Baud Rate>5. 9600

Press reset on the interface kit.

Message will appear on the LCD as uP 8086.

Press Download on the interface kit to prepare the processor to receive file.

Message will appear on the LCD as Reading RS 232.

Send file to the processor via serial port [COM1].

i.e. 3. Sendfile>Which File? filename .hex

Press Enter

Message will appear on the LCD as Data received

Page 26: Mp Lab Manual

26

DEPT.OF ECE,LITS ,KHAMMAM

10.Interface keypad to 8086 processor and display the key pressed on the 7-segment

display which is also interfaced to 8086

CODE SEGMENT

ASSUME CS:code,DS:code,ES:code,SS:code

CWR EQU 46h

PORTA EQU 40h

PORTB EQU 42h

PORTC EQU 44h

ORG 0400h

MOV AL, 88h ; port a and port c high as output

OUT CWR,AL ; port b and port c low as output

READKEY:

MOV DL,0 ; clear e/dl register

MOV AL,0F0h ; output all one's to pc high

OUT PORTC,AL

LP:

IN AL,PORTC

AND AL,0F0h

CMP AL,0F0h

JNZ LP

CALL FAR PTR ONEMS

KEYCHK:

IN AL,PORTC

AND AL,0F0h

CMP AL,0F0h

JZ KEYCHK ;wait for key press

Page 27: Mp Lab Manual

27

DEPT.OF ECE,LITS ,KHAMMAM

CALL FAR PTR ONEMS

MOV AL,7Fh

MOV BH,04h

NXTCOLM:

ROL AL, 01h ; scan each column

MOV DH,AL ; and wait for the data

OUT PORTC,AL ; in any of the four

IN AL,PORTC ; rows

AND AL,0F0h

MOV CL,04h

NXTROW:

ROL AL,01h ; scan each column

JNC CODEN ; scan each column

INC DL ; in any of the four

DEC CL ; rows

JNZ NXTROW

MOV AL,DH

DEC BH

JNZ NXTCOLM

JMP KEYCHK

CODEN:

MOV AL,DL

MOV DH,0h

MOV BX,OFFSET LOOKUP+8000h

ADD BX,DX

MOV AL,BYTE PTR[BX]

Page 28: Mp Lab Manual

28

DEPT.OF ECE,LITS ,KHAMMAM

OUT PORTB,AL

JMP READKEY

ONEMS:

PUSH AX

MOV AL,0FFh

LOP:

DEC AL

JNZ LOP

POP AX

RETF

LOOKUP:

DB 00h,04h,08h,0Ch,01h,05h,09h,0Dh

DB 02h,06h,0Ah,0Eh,03h,07h,0Bh,0Fh

CODE ENDS

END

Page 29: Mp Lab Manual

29

DEPT.OF ECE,LITS ,KHAMMAM

11.Write an interrupt service routine to 8086 when ever there is an interrupt

request on the interrupt pin which displays “hello” on a lcd

CODE SEGMENT

ASSUME CS:CODE,DS:CODE,ES:CODE

DISINT EQU 21h

DSPBUF EQU 9E00h

ORG 400h

MES1 DB 'BMSCE' ;maximum size of message can be 16 bytes

MES2 DB 'OF E AND C'

MES3 DB ' '

L1: MOV SI,OFFSET MES3+8000h ; move result format message

MOV DI,DSPBUF ; to display buffer

MOV CX,08h ; counter for movs instruction

REP MOVSW ; counter for movs instruction

INT DISINT

CALL DELAY

MOV SI,OFFSET MES1+8000h ; move result format message

MOV DI,DSPBUF ; to display buffer

MOV CX,08h ; counter for movs instruction

REP MOVSW ; move 8 words to display buffer

Page 30: Mp Lab Manual

30

DEPT.OF ECE,LITS ,KHAMMAM

INT DISINT

CALL DELAY

MOV SI,OFFSET MES2+8000h ; move result format message

MOV DI,DSPBUF ; to display buffer

MOV CX,08h ; counter for movs instruction

REP MOVSW ; move 8 words to display buffer

INT DISINT

CALL DELAY

JMP L1

DELAY PROC NEAR

MOV AX,0FF00h

AGAIN: DEC AX

JNZ AGAIN

RET

DELAY ENDP

CODE ENDS

END

Page 31: Mp Lab Manual

31

DEPT.OF ECE,LITS ,KHAMMAM

14) Interface a stepper motor to 8086 and operate it in clockwise and

anticlockwise

APPARATUS:-

Microprocessor trainer kit, ADC kit, power supply, data cable etc

THEORY:-

Stepper motor is a device used to obtain an accurate position control of rotating shafts. A stepper

motor employs rotation of its shaft in terms of steps, rather than continuous rotation as in case of

AC or DC motor. To rotate the shaft of the stepper motor, a sequence of pulses is needed to be

applied to the windings of the stepper motor, in proper sequence. The numbers of pulses required

for complete rotation of the shaft of the stepper motor are equal to the number of internal teeth

on its rotor. The stator teeth and the rotor teeth lock with each other to fix a position of the shaft.

With a pulse applied to the winding input, the rotor rotates by one teeth position or an angle x.

the angle x may be calculated as.

x = 3600 / no. of rotor teeth

After the rotation of the shaft through angle x, the rotor locks it self with the next tooth in the

sequence on the internal surface of the stator. The typical schematic of a typical stepper motor

with four windings is as shown below.

Page 32: Mp Lab Manual

32

DEPT.OF ECE,LITS ,KHAMMAM

The stepper motors have been designed to work

with digital circuits. Binary level pulses of 0-5V are required at its winding inputs to obtain the

rotation of the shafts. The sequence of the pulses can be decided, depending upon the required

motion of the shaft. By suitable sequence of the pulses the motor can be used in three modes of

operation.

One phase ON (medium torque)

Two phase ON (high torque)

Half stepping (low torque)

Page 33: Mp Lab Manual

33

DEPT.OF ECE,LITS ,KHAMMAM

WORKING:-

8255 is interfaced with 8086 in I/O mapped I/O. port C (PC0, PC1, PC2, PC3) is used to give

pulse sequence to stepper motor. The 8255 provides very less current which will not be able to

drive stepper motor coils so each of the winding of a stepper motor needs to be interfaced using

high speed switching Darlington transistors with max 1A, 80V rating with heat sink, with the

output port of 8255. Output the sequence in correct order to have the desired direction to rotate

the motor.

Page 34: Mp Lab Manual

34

DEPT.OF ECE,LITS ,KHAMMAM

Assembly Language Program to rotate Stepper Motor in Clockwise

direction

MODEL SMALL

.STACK 100

.DATA

PORTA EQU FFC0H ; PORTA ADDRESS

PORTB EQU FFC2H ; PORTB ADDRESS

PORTC EQU FFC4H ; PORTC ADDRESS

CWR EQU FFC6H ; CONTROL PORT ADDRESS

PHASEC EQU 03H

PHASEB EQU 06H ; SEQUENCE IN SERIES TO ROTATE MOTOR

PHASED EQU 0CH ; IN CLOCKWISE DIRECTION

PHASEA EQU 09H

.CODE

START:

MOV AL,@DATA

MOV DX,CTL

OUT DX,AL

AGAIN:

MOV AL,PHASEC

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

Page 35: Mp Lab Manual

35

DEPT.OF ECE,LITS ,KHAMMAM

UP:

LOOP UP

MOV AL,PHASEB

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

UP1:

LOOP UP1

MOV AL,PHASED

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

UP2:

LOOP UP2

MOV AL,PHASEA

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

Page 36: Mp Lab Manual

36

DEPT.OF ECE,LITS ,KHAMMAM

UP3:

LOOP UP3

JMP AGAIN ; REPEATE OUTPUT SEQUENCE

INT 03H

END START

Assembly Language Program to rotate Stepper Motor in

Anticlockwise direction

MODEL SMALL

.STACK 100

.DATA

PORTA EQU FFC0H ; PORTA ADDRESS

PORTB EQU FFC2H ; PORTB ADDRESS

PORTC EQU FFC4H ; PORTC ADDRESS

CWR EQU FFC6H ; CONTROL PORT ADDRESS

PHASEC EQU 03H

PHASEA EQU 09H ; SEQUENCE IN SERIES TO ROTATE MOTOR

PHASED EQU 0CH ; IN ANTICLOCKWISE DIRECTION

PHASEB EQU 06H

.CODE

START:

Page 37: Mp Lab Manual

37

DEPT.OF ECE,LITS ,KHAMMAM

MOV AL,@DATA

MOV DX,CTL

OUT DX,AL

AGAIN:

MOV AL,PHASEC

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

UP:

LOOP UP

MOV AL,PHASEA

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

UP1:

LOOP UP1

MOV AL,PHASED

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

UP2:

Page 38: Mp Lab Manual

38

DEPT.OF ECE,LITS ,KHAMMAM

LOOP UP2

MOV AL,PHASEB

MOV DX,PORTC

OUT DX,AL

MOV CX,0FFFFH

UP3:

LOOP UP3

JMP AGAIN ; REPEATE OUTPUT SEQUENCE

INT 03H

END START

Page 39: Mp Lab Manual

39

DEPT.OF ECE,LITS ,KHAMMAM

PROCEDURE:-

1. Connect power supply 5V & GND to both microprocessor trainer kit & Stepper motor

interfacing kit.

2. Connect data bus between microprocessor trainer kit & Stepper motor interfacing kit.

3. Enter the program to rotate Stepper motor in clockwise & anticlockwise.

4. Execute the program by typing GO E000:00C0 ENTER for clockwise, GO E000:0030

ENTER for anticlockwise.

5. Observe the rotation of stepper motor.

Page 40: Mp Lab Manual

40

DEPT.OF ECE,LITS ,KHAMMAM

AIM:- To Interface Analog-to-Digital converter to 8086 using 8255 and write Assembly

Language Program to read Digital value from ADC.

APPARATUS:-

Microprocessor trainer kit, ADC kit, power supply, data cable etc

THEORY:

ANALOG TO DIGITAL CONVERTER (0809):-

The ADC-0809 data acquisition component is a monolithic CMOS device with an 8-bit analog to

digital converter, 8 channel multiplexed control logic. The 8 bit A/D converter uses successive

approximation as the converter technique. The converter features a high impedance chopper

stabilized comparator, a 256R voltage divider with analog switch free and a successive

approximation register. The 8 channel multiplexed can directly access any of 8 single ended

analog signal.

FEATURES:-

1. Resolution 8 bits

2. Conversion time 100 micro sec.

3. Single supply 5V

4. 8 channel multiplexed with latched control logic

Page 41: Mp Lab Manual

41

DEPT.OF ECE,LITS ,KHAMMAM

5. easy interface to all microprocessor

6. 0 to 5V analog input voltage range with single 5V supply

7. low power consumption 15mW

8. latched tristate output

WORKING:-

ADC interface consists of a NAND gate oscillator witch feeds 50 KHz as the input clock to

ADC, input to channel is given through terminal blocks provided on the card. Channel selection

is done using port lines PC0, PC1 & PC2, START OF CONVERSION and ALE is controlled by

port line PC7. Converted digital output is read by ADC through PORTA lines by enabling OE.

OE line is connected to port line PC6.

In this method of interfacing microprocessor is continuously monitoring EOC line (which is

connected to port line PA7). When this goes high, make OE (PC6) high & then low, this will put

the digital equivalent of analog voltage of the given channel on data lines of ADC. Read the

digital data through port lines PA0 to PA7 and display the same data.

Page 42: Mp Lab Manual

42

DEPT.OF ECE,LITS ,KHAMMAM

ASSEMBLY LANGUAGE PROGRAM:-

MODEL SMALL

.STACK 100

.DATA

CONTROL EQU FFC6H ; Control port address for 8255

PORTA EQU FFC0H ; Port A address for 8255

PORTB EQU FFC2H ; Port B address for 8255

PORTC EQU FFC4H ; Port C address for 8255

CHANNEL EQU 07H

.CODE

START:

MOV AL,90H ;CONTROL WORD FOR 8255

MOV DX,CONTROL ;TO INITIALIZE PORTA AS INPUT, PORTB AS OUTPUT

OUT DX,AL ;PORTC AS OUTPUT PORT

MOV AL,CHANNEL ; OUTPUT CHANNEL NUMBER IS PLACED ON

MOV DX,PORTC ; PC0, PC1, PC2 LINES OF 8255 WHICH ARE CONNECTED

OUT DX,AL ; TO ADC TO SELECT RESPECTIVE CHANNEL OF ADC TO

; TAKE ANALOG INPUT

MOV AL,0FH ; AS PC7 OF 8255 IS CONNECTED TO START OF

MOV DX,CONTROL ; CONVERSION (SOC) OF ADC SO TO START CONVERSION

OUT DX,AL ; PC7 IS SET HIGH

MOV CX,3FFFH

Page 43: Mp Lab Manual

43

DEPT.OF ECE,LITS ,KHAMMAM

DELAY: LOOP DELAY

MOV AL,0EH ; RESET PC7

MOV DX,CONTROL

OUT DX,AL

MOV AL,0CH ; AS PC6 IS CONNECTED TO OE i.e. OUTPUT ENABLE OF

OUT DX,AL ; ADC SO TO DISABLE OE AND AND TO CHECK EOC

; (CONNECTED TO PA7) RESET PC6

UP: MOV DX,PORTA

IN AL,DX ; CHECK FOR EOC BY READING PORTA

AND AL,80H ; MASK PC7 BIT

CMP AL,80H ; COMPARE PC7 BIT WITH 1

JNZ UP ; IF EOC THEN READ DIGITAL VALUE FROM ADC

MOV AL,0DH

OUT DX,CONTROL ; TO CONFIGURE ADC TO OUTPUT THE DIGITAL DATA

OUT DX,AL ; SO SET OE (PC6) TO READ VALUE

MOV DX,PORTA ; READ DIGITAL DATA FROM PORTA

IN AL,DX ; DIGITAL DATA IS IN AL

INT 03H

Page 44: Mp Lab Manual

44

DEPT.OF ECE,LITS ,KHAMMAM

END START

PROCEDURE:-

1. Connect power supply 5V & GND to both microprocessor trainer kit & ADC interfacing kit.

2. Connect data bus between microprocessor trainer kit & ADC interfacing kit.

3. Enter the program to read digital data from ADC.

4. Execute the program by typing GO E000:4610 ENTER.

5. “ENTER THE CHANNEL NUMBER “, will be displayed on screen.

6. Now enter the channel number and apply the analog input to respective channel.

7. Equivalent digital output is displayed on screen.

Page 45: Mp Lab Manual

45

DEPT.OF ECE,LITS ,KHAMMAM

AIM:-

To Interface Digital -to-Analog converter to 8086 using 8255 and write Assembly Language

Program to generate Square Wave, Ramp Wave, Triangular Wave & Staircase Wave

form.

APPARATUS:-

Microprocessor trainer kit, ADC kit, power supply, data cable, CRO etc

THEORY:-

The DAC 0800 is a monolithic 8 bit high speed current output digital to analog converters

featuring setting time of 100nSEC. It also features high compliance complementary current

outputs to allow differential output voltage of 20 Vp-p with simple resistor load and it can be

operated both in unipolar and bipolar mode.

FEATURES:-

1. Fast setting output current 100nS

2. Full scale error +/- 1 LSB

3. Complementary current outputs

4. easy interface to all microprocessor

5. Wide power supply range +/- 4.5 to +/- 18V

6. low power consumption

Page 46: Mp Lab Manual

46

DEPT.OF ECE,LITS ,KHAMMAM

WORKING:-

When chip select of DAC is enabled then DAC will convert digital input value given through

portliness PB0-PB7 to analog value. The analog output from DAC is a current quantity. This

current is converted to voltage using OPAMP based current-to-voltage converter. The voltage

outputs (+/- 5V for bipolar 0 to 5V for unipolar mode) of OPAMP are connected to CRO to see

the wave form.

; RAMP WAVE GENERATOR with 8086 using 8255

MODEL SMALL

.STACK 100

.DATA

CONTROL EQU 0FFC6H ; Control port address for 8255

PORTA EQU 0FFC0H ; Port A address for 8255

PORTB EQU 0FFC2H ; Port B address for 8255

PORTC EQU 0FFC4H ; Port C address for 8255

.CODE

START:

MOV AX,@DATA ;Initialize Data segment

MOV DS,AX

MOV DX,CONTROL

MOV AL,80H ;Initialize all ports as output

OUT DX,AL ;Ports

Page 47: Mp Lab Manual

47

DEPT.OF ECE,LITS ,KHAMMAM

MOV BL,FFH ;Take FFH in BL analog equivalent to 5V

RAMP : MOV DX,PORTB

MOV AL,BL ;Copy to AL

OUT DX,AL ;And output it on the port

DEC BL ; To generate ramp wave this 5V is continuously decreased till 0V

JNZ RAMP ; Jump to RAMP if not 0

MOV BL,FFH ; To generate same wave this procedure is repeated

JMP RAMP

INT 03H

END START

;SQUARE WAVE GENERATOR with 8086 using 8255

MODEL SMALL

.STACK 100

.DATA

CONTROL EQU 0FFC6H ; Control port address for 8255

PORTA EQU 0FFC0H ; Port A address for 8255

PORTB EQU 0FFC2H ; Port B address for 8255

PORTC EQU 0FFC4H ; Port C address for 8255

.CODE

START:

MOV DX,CONTROL

Page 48: Mp Lab Manual

48

DEPT.OF ECE,LITS ,KHAMMAM

MOV AL,80H ; Initialize all ports as output

OUT DX,AL ; Ports

UP: MOV DX,PORTB

MOV AL,00H ;Output 00 for 0V level

CALL OUTPUT

MOV AL,0FFH ;Output FF for 5V level

CALL OUTPUT

JMP UP

OUTPUT:

OUT DX,AL

CALL DELAY

INT 21H

DELAY:

MOV CX,0FFH ; To vary through frequency alter the delay count

LUP1 LOOP LUP1

INT 21H

END START

Page 49: Mp Lab Manual

49

DEPT.OF ECE,LITS ,KHAMMAM

;TRIANGULAR WAVE GENERATOR with 8086 using 8255

MODEL SMALL

.STACK 100

.DATA

CONTROL EQU 0FFC6H ; Control port address for 8255

PORTA EQU 0FFC0H ; Port A address for 8255

PORTB EQU 0FFC2H ; Port B address for 8255

PORTC EQU 0FFC4H ; Port C address for 8255

.CODE

START:

MOV DX,CONTROL

MOV AL,80H ; Initialize all ports as output

OUT DX,AL ; Ports

BEGIN:

MOV DX,PORTB

MOV AL,00H ; Output 00 for 0V level

UP: CALL OUTPUT

INC AL ; To raise wave from 0V to 5V increment AL

CMP AL,00H

JNZ UP ; Jump UP till rising edge is reached i.e. 5V

Page 50: Mp Lab Manual

50

DEPT.OF ECE,LITS ,KHAMMAM

MOV AL,0FFH

UP1: CALL OUTPUT

DEC AL ; To fall wave from 5V to 0V decrement AL

CMP AL,0FFH

JNZ UP1 ; Jump UP till falling edge is reached i.e. 0V

JMP BEGIN

OUTPUT:

OUT DX,AL

CALL DELAY

INT 21H

DELAY:

MOV CX,07H ;To vary the frequency alter the delay count

LUP1:LOOP LUP1

INT 21H

END START

Page 51: Mp Lab Manual

51

DEPT.OF ECE,LITS ,KHAMMAM

;STAIRCASE WAVEFORM GENERATOR with 8086 using 8255

MODEL SMALL

.STACK 100

.DATA

CONTROL EQU 0FFC6H ; Control port address for 8255

PORTA EQU 0FFC0H ; Port A address for 8255

PORTB EQU 0FFC2H ; Port B address for 8255

PORTC EQU 0FFC4H ; Port C address for 8255

.CODE

START:

MOV DX,CONTROL

MOV AL,80H ;Initialize all ports as output

OUT DX,AL ;Ports

UP: MOV DX,PORTB

MOV AL,00H ;Output 00 for 0V level

CALL OUTPUT ; And wait for some time

MOV AL,0FFH ;Output FF for 5V level

CALL OUTPUT ; And wait for some time

Page 52: Mp Lab Manual

52

DEPT.OF ECE,LITS ,KHAMMAM

MOV AL,07FH ;Output 7F for 2.5V level

CALL OUTPUT ; And wait for some time

JMP UP

OUTPUT: OUT DX,AL

MOV CX,FFH

DELAY: LOOP DELAY ; To add DELAY

INT 03H

END START

PROCEDURE:-

1. Connect power supply 5V & GND to both microprocessor trainer kit & DAC interfacing

kit.

2. Connect data bus between microprocessor trainer kit & DAC interfacing kit.

3. Enter the program to generate Ramp, Square, Triangular & Staircase Wave.

4. Execute the program by typing GO E000:4770 ENTER for Ramp, GO E000:03A0

ENTER for Square, GO E000:0410 ENTER for Triangular, GO E000:4890 ENTER for

Staircase.

5. Observe the wave forms on CRO.