Your SlideShare is downloading. ×
Mp lab manual
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Mp lab manual

16,525

Published on

Published in: Education
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
16,525
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
931
Comments
0
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. MICROPROCESSORS AND MICROCONTROLLERS LABORATORY (ECE) MANUAL Prepared by S.Sreedhar Babu Assoc.prof[ece], (COURSE COORDINATOR) SCHOOL OF ELECTRICAL SCIENCES KONERU LAKSHMAIAH UNIVERSITY 2012-13.
  • 2. List of ExperimentsCycle - I: The following Programs/Experiments are to be written for the assembler Using TASM software.1. Programs on Data Transfer in forward and reverse direction using 8086.2. Programs on Arithmetic Instructions with 16-bit data using 8086.3. Programs on logical Instructions using 8086.4. Programs on String manipulation using 8086.5. Programs on Sorting and searching an array using 8086.6. Programs on Procedures and Macros for BCD to Binary conversion, factorial using 8086.7. Programs on Interrupts for using 8086.Cycle – II: Interfaced with 8051 using Machine language program and somePrograms/Experiments are to be written for the assembler using TOP VIEW SIMULATORsoftware for the interfacing.8. Programs on Arithmetic, Logic& Bit manipulation Instructions 8051.9. Interfacing 7-Segment Display 8051.10. LCD Interfacing to 8051.11. Interfacing of Binary Counters 8051.12. Interfacing Stepper Motor 8051.13. Interfacing A/D & D/A to 805114. Keyboard Interface 8051.15. Data Transfer between two PCs using RS.232 C Serial Port.Note: Minimum of 10 programs to be conducted.Lab Incharge HOD
  • 3. INTRODUCTIONEDITORAn editor is a program, which allows you to create a file containing the assembly language Statements foryour program. As you type in your program, the editor stores the ASCII codes for the letters and numbers insuccessive RAM locations. When you have typed in all of your programs, you then save the file on a floppyof hard disk. This file is called source file. The next step is to process the source file with an assembler. Inthe TASM assembler, you should give your source file name the extension, ASM.ASSEMBLERAn assembler program is used to translate the assembly language mnemonics for instructions to thecorresponding binary codes. When you run the assembler, it reads the source file of your Program the disk,where you saved it after editing on the first pass thro ugh the source program the assembler determines thedisplacement of named data items, the offset of labels and pails this information in a symbol table. On thesecond pass through the source program, the assembler produces the binary code for each instruction andinserts the offset etc that is calculated during the first pass. The assembler generates two files on floppy orhard disk. The first file called the object file is given the extension. OBJ. The object file contains the binarycodes for the instructions and information about the addresses of the instructions. The second file generatedby the assembler is called assembler list file. The list file contains your assembly language statements, thebinary codes for each instructions and the offset for each instruction. In TASM assembler, TASM source filename ASM is used to assemble the file. Edit source file name LST is used to view the list file, which isgenerated, when you assemble the file.LINKERA linker is a program used to join several object files into one large object file and convert to an exe file.The linker produces a link file, which contains the binary codes for all the combined modules. The linkerhowever doesn’t assign absolute addresses to the program, it assigns is said to be relocatable because it canbe put anywhere in memory to be run. In TASM, TLINK source filename is used to link the file.DEBUGGERA debugger is a program which allows you to load your object code program into system memory, executethe program and troubleshoot are debug it the debugger allows you to look at the contents of registers andmemory locations after your program runs. It allows you to change the contents of register and memorylocations after your program runs. It allows you to change the contents of register and memory locations andreturn the program. A debugger also allows you to set break point at any point in the program. If you inset abreakpoint the debugger will run the program upto the instruction where the breakpoint is set and stop
  • 4. execution. You can then examine register and memory contents to see whether the results are correct at thatpoint. In TASM, td filename is issued to debug the file.DEBUGGER FUNCTIONS1. Debugger allows to look at the contents of registers and memory locations.2. We can extend 8-bit register to 16-bit register which the help of extended register option.3. Debugger allows to set breakpoints at any point with the program.4. The debugger will run the program upto the instruction where the breakpoint is set and then stopexecution of program. At this point, we can examine registry and memory contents at that point.5. With the help of dump we can view register contents.6. We can trace the program step by step with the help of F7.7. We can execute the program completely at a time using F8.DEBUGGER COMMANDSASSEMBLE:To write assembly language program from the given address.A starting address <cr>Eg: a 1000H <cr>Starts program at an offset of 1000H.DUMP:To see the specified memory contentsD memory location first address last address(While displays the set of values stored in the specified range, which is given above)Eg: d 0100 0105 <cr>Display the contents of memory locations from 100 to 105(including).ENTER:To enter data into the specified memory locations(s).E memory location data data data data data …<cr>Eg: e 1200 10 20 30 40 ….Enters the above values starting from memory locations 1200 to 1203, by loading 10 into1200, 20 into 1201 and soon.GO:To execute the programG: one instruction executes (address specified by IP)G address <cr>: executes from current IP to the address specifiedG first address last addresses <cr>: executes a set of instructions specified between the given address.MOVE:Moves a set of data from source location to destination location
  • 5. M first address last address destination addressEg: m100 104 200Transfers block of data (from 100 to 104) to destination address 200.QUIT:To exit from the debugger.Q <cr>REGISTER:Shows the contents of RegistersR register nameEg: r axShows the contents of register.TRACE:To trace the program instruction by instruction.T = 0100 <cr>: traces only the current instruction. (Instruction specified by IP)T = 0100 02 <cr>: Traces instructions from 100 to 101, here the second argument spec ifies the number ofinstructions to be traced.UNASSEMBLE:To unassembled the program. Shows the opcodes along with the assembly language program.U 100 <cr>: unassembled 32 instructions starting from 100th location.U 0100 0109 <cr>: unassembles the lines from 100 to 104.
  • 6. Using Turbo – Assembler – Linker – Debugger(TASM, TLINK, TD)1. Open an MSDOS window.2. Set the PATH so that the TASM programs are available. The TASM programs are on the C drive; set thepath so that DOS can find them. This only needs to be done once each time you open an MSDOS prompt.set PATH=%PATH%; C:TASMBIN.3. Use a Text Editor to Edit the .ASM File.Create your file using one of the following programs:notepad proj.asmWordPad proj.asmedit proj.asm4. Compile the source code to create an object module.tasm/z/zi proj.asmThe /z switch causes TASM to display the lines that generate compilation errors. The /zi switch enablesinformation needed by the debugger to be included in the .OBJ file. Note that you should use "real mode"assembler, TASM.EXE. Do not use the "protected mode" assembler TASM32.EXE for the assignments thatwill be given in class5. Run Linke r TLINK.EXE- generate .EXE file from the .OBJ filetlink/v proj.6. Run the ProgramYour final program (if there were no errors in the previous step) will have an .EXE ending. To just run it,type:projIf you want to use the debugger to examine the instructions, registers, etc., type:td projThis brings up the regular full-screen version of the Turbo debugger.1. Tracing the Programs ExecutionThe Turbo debugger first starts, a Module Window which displays the Executable lines of program code,marked with a bullet in the left column of the window. You can set breakpoints or step to any of these linesof code. An arrow in the first column of the window indicates the location of the instruction pointer. Thisalways points to the next statement to be executed. To execute just that instruction use one of the twomethods listed under the Run menu item:o Trace into (can use F7 key): executes one instruction; traces "into" procedures.
  • 7. o Step over (can use F8 key): executes one instruction; skips (does not trace into) procedures.Hitting either of these executes the instruction, and moves the arrow to the next instruction. As eachinstruction executes, the effects might be visible in the Registers Window and Watches Window.2. Setting and Removing BreakpointsTo set a breakpoint, position the cursor on the desired line of source code and press F2. The line containingthe breakpoint will turn red. Pressing F2 again removes the breakpoint. To execute all instructions from thecurrent instruction pointer up to the next encountered breakpoint, choose Run (can use F9 key) from the Runmenu item.3. Examining RegistersAnother window, the Registers Window, can be opened to examine the current value of the CPU registersand flags. The View menu can be used to open this Registers Window. The registers and flags might changeas each instruction is executed.4. Examining MemoryTo examine memory, you will need to open an Inspector window. An Inspector window shows the contentsof a data structure (or simple variable) in the program you are debugging. It also allows you to modify thecontents of the data structure or variable. To open an Inspector window, place the cursor on what you wantto inspect and press CTRL-I. After youve examined the data item, press the ESC key to remove theInspector window.5. Vie wing the Programs OutputOutput written to the screen by a program is not immediately visible, since the main purpose of using adebugger is to examine the internal operation of the program. To observe what the user would see, pressALT-F5. The entire screen will change to a user-view showing the programs input and output (and possiblythat of previous programs as well). Press any key to return to the debugger screen.
  • 8. AN INDRODUCTION TO 8086, SIMPEPROGRAMS USING 8086 TRAINER KIT(a) AIM : Addition of two 8-bit numbers using IMMEDIATE addressing mode. APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic comment 2000 B0 05 Mov AL,05 Data 05 is stored in reg AL Data 04 is stored in reg BL 2002 B3 04 Mov BL,04 Data of AL and BL are 2004 02 C3 Add AL,BL added and stored in AL 2006 CC Int 03 StopRESULT: AL: 09b) AIM : Subtraction of two 8-bit numbers using immediate addressing mode.APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic comment 2000 B0 05 Mov AL,05 Data 05 is stored in reg AL Data 04 is stored in reg BL 2002 B3 04 Mov BL,04 Data of BL is subtracted 2004 2B C3 Sub AL,BL from AL and stored in AL 2006 CC Int 03 StopRESULT: AL: 01(c) AIM : Multiplication of two 8-bit numbers using immediate addressing mode.APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic comment 2000 B0 05 Mov AL,05 Data 05 is stored in reg AL Data 04 is stored in reg BL 2002 B3 04 Mov BL,04 Data of AL and BL are 2004 F7 E3 Mul BL multiplied and RESULT is stored in AL 2006 CC Int 03 StopRESULT : AL
  • 9. d) AIM : Division of two 8-bit numbers using immediate addressing mode.APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic comment 2000 B0 05 Mov AL,05 Data 05 is stored in reg AL Data 04 is stored in reg BL 2002 B3 04 Mov BL,04 Data of AL is divided by 2004 F6 F3 Div BL BL and RESULT stored in AL 2006 CC Int 03 StopRESULT : AL: 01RemainderAH: 01QuotientE) AIM : Addition of two 16-bit numbers using direct addressing mode.APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic comment Move contents of 1700 2000 8B060017 Mov AX,[1700] in reg AX Move contents of 1702 2004 8B1E0217 Mov BX,[1702] in reg BX Data of AX and BX are 2008 01D8 Add AX,BX added and RESULT stored in AX 200A CC Int 03 StopRESULT : AX=Input:-Location Data1700 881701 001702 441703 00
  • 10. f) AIM : Subtraction of two 16-bit numbers using direct addressing mode.APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic comment Move contents of 1700 2000 8B 06 00 17 Mov AX,[1700] in reg AX Move contents of 1702 2004 8B 1E 02 17 Mov BX,[1702] in reg BX Data of BX is subtracted from AX 2008 29 D8 Sub AX,BX and RESULT stored in AX 200A CC Int 03 StopRESULT : AX=Input:-Location Data Out put :1700 881701 001702 441703 00g) AIM : Addition of two 8-bit numbers using indirect addressing mode.APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic comment Move Data from 2000 2000 BE0017 Mov SI,1700 to SI Move contents of SI to 2003 8A04 Mov AL,[SI] reg AL 2005 46 Inc SI Incrementing SI Moving data from SI to 2006 8A1C Mov BL,[SI] BL Adding data of AL and 2008 02C3 Add AL,BL BL Move contents of AL 200A 89060018 Mov [1800],AL to 1800 200E CC Int 03 Stop
  • 11. RESULT :Input:-Location Data1700 041701 04Output :-1800 08b) AIM : Subtraction of two 8-bit numbers using indirect addressing mode.APPARATUS : 8086 Trainer kit.Program: Offset Address Opcode Label Mnemonic Comment Move Data from 2000 2000 BE0017 Mov SI,1700 to SI Move contents of SI to 2003 8A04 Mov AL,[SI] reg AL 2005 46 Inc SI Incrementing SI Moving data from SI to 2006 8A1C Mov BL,[SI] BL Subtract data of BL 2008 2BC3 Sub AL,BL from data of AL Move contents of AL 200A 89060018 Mov [1800],AL to 1800 200E CC Int 03 StopRESULT :Input:-Location Data1700 091701 04Output :-1800 05
  • 12. Ex.No.1 DATA TRANSFER Date:Aim: A. Write an ALP to transfer the data stored in consecutive memory locations, in the forward direction. B. Write an ALP to transfer the data stored in consecutive memory locations, in the reverse direction. C. Write an ALP to transfer the data stored in consecutive memory locations, in the forward direction overlapping.Software Used: Computer system with TASM.PROGRAM:A. Forward DirectionASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HARR1 DB 0H,1H,2H,3H,4H,5H,6H,7H,8H,9HCOUNT EQU 10DORG 3000HARR2 DB 10D DUP (0H)DATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV SI, 2000HMOV DI, 3000HMOV CX, COUNTBACK: MOV AH, [SI]MOV [DI], AHINC SI
  • 13. INC DILOOP BACKMOV AH, 4CHINT21HCODE ENDSEND STARTB.Reverse DirectionASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HARR1 DB 0H,1H,2H,3H,4H,5H,6H,7H,8H,9HCOUNT EQU 10DORG 3000HARR2 DB 10D DUP (0H)DATA ENDSCODE SEGMENTSTART: MOV AX, DATAMOV DS, AXMOV SI, 2000HMOV DI, 3000HMOV CX, COUNTADD DI, COUNT-1BACK: MOV AH, [SI]MOV [DI], AHINC SIDEC DILOOP BACK
  • 14. MOV AH, 4CHINT21HCODE ENDSEND STARTC.Forward Direction with OverlappingASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HARR1 DB 0H,1H,2H,3H,4H,5H,6H,7H,8H,9HCOUNT EQU $-ARR1OVERLAP EQU 06DORG 3000HARR2 DB 10D DUP (0H)DATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV SI, 2000HMOV DI, 3000HMOV CX, COUNT-OVERLAPNXTP: MOV AH, [SI]MOV [DI], AHINC SIINC DILOOP NXTPAGAIN: LEA SI, ARR1
  • 15. MOV CX, COUNTMOV AH, [SI]MOV [DI], AHINC SIINC DILOOP AGAINMOV AH, 4CHINT21HCODE ENDSEND STARTResult: Data stored in consecutive memory locations is transferred from 2000h memorylocation to 3000h memory location (a) in the forward direction (i.e. in the same order), (b) inthe reverse direction and (c) with overlapping in the forward direction.
  • 16. Ex.No.2 ARITHMETIC OPERATIONS Date:Aim: A. Write an ALP to perform addition on 16-bit data stored in consecutive memory locations and store the result from the next location onwards. B. Write an ALP to perform subtraction on 16-bit data stored in consecutive memory locations and store the result from the next location onwards. C. Write an ALP to perform multiplication on 16-bit data stored in consecutive memory locations and store the result from the next locations onwards. D. Write an ALP to perform division on 16-bit data stored in consecutive memory locations and store the result from the next location onwards. Software Used: Computer system with TASM. PROGRAM: A. Addition ASSUME CS: CODE, DS: DATA DATA SEGMENT ORG 2000H ADDEND DW 8765H ADDER DW 9876H SUM DW 0H CARRY DB 0H DATA ENDS CODE SEGMENT ORG 1000H START: MOV AX, DATA MOV DS, AX MOV AX, ADDEND ADD AX, ADDER JNC SKIP INC CARRY SKIP: MOV SUM, AX MOV AH, 4CH INT 21H CODE ENDS END START
  • 17. B. SubtractionASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HSUBTRAHEND DW 8765HSUBTRACTOR DW 9876HDIFFERENCE DW 0HBARROW DB 0HDATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV AX,SUBTRAHENDSUB AX, SUBTRACTORJNC SKIPINC BARROWSKIP: MOV DIFFERENCE, AXMOV AH, 4CHINT 21HCODE ENDSEND STARTC.MultiplicationASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HMULTIPLICANT DW 0FFFFHMULTIPLIER DW 123AHRES DD 0HDATA ENDSCODE SEGMENT
  • 18. ORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV AX, MULTIPLICANTMOV BX, MULTIPLIERMUL BXMOV WORD PTR [RES], AXMOV WORD PTR [RES+2], DXMOV AH, 4CHINT21HCODE ENDSEND STARTD.DivisionASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HDIVIDEND DW 8765HDIVISOR DW 1234HQUOTIENT DW 0HREMAINDER DW 0HDATA ENDSCODE SEGMENTSTART: MOV AX,DATAMOV DS, AXMOV AX, DIVIDENDMOV BX, DIVISORDIV BXMOV QUOTIENT, AXMOV REMAINDER, DXMOV AH, 4CH
  • 19. INT 21H CODE ENDS END STAR TResult:- An ALP is written to perform a) addition, (b) subtraction, (c) multiplication and (d)division operations using arithmetic instructions and the same is verified.
  • 20. Ex.No.3 LOGICAL OPERATIONS Date:Aim: A. Write an ALP to find number of 1’s in a given word. B. Write an ALP to find the number of even and odd numbers in the given array. C. Write an ALP to find the number of elements in the array having “1” in their 5th bit position.Software Used:Computer system with TASM.PROGRAM:A. Number of 1’s in a wordASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HNUM DW 5464COUNT EQU 16DBITCOUNT DB 0HDATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV CL, COUNTMOV AX, NUMNXTP: ROR AX, 01HJNC GOINC BITCOUNTGO: DEC CLJNZ NXTP MOV AH, 4CH
  • 21. INT 21H CODE ENDS END STARTB.Number of even and odd numbersASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HSERIES DW 3456H,4533H,1234H,1567H,0FFFFH,145AH,56D7,4E34H,3421H, 89C5HCOUNT EQU 0AHODDCOUNT DB 00HEVENCOUNT DB 00HDATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXLEA SI, SERIESMOV CL, COUNTNXTP: MOV AX, [SI]ROR AX, 01HJC ODDINC EVENCOUNTJMP OTHERODD: INC ODDCOUNTOTHER: INC SIDEC CLJNZ NXTPMOV AH, 4CH
  • 22. INT 21HCODE ENDS END STARTC.Number of elements having 1’s in their 5th bit positionASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HSERIES DB 21H,54H,05H,34H,32H,14H,18H,17H,53H,58HCOUNT EQU 0AHBITCOUNT DB 00HDATA ENDACODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXLEA SI, SERIESMOV CL, COUNTNXTP: MOV AX, [SI]TEST AX, 10HJZ GOINC BITCOUNTGO: INC SIDEC CLJNZ NXTPMOV AH, 4CHINT 21HCODE ENDS
  • 23. END START, Result: Logical operations such as Shift, rotate and test are used to find the a) no. of1’s in the given byte, b) no. of even and add numbers, c)no. of positive and negative numbers and d)no. of elements having 1’s in their 5th bit position.Ex.No.4 STRING MANIPULATIONS Date:Aim: A. Write an ALP to transfer the data in forward direction using string instructions. B. Write an ALP to transfer the data in reverse direction using string instructions. Software Used: Computer system with TASM. PROGRAM:A. Forward Direction using String InstructionsASSUME DS: DATA, CS: CODE, ES: EXTRADATA SEGMENTORG 2000HSTRING1 DB MICROPROCESSORCOUNT EQU $-STRING1DATA ENDSEXTRA SEGMENTORG 3000HSTRING2 DB 14D DUP (00H)EXTRA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV AX, EXTRAMOV ES, AXMOV CX, COUNTLEA SI, STRING1LEA DI, STRING2
  • 24. CLDREP MOVSBMOV AH, 4CHINT 21HCODE ENDSEND STARTB.Reverse Direction using String InstructionsASSUME DS: DATA, CS: CODE, ES: EXTRADATA SEGMENTORG 2000HSTRING1 DB MICROPROCESSORLENGTH_STRING DW $-STRING1DATA ENDSEXTRA SEGMENTORG 3000HSTRING2 DB 14D DUP (00H)EXTRA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV AX, EXTRAMOV ES, AXLEA SI, STRING1LEA DI, STRING2MOV CX, LENGTH_STRINGADD DI, CXDEC DIBACK: MOVSB
  • 25. SUB DI, 02HLOOP BACKMOV AH, 4CHINT 21HCODE ENDSEND STARTResult: String manipulations such as a) forward string, b) reverse string.
  • 26. Ex.No.5 SORTING Date:Aim: A. Write an ALP to sort the given array in signed ascending order. B. Write an ALP to sort the given array in unsigned descending order. C. Write an ALP to find the maximum and the minimum element in the given array. Software Used: Computer system with TASM. PROGRAM:A. Signed ascending orderASSUME DS: DATA, CS: CODEDATA SEGMENTORG 3000HARRAY DB 03H,07H,05H,01H,09H,04H,06H,02H,08HCOUNT EQU 09HDATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV DX, COUNTDEC DXBEGIN: MOV CX, DXLEA SI, ARRAYBACK: MOV AL, [SI]CMP AL,[SI+01]JNZ SKIPXCHG AL, [SI+01]
  • 27. XCHG AL, [SI]SKIP: INC SILOOP BACKDEC DXJNZ BEGINMOV AH, 4CHINT 21HCODE ENDSEND STARTB.Unsigned descending orderASSUME DS: DATA, CS: CODEDATA SEGMENTORG 3000HARRAY DB 03H,07H,05H,01H,09H,04H,06H,02H,08HCOUNT EQU 09HDATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV DX, COUNTDEC DXBEGIN: MOV CX, DXLEA SI, ARRAYBACK: MOV AL, [SI]CMP AL,[SI+01]JNB SKIPXCHG AL, [SI+01]
  • 28. XCHG AL, [SI]SKIP: INC SILOOP BACKDEC DXJNZ BEGINMOV AH, 4CHINT 21HCODE ENDSEND STARTC.Maximum and Minimum elementsASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HARRAY DW 5555H,9999H, 7777H, 2222H, 1111H, 8888H, 6666HA_LENTH EQU ($-ARRAY)/2MAX_NO DW 0HMIN_NO DW 0HDATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV CX, A_LENTH-1LEA SI, ARRAYMOV AX, [SI]MOV BX, AXBACK: INC SIINC SICMP AX, [SI]
  • 29. JNC SKIPMOV AX, [SI]JMP NEXTSKIP: CMP BX, [SI]JC NEXTMOV BX, [SI]NEXT: LOOP BACKMOV MAX_NO,AXMOV MIN_NO, BXMOV AH, 4CHINT 21HCODE ENDSEND STARTResult: Sorting the array in a) signed ascending order, b) unsigned descending order and c)searching for the maximum and minimum elements in the unsigned array, are implemented.
  • 30. Ex.No.6 PROCEDURE AND MACROS Date:Aim: A. Write an ALP to convert Hexadecimal numbers to BCD numbers. B. Write an ALP to find the factorial of given number. Software Used: Computer system with TASM. Flow Chart: PROGRAMA. Hexadecimal to BCD conversionASSUME DS: DATA, CS: CODEDATA SEGMENTORG 2000HHEXA DB 25H, 57H, 89H, 0A4HCOUNT EQU 04DECI DB 12 DUP (00H)BCD DW 04 DUP (00H)DATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXMOV SI, OFFSET HEXAMOV DI, OFFSET DECIMOV CX, COUNTBACK: XOR AX, AXMOV AL, [SI]MOV BL, 64H
  • 31. DIV BLMOV [DI], ALINC DIMOV AL, AHXOR AH, AHMOV BH, 0AHDIV BHMOV [DI], ALINC DIMOV [DI], AHINC SIINC DILOOP BACKCALL UP2PMOV AH, 4CHINT 21HUP2P PROC NEARMOV CH,COUNTMOV DI,OFFSET DECIMOV BP,OFFSET BCDCONTINUE: XOR AX,AXMOV AH,[DI]INC DIMOV AL,[DI]MOV CL,4SHL AL,CLINC DIADD AL,[DI]MOV DS:BP,AXINC DI
  • 32. INC BPINC BPDEC CHJNZ CONTINUERETUP2P ENDPCODE ENDSEND STARTB.Factorial of a given numberFACTORIAL MACROXOR CX, CXXOR AX, AXINC AXMOV CL, NUMBERCMP CL, 0JE GOREPEAT: MUL CXLOOP REPEATGO: MOV FACT, AXENDMASSUME CS: CODE, DS: DATADATA SEGMENTORG 2000HNUMBER DB 08HFACT DW 0DATA ENDSCODE SEGMENTSTART: MOV AX, DATAMOV DS, AX
  • 33. FACTORIALMOV AH, 4CHINT 21HCODE ENDSEND STARTResult: Programs on a) Procedure for converting Hexadecimal numbers to packed BCD and b)Macro for finding the factorial of a given number are implemented.
  • 34. Ex.No.7 INTERRUP TS Date:Aim: A. Write an ALP to find whether the given string is a palindrome or not. B. Write an ALP to enter the string through keyboard and display it. Software Used: Computer system with TASM. PROGRAM:A. String is palindrome or notASSUME DS: DATA, CS: CODEDATA SEGMENTORG 2000HSTRING DB RADARCOUNT EQU $-STRING-1MSG1 DB "STRING IS PALINDROME $"MSG2 DB "STRING IS NOT PALINDROME $"DATA ENDSCODE SEGMENTORG 1000HSTART: MOV AX, DATAMOV DS, AXLEA SI, STRINGLEA DX, MSG2MOV CX, COUNTMOV DI, SIADD DI, COUNT-1SHR CX, 1
  • 35. BACK: MOV AL, [SI]CMP AL, [DI]JNZ NEXTINC SIDEC DILOOP BACKLEA DX, MSG1NEXT: MOV AH, 09HINT 21HMOV AH, 4CHINT 21HCODE ENDSEND STARTB.Enter and Display the stringASSUME DS: DATA, CS: CODEDATA SEGMENTORG 2000HINPUT DB “ENTER THE STRING”, 0DH, 0AH, “$”OUTPUT DB “THE ENTERED STRING IS:” 0DH, 0AH, “$”S_LENTH DB 0BUFFER DB 80 DUP (0)DATA ENDSCODE SEGMENTSTART: MOV AX, DATAMOV DS, AXXOR CL, CLLEA DX, INPUTMOV AH, 09HINT 21HLEA BX, BUFFERREPEAT: MOV AH, 01H
  • 36. INT 21HCMP AL, 0DHJZ EXITINC CLMOV [BX], ALINC BXJMP REPEATEXIT: MOV S_LENTH, CLLEA BX, BUFFERADD BL, CLMOV AL,’$’MOV [BX], ALLEA DX, OUTPUTMOV AH, 09HINT 21HLEA DX, BUFFERMOV AH, 09HINT 21HCODE ENDSENDF STARTResult: Interrupts on a) whether the given string is a palindrome or not and b) entering the string throughkeyboard and displaying the same, are verified.
  • 37. 8051 INTRODUCTION AND INTERFACING WITH PERIPHERALDEVICESUSING TOP VIEWIMULATOR
  • 38. Ex.No.8 Arithmetic, Logic and Bit manipulation Instructions Date:Aim: Write an ALP to perform Addition, Subtraction, Multiplication, Division, Swap,Reset, Set, Bit, Byte manipulation Instructions. Software Used: Computer system with TOPVIEW SIMULATOR.PROCEDURE:In Top view simulator:  Select device 89C51 with 12000000Hz frequency.  Open the hex file (Ctrl + O or file->Load program).  Run the program at full speed. ( Run->go)  To stop the execution Run->stop execution.A.ADDITION$MOD51ORG 0000HMOV DPTR, #0101HMOVX A,@DPTRMOV B, ADEC DPLMOV A,@DPTRADD A, BINC DPTRINC DPTRMOVX @DPTR, ACLR AADDC A, #00HINC DPTRMOVX @DPTR, A
  • 39. STOP: SJMP STOPENDB.SUBTRACTION$MOD51ORG 0000HMOV DPTR, #0101HMOVX A,@DPTRMOV B, ADEC DPLMOVX @DPTR, ACLR CSUBB A,BINC DPTRINC DPTRMOVX @DPTR, ACLR AADDC A, #00HINC DPTR.MOVX @DPTR,ASTOP: SJMP STOPENDC.MULTIPLICATION$MOD51ORG 0000HMOV DPTR, # 0101HMOVX A,@DPTRMOV B, ADEC DPL
  • 40. MOVX A, @DPTRMUL A BINC DPTRINC DPTRMOVX @DPTR, AMOV A, BINC DPTRMOVX @DPTR, ASTOP: SJMP STOPENDD.DIVISION$MOD51ORG 0000HMOV DPTR, # 0101HMOV X A,@DPTRMOV B, ADEC DPLMOVX A, @DPTRDIV ABINC DPTRINC DPTRMOVX @DPTR, AMOV A, BINC DPTRMOVX @DPTR, ASTOP: SJMP STOPENDD.SWAP
  • 41. $MOD51ORG 0000HMOV DPTR, # 0101HMOVX A, @ DPTRSWAP AINC DPTRMOVX @ DPTR, ASTOP: SJMP STOPENDE.RESET$MOD51ORG 0000HMOV DPTR, # 0101HCLR CMOV A, ODOHMOV DPTR, # 0101HMOVX @ DPTR, ASTOP: SJMP STOPENDF.SET$MOD51ORG 0000HMOV DPTR, # 0101HSETB CMOV A,0D0HMOV DPTR, # 0101HMOVX @ DPTR, ASTOP: SJMP STOP
  • 42. ENDG.BIT$MOD51ORG 0000HMOV DPTR, # 0101HMOV A, ODOHMOVX @ DPTR, ACPL CMOV A, ODOHINC DPTRMOVX @DPTR, ASTOP: SJMP STOPENDH.BYTE$MOD51ORG 0000HMOV DPTR, # 0101HMOVX A @ DPTRCPL AINC DPTRMOVX @ DPTR, ASTOP: SJMP STOPENDI.COMPLIMENT$MOD51ORG 0000HMOV DPTR,#0101HMOVX A,@DPTR
  • 43. CPL AINC DPTRMOVX @DPTR,ASTOP: SJMP STOPENDResult: All the Arithmetic and special instruction operations are performed by using 8051.
  • 44. Ex. No 9 Interfacing of 7 – Segment Displays Date:Problem statement: Interface 7-segment displays (using BCD to 7-seg decoder) to the 8051 microcontroller.Aim: To display two Digit Decimal counter on 7- segment displays.Software Used: Computer system with TOPVIEW SIMULATOR.PROCEDURE:In Top view simulator:-  Select device 89C51 with 12000000Hz frequency.  Open the hex file (Ctrl + O or file->Load program).  Open LED module settings to configure the LED connections.( File-> External modules settings-> LED)  In seven segment display select Interface selection-> non-multiplexed. Display type->common cathode. Data input selection -> BCD.  Click on selection of port line and number of digits.  Select no. of digits as 2  Select control lines and port lines as shown in the below table.  Check with summary window for correct connections.  Open the LED module. (View->External modules->LED).  Run the program at full speed. ( Run->go)  The two digit decimal counter will shown up.  To stop the execution Run->stop execution.
  • 45. Table for Port line selection7-Segment Display PIN on 8051Digit2 A P1.0Digit2 B P1.1Digit2 C P1.2Digit2 D P1.3Digit2 Dp GNDDigit1 A P1.4Digit1 B P1.5Digit1 C P1.6Digit1 D P1.7Digit1 Dp GNDCircuit: Digit2 P1.0 A 7 P1.1 B BCD to 7 SEG SEG P1.2 C 8051 P1.3 D |_| Digit1 P1.4 A A BCD to 7 7 P1.5 BB SEG SEG P1.6 C C P1.7 D
  • 46. PROGRAM$MOD51ORG 0000HSJMP MAINORG 0030HMAIN:MOV A,#00HAG AIN:MOV P1,ALCALL DELAYADD A,#01DA ASJMP AGAINORG 0040HDELAY:MOV R2,0FFHUP1:MOV R1,0FFHUP2:NOPNOPNOPDJNZ R1,UP2DJNZ R2,UP1RETEND
  • 47. Simulated output:Result: Decimal counter is displayed on 7-Segment displays.
  • 48. Ex.No.10 Interfacing of 2 – line 16 – character LCD display Date:Problem statement:Interface LCD controller to the 8051 microcontroller.Aim: To display strings in two lines on a LCD module. Software Used: Computer system with TOPVIEW SIMULATOR.Procedure:In Top view simulator  Select device 89C51 with 12000000Hz frequency.  Open the hex file ( Ctrl + O or file->Load program).  Open LCD module settings to configure the LCD connections.( File-> External modules settings-> LCD) Check with the summary window for correct connections.  Select LCD as 2lines 16 characters and Data bus width as 8 bit.  In port line selection configure the port lines as per requirement. ( see the table for port selection).  Open the LCD module. (View->External modules->LCD).  Run the program at full speed. ( Run->go)  The strings are displayed on the LCD.  To stop the execution Run->stop execution.Table for Port line selectionPIN on 8051 PIN on LCDP1.0 … P1.7 D0…D7(Data lines)P2.0 RSP2.1 RWP2.2 E
  • 49. Circuit: P1.0 D0 LCD controller P1.7 D7 RS RW E 8051 P2.0 P2.1 P2.2Flow Chart:PROGRAM$MOD51RS EQU P3.1EN EQU P3.2RW EQU P3.3ORG 0000HMOV A,#38HLCALL LCD_COMDMOV A,#0EHLCALL LCD_COMDMOV A,#06HLCALL LCD_COMDMOV A,#01HLCALL LCD_COMDMOV A,#ELCALL LCD_TEXTMOV A,#C
  • 50. LCALL LCD_TEXTMOV A,#ELCALL LCD_TEXTLOOP:SJMP LOOPLCD_COMD:CLR CLCALL WRITERETLCD_TEXT:SETB CLCALL WRITERETWRITE:SETB ENCLR RWMOV RS,CMOV P1,ACLR ENLCALL DELAYRETDELAY:MOV R0,#60LOOP2:MOV R1,#255LOOP1:DJNZ R1,LOOP1DJNZ R0,LOOP2RETEND
  • 51. Simulator Output:Result:The strings in two lines are displayed on LCD module.
  • 52. Ex.No.11 LIGHT EMITTING DIODE (LED) Date:Problem statement:Interface LED controller to the 8051 microcontroller.Aim: Write an ALP for LED using 8051. Software Used: Computer system with TOPVIEW SIMULATOR.PROCEDURE:In Top view simulator:  Select device 89C51 with 12000000Hz frequency.  Open the hex file (Ctrl + O or file->Load program).  Open LED module settings to configure the LED connections.( File-> External modules settings-> LED)  In seven segment display select Interface selection-> non-multiplexed. Display type->common cathode. Data input selection -> BCD.  Click on selection of port line and number of digits.  Select no. of digits as 2  Select control lines and port lines as shown in the below table.  Check with summary window for correct connections.  Open the LED module. (View->External modules->LED).  Run the program at full speed. ( Run->go)  The two digit decimal counter will shown up.  To stop the execution Run->stop execution.Flow Chart:
  • 53. PROGRAM$MOD51CLR AREPEAT:MOV P1,ALCALL DELAYINC ASJMP REPEATDELAY:MOV R2,#0FFHBACK:MOV R1,#0FFHUP1:NOPNOPDJNZ R1,UP1DJNZ R2,BACKRETENDSimulator Output:Result: Decimal counter is displayed on LED displays.
  • 54. Exp.12 Interfacing of Stepper Motor Date:Aim: Interface the stepper motor to 8051 target system and write program to operate indifferent speeds both clock wise and anti clock wise directions.STEPPER MOTOR CONTROLLER INTERFACING MODULECIRCUIT DESCRIPTIONThe four winding of the motor is connected with PA0 to PA3 through buffer and drivingcircuit. So, the Port A of 8255 will have to initializes in output mode.HARDWARE INSTALLATION 1. Connect Stepper Motor interfacing module to 8255 – I of 8051 / 8085 Trainer Kit through 26 pin FRC Cable. 2. Be sure about the direction of the cable i.e. Pin No.1 of module should be connected to Pin No.1 of 8255 connector. 3. Connect +5V, GND from the trainer kit (+5V & GND signals are available in the 25 & 26 pin of FRC 8255 – I Connector). 4. Connect Motor Supply to +12V from the Trainer Kit.8255 Port Address:Port A – FF00HPort B –FF01HPort C – FF02HControl Word – FF03HProcedure:1. Create a source file in Assembly language.2. Assemble the source file using ASM51 cross Assembler and create LST & HEX files.3.Configure the windows hyper terminal with a baud rate 9600 , 8 data bits, no parity, 1stop bit and flow control XON / XOFF.
  • 55. 4. Establish a serial communication link between Host and Target system using hyper terminal. 5. Down load the HEX file from the host to the target system. 6. Connect stepper motor interface module to the target system and run the program. Program: This program will move the motor in Clock wise direction. For Anti Clock wise direction change F9, F5, F6, FA in place of FA, F6, F5, F9.Address Code Label Mnemonic Operand Comments2000 90 FF 03 MOV DPTR, #0FF03H2003 74 80 MOV A,#80H2005 F0 MOVX @DPTR,A Init ports of 8255 as all2006 90 FF 00 START: MOV DPTR,#0FF00H output ports2009 74 FA MOV A,#0FAH output code for step 1200B F0 MOVX @DPTR,A200C 11 1F ACALL delay between two DELAY steps200E 74 F6 MOV A,#0F6H output code for step 22010 F0 MOVX @DPTR,A2011 11 1F ACALL DELAY2013 74 F5 MOV A,#0F5H output code for step 32015 F0 MOVX @DPTR,A
  • 56. 2016 11 1F ACALL DELAY2018 74 F9 MOV A,#0F9H output code for step 4201A F0 MOVX @DPTR,A201B 11 1F ACALL delay between two DELAY steps201D 80 E7 SJMP START repeat for next cycle201F 7F 3F DELAY: MOV R7,#03FH delay count for controlling speed2021 7E 3F DELA: MOV R6,#03FH2023 00 DELA1: NOP2024 00 NOP2025 00 NOP2026 DE FB DJNZ R6,DELA12028 DF F7 DJNZ R7,DELA202A 22 RET Result: The Stepper Motor is interfaced to 8051 and operated with different speeds and directions.
  • 57. 8051 INTERFACING WITH PERIPHERAL DEVICESUSING ASSEMBLY LANGUAGE PROGRAM
  • 58. BINARY COUNTER INTERFACING WITH 8051AIM: To interface Binary Counter 8051 parallel port to demonstrate the generation of convert a binary number toa decimal.APPARATUS REQUIRED; 8051 Trainer Kit LED’S Resistors -330k ohmTHEORY: Before starting with counters there is some vital information that needs to be understood. The mostimportant is the fact that since the outputs of a digital chip can only be in one of two states, it must use adifferent counting system than you are accustomed to. Normally we use a decimal counting system; meaningeach digit in a number is represented by one of 10 characters (0-9). In a binary system, there can only be twocharacters, 0 and 1. A computer does not recognize 0 or 1. It only works o n voltage changes. What we call logic 0 to acomputer is zero volts. What we call logic 1 is +5 volts. When a logic state changes from a zero to a one thevoltage at the pin in question goes from zero volts to +5 volts. Likewise, when a logic state changes from aone to a zero the voltage is changing from +5 volts to zero volts.When counting up in a decimal system, we start with the first digit. When that digit ‘overflows’, i.e. getsabove 9, we set it to 0 and add one to the next digit over. The same goes for a binary system. When thecount goes above 1 we add one to the next digit over and set the first digit to 0. Here is an exampleDECIMAL TO BINARY CONVERSIONDecimal Number (base 10) Binary Number (base 2) 0 0 1 1 2 10 3 11 4 100 5 101 6 110 Decimal Number (base 10) Binary Number (base 2) 7 111 8 1000 9 1001
  • 59. BINARY COUNTING To convert a binary number to a decimal, we use a simple system. Each digit or ‘bit’ of the binarynumber represents a power of two. All you need to do to convert from binary to decimal is add up theapplicable powers of 2. In the example below, we find that the binary number 10110111 is equal to 183. Thediagram also shows that eight bits make up what is called a byte. Nibbles are the upper or lower four bits ofthat byte. Referring to nibbles and bytes are useful when dealing with other number systems such ashexadecimal, which is base 16. fig1. InterfacingPROGRAM: MOV DPTR, # 2023; Control register of 8255. MOV A, #80; 8255 in I/O mode operation MOVX @DPTR, A MOV A, #00HSTART: MOV DPTR, # 2020 (port A address ) INC A MOVX @DPTR, A LCALL DELAY
  • 60. CJNE A, #FFH, START XX: SJMP XXDELAY: MOV R1, # FFh CC: MOV R2, # FFh AA: DJNZ R2, AA MOV R3, # FFH BB: DJNZ R3, BB DJNZ R1, CC RETResult:
  • 61. Seven Segment Display Interfacing With 8051AIM:To interface Seven Segment Display to 8051 to generate a digit from 0 to 9 using common anode and Common cathode technique.APPARATUS REQUIRED8051 TRAINERCommon cathode Seven Segment DisplayCommon anode Seven Segment DisplayINTRODUCTION For the seven segment display you can use the LT-541 or LSD5061-11 chip. Each of the segments of thedisplay is connected to a pin on the 8051 (the schematic shows how to do this). In order to light up asegment on the the pin must be set to 0V. To turn a segment off the corresponding pin must be set to 5V.This is simply done by setting the pins on the 8051 to 1 or 0.LED displays are Power-hungry (10ma per LED) Pin- hungry (8 pins per 7-seg display)But they are cheaper than LCD display7-SEG Display is available in two types -1. Common anode & 2. Common cathode, but command anodedisplay is most suitable for interfacing with 8051 since 8051 port pins can sink current better than sourcingit.
  • 62. CREATING DIGIT PATTERNFor displaying Digit say 7 we need to light segments -a ,b, c. Since we are using Common anode display , todo so we have to to provide Logic -0 (0 v) at anode of these segments.so need to clear pins- P1.0,P1.1,P1.2. that is 1 1 1 1 1 0 0 0 -->F8h . Connection Hex CodeSegment Seg. 8051 pin number Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. a HEXnumber ba P1.0 0 1 1 0 0 0 0 0 0 C0b P1.1 1 0 0 0 0 0 1 1 0 06c P1.2 2 1 0 1 0 0 1 0 0 A4d P1.3 3 1 0 1 1 0 0 0 0 B0e P1.4 4 1 0 0 1 1 0 0 1 99f P1.5g p1.6 COMMON ANODEh(dp) P1.7Segment Seg. 8051 pin number Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. a HEXnumber ba P1.0 0 0 0 1 1 1 1 1 1 3fb P1.1 1 0 0 0 0 0 1 1 0 06c P1.2 2 0 1 0 1 1 0 1 1 5bd P1.3 3 0 1 0 0 1 1 1 1 4fe P1.4 4 0 1 1 0 0 1 1 0 66f P1.5g p1.6h(dp) P1.7 COMMON CATHODE
  • 63. You can also do this for some characters like A, E. But not for D or B because it will be sameas that of 0 & 8 . So this is one of limitation of 7-seg display.Since we can enable only one 7-seg display at a time, we need to scan these display at fast rate .Thescanning frequency should be high enough to be flicker- free. At least 30HZ .Therefore – time one digit isON is 1/30 secondsINTERFACINGNote that I am using Common Anode display. So the common Anode pin is tied to 5v .The cathode pins areconnected to port 1 through 330 Ohm resistance (current limiting).SOURCE CODE: 8000: MOV DPTR, #2023; Control register of 8255 MOV A, # 80; MOVX @DPTR, A; select I/O mode in 8255, out at Control register of 8255 MOV R0, # 00; MOV A, R0; XX: MOV DPTR, # 8500; Look up table address MOVC A, @A+DPTR; MOV DPTR, #2020; Port “A” Address MOVX @DPTR, A; LCALL DELAY INC R0
  • 64. CJMP R0, # 00FH, XX; YY: SJMP YY DELAY: MOV R1, # FF CC: MOV R2, # FF AA: DJNZ R2, AA MOV R3, # FF BB: DJNZ R3, BB DJNZ R1, CC RETLOOK UP TABLE 8500: C0, 06, A4, B0, 99, -----------------RESULT: To generate digits from 0 to 9 using common anode and common cathode technique.
  • 65. INTERFACING DAC WITH 8051AIM:To interface DAC with 8051 parallel port to demonstrate the generation of square, saw tooth and Triangular wave.APPARATUS REQUIRED; 8051 Trainer Kit DAC Interface BoardTHEORY:DAC 0809 is an 8 – bit DAC and the output voltage variation is between – 5V and +5V.The output voltagevaries in steps of 10/256 = 0.04 (appx.). The digital data input and the corresponding output voltages arepresented in the Table belowINPUT DATA IN HEX OUTPUT VOLTAGE(V) 00 -5.00 01 -4.96 02 -4.92 7F 00 FD 4.92 FE 4.96 FF 5.00 Table 1.Referring to Table1, with 00 H as input to DAC, the a nalog output is – 5V. Similarly, With FF H as input,the output is +5V. Outputting digital data 00 and FF at regular intervals, to DAC, results in different waveforms namely square, triangular, etc, Two methods of creating a DAC : binary weighted and R/2R ladder. The vast majority of integratedcircuit DACs, including the MC1408 (DAC 0809) used in this section use the R/2R method since it canachieve a much higher degree of precision. The first criterion for judging a DAC is its resolution, which is afunction of the number of binary inputs. The common ones are 8, 10, and 12 bits. The number of data bitinputs decides the resolution of the DAC since the number of analog output levels is equal to 2 n , where n isthe number of data bit inputs. Therefore, an 8-input DAC. Such as the DAC 0809 provides 256 discrete voltage (or current) levels of output.Similarly, the 12-bit DAC provides 4096 discrete voltage levels. There are also16-bit DACs, but they are more expensive.
  • 66. Figure 1. 8051Connection to DAC 0809ALGORITHM:(a) Square Wave Generation1. Move the port address of DAC to DPTR.2. Load the initial value (00) to Accumulator and move it to DAC.3. Call the delay program.4. Load the final value (FF) to accumulator and move it to DAC.5. Call the delay program.6. Repeat the steps 2 to 5.(b) Saw tooth Wave Generation1. Move the port address of DAC to DPTR.2. Load the initial value (00) to Accumulator.3. Move the accumulator content to DAC.4. Increment the accumulator content by 1.5. Repeat Steps 3 and 4.(c) Triangular Wave Generation1. Move the port address of DAC to DPTR.2. Load the initial value (00) to Accumulator.3. Move the accumulator content to DAC
  • 67. 4. Increment the accumulator content by 1.5. If accumulator content is zero proceed to next step. Else go to step 3.6. Load value (FF) to Accumulator7. Move the accumulator content to DAC8. Decrement the accumulator content by 1.9. If accumulator content is zero go to step2. Else go to step 7.PROGRAM: (a) Square Wave Generation MOV DPTR, # 2023; Control register of 8255. MOV A, #80; 8255 in I/O mode operation MOVX @DPTR, A MOV DPTR, # 2021 (port B address of DAC start)START: MOV A, #00H MOVX @DPTR, A LCALL DELAY MOV A, #FFH MOVX @DPTR, A LCALL DELAY SJMP STARTDELAY: MOV R1, #05H LOOP: MOV R2, #FFHHERE: DJNZ R2, HERE DJNZ R1, LOOP RETPROGRAM: (b) Saw Tooth Wave Generation MOV DPTR, # 2023; Control register of 8255. MOV A, #80; 8255 in I/O mode operation
  • 68. MOVX @DPTR,START: MOV A, #00H MOV DPTR, # 2021 (port B address of DAC start) GO: MOVX @DPTR, A INC A CJNE A, #FFH, GO SJMP STARTPROGRAM: (c) Triangular Wave Generation MOV DPTR, # 2023; Control register of 8255. MOV A, #80; 8255 in I/O mode operation MOVX @DPTR, ASTART: MOV A, #00H MOV DPTR, # 2021 (port B address of DAC start) GO: MOVX @DPTR, A INC A CJNE A, #FFH, GO GO1: MOVX @DPTR, A DEC A CJNE A, #00H, GO1 SJMP STARTResult : Thus the square, triangular and saw tooth wave form were generated by interfacing DAC with8051 trainer kit.
  • 69. ADC 0808/0809 INTERFACING WITH 8051AIM: To interface ADC with 8051 to generate digital output by giving an analog input voltage.APPARATUS REQUIRED; 8051 Trainer Kit ADC Interface BoardTHEORY: One of the most commonly used ADC is ADC0808/0809. ADC 0808/0809 is a Successiveapproximation type with 8 channels i.e. it can directly access 8 single ended analog signals.I/O PinsADDRESS LINE A, B, and C: The device contains 8-channels. A particular channel is selected by using theaddress decoder line. The TABLE 1 shows the input states for address lines to select any channel.Address Latch Enable ALE: The address is latched on the Low – High transition of ALE.START: The ADC’s Successive Approximation Register (SAR) is reset on the positive edge i.e. Low- Highof the Start Conversion pulse. Whereas the conversion is begun on the falling edge i.e. high – Low of thepulse.Output Enable: Whenever data has to be read from the ADC, Output Enable pin has to be pulled high thusenabling the TRI-STATE outputs, allowing data to be read from the data pins D0-D7.End of Conversion (EOC): This Pin becomes high when the conversion has ended, so the controller comesto know that the data can now be read from the data pins.Clock: External clock pulses are to be given to the ADC; this can be given either from LM 555 in Astablemode or the controller can also be used to give the pulses.ALGORITHM:1. Start. 2. Select the channel. 3. A Low – High transition on ALE to latch in the address. 4. A Low –High transition on Start to reset the ADC’s SAR. 5. A High – Low transition on ALE. 6. A High – Lowtransition on start to start the conversion. 7. Wait for End of cycle (EOC) pin to become high. 8. Make
  • 70. Output Enable pin High. 9. Take Data from the ADC’s output 10. Make Output Enable pin Low. 11.StopThe total numbers of lines required are: Datalines:8,ALE:1,START:1,EOC:1,Output Enable:1I.e. total 12 lines. You can directly connect the OE pin to Vcc. Moreover instead of polling for EOC just putsome delay so instead of 12 lines you will require 10 lines. We Can also provide the clock through thecontroller thus eliminating the need of external circuit for clock.Calculating Step SizeADC 0808 is an 8 bit ADC i.e. it divides the voltage applied at Vref+ & Vref- into 28 i.e. 256 steps.Step Size = (Vre f+ - Vref-)/256Suppose Vref+ is connected to Vcc i.e. 5V & Vref- is connected to the Gnd then the step size will beStep size= (5 - 0)/256= 19.53 mv.Calculating D out.The data we get at the D0 - D7 depends upon the step size & the Input voltage i.e. Vin.Dout = Vin /step Size.If you want to interface sensors like LM35 which has output 10mv/°C then I would suggest that you set theVref+ to 2.56v so that the step size will beStep size= (2.56 - 0)/256= 10 mv.So now whatever reading that you get from the ADC will be equal to the actual temperature. Here is a program for interfacing the ADC to microcontroller, as stated above have assumed that theOE pin is connected to Vcc & the clock is given by the controller.This program selects channel 0 as input channel reads from it & saves in the accumulator.NOTE: In the LAB, ADC is interfaced with 8051 Microcontroller through 8255 PPI.Port 2 of 8051 is connected to Port C of 8255, Port 1 of 8051 is connected to Port A of 8255,Port C is for interfacing signals and Port A is for Reading data from ADC.
  • 71. Fig.1 interfacing circu itPROGRAM: MOV DPTR, #2023 MOV A, #90: PA-I/P PORT, PORT B, C-O/P PORTS MOVX @DPTR, A BEGIN: MOV DPTR, #2022; Select CH-0 MOV A, #00 MOVX @DPTR, A MOV A, #0DH; Set PC6 (OE) MOV DPTR, #2023 MOVX @DPTR, A MOV A, #0FH; SET SOC MOVX @DPTR, A LCALL DELAY MOV A, #0EH MOVX @DPTR, A MOV A, #0CH MOVX @DPTR, A
  • 72. MOV DPTR, #2020 BACK: MOVX A,@DPTR JB 0E7, BACK MOV DPTR, #2020 REP: MOVX A,@DPTR ANL A, #80H JNB 0E7, REP MOV A, #0DH MOV DPTR, #2023 MOVX @DPTR, A MOV DPTR, #2020 MOVX A,@DPTR MOV DPTR, #9000H; Read the digital output from this address MOVX @DPTR, A SJMP BEGIN DELAY: MOV R3, #30H AG AIN: MOV R4, #FFH BACK: NOP NOP DJNZ R4, BACK DJNZ R3, AGAIN RETRESULT: Given input voltage varying from 5v to 0v at Channel 0 and observe the digital output value atthe address at 9000h, which is given in code.
  • 73. STEPPER MOTOR INTERFACING WITH 8051AIM: To interface a stepper motor with 8051 microcontroller and operate it.APPARATUS:8051Stepper motor interfacing boardTHEORY: A motor in which the rotor is able to assume only discrete stationary angular position is a steppermotor. The rotary motion occurs in a step-wise manner from one equilibrium position to the next. StepperMotors are used very wisely in position control systems like printers, disk drives, process control machinetools, etc. The basic two-phase stepper motor consists of two pairs of stator poles. Each of the four poles ha s itsown winding. The excitation of any one winding generates a North Pole. A South Pole gets induced at thediametrically opposite side. The rotor magnetic system has two end faces. It is a permanent magnet with oneface as South Pole and the other as North Pole. The Stepper Motor windings A1, A2, B1, B2 are cyclically excited with a DC current to run themotor in clockwise direction. By reversing the phase sequence as A1, B2, A2, B1, anticlockwise steppingcan be obtained. 8051 Interfacing with stepper motor
  • 74. Stepper motors can be driven in two different patterns or sqeunces. Namely, 1. Full Step Sequence 2. Half Step SequenceA normal 4 step sequence is like below.Step # Winding A Winding B Winding C Winding D1 1 0 0 12 1 1 0 03 0 1 1 04 0 0 1 1Going from step 1 to 4 we rotate motor clockwise, going from step 4 to 1 we rotate motor counter clockwise. Thestepper motor discussed here has total 6 leads. 4 leads representing 4 windings and 2 commons for centre tapped leads.Here we have used 2 phase 4 step sequence. It must also be noted we can start from any step. Be it step 1, 2, 3 or 4.But we must continue in proper order for proper rotation.In programs on blog I have mostly begun from step 3. Other step sequences are as belowHalf Step 8 Step SequenceStep # Winding A Winding B Winding C Winding D1 1 0 0 12 1 0 0 03 1 1 0 04 0 1 0 05 0 1 1 06 0 0 1 07 0 0 1 18 0 0 0 1Wave drive 4 step sequenceStep # Winding A Winding B Winding C Winding D1 1 0 0 02 0 1 0 03 0 0 1 04 0 0 0 1
  • 75. The Movement is associated with a step angle:Step angle Steps per revolution.72 5001.8 2002 1802.5 1445 727.5 4815 24 4 Pins Of Stepper Motor Controlled By 4 Bits Of 8051 P1.0 - P1.3; It Is Interfaced Using Darlington Arrays Such As Uln2003 As; 8051 Lacks Current To Run The Motor. So Uln2003 Is Used For Energizing Stator.; Program Below Shows Just Rotating The Motor Step Wise; But Step Width Is Unknown MOV A, #66H ; Load The Step Sequence BACK :MOV P1, A ; Load Sequence To Port RR A ; Change Sequence Rotate Clockwise ACALL DELAY : Wait For It SJMP BACK ; Now Keep Going DELAY :MOV R2, #100 H1 :MOV R3, #255 H2 :DJNZ R3, H2 DJNZ R2, H1 RET Step Angle: Step angle of the stepper motor is defined as the angle traversed by the motor in one step. To calculate step angle, simply divide 360 by number of steps a motor takes to complete one revolution. As we have seen that in half mode, the number of steps taken by the motor to complete one revolution gets doubled, so step angle reduces to half. As in above examples, Stepper Motor rotating in full mode takes 4 steps to complete a revolution, So step angle can be calculated as...Step Angle ø = 360° / 4 = 90°.And in case of half mode step angle gets half
  • 76. so 45°.So this way we can calculate step angle for any stepper motor. Usually step angle is given in the spec sheetof the stepper motor you are using. Knowing stepper motors step angle helps you calibrate the rotation of motor also to helps you move the motorto correct angular position.; This Other Program Code How In Same Interfacing To Rotate A Stepper Motor; 64 Degrees In Clockwise Direction Using 4 Step Sequence; It Takes Some Calculations; Consider A Motor With Step Angle 2 Degree; So Steps Per Revolution = 180; No Of Rotor Teeth = 45; Movement Per 4 Step Sequence is 8 Degrees; For 64 Degree Movement We Need To Send 8 Consecutive 4 Step Sequence; That Is It Will Cover 32 StepsORG 0000HMOV A, #66HMOV R1, #32H ; 32 Steps To Be TakenBACK :RR A ; Rotate ClockwiseMOV P1, A ;ACALL DELAY ;DJNZ R0, BACK ;ENDDELAY: MOV R2, #100 H1: MOV R3, #255 H2: DJNZ R3, H2 DJNZ R2, H1 RETResult: By applying step sequence in program rotate the motor in clock wise and anti clock wise direction.

×