stannescet.ac.in · web view2019. 6. 13. · thus a given byte or word in a string of a...
TRANSCRIPT
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
INDEX
EXPT.NO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
NAME OF THE EXPERIMENT
Basic arithmetic and Logical operations
Move a Data Block Without Overlap
Code conversion, decimal arithmetic and Matrixoperations.
Floating point operations, string manipulations, sortingand searchingPassword Checking, Print Ram Size And System DateCounters and Time Delay
Traffic light control
Stepper motor control
Digital clock
Key board and Display
Printer status
Serial interface and Parallel interface
A/D and D/A interface and Waveform Generation
Basic arithmetic and Logical operations
Square and Cube program, Find 2’s complement of anumber
Unpacked BCD to ASCII
PAGENO 3
10
11
17
31
36
38
40
42
45
48
49
53
59
70
72
2
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
BASIC ARITHMETIC AND LOGICAL OPERATIONS USING 8086 PROGRAMMING
EXPT NO: 01 DATE:AIM: To write an Assembly Language Program (ALP) for performing the Arithmeticoperation of two byte numbers.
APPARATUS REQUIRED:
SL.N O 1. 2.
ITEM
Microprocessor kitPower Supply
SPECIFICATION
8086 kit+5 V dc
QUANTITY
11
PROBLEM STATEMENT: Write an ALP in 8086 to add and subtract two byte numbers stored in thememory location 1000H to 1003H and store the result in the memory location1004H to 1005H.Also provide an instruction in the above program to consider thecarry also and store the carry in the memory location 1006H.ALGORITHM: (iii) Multiplication of 16-bit(i) 16-bit additionInitialize the MSBs of sum to 0
Get the first number.Add the second number to the firstnumber.If there is any carry, incrementMSBs of sum by 1.Store LSBs of sum.Store MSBs of sum.
(ii) 16-bit subtraction Initialize the MSBs of difference to 0 Get the first number Subtract the second number from the first number. If there is any borrow, increment MSBs of difference by 1. Store LSBs of difference Store MSBs of difference.
numbers: Get the multiplier. Get the multiplicand Initialize the product to 0. Product=product+ multiplicand Decrement the multiplier by 1 If multiplicand is not equal to 0,repeat from step (d) otherwise store the product.(iv) Division of 16-bit numbers. Get the dividend Get the divisor Initialize the quotient to 0. Dividend = dividend – divisor If the divisor is greater, store the quotient. Go to step g.
If dividend is greater, quotient= quotient + 1. Repeat fromstep (d)Store the dividendvalue as remainder.
3
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
FLOWCHART
ADDITION
START
SET UP COUNTER (CY)
GET FIRST OPERAND
DEPT OF ECE
SUBTRACTION
START
SET UP COUNTER (CARRY)
GET FIRSTOPERAND TO A
GET SECOND OPERANDTOA
SUBTRACTSECOND OPERAND FROM MEMORY
A=A+BIS THEREANY CY
YESIS THEREANY CARRY
COUNTER =COUNTER + 1
NO
STORE THE SUM
NO
YES
COUNTER =COUNTER + 1
STORE THEDIFFERENCE
STORE THE CARRY
STORE THE CARRY STOP
STOP
4
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
ADDITION ADDRESS
DEPT OF ECE
Opcodes PROGRAM
MOV CX, 0000H
MOV AX,[1200]
MOV BX, [1202]
ADD AX,BX
JNC L1
INC CX
L1 : MOV [1206],CX
MOV [1204], AX
HLT
COMMENTS
Initialize counter CX
Get the first data in AX reg
Get the second data in BX reg
Add the contents of both theregs AX & BX
Check for carry
If carry exists, increment theCX
Store the carry
Store the sum
Stop the program
SUBTRACTION
ADDRESS OPCODES PROGRAM
MOV CX, 0000H
MOV AX,[1200]
MOV BX, [1202]
SUB AX,BX
JNC L1
INC CX
L1 : MOV [1206],CX
MOV [1204], AX
HLT
COMMENTS
Initialize counter CX
Get the first data in AX reg
Get the second data in BX reg
Subtract the contents of BX fromAX
Check for borrow
If borrow exists, increment theCX
Store the borrow
Store the difference
Stop the program
5
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
RESULT:.ADDITION
DEPT OF ECE
MEMORY
DATA
SUBTRACTION
MEMORY
DATA
MANUAL CALCULATION
.
6
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
FLOWCHART
MULTIPLICATION
StartStart
DIVISION
Start
Get Multiplier & MultiplicandGet Multiplier & Multiplicand MULTIPLICAND MULTIPLICAND
Load Divisor &Dividend
REGISTER=00 REGISTER=00
QUOTIENT = 0
REGISTER = REGISTER REGISTER = + MULTIPLICAND REGISTER + MULTIPLICAND
DIVIDEND =DIVIDEND-DIVISOR
QUOTIENT = QUOTIENT+1Multiplier=MULTIPLIER Multiplier=MU–1 LTIPLIER – 1
NO
NO IS IS MULTIPLIMULTIPLIERER=0?
=0?
YES
STORE THE RESULT
ISDIVIDEND<DIVISOR
?
YES
STORE QUOTIENTSTORE REMAINDER= DIVIDEND NOW
STOP STOP
7
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
MULTIPLICATION
ADDRESS Opcodes PROGRAM
MOV AX,[1200]
MOV BX, [1202]
MUL BX
MOV [1206],AX
MOV AX,DX
MOV [1208],AX
HLT
DIVISION
ADDRESS Opcodes PROGRAM
MOV AX,[1200]
MOV DX, [1202]
MOV BX, [1204]
DIV BX
MOV [1206],AX
MOV AX,DX
MOV [1208],AX
HLT
COMMENTS
Get the first data
Get the second data
Divide the dividend by divisor
Store the lower order product
Copy the higher order product toAXStore the higher order product
Stop the program
Get the first data
COMMENTS
Get the first data
Get the second data
Multiply both
Store the lower order product
Copy the higher order product toAXStore the higher order product
Stop the program
8
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
RESULT:.MULTIPLICATION
DEPT OF ECE
MEMORY
DATA
DIVISON
MEMORY
DATA
MANUAL CALCULATION
9
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
MOVE A DATA BLOCK WITHOUT OVERLAP
DEPT OF ECE
EXP.NO: 02AIM:To convert a given Move a data block without overlap .ALGORITHM:
1. Initialize the memory location to the data pointer.2. Increment B register.3. Increment accumulator by 1 and adjust it to decimal every time.4. Compare the given decimal number with accumulator value.5. When both matches, the equivalent hexadecimal value is in Bregister.6. Store the resultant in memory location.
PROGRAM:
DATE:
DATA SEGMENTX DB 01H,02H,03H,04H,05H ;Initialize Data Segments Memory LocationsY DB 05 DUP(0)DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATA ; Initialize DS to point to start of the memoryMOV DS,AX ; set aside for string of dataMOV CX,05H ; Load counterLEA SI,X+04 ; SI pointer pointed to top of the memory blockLEA DI,X+04+03 ; 03 is displacement of over lapping, DI pointed to;the top of the destination blockCODE ENDSEND START
Output:
RESULT: Thus the output for the Move a data block without overlap was executed successfully
10
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
CODE CONVERSION, DECIMAL ARITHMETIC AND MATRIX OPERATIONS.
EXP.NO: 03AIM: To convert a given decimal number to hexadecimal.ALGORITHM:
1. Initialize the memory location to the data pointer. 2. Increment B register. 3. Increment accumulator by 1 and adjust it to decimal every time. 4. Compare the given decimal number with accumulator value. 5. When both matches, the equivalent hexadecimal value is in Bregister. 6. Store the resultant in memory location.FLOWCHART :
CODE CONVERSIONS –DECIMAL TO HEX DATE:
11
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
PROGRAM:
DEPT OF ECE
INPUT
MEMORY
OUTPUT
DATA
12
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
CODE CONVERSION –HEXADECIMAL TO DECIMALAIM:To convert a given hexadecimal number to decimal.ALGORITHM: 1. Initialize the memory location to the data pointer. 2. Increment B register. 3. Increment accumulator by 1 and adjust it to decimal every time. 4. Compare the given hexadecimal number with B register value. 5. When both match, the equivalent decimal value is in A register. 6. Store the resultant in memory location.
13
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
14
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
DECIMAL ARITHMETIC AND MATRIX OPERATIONSAIM:
To write a program for addition of two matrix by using 8086.
APPARATUS REQUIRED:8086 Microprocessor Kit
ALGORITH:1. Initialize the pointer only for data and result2. Load AL with count3. Add two matrix by each element4. Process continues until CL is zero5. Store result.
FLOWCHART
15
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PROGRAM
RESULT: Thus the output for the addition for two matrix was executed successfully.
16
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
FLOATING POINT OPERATIONS, STRING MANIPULATIONS,SORTING AND SEARCHING
EXPT NO:04COPYING A STRINGAIM: To move a string of length FF from source to destination.
ALGORITHM: a. Initialize the data segment .(DS) b. Initialize the extra data segment .(ES) c. Initialize the start of string in the DS. (SI) d. Initialize the start of string in the ES. (DI) e. Move the length of the string(FF) in CX register. f. Move the byte from DS TO ES, till CX=0.
START
DATE:
Initialize DS,ES,SI,DI
CX=length of string,DF=0.
Move a byte from source string (DS)to destination string (ES)
Decrement CX
NO
Check forZF=1
STOP
17
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
COPYING A STRINGADDRESS OPCODES
DEPT OF ECE
PROGRAM
MOV SI,1200H
MOV DI,1300H
MOV CX,0006H
CLD
REP MOVSB
HLT
COMMENTS
Initialize destination address
Initialize starting address
Initialize array size
Clear direction flag
Copy the contents of source intodestination until count reaches zeroStop
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY
DATA
Thus a string of a particular length is moved from source segment to destination segment
18
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
SEARCHING A STRINGAIM: To scan for a given byte in the string and find the relative address of the byte from thestarting location of the string.ALGORITHM: a. Initialize the extra segment .(ES) b. Initialize the start of string in the ES. (DI) c. Move the number of elements in the string in CX register. d. Move the byte to be searched in the AL register. e. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DI to BX.
START
Initialize DS,ES ,SI,DI
CX=length of the string,DF=0.
Scan for a particular characterspecified in AL Register.
NO
Check forZF=1
Move DI to BX
STOP
19
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
SEARCHING FOR A CHARACTER IN THE STRINGADDRESS OPCODESPROGRAM
MOV DI,1300H
MOV SI, 1400H
MOV CX, 0006H
CLD
MOV AL, 08H
REPNE SCASB
DEC DI
MOV BL,[DI]
MOV [SI],BL
HLT
RESULT:
INPUT
MEMORY
DATA
DEPT OF ECE
COMMENTS
Initialize destination address
Initialize starting address
Initialize array size
Clear direction flag
Store the string to be searched
Scan until the string is found
Decrement the destination address
Store the contents into BL reg
Store content of BL in source address
Stop
OUTPUT
MEMORY LOCATION
DATA
Thus a given byte or word in a string of a particular length in the extra segment(destination)is found .
20
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
FIND AND REPLACEAIM:
To find a character in the string and replace it with another character.
DEPT OF ECE
ALGORITHM: a. Initialize the extra segment .(E S) b. Initialize the start of string in the ES. (DI) c. Move the number of elements in the string in CX register. d. Move the byte to be searched in the AL register. e. Store the ASCII code of the character that has to replace the scanned byte in BL register. f. Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat scanning. g. If the byte is found, ZF=1.Move the content of BL register to ES:DI.
START
Initialize DS, ES, SI, DI
CX=length of the string in ES,DF=0.DF=0.
Scan for a particular characterspecified in AL Register.
NO
Check for ZF=1
YES
Move the content of BLto ES:DI
STOP
21
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
FIND AND REPLACE A CHARACTER IN THE STRINGADDRESS OPCODESPROGRAMCOMMENTS
MOV DI,1300H
MOV SI,1400H
MOV CX, 0006H
CLD
MOV AL, 08H
MOV BH,30H
REPNE SCASB
DEC DI
MOV BL,[DI]
MOV [SI],BL
MOV [DI],BH
HLT
RESULT:
INPUT
MEMORY
DATA
Initialize destination address
Initialize starting address
Initialize array size
Clear direction flag
Store the string to be searched
Store the string to be replaced
Scan until the string is found
Decrement the destination address
Store the contents into BL reg
Store content of BL in source address
Replace the string
Stop
OUTPUT
MEMORY
DATA
Thus a given byte or word in a string of a particular length in the extra segment(destination)is found and is replaced with another character.
22
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
ASCENDING & DESCENDING
AIM:
DEPT OF ECE
To write an Assembly Language Program (ALP) to sort a given array inascending and descending order.
APPARATUS REQUIRED:
SL.N O 1. 2.
ITEM
Microprocessor kitPower Supply
SPECIFICATION
8086+5 V dc
QUANTITY
11
PROBLEM STATEMENT:
An array of length 10 is given from the location. Sort it into descendingand ascending order and store the result.
ALGORITHM:(i)Sorting in ascending order:a. Load the array count in two registers C1 and C2.b. Get the first two numbers.c. Compare the numbers and exchange if necessary so that the two numbers are in ascending order.d. Decrement C2.e. Get the third number from the array and repeat the process until C2 is 0.f. Decrement C1 and repeat the process until C1 is 0.(ii) Sorting in descending order:a. Load the array count in two registers C1 and C2.b. Get the first two numbers.c. Compare the numbers and exchange if necessary so that the two numbers are in descending order.d. Decrement C2.e. Get the third number from the array and repeat the process until C2 is 0.f. Decrement C1 and repeat the process until C1 is 0.
23
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
FLOWCHARTASCENDING ORDER
DEPT OF ECE
DESCENDING ORDER
STARTSTART
INITIALIZE POINTER
COUNT = COUNT – 1
FLAG = 0
IS POINTER POINTER +1
NO
TEMP = POINTERPOINTER = POINTER + 1 POINTER + 1 = TEMP
YES
INITIALIZE POINTER
COUNT = COUNT – 1
FLAG = 0
IS POINTER POINTER +1
NO
TEMP = POINTERPOINTER = POINTER + 1 POINTER + 1 = TEMP
YES
POINTER = POINTER +1COUNT = COUNT + 1
POINTER = POINTER +1COUNT = COUNT + 1
NO
IS
COUNT
=0
NOIS FLAG
= 0YES
STOP
YES
NOIS
COUNT
=0 YES
IS FLAG
= 0YES
STOP
24
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
ASCENDING
ADDRESS OPCODES PROGRAMMOV SI,1200H
MOV CL,[SI]L4 : MOV SI,1200HMOV DL,[SI]INC SIMOV AL,[SI]L3 : INC SIMOV BL,[SI]CMP AL,BLJNB L1DEC SIMOV [SI],ALMOV AL,BLJMP L2L1 : DEC SIMOV [SI],BL
L2 : INC SIDEC DLJNZ L3
MOV [SI],ALDEC CLJNZ L4
HLT
DESCENDING
ADDRESS OPCODES PROGRAMMOV SI,1200H
MOV CL,[SI]L4 : MOV SI,1200HMOV DL,[SI]INC SIMOV AL,[SI]L3 : INC SI
DEPT OF ECE
COMMENTSInitialize memory location for array sizeNumber of comparisons in CLInitialize memory location for array sizeGet the count in DLGo to next memory locationGet the first data in ALGo to next memory locationGet the second data in BLCompare two data’sIf AL < BL go to L1Else, Decrement the memory locationStore the smallest dataGet the next data ALJump to L2Decrement the memory locationStore the greatest data in memorylocationGo to next memory locationDecrement the countJump to L3, if the count is not reachedzeroStore data in memory locationDecrement the countJump to L4, if the count is not reachedzeroStop
COMMENTSInitialize memory location for array sizeNumber of comparisons in CLInitialize memory location for array sizeGet the count in DLGo to next memory locationGet the first data in ALGo to next memory location
25
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
MOV BL,[SI]CMP AL,BLJB L1DEC SIMOV [SI],ALMOV AL,BLJMP L2L1 : DEC SIMOV [SI],BL
L2 : INC SIDEC DLJNZ L3
MOV [SI],ALDEC CLJNZ L4
HLT
RESULT:.ASCENDING
DEPT OF ECE
Get the second data in BLCompare two data’sIf AL > BL go to L1Else, Decrement the memory locationStore the largest dataGet the next data ALJump to L2Decrement the memory locationStore the smallest data in memorylocationGo to next memory locationDecrement the countJump to L3, if the count is not reachedzeroStore data in memory locationDecrement the countJump to L4, if the count is not reachedzeroStop
MEMORY
DATA
DESCENDING
MEMORY
DATA
Thus given array of numbers are sorted in ascending & descending order.
26
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
LARGEST& SMALLEST
AIM:
DEPT OF ECE
To write an Assembly Language Program (ALP) to find the largest andsmallest number in a given array.
APPARATUS REQUIRED:
SL.N O 1. 2.
ITEM
Microprocessor kitPower Supply
SPECIFICATION
8086+5 V dc
QUANTITY
11
PROBLEM STATEMENT:
An array of length 10 is given from the location. Find the largest andsmallest number and store the result.
ALGORITHM:(i)Finding largest number:a.b.c.d.
(ii)e.f.g.h.
Load the array count in a register C1.Get the first two numbers.Compare the numbers and exchange if the number is small.Get the third number from the array and repeat the process until C1 is 0.
Finding smallest number:Load the array count in a register C1.Get the first two numbers.Compare the numbers and exchange if the number is large.Get the third number from the array and repeat the process until C1 is 0.
27
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
FLOWCHARTLARGEST NUMBER IN AN ARRAY
START
INITIALIZE COUNTPOINTER MAX = 0
PONITER =POINTER + 1
DEPT OF ECE
SMALLEST NUMBER IN AN ARRAYSTART
INITIALIZE COUNTPOINTER MIN = 0
PONITER =POINTER + 1
YESIS MAX
YES POINTER ? NO
IS MINPOINTER?
NO
MIN = POINTERMAX = POINTER
COUNT = COUNT-1
NO
IS COUNT = 0 ?
YES
STORE MAXIMUMYES
NO
COUNT = COUNT-1
IS COUNT = 0 ?
STORE MINIIMUM
STOP STOP
28
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
LARGEST
ADDRESS OPCODES PROGRAM
MOV SI,1200HMOV CL,[SI]INC SIMOV AL,[SI]DEC CLL2 : INC SICMP AL,[SI]JNB L1MOV AL,[SI]L1 : DEC CLJNZ L2MOV DI,1300HMOV [DI],AL
HLT
SMALLEST
ADDRESS OPCODES PROGRAM
MOV SI,1200HMOV CL,[SI]INC SIMOV AL,[SI]DEC CLL2 : INC SICMP AL,[SI]JB L1MOV AL,[SI]L1 : DEC CLJNZ L2MOV DI,1300HMOV [DI],AL
HLT
DEPT OF ECE
COMMENTS
Initialize array sizeInitialize the countGo to next memory locationMove the first data in ALReduce the countMove the SI pointer to next dataCompare two data’sIf AL > [SI] then go to L1 ( no swap)Else move the large number to ALDecrement the countIf count is not zero go to L2Initialize DI with 1300HElse store the biggest number in 1300locationStop
COMMENTS
Initialize array sizeInitialize the countGo to next memory locationMove the first data in ALReduce the countMove the SI pointer to next dataCompare two data’sIf AL < [SI] then go to L1 ( no swap)Else move the large number to ALDecrement the countIf count is not zero go to L2Initialize DI with 1300HElse store the biggest number in 1300locationStop
29
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:.LARGEST
MEMORY
DATA
SMALLEST
MEMORY
DATA
Thus largest and smallest number is found in a given array.
30
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PASSWORD CHECKING, PRINT RAM SIZE AND SYSTEM DATE
EXPT NO:05DATE:AIM: To write an Assembly Language Program (ALP) for performing the Arithmeticoperation of two byte numbers
APPARATUS REQUIRED:
SL.N O 1. 2.
ITEM
Microprocessor kitPower Supply
SPECIFICATION
8086 kit+5 V dc
QUANTITY
11
PROGRAM:;PASSWORD IS MASM1234DATA SEGMENTPASSWORD DB 'MASM1234'LEN EQU ($-PASSWORD)MSG1 DB 10,13,'ENTER YOUR PASSWORD: $'MSG2 DB 10,13,'WELCOME TO ELECTRONICS WORLD!!$'MSG3 DB 10,13,'INCORRECT PASSWORD!$'NEW DB 10,13,'$'INST DB 10 DUP(0)DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXLEA DX,MSG1MOV AH,09HINT 21HMOV SI,00UP1:MOV AH,08HINT 21HCMP AL,0DHJE DOWNMOV [INST+SI],ALMOV DL,'*'MOV AH,02HINT 21HINC SIJMP UP1DOWN:
31
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
MOV BX,00MOV CX,LENCHECK:MOV AL,[INST+BX]MOV DL,[PASSWORD+BX]CMP AL,DLJNE FAILINC BXLOOP CHECKLEA DX,MSG2MOV AH,09HINT 21HJMP FINISHFAIL:LEA DX,MSG3MOV AH,009HINT 21HFINISH:INT 3CODE ENDSEND STARTEND
;Today.asm Display month/day/year.; Feb 1st, 2012;CIS 206 Ken Howard .MODEL small .STACK 100h .DATA mess1 DB 10, 13, 'Today is $' ; 10=LF, 13=CR .CODE
Today PROC MOV AX, @data MOV DS, AX MOV DX, OFFSET mess1 ; Move string to DX MOV AH, 09h; 09h call to display string (DX > AH > DOS) INT 21H; Send to DOS ; CX year, DH month, DL day MOV AH, 2AH; Get the date (appendix D) INT 21H; Send to DOS PUSH CX; Move year to the stack MOV CX, 0; Clear CX
DEPT OF ECE
MOV CL, DL PUSH CX; Move day to stack MOV CL, DH; Move month > CL PUSH CX; Move month to stackMOV DH, 0; Clear DH; ************************** DISPLAY MONTH ************************
32
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
; Set up for division ; Dividend will be in DX/AX pair (4 bytes) ; Quotient will be in AX ; Remainder will be in DX MOV DX, 0; Clear DX POP AX; Remove month from stack into AX MOV CX, 0; Initialize the counter MOV BX, 10; Set up the divisordividem: DIV BX; Divide (will be word sized) PUSH DX; Save remainder to stack ADD CX, 1; Add one to counter MOV DX, 0; Clear the remainder CMP AX, 0; Compare quotient to zero JNE dividem; If quoient is not zero, go to "dividem:"divdispm:
DEPT OF ECE
POP DX; Remove top of stack into DX ADD DL, 30h; ADD 30h (2) to DL MOV AH, 02h; 02h to display AH (DL) INT 21H; Send to DOS LOOP divdispm; If more to do, divdispm again ; LOOP subtracts 1 from CX. If non-zero, loop. MOV DL, '/'; Character to display goes in DL MOV AH, 02h; 02h to display AH (DL) INT 21H; Send to DOS; ************************** DISPLAY DAY ************************ ; Set up for division ; Dividend will be in DX/AX pair (4 bytes) ; Quotient will be in AX ; Remainder will be in DX MOV DX, 0; Clear DX POP AX; Remove day from stack into AX MOV CX, 0; Initialize the counter MOV BX, 10; Set up the divisordivided: DIV BX; Divide (will be word sized) PUSH DX; Save remainder to stack
ADD CX, 1; Add one to counter MOV DX, 0; Clear the remainder CMP AX, 0; Compare quotient to zero JNE divided; If quoient is not zero, go to "divided:"divdispd: POP DX; Remove top of stack ADD DL, 30h; ADD 30h (2) to DL MOV AH, 02h; 02h to display AH (DL) INT 21H; Send to DOS LOOP divdispd; If more to do, divdispd again ; LOOP subtracts 1 from CX. If non-zero, loop.
33
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
MOV DL, '/'; Character to display goes in DL MOV AH, 02h; 02h to display AH (DL) INT 21H; Send to DOS ; ************************** DISPLAY YEAR ************************ ; Set up for division ; Dividend will be in DX/AX pair (4 bytes) ; Quotient will be in AX ; Remainder will be in DX MOV DX, 0; Clear DX POP AX; Remove month from stack into AX MOV CX, 0; Initialize the counter MOV BX, 10; Set up the divisor dividey: DIV BX; Divide (will be word sized) PUSH DX; Save remainder to stack ADD CX, 1; Add one to counter MOV DX, 0; Clear the remainder CMP AX, 0; Compare quotient to zero JNE dividey; If quoient is not zero, go to "dividey:"divdispy: POP DX; Remove top of stack into DX ADD DL, 30h; ADD 30h (2) to DL MOV AH, 02h; 02h to display AH (DL) INT 21H; Send to DOS LOOP divdispy; If more to do, divdisp again ; LOOP subtracts 1 from CX. If non-zero, loop. MOV al, 0; Use 0 as return code MOV AH, 4ch; Send return code to AH INT 21H; Send return code to DOS to exit.
Today ENDP; End procedureEND Today; End code. Start using "Today" procedure.MVI A, 80H: Initialize 8255, port A and port BOUT 83H (CR): in output modeSTART: MVI A, 09HOUT 80H (PA): Send data on PA to glow R1 and R2MVI A, 24HOUT 81H (PB): Send data on PB to glow G3 and G4MVI C, 28H: Load multiplier count (40ıο) for delayCALL DELAY: Call delay subroutineMVI A, 12HOUT (81H) PA: Send data on Port A to glow Y1 and Y2OUT (81H) PB: Send data on port B to glow Y3 and Y4MVI C, 0AH: Load multiplier count (10ıο) for delayCALL: DELAY: Call delay subroutineMVI A, 24HOUT (80H) PA: Send data on port A to glow G1 and G2MVI A, 09HOUT (81H) PB: Send data on port B to glow R3 and R4MVI C, 28H: Load multiplier count (40ıο) for delay
34
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
CALL DELAY: Call delay subroutineMVI A, 12HOUT PA: Send data on port A to glow Y1 and Y2OUT PB: Send data on port B to glow Y3 and Y4MVI C, 0AH: Load multiplier count (10ıο) for delayCALL DELAY: Call delay subroutineJMP STARTDelay Subroutine:DELAY: LXI D, Count: Load count to give 0.5 sec delayBACK: DCX D: Decrement counterMOV A, DORA E: Check whether count is 0JNZ BACK: If not zero, repeatDCR C: Check if multiplier zero, otherwise repeatJNZ DELAYRET: Return to main program
Ram size:
ORG 0000H CLR PSW3 CLR PSW4 CPL A ADD A, #01H MOV A,R3AGAIN: SJMP AGAIN
DEPT OF ECE
RESULT: Thus the output for the Password checking, Print RAM size and system date wasexecuted successfully
35
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
Counters and Time Delay
EXP.NO: 06
AIM:
DATE:
To write an assembly language program in 8086 to Counters and Time Delay
SPECIFICATION8086+5 V, dc,+12 V dc--
QUANTITY 1 1 1 1
APPARATUS REQUIRED:SL.NOITEM 1.Microprocessor kit 2.Power Supply 3.Stepper Motor Interface board 4.Stepper Motor
PROGRAM: .MODEL SMALL .DATA
MSGIN DB 'Enter delay duration (0-50): $'MSG1 DB 'This is Microprocessor!$'DELAYTIME DW 0000H
.CODE
MOV DX,@DATAMOV DS,DXLEA DX,MSGINMOV AH,09HINT 21H
IN1: MOV AH,01H INT 21H CMP AL,0DH ; JE NXT SUB AL,30H MOV DL,AL MOV AX,BX MOV CL,0AH MUL CL MOV BX,AX AND DX,00FFH ADD BX,DX MOV DELAYTIME,BX LOOP IN1
36
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
NXT:MOV CX,DELAYTIME MOV DL,10 MOV AH,02H INT 21H
LEA SI,MSG1
LP: PUSH DX MOV DL,[SI] CMP DL,'$' JE NXT2 MOV AH,02HINT 21HADD SI,1POP DXMOV DI,DELAYTIMEMOV AH, 0INT 1AhMOV BX, DX
Delay:MOV AH, 0INT 1AhSUB DX, BXCMP DI, DXJA Delay
LOOP LP
NXT2: MOV AH,4CH INT 21H
END
DEPT OF ECE
RESULT: Thus the output for the Counters and Time Delay was executed successfully
37
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
TRAFFIC LIGHT CONTROL
EXP.NO: 07
AIM:
DATE:
To write an assembly language program in 8086 to Traffic light controlAPPARATUS REQUIRED:SL.NOSPECIFICATIONQUANTITYITEM 1.80861Microprocessor kit 2.+5 V, dc,+12 V dc1Power Supply 3.-1Traffic light control Interface board
PROGRAM:
38
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
39
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
STEPPER MOTOR INTERFACING
DEPT OF ECE
EXP.NO: 08 DATE:
AIM: To write an assembly language program in 8086 to rotate the motor at different speeds.
APPARATUS REQUIRED:
SL.NO 1. 2. 3. 4.
ITEMMicroprocessor kitPower SupplyStepper Motor Interface boardStepper Motor
SPECIFICATION8086+5 V, dc,+12 V dc--
QUANTITY 1 1 1 1
PROBLEM STATEMENT:
Write a code for achieving a specific angle of rotation in a given time and particularnumber of rotations in a specific time.
THEORY:
A motor in which the rotor is able to assume only discrete stationary angularposition is a stepper motor. The rotary motion occurs in a stepwise manner from oneequilibrium position to the next.Two-phase scheme: Any two adjacent stator windings areenergized. There are two magnetic fields active in quadrature and none of the rotor pole facescan be in direct alignment with the stator poles. A partial but symmetric alignment of therotor poles is of course possible.
ALGORITHM:
For running stepper motor clockwise and anticlockwise directions(i)Get the first data from the lookup table.(ii)Initialize the counter and move data into accumulator.(iii) Drive the stepper motor circuitry and introduce delay(iv)Decrement the counter is not zero repeat from step(iii)(v)Repeat the above procedure both for backward and forward directions.
SWITCHING SEQUENCE OF STEPPER MOTOR:
MEMORYLOCATION4500450145024503
A1
1001
A2
0110
B1
0011
B2
0100
HEXCODE09 H05 H06 H0A H
40
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
FLOWCHART:
DEPT OF ECE
START
INTIALIZE COUNTER FOR LOOK UP TABLE
GET THE FIRST DATA FROM THE ACCUMULATOR
MOVE DATA INTO THE ACCUMULATOR
DRIVE THE MOTOR CIRCUITARY
DELAY
DECREMENT COUNTER
IS B = 0 ?
GET THE DATA FROM LOOK UP TABLE
PROGRAM TABLEADDRESS OPCODE PROGRAM
START : MOV DI, 1200H
MOV CX, 0004HLOOP 1 : MOV AL,[DI]OUT 0C0,ALMOV DX, 1010HL1 : DEC DXJNZ L1INC DILOOP LOOP1JMP START
1200 : 09,05,06,0A
Go to next memory locationLoop until all the data’s have been sentGo to start location for continuousrotationArray of data’s
Introduce delay
COMMENTSInitialize memory location to store thearray of numberInitialize array sizeCopy the first data in ALSend it through port address
RESULT: Thus the assembly language program for rotating stepper motor in both clockwiseand anticlockwise directions is written and verified.
41
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
DIGITAL CLOCK
EXP.NO: 09
Aim
DATE:
To display the digital clock specifically by displaying the hours, minutes and secondsusing 8086 kits
Apparatus required
S.No12
ItemMicroprocessor kit Power Supply
Specification80865V +5 V, dc, +12 V dcPreliminary Settings
Org 1000hStore time value in memory location 1500- Seconds 1501- Minutes 1502- HoursDigital clock program
42
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
43
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
Result Thus the digital clock program has been written and executed using 8086microprocessor kit and the output of digital clock was displayed as [hours: minutes: seconds]successfully.
44
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
INTERFACING PRGRAMMABLE KEYBOARD AND DISPLAY CONTROLLER- 8279
EXP.NO:10
AIM :To display the rolling message “ HELP US “ in the display.
DATE:
APPARATUS REQUIRED: 8086 Microprocessor kit, Power supply, Interfacing board.
ALGORITHM : Display of rolling message “ HELP US “ 1. Initialize the counter 2. Set 8279 for 8 digit character display, right entry 3. Set 8279 for clearing the display 4. Write the command to display 5. Load the character into accumulator and display it 6. Introduce the delay 7. Repeat from step 1.
1. Display Mode Setup: Control word-10 H
00
DD 00- 8Bit character display left entry 01- 16Bit character display left entry 10- 8Bit character display right entry 11- 16Bit character display right entryKKK- Key Board Mode 000-2Key lockout.2.Clear Display: Control word-DC H
11
11
00
1CD
1CD
1CD
0CF
0CA
00
00
1 D
0D
0K
0K
0K
11 A0-3; B0-3 =FF
1-Enables Clear display0-Contents of RAM will be displayed
1-FIFO Status is cleared
451-Clear all bits(Combined effect of CD)
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
3. Write Display: Control word-90H
11
00
00
1 0 0 0 0
DEPT OF ECE
AI A A A A
Selects one of the 16 rows of display.
Auto increment = 1, the row address selected will be incremented after each of read andwrite operation of the display RAM.FLOWCHART
SEGMENT DEFINITION
DATA BUS D7 D6
c
D5
b
D4
a
D3
dp
D2
g
D1
f
D0
eSEGMENTS d
46
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
PROGRAM TABLE
DEPT OF ECE
PROGRAMSTART : MOV SI,1200HMOV CX,000FHMOV AL,10OUT C2,ALMOV AL,CCOUT C2,ALMOV AL,90OUT C2,ALL1 : MOV AL,[SI]OUT C0,ALCALL DELAYINC SILOOP L1JMP STARTDELAY : MOV DX,0A0FFHLOOP1 : DEC DXJNZ LOOP1RET
LOOK-UP TABLE:
12001204
98FF
681C
7C29
C8FF
Initialize arrayCOMMENTS
Initialize array sizeStore the control word for display modeSend through output portStore the control word to clear displaySend through output portStore the control word to write displaySend through output portGet the first dataSend through output portGive delayGo & get next dataLoop until all the data’s have been takenGo to starting locationStore 16bit count valueDecrement count valueLoop until count values becomes zeroReturn to main program
RESULT:
MEMORYLOCATION1200H1201H1202H1203H1204H1205H1206H1207H
7-SEGMENT LED FORMATcbadp eg001100110100111110100100111111000110010100111111
HEX DATAf00001011
98687CC8FF1C29FF
d10011001
Thus the rolling message “HELP US” is displayed using 8279 interface kit.
47
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PRINTER STATUS
EXP.NO:11AIM:To display the Printer Status in the display
APPARATUS REQUIRED: 8086 Microprocessor kit, Power supply, interfacing board.
PROGRAM:
XOR AX, AXXOR BX, BX
;this divides my 3digit number by 100 giving me my, hundredth digitMOV AX, RESMOV BX, 100DIV BX
;prints the hundredth digitADD AL, '0'MOV DL, ALPUSH AX ; save AX on the stackMOV AH, 02hINT 21hPOP AX ; restore ax
;divides the remainder by 10 giving me my tens digitMOV BX, 10DIV BX
;prints my tens digitADD AL, '0'MOV DL, ALPUSH AX ; save AX on the stackMOV AH, 02hINT 21hPOP AX ; restore ax
;print my last remainder which is my onesADD AH, '0'MOV DL, AHMOV AH, 02hINT 21h
RESULT: Thus the output for the Move a data block without overlap was executed successfully
DATE:
48
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
SERIAL INTERFACE AND PARALLEL INTERFACE
EXP.NO: 12 DATE:
To connect two 8086 microprocessor kits and to serially communicate witheach other by considering transmitter and receiver kits.Apparatus required
Aim
Procedure1. Take two no of 8086 microprocessor kits.2. Enter the transmitter program in transmitter kit.3. Enter the receiver program in receiver kit.4. Interface the two kits with 9-9 serial cable in the serial port of the microprocessor kits.(LCD kit means PC-PC cable. LED kit means kit-kit cable)5. Enter the data in transmitter kit use the memory location 1500.6. Execute the receiver kit.7. Execute the transmitter kit.8. Result will be available in receiver kit memory location 1500.
Transmitter Program
49
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
Receiver Program
ResultThus the serial communication between two 8086 microprocessor kits has beenestablished and the data is transmitted in one kit and received in the other kitsuccessfully
50
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PARALLEL COMMUNICATION BETWEEN TWO 8086 MICROPROCESSORS KITS AimTo connect two 8086 microprocessor kits and to establish parallel communication with eachother by considering transmitter and receiver kits.Apparatus required
Procedure1. Take two 8086 microprocessor kits.2. Enter the transmitter program in transmitter kit.3. Enter the receiver program in receiver kit.4. Interface the two kits with 26-core cable on PPI-1.5. Execute the receiver kit.6. Execute the transmitter kit.7. Go and see the memory location 1200 in receiver to get same eight data.8. Data is available in transmitter kit in the memory location.9. Change the data & execute the following procedure & get the result in receiver kit.
Transmitter program
51
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
Receiver Program
DEPT OF ECE
ResultThus the serial communication between two 8086 microprocessor kits has been establishedand the data is transmitted in one kit and received in the other kit successfully.
52
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
A/D AND D/A INTERFACE AND WAVEFORM GENERATION
EXPT NO:13DATE:AIM: To write an assembly language program to convert an analog signal into a digital signalusing an ADC interfacing.APPARATUS REQUIRED: ITEMSL.NOSPECIFICATIONQUANTITY 1.80861Microprocessor kit 2.+5 V dc,+12 V dc1Power Supply 3.-1ADC Interface boardTHEORY: An ADC usually has two additional control lines: the SOC input to tell the ADC when tostart the conversion and the EOC output to announce when the conversion is complete. Thefollowing program initiates the conversion process, checks the EOC pin of ADC 0809 as towhether the conversion is over and then inputs the data to the processor. It also instructs theprocessor to store the converted digital data at RAM location.ALGORITHM: (i)Select the channel and latch the address. (ii)Send the start conversion pulse. (iii) Read EOC signal. (iv)If EOC = 1 continue else go to step (iii) (v)Read the digital output. (vi)Store it in a memory location.FLOW CHART: START
SELECT THE CHANNEL AND LATCH ADDRESS
SEND THE START CONVERSION PULSE
NOIS EOC = 1?
YES
READ THE DIGITALOUTPUT
STORE THE DIGITAL VALUE IN THE MEMORY LOCATION SPECIFIED
STOP
53
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
PROGRAM TABLE
DEPT OF ECE
PROGRAM
MOV AL,00OUT 0C8H,ALMOV AL,08OUT 0C8H,ALMOV AL,01OUT 0D0H,ALMOV AL,00MOV AL,00MOV AL,00MOV AL,00OUT 0D0H,ALL1 : IN AL, 0D8HAND AL,01CMP AL,01JNZ L1
IN AL,0C0HMOV BX,1100MOV [BX],ALHLTRESULT:
ANALOGVOLTAGE
COMMENTS
Load accumulator with value for ALE highSend through output portLoad accumulator with value for ALE lowSend through output portStore the value to make SOC high in the accumulatorSend through output port
Introduce delay
Store the value to make SOC low the accumulatorSend through output port
Read the EOC signal from port & check for end ofconversion
If the conversion is not yet completed, read EOC signalfrom port againRead data from portInitialize the memory location to store dataStore the dataStop
DIGITAL DATA ON LEDDISPLAY
HEX CODE IN MEMORYLOCATION
Thus the ADC was interfaced with 8086 and the given analog inputs were converted into itsdigital equivalent.
54
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
INTERFACING DIGITAL – TO – ANALOG CONVERTERAIM : 1. To write an assembly language program for digital to analog conversion 2. To convert digital inputs into analog outputs & To generate different waveformsAPPARATUS REQUIRED: SL.NOSPECIFICATIONQUANTITYITEM 1.8086 Vi Microsystems1Microprocessor kit 2.+5 V, dc,+12 V dc1Power Supply 3.-1DAC Interface boardPROBLEM STATEMENT: The program is executed for various digital values and equivalent analog voltages aremeasured and also the waveforms are measured at the output ports using CRO.THEORY: Since DAC 0800 is an 8 bit DAC and the output voltage variation is between –5vand +5v. The output voltage varies in steps of 10/256 = 0.04 (approximately). The digital datainput and the corresponding output voltages are presented in the table. The basic idea behindthe generation of waveforms is the continuous generation of analog output of DAC. With 00(Hex) as input to DAC2 the analog output is –5v. Similarly with FF H as input, the output is+5v. Outputting digital data 00 and FF at regular intervals, to DAC2, results in a square waveof amplitude 5v.Output digital data from 00 to FF in constant steps of 01 to DAC2. Repeatthis sequence again and again. As a result a saw-tooth wave will be generated at DAC2output. Output digital data from 00 to FF in constant steps of 01 to DAC2. Output digital datafrom FF to 00 in constant steps of 01 to DAC2. Repeat this sequence again and again. As aresult a triangular wave will be generated at DAC2 output.ALGORITHM: Measurement of analog voltage: (i)Send the digital value of DAC. (ii)Read the corresponding analog value of its output. Waveform generation: Square Waveform: (i)Send low value (00) to the DAC. (ii)Introduce suitable delay. (iii) Send high value to DAC. (iv)Introduce delay. (v)Repeat the above procedure. Saw-tooth waveform: (i)Load low value (00) to accumulator. (ii)Send this value to DAC. (iii) Increment the accumulator. (iv)Repeat step (ii) and (iii) until accumulator value reaches FF. (v)Repeat the above procedure from step 1. Triangular waveform: (i)Load the low value (00) in accumulator. (ii)Send this accumulator content to DAC. (iii) Increment the accumulator. (iv)Repeat step 2 and 3 until the accumulator reaches FF, decrement the accumulator and send the accumulator contents to DAC. (v)Decrementing and sending the accumulator contents to DAC. (vi)The above procedure is repeated from step (i)
55
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
FLOWCHART:MEASUREMENT OF ANALOG VOLTAGE
START
DEPT OF ECE
SQUARE WAVE FORMSTART
INTIALISE THEACCUMULATOR SEND ACC CONTENT TO DAC
DELAY
LOAD THE ACC WITH MAXVALUE SEND ACC CONTENT TO DAC
DELAY
SEND THEDIGITALVALUE TO ACCUMULATOR
TRANSFER THE ACCUMULATORCONTENTS TO DAC
READ THE CORRESPONDING ANALOG VALUE
STOP
SAWTOOTH WAVEFORMSTART
TRIANGULAR WAVEFORMSTART
INITIALIZEACCUMULATOR
SEND ACCUMULATOR CONTENT TO DAC
INCREMENTACCUMULATOR CONTENT
YESIS ACC FF
NOYES
DECREMENTACCUMULATOR CONTENT
INITIALIZEACCUMULATOR
SEND ACCUMULATOR
CONTENT TO DAC
INCREMENTACCUMULATOR CONTENT
NOIS ACC FF
SENDACCUMULATORCONTENT TO DAC
IS ACC 00YES NO
56
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
MEASUREMENT OF ANALOG VOLTAGE:
PROGRAM
MOV AL,7FHOUT C0,ALHLT
COMMENTS
DEPT OF ECE
Load digital value 00 in accumulatorSend through output portStop
DIGITAL DATA ANALOG VOLTAGE
PROGRAM TABLE: Square Wave
PROGRAM
L2 : MOV AL,00HOUT C0,ALCALL L1MOV AL,FFHOUT C0,ALCALL L1JMP L2L1 : MOV CX,05FFHL3 : LOOP L3RET
COMMENTS
Load 00 in accumulatorSend through output portGive a delayLoad FF in accumulatorSend through output portGive a delayGo to starting locationLoad count value in CX registerDecrement until it reaches zeroReturn to main program
PROGRAM TABLE: Saw tooth Wave
PROGRAM
L2 : MOV AL,00HL1 : OUT C0,ALINC ALJNZ L1JMP L2
COMMENTS
Load 00 in accumulatorSend through output portIncrement contents of accumulatorSend through output port until it reaches FFGo to starting location
57
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PROGRAM TABLE: Triangular Wave
PROGRAM
L3 : MOV AL,00HL1 : OUT C0,ALINC ALJNZ L1MOV AL,0FFHL2 : OUT C0,ALDEC ALJNZ L2JMP L3
COMMENTS
Load 00 in accumulatorSend through output portIncrement contents of accumulatorSend through output port until it reaches FFLoad FF in accumulatorSend through output portDecrement contents of accumulatorSend through output port until it reaches 00Go to starting location
RESULT:WAVEFORM GENERATION:
WAVEFORMS AMPLITUDE TIMEPERIOD
Square WaveformSaw-tooth waveform
Triangular waveform
MODEL GRAPH:
Square Waveform Saw-tooth waveform
Triangular waveform
Thus the DAC was interfaced with 8085 and different waveforms have been generated.
58
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
BASIC ARITHMETIC AND LOGICAL OPERATIONS
EXPT NO:14
8 BIT ADDITIONAIM:
DATE:
To write a program to add two 8-bit numbers using 8051 microcontroller.
ALGORITHM:
1. Clear Program Status Word.2. Select Register bank by giving proper values to RS1 & RS0 of PSW.3. Load accumulator A with any desired 8-bit data.4. Load the register R 0 with the second 8- bit data.5. Add these two 8-bit numbers.6. Store the result.7. Stop the program.
FLOW CHART:
START
Clear PSW
Select RegisterBank
Load A and R 0with 8- bit datas
Add A & R 0
Store the sum
STOP
59
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
8 Bit Addition (Immediate Addressing)ADDRESS LABEL MNEMONIC OPERAND
4100
4101
4103
4105
4108
4109 L1
CLR
MOV
ADDC
MOV
MOVX
SJMP
C
A, data1
A, # data 2
DPTR, #4500H@ DPTR, A
L1
DEPT OF ECE
HEXCODEC3
74,data1
24,data2
90,45,00
F0
80,FE
COMMENTS
Clear CY Flag
Get the data1 inAccumulatorAdd the data1 withdata2Initialize the memorylocationStore the result inmemory locationStop the program
RESULT:
OUTPUTMEMORY LOCATION
4500
DATA
Thus the 8051 ALP for addition of two 8 bit numbers is executed.
60
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
8 BIT SUBTRACTIONAIM: To perform subtraction of two 8 bit data and store the result in memory.
ALGORITHM: a. Clear the carry flag. b. Initialize the register for borrow. c. Get the first operand into the accumulator. d. Subtract the second operand from the accumulator. e. If a borrow results increment the carry register. f. Store the result in memory.
FLOWCHART:START
DEPT OF ECE
CLEAR CARRYFLAG
GET I’STOPERAND INACCR
SUBTRACT THE2’ND OPERANDFROM ACCR
NIS CF=1
Y
INCREMENTTHE BORROWREGISTER
STORERESULT INMEMORY
STOP
61
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
8 Bit Subtraction (Immediate Addressing)ADDRESS LABELMNEMONIC OPERAND
4100
4101
4103
4105
4108
4109 L1
CLR
MOV
SUBB
MOV
MOVX
SJMP
C
A, # data1
A, # data2
DPTR, # 4500
@ DPTR, A
L1
DEPT OF ECE
HEXCODEC3
74, data1
94,data2
90,45,00
F0
80,FE
COMMENTS
Clear CY flag
Store data1 inaccumulatorSubtract data2 fromdata1Initialize memorylocationStore the differencein memory locationStop
RESULT:
OUTPUTMEMORY LOCATION
4500
DATA
Thus the 8051 ALP for subtraction of two 8 bit numbers is executed.
62
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
8 BIT MULTIPLICATION
DEPT OF ECE
AIM: To perform multiplication of two 8 bit data and store the result in memory.
ALGORITHM: a. Get the multiplier in the accumulator. b. Get the multiplicand in the B register. c. Multiply A with B. d. Store the product in memory.
FLOWCHART:
START
GETMULTIPLIERIN ACCR
GETMULTIPLICANDIN B REG
MULTIPLY AWITH B
STORERESULT INMEMORY
STOP
63
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
8 Bit MultiplicationADDRESS LABEL
4100
4102
4104
4106
4109
401A
410B
410D
410E STOP
DEPT OF ECE
MNEMONIC
MOV
MOV
MUL
MOV
MOVX
INC
MOV
MOV
SJMP
OPERAND
A ,#data1
B, #data2
A,B
DPTR, #4500H@ DPTR, A
DPTR
A,B
@ DPTR, A
STOP
HEXCODE74, data1
75,data2
F5,F0
90,45,00
F0
A3
E5,F0
F0
80,FE
COMMENTS
Store data1 inaccumulatorStore data2 in B reg
Multiply both
Initialize memorylocationStore lower orderresultGo to next memorylocation
Store higher orderresult
Stop
RESULT:
INPUTMEMORY LOCATION
4500
4501
DATA OUTPUTMEMORY LOCATION
4502
4503
DATA
Thus the 8051 ALP for multiplication of two 8 bit numbers is executed.
64
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
8 BIT DIVISION
AIM: To perform division of two 8 bit data and store the result in memory.
ALGORITHM: 1. Get the Dividend in the accumulator. 2. Get the Divisor in the B register. 3. Divide A by B. 4. Store the Quotient and Remainder in memory.
FLOWCHART:
START
DEPT OF ECE
GET DIVIDENDIN ACCR
GET DIVISOR INB REG
DIVIDE A BY B
STOREQUOTIENT &REMAINDERIN MEMORY
STOP
65
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
8 Bit DivisionADDRESS LABEL MNEMONIC
4100
4102
4104
4015
4018
4109
410A
410C
410D STOP
MOV
MOV
DIV
MOV
MOVX
INC
MOV
MOV
SJMP
DEPT OF ECE
OPERAND
A, # data1
B, # data2
A,B
DPTR, # 4500H
@ DPTR, A
DPTR
A,B
@ DPTR, A
STOP
HEXCODE74,data1
75,data2
84
90,45,00
F0
A3
E5,F0
COMMENTS
Store data1 inaccumulatorStore data2 in B reg
Divide
Initialize memorylocationStore remainder
Go to next memorylocation
Store quotientF0
80,FE Stop
RESULT:
INPUTMEMORY LOCATION4500(dividend)
4501 (divisor)
OUTPUTMEMORY LOCATION4502(remainder)
4503 (quotient)
DATA DATA
Thus the 8051 ALP for division of two 8 bit numbers is executed.
66
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
LOGICAL AND BIT MANIPULATIONAIM:
DEPT OF ECE
To write an ALP to perform logical and bit manipulation operations using 8051microcontroller.
APPARATUS REQUIRED: 8051 microcontroller kit
ALGORITHM:
1.2.3.4.5.6.7.8.
Initialize content of accumulator as FFHSet carry flag (cy = 1).AND bit 7 of accumulator with cy and store PSW format.OR bit 6 of PSW and store the PSW format.Set bit 5 of SCON.Clear bit 1 of SCON.Move SCON.1 to carry register.Stop the execution of program.
FLOWCHART:
START
Set CY flag, AND CY with MSB ofACC
Store the PSW format, OR CY with bit 2 IE reg
Clear bit 6 of PSW, Store PSW
Set bit 5 of SCON , clear bit 1 and storeSCON
Move bit 1 of SCON to CY and store PSW
STOP
67
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
PROGRAM TABLE
ADDRESS HEX CODE410090,45,00
4103
4105
4016
4018410A
410B
410C
410E
41104112
4113
41144116
4118411A
411B
411C
411E
4120
4122
74,FF
D3
82,EF
E5,D0F0
A3
72,AA
C2,D6
E5,D0F0
A3
D2,90C2,99
E5,98F0
A3
A2,99
E5,D0
F0
80,FE L2
LABEL MNEMONICS
MOV
MOV
SETB
ANL
MOVMOVX
INC
ORL
CLR
MOVMOVX
INC
SETBCLR
MOVMOVX
INC
MOV
MOV
MOVX
SJMP
OPERAND
DPTR,#4500
A,#FF
C
C, ACC.7
A,DOH@DPTR,A
DPTR
C, IE.2
PSW.6
A,DOH@DPTR,A
DPTR
SCON.5SCON.1
A,98H@DPTR,A
DPTR
C,SCON.1
A,DOH
DEPT OF ECE
COMMENT
InitializememorylocationGet the data inaccumulatorSet CY bit
Perform AND with 7thbit of accumulator
Store the result
Go to next location
OR CY bit with 2nd bitif IE regClear 6th bit of PSW
Store the result
Go to next location
Set 5th of SCON regClear 1st bit of SCONreg
Store the result
Go to next location
Copy 1st bit of SCONreg to CY flag
Store the result@DPTR,A
L2 Stop
68
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
RESULT:
DEPT OF ECE
MEMORYLOCATION
4500H (PSW)
SPECIAL FUNCTION REGISTER FORMAT
CY AC FO RS1 RS0 OV - P
BEFORE
00H
AFTER
88HEXECUTION EXECUTION
4501H (PSW) CY AC FO RS1 RS0 OV - P 40H 88H
4502H (SCON) SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH 20H
4503H (PSW) CY AC FO RS1 RS0 OV - P FFH 09H
Thus the bit manipulation operation is done in 8051 microcontroller.
69
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
Square and Cube program, Find 2’s complement of a number
EXPT NO: 15
AIM:
DATE:
To convert Square and Cube program, Find 2’s complement of a number using 8051micro controller
RESOURCES REQUIERED: 8051 microcontroller kit Keyboard Power supply
PROGRAM:org 0000h; sets the program counter to 0000hmov a,#n;assign value 'n' in decimal to A which is converted to it'sequivalent hexadecimal valuemov b,#n;assign value 'n' in decimal to B which is converted to it'sequivalent hexadecimal valuemov r0,#n;assign value 'n' in decimal to R0 which is converted to it'sequivalent hexadecimal valuemul ab; multiplying 'A' with 'B'mov 40h,a; lower byte is stored in address 40hmov 41h,b; higher byte is stored in address 41hmov r1,a; move value of 'A' to R1mov a,b; move value of 'B' to 'A'mov b,r0; move value of R0 to bmul ab; multiply 'A' and 'B'mov b,a; lower byte obtained is moved from 'A' to 'B'mov r2,b; move value of 'B' to R2mov a,r1; move value of R1 to 'A'mov b,r0; move value of R0 to 'B'mul ab; multiplying 'A' and 'B'mov 50h,a; Lower byte obtained is stored in address 50h
70
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
mov r3,b; higher byte obtained is stored in R3mov a,r2; move value from R2 to 'A'add a,r3; add value of 'A' with R3 and store the value in 'A'mov b,a; move value from 'A' to 'B'mov 51h,b; store value obtained in address 51hend
SQUARE PGM USING 8051ORG 00h02LJMP MAIN
03 DELAY:04 ;MOV R0,#2
05 MOV TMOD, #01H06 MOV TH0, #HIGH (-50000)
07 MOV TL0, #LOW (-50000)08 SETB TR0
09 JNB TF0,10 CLR TF0
12 ;DJNZ R0,DELAY13 RET14 MAIN:
15 MOV DPTR,#300H16 MOV A,#0FFH
17 MOV P1,A18 BACK:
19 LCALL DELAY20 MOV A,P1
21 MOVC A,@A+DPTR22 ;MOV P2,#00H
23 ;LCALL DELAY24 MOV P2,A
25 SJMP BACK26 ORG 300H
27 XSQR_TABLE:28 DB 0,1,4,9,16,25,36,49,64,81
29 END Thus the Square and Cube program, Find 2’s complement of a number is done in8051 microcontroller
71
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
Unpacked BCD to ASCII
EXPT NO:16
AIM:To convert BCD number into ASCII by using 8051 micro controller
DATE:
RESOURCES REQUIERED: 8051 microcontroller kit Keyboard Power supply
72
EC6513 – MICROPROCESSOR AND MICROCONTROLLER LAB
FLOWCHART:
DEPT OF ECE
RESULT: The given number is converted into ASCII using 8051 microcontroller kit.
73