Top Banner
III B.Tech ECE-II Sem MRITS MICROPROCESSOR AND MICROCONTROLLERS LAB
47
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: MPMCECE(1)

III B.Tech ECE-II Sem

MRITSMICROPROCESSOR AND MICROCONTROLLERS LAB

Page 2: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

M R I T S Page 39

Page 3: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

M R I T S Page 39

Page 4: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

INDEX

1. Study of MASM…………………………………………………………….4

2. 16-bit Arithmetic Operations……………………………………………..10

3. Sorting of Array for 8086………………………………………………....12

4. Sting Manipulations for 8086…………………………………………….14

5. Searching for Character in a String……………………………………..18

6. Parallel Communication between Two Microprocessors using 8255….19

7. Digital Clock Design using 8086………………………………………….21

8. Interfacing DAC to 8086………………………………………………….23

9. Arithmetic, Logical and Bit Manipulation Instructions of 8051…….....25

10. Interfacing LCD to 8051………………………………………………...29

11. Interfacing Matrix keyboard to 8051…………………………………..32

12. UART Operation in 8051………………………………………………..35

13. Timer/Counters in 8051…………………………………………………36

14. Interrupt Handling in 8051……………………………………………...37

M R I T S Page 39

Page 5: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO.1 STUDY OF MASM

Introduction:The aim of this experiment is to introduce the student to assembly language programming and the use of the tools that he will need throughout the lab experiments. This first experiment let the student use the Microsoft Macro Assembler (MASM). Editing, Assembling, Linking, Execute up can be done using MASM software

Objectives:1. Introduction to Microsoft Macro Assembler (MASM)2. General structure of an assembly language program3. Use of the Dos Debugger program

Overview:In general, programming of microprocessor usually takes several iterations before the right sequence of machine code instruction is written. The process, however is facilitated using a special program called an “Assembler”. The Assembler allows the user to write alphanumeric instructions. The Assembler, in turn, generates the desired machine instructions from the assembly language instructions. Assembly language programming consists of following steps:

STEP PRODUCES1 Editing Source file2 Assembling Object file3 Linking Executable file4 Executing Results4Assembling the program:The assembler is used to convert the assembly language instructions tomachine code. It is used immediately after writing the Assembly language program. The assembler starts by checking the syntax or validity of the structure of each instruction in the source file .if any errors are found, the assemblers displays a report on these errors along with brief explanation oftheir nature. However If the program does contain any errors ,the assemblerproduces an object file that has the same name as the original file but with the “.obj” extensionLinking the program:The Linker is used convert the object file to an executable file. The executablefile is the final set of machine code instructions that can directly be executed by the microprocessor. It is the different than the object file in the sense that it is self-contained and re-locatable. An object file may represent one segment of a long program. This segment can not operate by itself, and must be integrated with other object files representing the rest of the program, in order to produce the final self-contained executable file In addition to the executable file; the linker can also generate a special file called the “map” file this file contains information about the start, end, length of thestack, code, and data segments it also lists the entry point of the program.Executing the program:

M R I T S Page 39

Page 6: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

The executable contains the machine language code .it can be loaded in the RAM and executed by the microprocessor simply by typing ,from the DOS prompt ,the name of the file followed by the carriage Return Key (Enter Key). If the program produces an output on the screen or sequence of control signals to control a piece of hard ware, the effect should be noticed almostimmediately How ever, if the program manipulates data in memory, nothing would seem to have happened as a result of executing the program.

Debugging the programThe debugger can also be used to find logical errors in the program. Even if a program does not contain syntax errors it may not produce the desired results after execution. Logical errors may be found by tracing the action of the program. once found, the source file should be rewrite to fix the problem, then the re-assembled and re-linked. A special program called the debugger is designed for that purpose.The debugger allows the user to trace the action of the program, by single stepping through the program or executing the program up to a desired point, called break point. It also allows the user to inspect or change the contents of the microprocessor internal registers or the contents of any memory location.The DOS -Debugger:The DOS “Debug” program is an example of simple debugger that comes with MS-DOS.Hence it is available on any PC .it was initially designed to give the user the capability totrace logical errors in executable file. It allows the user to take an existing executablefile and unassembled it, i.e convert it to assembly language. Also, it allows the user towrite assembly language instructions directly, and then convert them to machinelanguage. The program is simple and easy to use. But offers limited capabilities, whichmake it unsuitable for serious assembly language programming.Below, are summarized the basic DOS - Debugger commands

COMMAND SYNTAXAssemble A [address]Compare C range addressDump D [range]Enter E address[list]Fill F range listGo G [=address] [addresses]Hex H value1 value2Input I portLoad L[address] [drive][firstsector][number]Move M range addressName N[pathname][argument list]Output O port byteProceed P[=address][number]Quit QRegister R[register]Search S range listTrace T[=address][value]Unassembled u[range]Write W[address}[drive][firstsector][number]

M R I T S Page 39

Page 7: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

MS-MASM:

Microsoft’s Macro Assembler (MASM) is an integrated software package Written by Microsoft Corporation for professional software developers. it consists of an editor, an assembler, a linker and a debugger(Code View). The programmer’s workbench combines these four parts into a user-friendly programming environment with built in on line help. The following are the steps used if you are to run MASM from DOS

The following are the steps used if you are to run MASM from DOS

COMMAND FILE NAME1 Edit, any editor will do Name.asm2 Masm Filename Name.obj3 Filename

A.1 The Assembly Language Process Using the Command line

The following section explains how to assemble and link a file using the command line from a DOS window. The steps are:

1. Create or edit the source code (.asm file) using any ASCII text editor. Warning --the file must be saved in an ASCII format - some editors like 'winword', or 'word'store the file by default in a binary format. To save as an ASCII format in some ofthe Microsoft editors, select output type as *.TXT but specify the full file name as

myfile.asm (the .asm extension should be used for assembly language files).

2. Invoke the masm program to assemble the file and produce a .obj file andoptionally, a .lst file.

3. Invoke the link program to produce a .exe program (or a .com program via acommand line argument).Assume we have an assembly language file called test.asm that has been saved inASCII format.Open a DOS window. To assemble the file, change to the directory where the fileis via the 'cd'command, and type:

C:\> masm testIf assembly is successful, this will produce a file called test.obj. If errors are present, youwill be given the line numbers where the syntax errors occurred. You can also produce alisting file (.lst) which shows opcodes for all instructions via:

C:\> masm test,test, test

M R I T S Page 39

Page 8: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

It is a good idea to always create a .lst file output. A .exe file must be created from the.obj file via the link program. Type:

C:\> link test

You will be prompted for file names for the Run file, List file, libraries, and Definitionsfile. Just hitting <enter> for each choice will use the defaults. This will produce a test.exefile which can then be executed. You can also produce the .exe file with no promptingfrom the link program via:

C:\> link test,,,,,Use 5 commas after filename (test) to provide defaults for all other choices.Using the command line for masm/link is probably the easiest thing to do if you are onlyassembling/linking one source file. Most of your labs will only consist of one source file.

M R I T S Page 39

Page 9: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

MICROPROCESSOR LAB EXECUTION PROCEDURE

STEP1: opening the DOS promptClick start menu button and click on Run and then typeCmd at command prompt immediately DOS window will beappeared

STEP2: checking the masm installationTo know MASAM is installed or not simply type masm at the commandprompt Upon that it replies masm version vendor (Microsoft), etc... If u getany error there is know masm in that PC

STEP3: directory changing (create a folder with your branch and no in D drive)Change the current directory to your won directory suppose your folder in Ddrive type the following commands to change the directory at commandprompt type D: hit enter now your in D drive type cd folder name hit theenter

Ex. D cd ece10Now we are in folder cse10

STEP4: writing the programAt the command prompt type the edit programname.asm

Ex. Edit add.asmImmediately editor window will be opened here you have to writ theprogram Type the program in that window after completion save theprogram, to save the programGo to file opt in the menu bar and select save opt now your code is ready toassemble

STEP5: assembling, linking and executing the programGo to file opt click exit opt now DOS prompt will be displayed to assemblethe program type the following commands at the DOS promptmasm program name, program name, program name hit the enter

Ex. Masm add,add,add enter

If there are any errors in the program assembler reports all of them at thecommand prompt with line no’s, if there are now bugs your ready to link theprogram. To link the program type the following line at command promptLink programname,,,,, (5 commas)

Ex. Link add,,,,,

After linking your ready to execute the program to execute the program typethe following command

Debug programname.exe hit the enter

M R I T S Page 39

Page 10: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

Ex. Debug add.exe

Now you entered into the execution part of the program here you have to execute the program instruction by instruction (debugging) first of all press the r key(register) hit the enter key it’ll displays all the registers and their initial values in HEXDECIMAL note down the values of all the register which are used in the program. To execute the next instruction press t key (TRACE) hit the enter it’ll execute that instruction and displays the contents of all the register. You have to do this until you reach the last instruction of the program. After execution you have to observe the results (in memory or registers based on what you have written in the program).

STEP6: copying list file (common for all programs):

A list file contains your code starting address and end address along withyour programFor every program assembler generates a list file at your folder,programname.lst(ex. Add.lst) you should copy this to your lab observationOpening a list file

Edit programname.lstEx. Edit add.lst

M R I T S Page 39

Page 11: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO.2 16 BIT ARITHMETIC OPERATIONS

AIM: Write an ALP to 8086 to perform 16-bit arithmetic operations in various Addressing modes.

TOOLS: PC installed with MASM/TASM

PROGRAM:

.MODEL SMALL

.STACK 42HASSUME CS:CODE,DS:DATADATA SEGMENTOPR1 DW 4269HOPR2 DW 1000HADDRES DW ?SUBRES DW ?MULRESLW DW ?MULRESHW DW ?DIVQ DW ?DATA ENDSCODE SEGMENTSTART:

MOV AX,DATAMOV DS,AXMOV AX,4269H ;IMMEDIATE ADDRESSING MODEADD AX,OPR2 ;DIRECT ADDRESSING MODEMOV ADDRES,AXMOV BX,OFFSET OPR1MOV AX,[BX] ;REGISTER BASE ADDRESING MODESUB AX,OPR2MOV SUBRES,AXMOV AX,OPR1MOV BX,OPR2 ;MUL BX ; REGISTER ADDRESIING MODEMOV MULRESLW,AX ;DIRECT ADDRESSING MODEMOV MULRESHW,DX ;DIRECT ADDRESSING MODEMOV SI, OFFSET DIVQ ; INDEXED ADDRESSING MODEMOV AX,OPR1MOV BX,OPR2DIV BXMOV [SI], AXMOV[SI+2],DX MOV AH,4CHINT 21H

M R I T S Page 39

Page 12: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

CODE ENDSEND START

END

OBSERVATIONS:Before execution: ADDRES DATA ADDRES DATADS:0000= ES:0000=DS:0001= ES:0001=DS:0002= ES:0002=DS:0003= ES:0004=ES:0005=ES:0006=ES:0007=ES:0008=After execution: ADDRES DATA ADDRES DATADS:0000= ES:0000=DS:0001= ES:0001=DS:0002= ES:0002=DS:0003= ES:0003=ES:0004=ES:0005=ES:0006=ES:0007=Calculations:UNSIGNED NUMBERSINPUT: OPR1 = 4269HOPR2 = 1000HOUTPUT: ALL RESULTS ARE STORED IN EXTRA SEGMENT(ES)ADDRES = 5269HSUBRES=3269HMULRESLW=9000HMULRESHW=0426HDIVQ=4HDIVR=269H

List file:Result:

M R I T S Page 39

Page 13: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO.3 SORTING AN ARRAY FOR 8086

AIM: Write and execute an ALP to 8086 processor to sort the given 16-bit numbers in ascending and descending order.TOOLS:PC installed with masm 6.11Program:

ASCENDING ORDER

.MODEL SMALL

.STACK 45HASSUME CS:CODE,DS:DATADATA SEGMENTLIST DW 0125H,0144H,3001H,0003H,0002HCOUNT EQU 05HDATA ENDSCODE SEGMENTSTART:MOV AX,DATAMOV DS,AXMOV DX,COUNT-1BACK:MOV CX,DXMOV SI,OFFSET LISTAGAIN:MOV AX,[SI]CMP AX,[SI+2]JC GOXCHG AX,[SI+2]XCHG AX,[SI]GO:INC SIINC SILOOP AGAINDEC DXJNZ BACKINT 03HCODE ENDSEND STARTEND

OBERSVATIONS:USE GO COMMAND TO EXECUTE (EX.G 0000:0018)INPUT: LIST(DS: 0000H) = 25H,01H,44H,01H,01H,30H,03H,00H,02H,00H

OUTPUT: LIST(DS: 0000H) = 02H,00H,03H,00H,25H,01H,44H,01H,01H,30H

M R I T S Page 39

Page 14: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

DESCENDING ORDER

.MODEL SMALL

.STACK 45HASSUME CS:CODE,DS:DATADATA SEGMENTLIST DW 0125H,0144H,3001H,0003H,0002HCOUNT EQU 05HDATA ENDSCODE SEGMENTSTART:MOV AX,DATAMOV DS,AXMOV DX,COUNT-1BACK:MOV CX,DXMOV SI,OFFSET LISTAGAIN:MOV AX,[SI]CMP AX,[SI+2]JNC GOXCHG AX,[SI+2]XCHG AX,[SI]GO:INC SIINC SILOOP AGAINDEC DXJNZ BACKINT 03HCODE ENDSEND STARTENDOBERSVATIONS:USE GO COMMAND TO EXECUTE (EX.G 0000:0018)INPUT: LIST(DS: 0000H) = 25H,01H,44H,01H,01H,30H,03H,00H,02H,00HOUTPUT: LIST(DS: 0000H) = 01H,30H,44H,01H,25H,01H,03H,01H,00H,02H

LIST FILE:

RESULT:

M R I T S Page 39

Page 15: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO.4 SRTING MANIPULATIONS FOR 8086

A)MOVE BLOCK

AIM: To write an assembly language program to move the block of data from a source BLOCK to the specified destination BLOCK.

TOOLS: PC installed with MASM 6.11PROGRAM:

.MODEL SMALL

.STACK 45HASSUME CS:CODE,DS:DATADATA SEGMENTSTRING DB 04H,0F9H,0BCH,98H,40HCOUNT EQU 05HDATA ENDSEXTRA SEGMENTORG 0010HSTRING1 DB 5 DUP(?)EXTRA ENDSCODE SEGMENTSTART:MOV AX,DATAMOV DS,AXMOV AX,DATAMOV ES,AXMOV SI,OFFSET STRINGMOV DI,OFFSET STRING1MOV CL,COUNTCLDREP MOVSBINT 03HCODE ENDSEND STARTEND

OBSERVATIONS::INPUT: STR (DS:0000H) = 04H,F9H,BCH,98H,40HOUTPUT: STR1 (DS:0010H) = 04H,F9H,BCH,98H,40HLIST FILE:

RESULT:

M R I T S Page 39

Page 16: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

B) REVERSE STRING

AIM: To write an assembly language program to reverse the given string.

TOOLS: PC installed with MASM 6.11

PROGRAM:

.MODEL SMALL

.STACK 48HASSUME CS:CODE,DS:DATADATA SEGMENTSTR DB 01H,02H,03H,04HCOUNT EQU 02HDATA ENDSCODE SEGMENTSTART:MOV AX,DATAMOV DS,AXMOV CL,COUNTMOV SI,OFFSET STRMOV DI,0003HBACK:MOV AL,[SI]XCHG [DI],ALMOV [SI],ALINC SIDEC DIDEC CLJNZ BACKINT 03HCODE ENDSEND STARTEND

OBSERVATIONS::INPUT: STR (DS:0000H) = 01H,02H,03H,04HOUTPUT: STR (DS:0000H) = 04H,03H,02H,01H

LIST FILE:

RESULT:

M R I T S Page 39

Page 17: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

C)LENGTH OF THE STRING

AIM: To write an assembly language program to find the length of the given string.

TOOLS: PC installed with MASM 6.11

PROGRAM:

.MODE SMALL

.STACK 45HASSUME CS:CODE,DS:DATADATA SEGMENTSTR DB 01H,03H,08H,09H,05H,07H,02HLENGTH DB ?DATA ENDSCODE SEGMENTSTART:MOV AX,DATAMOV DS,AXMOV AL,00HMOV CL,00HMOV SI,OFFSET STRBACK:CMP AL,[SI]JNC GOINC CLINC SIJNZ BACKGO:MOV LENGTH,CLINT 03HCODE ENDSEND STARTEND

OBSERVATIONS::INPUT: STR (DS:0000H) = 01H, 03H,08H,09H,05H,07H,02HOUTPUT: LENGTH = 07H (CL)

LIST FILE:

RESULT:

D) STRING COMPARISON

AIM: Write an ALP to 8086 to compare the given strings.

TOOLS: PC installed with MASM 6.11

M R I T S Page 39

Page 18: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

Program:

.MODEL SMALL

.STACK 45HASSUME CS:CODE,DS:DATADATA SEGMENTSTRING DB 04H,05H,07H,08HCOUNT EQU 04HORG 0010HSTRING1 DB 04H,05H,07H,08HDATA ENDSCODE SEGMENTSTART:MOV AX,DATAMOV DS,AXMOV ES,AXMOV SI,OFFSET STRINGMOV DI,OFFSET STRING1MOV CL,COUNTCLDREP CMPSBINT 03HCODE ENDSEND STARTEND

OBSERVATIONS:

INPUT: STR (DS:0000H) = 04H,05H,07H,08HSTR1 (DS:0010H) = 04H,06H,07H,09H

OUTPUT: I ): IF STR = STR1 THEN ZF = 1 & II ): IF STR ≠ STR1 THEN ZF = 0

LISTFILE:

RESULT:

M R I T S Page 39

Page 19: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 5 SEARCH ING FOR CHARACTER IN A STRING

AIM: Write an ALP for searching for a number or character in a string for 8086.

TOOLS: PC installed with MASM 6.11

Program:.MODEL SMALL.STACK 42HASSUME CS:CODE,ES:EXTRAEXTRA SEGMENTSTRR DB "MRECW"COUNT EQU 05HEXTRA ENDSCODE SEGMENTSTART:MOV AX,EXTRAMOV ES,AXMOV DI,OFFSET STRR CLDMOV AL, 'R' MOV CX, COUNTREPNE SCASBJNZ LOOP1DEC DIMOV AH,ES:[DI] ; Displays the location of the searched data if found in the string JMP LOOP2 ;the memory location 2000H LOOP1:MOV AH,00H ;Displays 0000H at the memory location 2000H, if the LOOP2:INT 3CODE ENDSEND STARTEND

LISTFILE:

RESULT:

M R I T S Page 39

Page 20: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO:6 PARALLEL COMMUNICATION BETWEEN TWO MICROPROCESSORS

USING 8255

AIM: Write an ALP for parallel communication between two microprocessors using 8255

TOOLS: i)UXASM ii)TKUP

iii)TKUP86 KIT iv)FRC CABLE

PROGRAM:FOR DATA IN KIT

#INCLUDE "TKUP86.DEF" ORG 0FFFF0H

JMPF 0F000H,0F000HORG 0FF000H MOV AL,080HMOV DX,CMD8255OUT DX,ALMOV AL,00HMOV DX,PA8255OUT DX,ALMOV DX,PB8255OUT DX,ALMOV DX,PC8255OUT DX,AL

RPT: MOV AL,47HMOV DX,PA8255OUT DX,ALMOV DX,PB8255OUT DX,ALMOV DX,PC8255OUT DX,AL

` JMP RPT

M R I T S Page 39

Page 21: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

PROGRAM:FOR DATA OUT KIT

#INCLUDE "TKUP86.DEF ORG 0FFFF0H

JMPF 0F000H,0F000H

ORG 0FF000H MOV AL,090HMOV DX,CMD8255OUT DX,ALMOV AL,00HMOV DX,PA8255OUT DX,ALMOV DX,PB8255OUT DX,ALMOV DX,PC8255OUT DX,AL

RPT: MOV DX,PA8255IN AL,DXMOV [0200H],ALMOV DX,PB8255OUT DX,ALMOV DX,PC8255OUT DX,AL

` JMP RPT

LISTFILE:

RESULT:

M R I T S Page 39

Page 22: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 7 DIGITAL CLOCK DESIGN USING 8086

AIM: Write an ALP for digital clock design using 8086

TOOLS: i)UXASM ii)TKUP

iii)TKUP86 KIT iv)FRC CABLE

PROGRAM:

;CONNECT BH4(PORT A) TO CNLED

#INCLUDE "TKUP86.DEF"

;******* INCLUDE EXTERNS NOW;

;******* START CODING HERE; ORG 0FFFF0H

JMPF 0F000H,0F000H ; the basic reset jump

ORG 0FF000HSTART MOV SP,STKPTR ; load stack pointer

CALL INIT8255 ; initialize 8255MOV AL,0CHMOV [0200H],ALMOV AL,00H

NXTHR MOV CX,003CHNXTMNT MOV BX,003CHNXTSEC CALL SECDLY

MOV DX,PA8255MOV AL,07HOUT DX,ALDEC BXJNE NXTSECMOV DX,PA8255MOV AL,38HOUT DX,ALDEC CX

M R I T S Page 39

Page 23: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

JNE NXTMNTMOV DX,PA8255MOV AL,0C0HOUT DX,ALMOV AX,[0200H]DEC AXMOV [0200H],AXJNE NXTHR

SECDLY PUSH AXPUSH BXPUSH CXPUSH DXMOV CX,1234H

DLY NOPNOPLOOP DLYPOP DXPOP CXPOP BXPOP AXRET

;******* initialize 8255 INIT8255

MOV AL,080HMOV DX, CMD8255OUT DX,ALMOV AL,00HMOV DX,PA8255OUT DX,ALMOV DX,PB8255OUT DX,ALMOV DX,PC8255OUT DX,ALRET

LISTFILE:

RESULT:

M R I T S Page 39

Page 24: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 8 INTERFACING DAC TO 8086

AIM: Write an ALP for interfacing DAC to 8086

TOOLS: i)UXASM ii)TKUP

iii)TKUP86 KIT iv)FRC CABLE

v)DAC KIT

PROGRAM:;CONNECT BH4(PORT A) TO DAC BH1A;CONNECT BH5(PORTB) TO DAC BH2B;CONNECT CRO PROBES TO CND1_1 OF DAC

#INCLUDE "TKUP86.DEF"

ORG 0FFFF0HJMPF 0F000H,0F000HORG 0FF000H MOV AL,080HMOV DX,CMD8255OUT DX,ALMOV AL,00HMOV DX,PA8255OUT DX,ALMOV DX,PB8255OUT DX,ALMOV DX,PC8255OUT DX,AL

RPT: MOV AL,00HMOV AL,0FFH

AGAIN:MOV DX,PA8255OUT DX,ALCALL DELAYCALL DELAYCALL DELAYCALL DELAYCALL DELAYCALL DELAYINC AXJNE AGAIN

M R I T S Page 39

Page 25: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

JMP RPT

DELAY:MOV CX,0FF00HNXT2: MOV BX,1234HNXT: NOP

NOPNOPNOPNOPDEC BXJNE NXTRET

LISTFILE:

RESULT:

M R I T S Page 39

Page 26: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 9 ARITHMETIC, LOGICAL AND BIT MANIPULATION INSTRUCTIONS OF 8051

AIM: Write an ALP for Arithmetic, logical and bit manipulation operations in 8051

TOOLS: i) UXASM ii) TKUP

iii) TKUP86 KIT iv) FRC CABLE

A) PROGRAM: FOR ARITHMETIC INSTRUCTIONS OF 8051

#INCLUDE "TKUP52.DEF" ORG 0000H

START: LJMP MAIN ORG 0150H

MAIN MOV SP,#50HMOV R0,#20HMOV R1,#07HMOV A,R0ADD A,R1MOV P1,ALCALL DELAYMOV A,R0SUBB A,R1MOV P1,ALCALL DELAYMOV A,R0MOV 0F0H,R1

MUL ABMOV P1,ALCALL DELAYMOV P1,0F0HLCALL DELAYMOV A,R0MOV 0F0H,R1DIV ABMOV P1,ALCALL DELAYMOV P1,0F0HLCALL DELAYLJMP MAIN

M R I T S Page 39

Page 27: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

DELAYNOPMOV R4,#020H

DLY3 MOV R3,#0FFHDLY2 MOV R2,#0FFH

NOPDLY1 NOP

NOPNOPNOPDJNZ R2,DLY1DJNZ R3,DLY2DJNZ R4,DLY3RET ;

B)PROGRAM: FOR LOGICAL INSTRUCTIONS OF 8051

i) #INCLUDE "TKUP52.DEF"

ORG 0000HSTART: LJMP MAIN

ORG 0150HMAIN MOV SP,#50H

MOV A,#35HANL A,#0FHMOV P1,AACALL DLYMOV A,#04HORL A,#30HMOV P1,AACALL DLYMOV A,#54HXRL A,#78HMOV P1,AACALL DLYMOV A,#55HCPL AMOV P1,AACALL DLY

DLY NOPNOPMOV R4,#020H

DLY3 MOV R3,#0FFHDLY2 MOV R2,#0FFH

M R I T S Page 39

Page 28: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

NOPDLY1 NOP

NOPNOPNOPDJNZ R2,DLY1DJNZ R3,DLY2DJNZ R4,DLY3RET

ii)

#INCLUDE "TKUP52.DEF" ORG 0000HSTART: LJMP MAIN ORG 0150H MAIN: MOV SP,#060H

MOV A,#0A5HMOV P1,ALCALL SFTDLRR AMOV P1,ALCALL SFTDLSWAP AMOV P1,ALCALL SFTDLRL A MOV P1,ALCALL SFTDLSETB CRLC AMOV P1,ALCALL SFTDLRRC AMOV P1,ALCALL SFTDLLJMP MAIN

SFTDL MOV R4,#50HDL3 MOV R5,#0FFHDL2 MOV R6,#0FFHDL1 DJNZ R6,DL1

DJNZ R5,DL2DJNZ R4,DL3RET

M R I T S Page 39

Page 29: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

C)PROGRAM: FOR BIT MANIPULATION INSTRUCTIONS OF 8051

#INCLUDE "TKUP52.DEF" ORG 0000H

START: LJMP MAIN ORG 0150H

MAIN MOV SP,#50HMOV P1,#00HSETB 00HMOV C,00HMOV P1_7,CLCALL SFTDLCLR CANL C,00HMOV P1_7,CLCALL SFTDLCPL CMOV P1_7,CLCALL SFTDLORL C,00HMOV P1_7,CLCALL SFTDLLJMP MAIN

SFTDL MOV R4,#50HDL3 MOV R5,#0FFHDL2 MOV R6,#0FFHDL1 DJNZ R6,DL1

DJNZ R5,DL2DJNZ R4,DL3RET

LISTFILE:

RESULT:

M R I T S Page 39

Page 30: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 10 INTERFACING LCD TO 8051

AIM: Write an ALP for interfacing LCD to 8051

TOOLS: i)UXASM ii)TKUP

iii)TKUP86 KIT iv)FRC CABLE

PROGRAM:

;CONNECT BH4 TO CNLCDC;CONNECT BH6 TO CNLCDD

#INCLUDE "TKUP52.DEF"

ORG 0000HSTART: LJMP MAIN

ORG 0150HMAIN MOV SP,#060H LCALL INIT8255

LOOP MOV DPTR,#CMDTBLLCALL INIT_LCDMOV DPTR,#STRTBL

LP1 MOV A,#0MOVC A,@A+DPTRCJNE A,#00,LP2LCALL DELAYLCALL DELAYLCALL DELAYLJMP MAIN

LP2 LCALL WR_DATINC DPTRLCALL SDELAYLJMP LP1

;******* LCD init moduleINIT_LCD

MOV A,#0MOVC A,@A+DPTRCJNE A,#00,IL2RET

M R I T S Page 39

Page 31: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

IL2 LCALL WR_CMDINC DPTR

LJMP INIT_LCD

;******* LCD Write CMD moduleWR_CMD PUSH DPH

PUSH DPLMOV DPTR,#PB8255LCALL WRPORTLCALL SDELAYMOV A,#04MOV DPTR,#PA8255LCALL WRPORTLCALL SDELAYMOV A, #00MOV DPTR,#PA8255LCALL WRPORTLCALL SDELAY POP DPLPOP DPHRET

;******* LCD Write Data moduleWR_DAT PUSH DPH

PUSH DPLMOV DPTR,#PB8255LCALL WRPORTLCALL SDELAYMOV A,#05HMOV DPTR,#PA8255LCALL WRPORTLCALL SDELAYMOV A,#01HMOV DPTR,#PA8255LCALL WRPORTLCALL SDELAYPOP DPLPOP DPHRET

;****** Write PortWRPORT CLR P1_7

MOVX @DPTR,ASETB P1_7RET

M R I T S Page 39

Page 32: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

;****** Read PortRDPORT CLR P1_7

MOVX A,@DPTR SETB P1_7RET

;******* Delay moduleSDELAY NOP

MOV R0,#0FFHMOV R1,#01HLJMP DLY1NOP

DELAY NOPMOV R0,#0FFHMOV R1,#055HNOP

DLY1 DJNZ R0,DLY1MOV R0,#0FFHDJNZ R1,DLY1RET

;******* initialize 8255 INIT8255

MOV A,#080HMOV DPTR,#CMD8255LCALL WRPORTRET

ORG 0500H;******* initialize seven segment tableCMDTBL HEX 38,0E,02,01,00STRTBL ASCII "HELLO ADM - TKUP"ENDTBL HEX 00,00

LISTFILE:

RESULT:

M R I T S Page 39

Page 33: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 11 INTERFACING MATRIX/KEYBOARD TO 8051

AIM: Write an ALP for interfacing Matrix/keyboard to 8051

TOOLS: i) UXASM ii) TKUP

iii) TKUP86 KIT iv)FRC CABLE

PROGRAM:

;******* 8255_KBD

;******* INCLUDE DEFINATION FILES NOW; 1. Connect 8255 PA0-7 to CNMUX of L1C peripheral board; 2. Connect 8255 PC0-7 to CNKEY of L1C peripheral board; 3. Connect 8255 PB0-7 to CNSEG of L1C peripheral board; 4. Moitor one segment showing 0000->0001->....->000F->0000 (keypress)

#INCLUDE "TKUP52.DEF" ORG 0000HSTART: LJMP MAIN

ORG 0150HMAIN MOV SP,#060H

LCALL INIT8255MOV DPTR,#NUM1LCALL CLRMEMMOV DPTR,#NUM2LCALL CLRMEMMOV DPTR,#NUM3LCALL CLRMEMNOP

LOOP LCALL SCANKBDMOV DPTR,#NUM3MOVX A,@DPTRMOV DPTR,#SEGTBLMOVC A,@A+DPTRMOV DPTR,#PB8255LCALL WRPORTMOV A,#070HMOV DPTR,#PA8255LCALL WRPORTLJMP LOOP

M R I T S Page 39

Page 34: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

;******* MATRIX KBD SCAN module;******* Output either E0,D0,B0,70 for Row 1,2,3,4;******* Read PC port anded with 0x0F, expect 0F,0E,0D,0B,07

SCANKBD MOV A,#00HSKLOOP MOV DPTR,#NUM1

MOVX @DPTR,AMOV DPTR,#KBDTBLMOVC A,@A+DPTRCJNE A,#00,SKL1RET

SKL1 MOV DPTR,#PC8255LCALL WRPORTMOV DPTR,#PC8255LCALL RDPORTANL A,#0FHCJNE A,#0FH,SKL2MOV DPTR,#NUM1MOVX A,@DPTRINC ALJMP SKLOOP

SKL2 LJMP GETKEY

;******* GETKEY module

GETKEY MOV DPTR,#NUM2MOVX @DPTR,AMOV DPTR,#RETTBLMOVC A,@A+DPTRMOV R0,AMOV DPTR,#NUM1MOVX A,@DPTRMOV DPTR,#ROWTBLMOVC A,@A+DPTRADD A,R0MOV DPTR,#NUM3MOVX @DPTR,ARET

;****** Clear memory locationCLRMEM MOV A,#0

MOVX @DPTR,ARET

WRPORT CLR P1_7MOVX @DPTR,ASETB P1_7

M R I T S Page 39

Page 35: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

RET

;****** Read PortRDPORT CLR P1_7

MOVX A,@DPTR SETB P1_7RET

;******* Delay moduleSDELAY NOP

MOV R0,#0FFHMOV R1,#01HLJMP DLY1NOP

DELAY NOPMOV R0,#0FFH ; load lsb of delay=0x34FFMOV R1,#055H ; load msbNOP

DLY1 DJNZ R0,DLY1MOV R0,#0FFH ; decrement msb countDJNZ R1,DLY1RET ; end of delay

;******* initialize 8255 INIT8255

MOV A,#081H ; make all ports outputMOV DPTR,#CMD8255 ; write to command registerLCALL WRPORTRET

ORG 0500H;******* initialize seven segment tableSEGTBL HEX 3F,06,5B,4F,66,6D,7D,07,7F,6F,77,7C,39,5E,79,71,00KBDTBL HEX E0,D0,B0,70,00RETTBL HEX 00,00,00,00,00,00,00,03,00,00,00,02,00,01,00,00,00ROWTBL HEX 00,04,08,0C,00

LISTFILE:

RESULT:

M R I T S Page 39

Page 36: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 12 UART OPERATION IN 8051

AIM: To observe the UART operation in 8051

TOOLS: i) UXASM ii) TKUP

iii) TKUP86 KIT iv)FRC CABLE

PROGRAM:; CONNECT THE RS232 FROM PC TO TKUP51 KIT;CONNECT THE Tx PIN OF 8051 TO Rx OF MAX232 AND VICE VERSA;CONNECT PORT1 TO CNLED

#INCLUDE "TKUP52.DEF" ORG 0000HSTART: LJMP MAIN

ORG 0150HMAIN: MOV SP,#060H

MOV IE,#85H MOV TMOD,#20H MOV TH1,#0FAH MOV SCON,#50H SETB TCON6

RPT: MOV SBUF,#'Y'HERE: JNB SCON1,HERE

CLR SCON1 MOV A,#'A' MOV P1,A SJMP RPT

LISTFILE:

RESULT:

M R I T S Page 39

Page 37: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

EXPERIMENT NO: 1 3 TIMER/COUNTERS IN 8051

AIM: Write an ALP to verify timer/counter operation in 8051

TOOLS: i)UXASM ii)TKUP

iii)TKUP86 KIT iv)FRC CABLE

PROGRAM:#INCLUDE "TKUP52.DEF" ORG 0000HSTART: LJMP MAIN ORG 0150H MAIN: MOV SP,#060H MOV TMOD,#01HBACK: MOV TL0,#075H MOV TH0,#0B8H MOV P1,#0AAH

LCALL SFTDLACALL DELAY

MOV TL0,#00H MOV TH0,#00H MOV P1,#055H ACALL DELAY LCALL SFTDL

SJMP BACK ORG 300HDELAY: SETB TCON4AGAIN: JNB TCON5,AGAIN CLR TCON4 CLR TCON5 RET SFTDL MOV R4,#10HDL3 MOV R5,#0FFHDL2 MOV R6,#0FFHDL1 DJNZ R6,DL1

DJNZ R5,DL2DJNZ R4,DL3RET

M R I T S Page 39

Page 38: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

LISTFILE:RESULT:

EXPERIMENT NO: 14 INTERRUPT HANDLING IN 8051

AIM: Write an ALP to verify the interrupt handling in 8051

TOOLS: i)UXASM ii)TKUP

iii)TKUP86 KIT iv)FRC CABLEPROGRAM:

#INCLUDE "TKUP52.DEF" ORG 0000H

START: LJMP MAIN ORG 0150H

MAIN MOV SP,#50HMOV IE,#85H

HERE MOV P1,#7EHSJMP HEREORG 0003H ;INT0 ISRMOV P1,#0AAHLCALL DELAYLCALL DELAYLCALL DELAYRETIORG 0013H ;INT1 ISRMOV P1,#0A5HLCALL DELAYLCALL DELAYRETI

DELAY NOPMOV R4,#020H

DLY3 MOV R3,#0FFHDLY2 MOV R2,#0FFHDLY1 NOP

NOPDJNZ R2,DLY1DJNZ R3,DLY2DJNZ R4,DLY3RET

LISTFILE:

RESULT:

M R I T S Page 39

Page 39: MPMCECE(1)

MICROPROCESSOR AND MICROCONTROLLERS LAB

M R I T S Page 39