jawaharlal nehru engineering collegejnec.org/lab-manuals/ect/te/part-ii/mpp_revised_1_ (1).pdf ·...
TRANSCRIPT
Jawaharlal N ehru E ngin eerin g Co llege
Laboratory Manual
MICROCONTROLLER & ADVANCED PROCESSOR
For
Third Year Students
Manual made by
Prof. Ms.S.D.Gavarskar
Prof.Ms. V.P.Yadav
Prof. P.B.Murmude
Author JNEC, Aurangabad
MGM’S
Jawaharlal Nehru Engineering CollegeN-6, CIDCO, Aurangabad
Department of Electronics &Telecommunication
Vision of the Department:
To develop GREAT technocrats and to establish centre of excellence in the field of
Electronics and Telecommunications.
▸ Global technocrats with human values
▸ Research and lifelong learning attitude,
▸ Excellent ability to tackle challenges
▸ Awareness of the needs of society
▸ Technical expertise
Mission of the Department:
1. To provide good technical education and enhance technical competency by
providing good infrastructure, resources, effective teaching learning process
and competent, caring and committed faculty.
2. To provide various platforms to students for cultivating professional attitude
and ethical values.
3. Creating a strong foundation among students which will enable them to pursue
their career choice.
Jawah arlal Nehru Engineering Co llege
Technical Document
This technical document is a series of Laboratory manuals of Electronics and TelecommunicationDepartment and is a certified document of Jawaharlal Nehru Engineering College. The care has beentaken to make the document error-free. But still if any error is found. Kindly bring it to the notice ofsubject teacher and HOD.
Recommended by,
HOD
Approved by,
Principal
Copies:
1. Departmental Library2. Laboratory3. HOD4. Principal
FOREWORD
It is my great pleasure to present this laboratory manual for third year engineering students for thesubject of Microcontroller and advanced processor keeping in view the vast coverage required forvisualization of concepts of processor.
As a student, many of you may be wondering with some of the questions in your mind regarding thesubject and exactly what has been tried is to answer through this manual.
Faculty members are also advised that covering these aspects in initial stage itself, will greatly relivedthem in future as much of the load will be taken care by the enthusiasm energies of the students oncethey are conceptually clear.
H.O.D.
LABORATO RY MANU AL CONT ENT S
This manual is intended for the Third year students of engineering branches in the subject ofMicrocontroller and advanced processors. This manual typically contains practical/Lab Sessions relatedProcessors covering various aspects related to the subject to enhance understanding.
Students are advised to thoroughly go through this manual rather than only topics mentioned in thesyllabus as practical aspects are the key to understanding and conceptual visualization of theoreticalaspects covered in the books.
Good Luck for your Enjoyable Laboratory Sessions
Prof. Ms.S.D.GAVARSKAR
Prof.Ms. V.P.Yadav
Prof. P.B.Murmude
SUBJECT INDEX
1. Do’s and Don’ts in the laboratory
2. Lab Experiments:
1. Any four programs on 8086 (MASM/ Debugger/Emulator).a. Addition of two 16 bit numberb. Subtraction of two 16 bit numberc. Find largest numberd. Average of two number
2. To Study 8051 assembler and simulator (Kiel)
3. To Examine flags and stack (Kiel)
4. To Simulate I/O ports (Kiel)
5. Program to exchange block on 8086.
6. Arithmetic operation IIa) Program for HEX and BCD add and subtract (8051kit)
7. Arithmetic operation IIa) Multiplication of two numbers(8051 kit)
b) Division of two numbers(8051 kit)
8. Program to test I\O ports(test LED interfacing)
9. The 8051 serial interface.
10. . Interfacing DAC and ADC to the 8051.
11. Interfacing stepper motor.
3. Quiz on the subject
4. Conduction of Viva-Voce Examinations
5. Evaluation and Marking System
DOs a nd DON’ TS in La bo ra to ry:
1. Do not handle any equipment before reading the instructions/Instruction manuals
2. Read carefully the power ratings of the equipment before it is switched on whether ratings 230V/50Hz or 115V/60 Hz. For Indian equipments, the power ratings are normally 230V/50Hz. If youhave equipment with 115/60 Hz ratings, do not insert power plug, as our normal supply is 230V/50 Hz,which will damage the equipment.
3. Observe type of sockets of equipment power to avoid mechanical damage
4. Do not forcefully place connectors to avoid the damage
5. Strictly observe the instructions given by the teacher/Lab Instructor
Instruction for Lab oratory Teachers::1. Submission related to whatever lab work has been completed should be done during the next lab
session.
2. The promptness of submission should be encouraged by way of marking and evaluation patterns thatwill benefit the sincere students.
Experiment no 1
Aim: Any four programs on 8086
Exercise a): Addition of two 16 bit nos
Aim: -Addition of two 16 bit numbers
Statement: - Write an 8086 based assembly language program to add two 16 bit nos stored at memory locations
Algorithm:
Initialize data segment
Assign CS as Code Segment and DS as data segment
Reserve memory for data and result
Enter data on reserved memory
Move first no to accumulator
Move second no to another register
Add the register to accumulator
Store result from accumulator to a memory location
Stop
Data: - Two 16 bit no's
Result: - Addition of two no's
Sample ProgramCODESEGMENT
ASSUME CS:CODE,DS: DATA
MOV AX, DATA
MOV DS, AX
MOV AX, NUM1
MOV BX, NUM2ADD AX, BX
MOV NUM3, AX
CODE ENDS
DATA SEGMENT
Initialize Data Segment
MOVE FIRST NO TO Acc MOVE SECOND NO TO REGISTER
ADDITION OF TWO NOS STORE THE RESULT
FIRST NO SECOND NO RESULT
NUM1 DW 1000H
NUM2 DW 2100H
NUM3 DW ?
DATA ENDSRESULT
CONCLUSIONThis program successfully added two 16 bit data and stored in memory defined by directives.
Experiment no. 1
Exercise b): Subtraction of two 16 bit nos
Aim: -Subtraction of two 16 bit numbers
Statement: - Write an 8086 based assembly language program to subtract two 16 bit nos stored at memory locations
Algorithm:
Initialize data segment
Assign CS as Code Segment and DS as data segment
Reserve memory for data and result
Enter data on reserved memory
Move first no to accumulator
Move second no to another register
Subtract the register to accumulator
Store result from accumulator to a memory location
Stop
Data: - Two 16 bit no's
Result: - Subtract of two no's
Sample ProgramCODE SEGMENT
ASSUME CS:CODE,DS DATA
MOV AX, DATA
MOV DS, AX
MOV AX, NUM1
MOV BX, NUM2
SUB AX, BX
MOV NUM3, AX
CODE ENDS
DATA SEGMENTInitialize Data Segment
MOVE FIRST NO TO Acc MOVE SECOND NO TO REGISTER
ADDITION OF TWO NOS STORE THE RESULT
FIRST NO SECOND NO RESULT
NUM1 DW 2100H
NUM2 DW 1000H
NUM3 DW ?
DATA ENDS
RESULT
CONCLUSION
This program successfully subtracts two 16 bit data and stored in memory defined by directives
Experiment no. 1
Exercise c): Finding the Largest No
Aim: - Find the largest no from given data of N bytes
Statement: - Write an 8086 based assembly language program to find the largest no from givendata of N bytes starting from 0100H & store largest no to location MAX at 0200H
Algorithm:
o Initialize data segment
o Assign CS as Code Segment and DS as data segment
o Reserve memory for data and result
o Assign BX to access offset of BLOCK
o Initialize counter in CX.
o Move 00H to accumulator.
o Compare accumulator with content in BLOCK
o If no is greater, carry will come, if not, means that no. is small and neglect that no. goto next Otherwise move that no to accumulator for further comparison.
o Increment BX Goto UP until CX becomes 0 11.Move the contents of accumulator i.e.largest no to location of MAX 10.Stop
Data: - DATA onwards 0100HResult: - Largest no at MAC i.e 0200H.
Sample ProgramCODE SEGMENT
ASSUME CS: CODE, DS: DATA
MOV AX, DATA
MOV DS, AX
MOV BX,OFFSET BLOCK1
MOV AL,00HUP: CMP AL[BX]
JNC NEXT
MOV AL,[BX]
NEXT: INC BX
LOOP UP MOV [MAX],AL
CODE ENDS
DATA SEGMENT
BLOCK DB 11H,21H,43H,32,H,22H
MAX DB ?
DATA ENDS
END
RESULT
MAX = NUM3=AL= 43H
CONCUSION
This program successfully finds largest number stored in memory defined by directives
Experiment no. 1
Exercise d): Average of two 16 bit nos
Aim: -Average of two 16 bit numbers
Statement: - Write an 8086 based assembly language program to find average of two 16 bit nos stored at memory locations
Algorithm:
Initialize data segment
Assign CS as Code Segment and DS as data segment
Reserve memory for data and result
Enter data on reserved memory
Move first no to accumulator
Move second no to another register
Add the register to accumulator
Divide by two
Store result from accumulator to a memory location
Stop
Data: - Two 16 bit no's
Result: - Average of two no's
Sample ProgramCODESEGMENT
ASSUME CS:CODE,DS: DATA
MOV AX, DATA
MOV DS, AX
MOV AX, NUM1MOV BX, NUM2
ADD AX, BX
MOV CX ,02 H
DIV CX
MOV NUM3, AX
CODE ENDS
DATA SEGMENT
Initialize Data SegmentMOVE FIRST NO TO Acc MOVE SECOND NO TO REGISTER
ADDITION OF TWO NOS STORE THE RESULT
FIRST NO SECOND NO RESULT
NUM1 DW 1000H NUM2 DW 2000H
NUM3 DW ?
DATA ENDS
CONCLUSIONThis program successfully calculates average of two 16 bit data and stored in memory defined by
directives
Experiment no. 2
Aim - To study of assembler/simulator of 8051 microcontroller using KEIL µVision 3 software.
Theory-
Assembler-
An assembler allows to you to writer program using MCU instructions. It is used where almost speed,small code size and exact hardware control is essential. The KEIL assembler translate symbolic assemblerlanguage mnemonics into executable machine code while supporting source level , symbolic debugger powerfulcapabilities like macro processing.
The assembler translates assembly source files into reloadable object modules and optionally createslisting files with symbol tables and cross reference details, complete line number, symbol type information iswritten to generate object files. This information allows exact display of program variables in your debugger.Line numbers are used for source level debugging at the other third party debugging tools.
KEIL assembler supports several different types of macro processors depending on architecture.Standard macro processor is easier macro processor to use. It allows you to define and use macros in yourassembly programs using syntax that is compatible with that used in many other assemblers. Macro processinglanguage at the MPL is a string replacement facility that is compatible with in ASM-51. Micro processor MPLhas several predefined macro processor. Macros save development and maintenance since common sequenceneed to be developed once.
Simulation-
Simulator mode configures the µvision debugger as software only product that accuratesimulates target systems including systems including instruction and on chip peripherals. This allowsapplication code testing before hardware is available and gives you several benefits for rapid, reliableembedded software development.
Simulation allows software testing on your desktop with no hardware environment. Early softwaredebugging on functional bases improves overall software reliability. Simulation allows break points that areimpossible with hardware debuggers. Simulation offers optimal inputs signals hardware debugger add extranoise. Single stepping through single processing algorithm is possible. External signal are stepped when CPUhalts. Failure entries that would destroy real hardware peripherals are easily chore.
KEIL Compiler-
The µvision IDE is the easiest way for the most developers to create embedded SIM programs. Tolaunch µvision click on your icon desktop at the selected KEIL µvision3 for start menu. The µvision screenprovides a menu bar that contains means of commands various tool bars that contains buttons for commoncommands and window that displays project details, source files, dialogue box, and other information ofcourse, multiple windows can be open simultaneously.
1. Menu Bar –
It provides access to most µvision commands including file operations, editor operations, project maintenancedevelopment tool setting program debugging, window selection and manipulation and online help.
2. File Menu –It includes commands that are open, save, print and close source files device database and license managerdialogs are accessed from this menu.
3. Edit Menu-It includes editing commands like undo, cut, copy, paste and indentation, bookmark functions advanced editor
functions, editor configuration.
4. View Menu-It includes commands that select which to do editor window and debugger window to display as well ascommands that configure window viewing options.
5. Project Menu-It includes commands that open, import, close project files. In addition project group and file options projectmore functions are accessed from this menu.
6. Debug Menu-It includes commands that start and stop depression, run the program, single step, half program executionmodify the program memory map. In addition commands are available to manage break points, setting tracerecording, enable execution profile analyzer and performance analyzer and manage debug.
7. Flash Menu –It include commands you use configure, program flash memory for embedded target system.
8. Peripheral Menu-It includes dialogues that display and allow you change on-chip peripheral settings. The content of this menuare failed to explain specific microcontroller you to do.
e.g. Dialogs are typically available for SIM configuration , interrupt , timer/counter general purpose
UART’s,
��2 C CAN, PWM real time clock watch dog
timers9. Tool Menu-
It allows you to configure and integrate your several third party utilities directly from µvisionIDE.
10. SVCS Menu-It allows you to configure and integrate your several third party µvision.
11. Window Menu-It includes arrange, split, select and close work space currently open bottom of menu.
12. Help menu-It includes lone help system, list peripherals, access requests to technical support , check for product uploadsdisplay product µvision.
TOOL BARS-
The µvision IDE incorporates several tool bars that contain buttons for most commonly used commands.
1. File tool bar contains buttons for commands used to edit source file.2. Build tool bar contains buttons for commands used to build target.3. Debug tool bar contains buttons for commands used in debugger.
Simulator and programmer for 8051-
A simulator is software to mimic a microcontroller operation with a Personal Computer. This helps inrunning the assembly language program off-line and debug for errors. This is also a powerful learning toolbefore actually working with a Microcontroller A programmer is hardware used to transfer the machine codeto the internal program memory of a microcontroller.
Working with KEIL Compiler µVision3-
KEIL Compiler µVision3 is a simulator/assembler for 8051 microcontroller to write and edit the codein assembly language, compile it and also to run the code. Output of the assembly language program can beverified using simulator.
Steps to use KEIL Compiler µVision3-
1. After installing the software, open8051 IDE2. To create new project, go to:
Project New Project Save project (save project without any extension) select Microcontroller.
3. To write the assembly code in the editor , go toFile New
4. After writing the assembly code in the editor, save the file with .asm extension.5. Then go to work space and right click on source group and then add saved file.
6. Then write click on the added file and select built option to check the errors.7. Check for the errors in the output window
View Output8. Once the error free code was made, debug the code.
Debug Start debug session
9. Debug options area. Step into – Each time only one instruction will be executed (single step mode).b. Run– To run the whole code at once.
10. Additional things:a. To view RAM, program memory, SFRs, and External memory, serial window, logic analyzer,
performance analyzer window use the option VIEW.b. To set break points in the code (where debugging stops at that point)
Debug Insert Break Point11. To stop the simulation
Debug Stop debug session
After checking the code in the simulator, the code (file with .HEX extension in Intel HEX format) is loadedinto Atmel 89C51 microcontroller using Universal Programmer. Although a separate 8051 assembly can beused at times assemble and generate Hex code for an assembly language program, KEIL CompilerµVision3 can perform that task.
Conclusion-
In this experiment we have understood how to create, debug and execute project using KEIL µvision 3.
Experiment no. 3
Aim: Examining flags and stacks.(Kiel)
Theory:
CPU Registers
These topics provide an overview of the CPU registers available on the x51 variants. In additionto the CPU registers R0 - R7, all x51 variants have an SFR space that is used to address on-chipperipherals and I/O ports. The SFR area includes the CPU registers SP (stack pointer), PSW (programstatus word), A (accumulator, accessed via the SFR space as ACC), B, DPL and DPH (16-bit registerDPTR).
8051 Variants
The classic 8051 provides 4 register banks of 8 registers each. These register banks are mappedinto the DATA memory area at address 0 – 0x1F. In addition the CPU provides a 8-bit A (accumulator)and B register and a 16-bit DPTR (data pointer) for addressing XDATA and CODE memory. Theseregisters are also mapped into the SFR space as special function registers.
Program Status Word (PSW)
The Program Status Word (PSW) contains status bits that reflect the current CPU state. The8051 variants provide one special function register called PSW with this status information. The 251provides two additional status flags, Z and N, that are available in a second special function registercalled PSW1.
PSW Register (all 8051 and 251 variants)
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
CY AC FO RS1 RS0 OV UD P
Additional PSW1 Register (on 251 Architecture only)
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
CY AC N RS1 RS0 OV Z —
The following table describes the status bits in the PSW:
RS1 RS0 Working Register Bank and Address0 0 Bank0 (D:0x00 - D:0x07)
0 1 Bank1 (D:0x08 - D:0x0F)1 0 Bank2 (D:0x10 - D:0x17)
1 1 Bank3 (D:0x18H - D:0x1F)Symbol Function
CY Carry flag
AC Auxiliary Carry flag (For BCD Operations)
F0 Flag 0 (Available to the user for General Purpose)
RS1,RS0
Register bank select:RS1 RS0 Working Register Bank and Address0 0 Bank0 (D:0x00 - D:0x07)0 1 Bank1 (D:0x08 - D:0x0F)1 0 Bank2 (D:0x10 - D:0x17)1 1 Bank3 (D:0x18H - D:0x1F)
0V Overflow flag
UD User definable flag
P Parity flag
— Reserved for future use (251 Only)
Z Zero flag (251 Only)
N Negative flag (251 Only)
Sample Code
MOV A,#02HMOV B,#25HMUL ABMOV R1,AMOV R2,BEND
RESULT
Conclusion: Thus we have examined flags and stack status.
Experiment no. 4
Aim: Simulating I/O ports (Keil).
Theory:
All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured asinputs or outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to beconnected to peripheral devices are available for use
PORT 0 :Port-0 can be used as a normal bidirectional I/O port or it can be used for address/data interfacing foraccessing external memory. When control is '1', the port is used for address/data interfacing. When thecontrol is '0', the port can be used as a bidirectional I/O port.
P O RT 0 as an I n put P o rt Let us assume that control is '0'. When the port is used as an input port, '1' is written to the latch. Inthis situation both the output MOSFETs are 'off'. Hence the output pin have floats hence whateverdata written on pin is directly read by read pin.
P O RT 0 as an O ut p ut P o r t Suppose we want to write 1 on pin of Port 0, a '1' written to the latch which turns 'off' the lower FETwhile due to '0' control signal upper FET also turns off as shown in fig. above. Here we wants logic '1' onpin but we getting floating value so to convert that floating value into logic '1' we need to connect thepull up resistor parallel to upper FET . This is the reason why we needed to connect pull up resistor toport 0 when we want to initialize port 0 as an output port.
PORT 1:Port-1 dedicated only for I/O interfacing. When used as output port, not needed to connect additionalpull-up resistor like port 0. It have provided internally pull-up resistor. The pin is pulled up or downthrough internal pull-up when we want to initialize as an output port. To use port-1 as input port, '1' hasto be written to the latch. In this input mode when '1' is written to the pin by the external device thenit read fine. But when '0' is written to the pin by the external device then the external source must sinkcurrent due to internal pull-up. If the external device is not able to sink the current the pin voltage mayrise, leading to a possible wrong reading.
PORT 2:It has 8-pins (P2.0-P2.7).Port-2 we use for higher external address byte or a normal input/output port.
The I/O operation is similar to Port-1. Port-2 latch remains stable when Port-2 pin are used for externalmemory access. Here again due to internal pull-up there is limited current driving capability.PORT 3:
Port-3 (P3.0-P3.7) having alternate functions to each pin,The internal structure of a port-3 pin is shownin fig below.
Following are the alternate functions of port 3:
It work as an IO port same like Port 2. only alternate function of port 3 makes its architecturedifferent than other ports.
Algorithm:
o Move data to accumulator.o Move data from accumulator to port 0, port 1 and port 2.o Delay subroutine.
o Move another data to accumulator.o Move data from accumulator to port 0, port 1 and port 2.
o Give delayo In delay subroutine initialize the counter.o Decrement count value until 0.
o stopSample code:
ASSEMBLY PROGRAMORG 0000HBACK: MOV A,#55H
MOV P0,AMOV P1,A MOV P2,AACALL DELAY MOV A,#0AAHMOV P0,A
MOV P1,A MOV P2,A ACALL DELAYSJMP BACK
DELAY: MOV R5,#11H3: MOV R4,#246H2: MOV R3,#255H1: DJNZ R3,H1
DJNZ R4,H2DJNZ R5,H3RET END
RESULT
Conclusion: Thus we simulate of I/O ports and observed simultaneously.
Experiment no. 5
Exchange contents-of BLOCK I with BLOCK2Aim: -Exchange contents of block 1 with block 2
Statement: - Write an 8086 based assembly language program to exchange contents of blockl with block2, Block 1 starts with 0100H and block 2 starts at 0200H
Algorithm
Initialize data segment
Assign CS as Code Segment and DS as data segment
Reserve memory for data and result
Assign BX to access offset of BLOCK 1
Assign SI to access offset of BLOCK2
Initalise counter in CX as many data bytes present in block
Move contents of AX in place of contents of BLOCK1
Increment BX
Increment SI
Loop until CX becomes 0
Stop
Data: - Block1 starts at 0100H and Block 2 starts at 0200H Result: - Exchanged the contents ofBlock 1 with Block 2
Sample ProgramCODE SEGMENT
ASSUME CS: CODE, DS: DATA
MOV AX, DATA
MOV DS, AX
MOV BX, OFFESET BLOCK1MOV SI, OFFSET BLOCK2
MOV CX, 04H
UP: MOV AL, [BX]
XCHG AL, [SI]
INC BX
INC SI
LOOP UP
CODE ENDS
DATA SEGMENT
BLOCK1 DB 01H,02H,03H,04HBLOCK2 DB 11H,22H,33H,44HDATA ENDS
END
RESULTBLOCK1 01H, 02H, 03H, 04HBLOCK2 11H, 22H, 33H, 44H
AFTER EXECUTIBLOCK1 01H,BLOCK2 11H,
ON02H,22H,
03H,33H,
04H44H
CONCLUSION
In this experiment content of block1 exchanged with block2, it is verified.
Experiment no. 6
Arithmetic operation I (8051kit)
Exercise a): Addition of two 16 bit hex numbers.
Aim: Arithmetic operation II (HEX and BCD add and subtract)
Statement: write an 8051 based assembly language program for HEX and BCD addition subtraction.
Algorithm:
HEX Addition
1. Move first number to a register.
2. Move second number to another register.
3. Add two registers.
4. Stop
HEX Subtraction
1. Move first number to a register.
2. Move second number to another register.
3. Subtract two registers.
4. Stop
BCD addition
1. Move first number accumulator.2. Add immediate value into accumulator.3. Adjust decimal in accumulator.4. Stop
BCD subtraction
1. Move first number accumulator.
2. Subtract with carry immediate value from accumulator.3. Adjust decimal in accumulator.4. Stop
I) Arithmetical operations:i) 8 bit additionSample code MOV A,#02MOV B,#02ADD A,BRET
OUTPUT:
Input Output
REGISTER Data REGISTER DataA 02 A 04
B 02
ii) 8 bit subtraction
MOV A,#04MOV B,#02SUBB A,BRET
OUTPUT:Input Output
REGISTER Data REGISTER Data
A 04 A 02
B 02
iii) BCD addition
MOV A, #9ADD A, #11;
DA A;
ENDiii) Subtraction
MOV A, #9SUBB A, #11;DA A;
END
Conclusion:
This experiment performs HEX and BCD addition successfully and result is verified.
Experiment no. 7
ARITHMATIC OPERATION II
Exercise a): Division of a 16 bit number and 8 bit number
Aim: -Division of two 16 bit numbers
Statement: - Write an 8086 based assembly language program to Divide 16 bit no by 8 bit no stored at memory location.
Algorithm:
Initialize data segment
Assign CS as Code Segment and DS as data segment
Reserve memory for data and result
Enter data on reserved memory
Move first no to accumulator
Move second no to another register
Divide accumulator by register
Store result from accumulator to a memory location
Stop
Data: - 16 bit no and 8 bit no.
Result: - Division of two no's
Sa m p l e p ro gra m :
7208,09 E5,20 MOV A,0F0H A=B720A,0B F5,21 MOV 21H,A 21H=Aa720C 22 RET Stop
Experiment no. 7
Exercise b): Multiplication of 16 bit no. by 8 bit no.
Aim: -Division of two 16 bit numbers
Statement: - Write an 8086 based assembly language program to multiply 16 bit no by 8 bit no stored at memory location.
Algorithm:
Initialize data segment
Assign CS as Code Segment and DS as data segment
Reserve memory for data and result
Enter data on reserved memory
Move first no to accumulator
Move second no to another register
Multiply accumulator by register
Store result from accumulator to a memory location
Stop
Data: - 16 bit number and 8 bit number.
Result: - Multiplication of two number
Sa m p l e p ro gra m :
Conclusion:-
This experiment performs multiplication and division of 16 bit and 8 bit data, and result isverified.
Experiment no. 8
Aim: - Program to test I\O ports
a)To write a program to interface LED to 8051 kit
Statement: - Interface LED to 8051 kit and make it blink on and off.
Algorithm:
Initialize with address 6500h
Initialize accumulator with 00h
Move output data on port 1
Call delay
Complement accumulator
Move output data on port 1
StopResult: Blinking of LED.
Sample program:Memoryaddress
op code label Mnemonics Comments
6500 ORG 6500H
6500 74,00 MOV A, #00H ACC=00H
6502 F5,90 MOV 90H,A Output data of accumulator on port 1
6504 79,03 LOOP MOV R1,#03H R1=03h
6506 7A,FF MOV R2,#0FFH R2=FFh
6508 12,01,14 LCALL DELAY Call delay
650B F4 CPL A Complement accumulator
650C F5,90 MOV 90H,A Output data of accumulator on port 1
650E 80,F4 SJMP LOOP Continue.
Conclusion: Thus we have studied testing of I/O ports, program for LED interfacing and verified itsuccessfully.
Experiment no. 9
Aim: - The 8051 serial interface
Statement: - Write a assembly language program to transfer the data serially.
Algorithm:-o Select timer mode in TMOD register.o Select baud rate for transmission.o Select serial communication mode in SCON register.o Start timer.o Select maximum number of characters to send.o Move first character into data pointer.o Clear accumulator.o Move first character into accumulator.o Move that character into SBUF register.o Transfer first character.o Observe transfer interrupto Clear TI flag.o Increment data pointer for next character.o Repeat the process until all characters are transfer.o Stop
Theory:-
Ser ial Data Input/ Output
Computers must be able to communicate with other computers in modern multiprocessor distributedsystems. One cost-effective way to communicate is to send and receive data bits serially. The 8051 hasa serial data communication circuit that uses register SBUF to hold data. Register SCON controls datacommunication, register PCON controls data rates, and pins RXD (P3.0) and TXD (P3.1) connect to theserial data network.
SBUf is physically two registers. One is write only and is used to hold data to be transmitted out of the8051 via TXD. The other is read only and holds received data from external sources via RXD. Bothmutually exclusive registers use address 99h.
There are four programmable modes for serial data communication that are chosen by setting the SMXbits in SCON. Baud rates are determined by the mode chosen.
Ser ial Data Interr upts
Serial data communication is a relatively slow process, occupying many milliseconds per data byte toaccomplish. In order not to tie up valuable processor time, serial data flags are RI & TI.
SC O N Fun ct ion Regi s te r s
TH E SERI A L P O RT C O N T ROL ( SC O N ) SP EC I AL F U NC T I O N R E G I S T E R Bit symbol Function7 SM0 Serial port mode bit 0. Set/cleared by program to select mode.6 SM1 Serial port mode bit 1. Set/cleared by program to select mode.
SM0 SM1 ModeDescription0 0 0 Shift register; baud = f/120 1 1 8-bit UART; baud = variable1 0 2 9-bit UART; baud = 1/32 or f/641 1 3 9-bit UART; baud = variable
5 SM2 Multiprocessor communications bit. Set/cleared by program to enable multiprocessor communications in modes 2 and 3. When set to 1 an interrupt is generated if bit 9 of the received data is a 1; no interrupt is generated if bit 9 is a0. If set to 1 for mode 1, no interrupt will be generated unless a valid stop bit isreceived. Clear to 0 if mode 0 is in use.
4 REN Receive enable bit. Set to 1 to enable reception; cleared to 0 to dissable reception.3 TB8 Transmitted bit B. Set/cleared by program in modes 2 and 3.2 RB8 Received bit B. Bit B of received data in modes 2 and 3; stop bit in mode 1. Not used
in
mode 0.1 T1 Transmit interrupt flag. Set to one at the end of bit 7 time in mode 0, and at the
beginning
of the stop bit for other modes. Must be cleared by the program.0 R1 Receive interrupt flag. Set to one at the end of bit 7 time in mode 0, and halfway
through the stop bit for other modes. Must be cleared by the program.
Sample program:-
MOV TMOD,#20H
MOV TH1,#0FAH
MOV SCON,#50H
SETB TR1
MOV R1,#15
BACK:MOV DPTR,#MYDATA
NEXT:CLR A
MOVC A , @ A +D P T R
MOV SBUF,A
HERE: JNB TI, HERE
CLR TI
INC DPTR
DJNZ R1,NEXT
SJMP BACK
MYDATA: DB " HAVE A NICE DAY 0"
STOP: SJMP STOP
END
Result
Conclusion:-
In this experiment we have successfully transfer data serially.
Experiment No 10
ADC 0808/0809 INTERFACING WITH 8051
AIM:To interface ADC with 8051 to generate digital output by giving an analog input voltage.
APPARATUS REQUIRED;8051 Trainer KitADC Interface BoardThis 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.
PROGRAM:MOV DPTR, #2023MOV A, #90: PA-I/P PORT, PORT B, C-O/P PORTSMOVX @ D P T R, ABEGIN: MOV DPTR, #2022; Select CH-0MOV A, #00MOVX @ D P T R, A
MOV A, #0DH; Set PC6 (OE)MOV DPTR, #2023MOVX @ D P T R, AMOV A, #0FH; SET SOCMOVX @ D P T R, ALCALL DELAY MOV A, #0EH MOVX @ D P T R, AMOV A, #0CH MOVX @ D P T R, AMOV DPTR, #2020BACK: MOVX A , @ D P T RJB 0E7, BACKMOV DPTR, #2020REP: MOVX A , @ D P T RANL A, #80HJNB 0E7, REPMOV A, #0DHMOV DPTR, #2023MOVX @ D P T R, A MOV DPTR, #2020MOVX A , @ D P T RMOV DPTR, #9000H; Read the digital output from this addressMOVX @ D P T R, ASJMP BEGINDELAY: MOV R3, #30HAGAIN: MOV R4, #FFHBACK: NOPNOPDJNZ R4, BACK DJNZ R3, AGAINRETResult
Analog input voltage converted into its digital equivalent.
Conclusion-
ADC (0809) successfully interfaced with 8051 microcontroller using 8255.
Experiment No 11
Aim- Stepper motor interfacing with 8051
Statement- Interface stepper motor with 8051 microcontroller.
Theory-STEPPER MOTOR
A stepper motor is a brushless, synchronous electric motor that converts digital pulses intomechanical shaft rotation. Every revolution of the stepper motor is divided into a discrete number ofsteps, and the motor must be sent a separate pulse for each step.
INTERFACING STEPPER MOTOR
Fig. 1 shows how to interface the Stepper Motor to microcontroller. As you can see the steppermotor is connected with Microcontroller output port pins through a ULN2803A array. So when themicrocontroller is giving pulses with particular frequency to ls293A, the motor is rotated in clockwise oranticlockwise;
Interfacing Diagram-
Result-
The stepper motor will rotate in steps as per given angle.
3. Quiz on the Subject1).The advantages of assembly level programming isA) flexibility of programming is more B) chances of error are lessC) debugging is easy D) all of the mentioned
2). The coded object modules of the program to be assembled are present inA) .ASM file B) .OBJ fileC) .EXE file D) .OBJECT file
3). The directory that is under work must have the files that are related toA) Norton’s editor B) AssemblerC) Linker D) all of the mentioned
4). The listing file containsA) total offset map of source file B) offset address and labelsC) memory allotments for different labels D) all of the mentioned
5). The disadvantage of machine level programming is A) time consuming B) chances of error are moreC) debugging is difficult D) all of the mentioned
6). A part of memory that can be addressed by more than one processor for communication is known asA) memory module B) bus windowC) RAM D) memory management unit
7). When a subprocessor wants to communicate with the bus window, it informs the main processor toA) enable control buffer B) storage bufferC) disable tristate buffer D) translation look aside buffer
8). For MEMR(active low) and MEMWR(active low) operations the mode of isolation buffer shouldrespectively be inA) receiver mode, receiver mode B) transmit mode, receiver modeC) receiver mode, transmit mode D) transmit mode, transmit mode
9). The complete software system is divided intoA) main program B) IRT2 for first sub processing the unitC) Interrupt routine IRT3 for first sub processing the unit D) all of the mentioned
10). The EXE files should not exceed the size ofA) 30 KB B) 50 KBC) 60 KB D) 40 KB
11. To initialise any port as an output port what value is to be given to it?a) 0xFF b) 0x00c) 0x01 d) A port is by default an output port
12. Which out of the four ports of 8051 needs a pull-up resistor for using it is as an input or an outputport?a) PORT 0 b) PORT 1 c) PORT 2 d) PORT 3
13. Which of the ports act as the 16 bit address lines for transferring data through it?a) PORT 0 and PORT 1 b) PORT 1 and PORT 2 c) PORT 0 and PORT 2 d) PORT 1 and PORT 3
14. Which of the following registers are not bit addressablea) SCON b) PCONc) A d) PSW
15. Which instruction is used to check the status of a single bit?a) MOV A,P0 b) ADD A,#05Hc) JNB PO.0, label d) CLR P0.05H
16. Which addressing mode is used in pushing or popping any element on or from the stack?a) immediate b) directc) indirect d) register
17. Which operator is the most important while assigning any instruction as register indirect instruction?a) $ b) #
c) @ d) &
18. What is the advantage of register indirect addressing mode?a) it makes use of registers R0 and R1 b) it uses the data dynamicallyc) it makes use of operator @ d) it is easy
19. Which of the following comes under indexed addressing mode?a) MOVX A, @ D P T R b) MOVC @ A +D P T R,Ac) MOV A,R0 d) MOV @ R0,A
20. Is this a valid statement ?SETB Aa) yes b) noc) cant be determined d) none of the mentioned
4. Conduction of VIVA-VOCE Examinations: -
Teacher should conduct oral exams of the students with full preparation. Normally the objectivequestions with guess are to be avoided. To make it meaningful, the questions should be such that depthof the student in the subject is tested. Oral Exams are to be conducted in co-cordial situation.Teachers taking oral exams should not have ill thoughts about each other & courtesies should be offeredto each other in case of opinion, which should be critically suppressed in front of the students.
5. Evaluation and marking system: -
Basic honesty in the evaluation and marking system is essential and in the process impartial nature of theevaluator is required in the exam system. It is a primary responsibility of the teacher to see that rightstudents who really put their effort &intelligence are correctly awarded.
The marking pattern should be justifiable to the students without any ambiguity and teacher should seethat students are faced with just circumstance.
Quiz answers:
1).The advantages of assembly level programming isA) flexibility of programming is more B) chances of error are lessC) debugging is easy D) all of the mentioned
Ans.D
2). The coded object modules of the program to be assembled are present inA) .ASM file B) .OBJ fileC) .EXE file D) .OBJECT file
Ans.B
3). The directory that is under work must have the files that are related toA) Norton’s editor B) AssemblerC) Linker D) all of the mentioned
Ans.D
4). The listing file containsA) total offset map of source file B) offset address and labelsC) memory allotments for different labels D) all of the mentioned
Ans.D
5). The disadvantage of machine level programming is A) time consuming B) chances of error are moreC) debugging is difficult D) all of the mentioned
Ans.D
6). A part of memory that can be addressed by more than one processor for communication is known asA) memory module B) bus windowC) RAM D) memory management unit
Ans.B
7). When a subprocessor wants to communicate with the bus window, it informs the main processor toA) enable control buffer B) storage bufferC) disable tristate buffer D) translation look aside buffer
Ans.C
8). For MEMR(active low) and MEMWR(active low) operations the mode of isolation buffer shouldrespectively be inA) receiver mode, receiver mode B) transmit mode, receiver modeC) receiver mode, transmit mode D) transmit mode, transmit modeAns.C
9). The complete software system is divided intoA) main program B) IRT2 for first sub processing the unitC) Interrupt routine IRT3 for first sub processing the unit D) all of the mentioned
Ans.D
10). The EXE files should not exceed the size ofA) 30 KB B) 50 KBC) 60 KB D) 40 KB
Ans.B
11. To initialise any port as an output port what value is to be given to it?a) 0xFF b) 0x00c) 0x01 d) A port is by default an output portAnswer: d
12. Which out of the four ports of 8051 needs a pull-up resistor for using it is as an input or an outputport?a) PORT 0 b) PORT 1c) PORT 2 d) PORT 3Answer: a13. Which of the ports act as the 16 bit address lines for transferring data through it?a) PORT 0 and PORT 1 b) PORT 1 and PORT 2 c) PORT 0 and PORT 2 d) PORT 1 and PORT 3
14. Which of the following registers are not bit addressablea) SCON b) PCONc) A d) PSW
Answer: b15. Which instruction is used to check the status of a single bit?a) MOV A,P0 b) ADD A,#05Hc) JNB PO.0, label d) CLR P0.05H Answer: c16. Which addressing mode is used in pushing or popping any element on or from the stack?
a) immediate b) direct
c) indirect d) registerAnswer: b17. Which operator is the most important while assigning any instruction as register indirect
instruction?a) $ b) #c) @ d) & Answer: c18. What is the advantage of register indirect addressing mode?a) it makes use of registers R0 and R1 b) it uses the data dynamicallyc) it makes use of operator @ d) it is easyAnswer: b19. Which of the following comes under indexed addressing mode?a) MOVX A, @ D P T R b) MOVC @ A +D P T R,Ac) MOV A,R0 d) MOV @ R0,AAnswer: b.20. Is this a valid statement ?SETB Aa) yes b) noc) cant be determined d) none of the mentioned
Answer: b