You are on page 1of 54

DEP T.

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

DEP T.OF ECE,LITS ,KHAMMAM

MICROPROCESSORS AND INTERFACING LAB

(III-I SEM)

DEP T.OF ECE,LITS ,KHAMMAM

S.NO NAME OF THE EXPERIMENT PAGE NO Assembly language Program (ALP) to 8086 processor to add, 1 9 2 3 4 5 6 7 8 9 10 11 12
subtract and multiply two 16 bit unsigned numbers Assembly language Program (ALP) to 8086 processor to divide a 32 bit unsigned number by a 16 bit unsigned number Assembly language Program (ALP) to 8086 processor to sort the given array of 32 bit numbers in ascending and descending order Assembly language Program (ALP) to 8086 processor to find the length of a given string Assembly language Program (ALP) to 8086 processor to reverse the given string and verify whether it is a palindrome Assembly language Program (ALP) to 8086 processor to verify the password Assembly language Program (ALP) to 8086 processor to insert or delete a character/ number from the given string Interface a keypad to 8086 microprocessor and display the key number pressed on the 7- segment display which is also interfaced to 8086 Write an interrupt service routine to 8086 when ever there is an interrupt request on interrupt pin, which displays hello on a LCD Interface a stepper motor to 8086 and operate it in clockwise and anti-clock wise by choosing variable step-size 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 Interface an ADC to 8086 and generate step, ramp, triangle and square waveforms with different periods

12 13 15 16 19 21 26 29 31 40 45

DEP T.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 softwares 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

DEP T.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 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, , ;

DEP T.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.

DEP T.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

DEP T.OF ECE,LITS ,KHAMMAM

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]

DEP T.OF ECE,LITS ,KHAMMAM

MAP expanded memory pages

XM [Lpage] [Ppage] [handle]

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

DEP T.OF ECE,LITS ,KHAMMAM

int 03 code ends end start

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
10

DEP T.OF ECE,LITS ,KHAMMAM

jnz go1 int 03 code ends end start 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
11

DEP T.OF ECE,LITS ,KHAMMAM

jnz go1 int 03 code ends end start

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

12

DEP T.OF ECE,LITS ,KHAMMAM

Expt3a): Write and execute an Assembly Language Program to 8086 Processor to sort the given array of numbers in Ascending order
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 13

DEP T.OF ECE,LITS ,KHAMMAM 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
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 14

DEP T.OF ECE,LITS ,KHAMMAM DEC CX JNZ UP1 MOV AH,4CH INT 03h CODE ENDS END START

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
15

DEP T.OF ECE,LITS ,KHAMMAM

code ends end start

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

16

DEP T.OF ECE,LITS ,KHAMMAM

code ends end start

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

17

DEP T.OF ECE,LITS ,KHAMMAM

LOOP UP LEA SI,STR1 LEA DI,STR2 CLD MOV CX,LEN REPE CMPSB CMP CX,0H 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

18

DEP T.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

19

DEP T.OF ECE,LITS ,KHAMMAM

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

20

DEP T.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

21

DEP T.OF ECE,LITS ,KHAMMAM

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 dec cl jnz go2 jmp exit go1: mov al,dl stosb dec cl jnz go2 exit: int 03 code ends end start

22

DEP T.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

23

DEP T.OF ECE,LITS ,KHAMMAM

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

24

DEP T.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.

25

DEP T.OF ECE,LITS ,KHAMMAM

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

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

26

DEP T.OF ECE,LITS ,KHAMMAM

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

27

DEP T.OF ECE,LITS ,KHAMMAM

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] OUT PORTB,AL JMP READKEY

ONEMS: PUSH AX MOV AL,0FFh LOP: DEC AL JNZ LOP POP AX RETF LOOKUP:

28

DEP T.OF ECE,LITS ,KHAMMAM

DB 00h,04h,08h,0Ch,01h,05h,09h,0Dh DB 02h,06h,0Ah,0Eh,03h,07h,0Bh,0Fh CODE ENDS END

29

DE PT.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

30

DE PT.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

31

DE PT.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.

32

DE PT.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)

33

DE PT.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.

34

DE PT.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

35

DE PT.OF ECE,LITS ,KHAMMAM

OUT DX,AL AGAIN: MOV AL,PHASEC MOV DX,PORTC OUT DX,AL MOV CX,0FFFFH 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

36

DE PT.OF ECE,LITS ,KHAMMAM

MOV AL,PHASEA MOV DX,PORTC OUT DX,AL MOV CX,0FFFFH

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

37

DE PT.OF ECE,LITS ,KHAMMAM

PHASEC EQU 03H PHASEA EQU 09H ; SEQUENCE IN SERIES TO ROTATE MOTOR PHASED EQU 0CH ; IN ANTICLOCKWISE DIRECTION PHASEB EQU 06H

.CODE START: 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

38

DE PT.OF ECE,LITS ,KHAMMAM

UP1: LOOP UP1

MOV AL,PHASED MOV DX,PORTC OUT DX,AL MOV CX,0FFFFH UP2: 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

39

DE PT.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.

40

DE PT.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

41

DE PT.OF ECE,LITS ,KHAMMAM

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

42

DE PT.OF ECE,LITS ,KHAMMAM

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.

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:

43

DE PT.OF ECE,LITS ,KHAMMAM

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

44

DE PT.OF ECE,LITS ,KHAMMAM

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

END START

45

DE PT.OF ECE,LITS ,KHAMMAM

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.

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

46

DE PT.OF ECE,LITS ,KHAMMAM

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

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

47

DE PT.OF ECE,LITS ,KHAMMAM

.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

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

48

DE PT.OF ECE,LITS ,KHAMMAM

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

49

DE PT.OF ECE,LITS ,KHAMMAM

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

;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

50

DE PT.OF ECE,LITS ,KHAMMAM

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

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

51

DE PT.OF ECE,LITS ,KHAMMAM

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

;STAIRCASE WAVEFORM GENERATOR with 8086 using 8255

MODEL SMALL .STACK 100

52

DE PT.OF ECE,LITS ,KHAMMAM

.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 MOV AL,07FH ;Output 7F for 2.5V level CALL OUTPUT ; And wait for some time JMP UP

53

DE PT.OF ECE,LITS ,KHAMMAM

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.

54

You might also like