MC Manual
MC Manual
MC Manual
Laboratory Manual
Microcontrollers Lab
Subject code: ECL401
SE, Semester – IV
(R-2019-C-Scheme)
LIST OF EXPERIMENTS
Course Name : Microcontroller lab
Course Code : ECL401
Class : SE
Semester : IV (REV- 2019)
6
Transfer of data bytes between internal & external memory
VISION
MISSION
M2 To provide an ambience which nurtures research ideas and initiate project based learning
in futuristic domains of Electronics & Telecommunication Engineering.
PROGRAM OUTCOMES(POs)
PO12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
PSO1: Able to embed the ability to apply the fundamentals of Electronics & Telecommunication
Engineering to various areas like Analog Circuits, Communication systems, Signal
processing,
Data Analytics, Embedded systems, VLSI, RF and Microwave Circuits.
PSO2: Able to design and analyze complex Electronics & Telecommunication Engineering
problems
using modern hardware and software tools to implement optimized solutions for variety of
applications.
PEO-2: To produce researcher who have clear thinking, articulation and interest to carry out
theoretical and/or applied research resulting in significant advancement in the field of
specialization.
PEO-4: To develop the ability among students to synthesize data and technical concepts from
applications to product design with ethical attitude, commitment to social
responsibilities and
environment consciousness.
Course objectives:
Course outcomes:
General Instructions
1. Use of mobile phones, TAB is strictly prohibited.
using.
CERTIFICATE
______________________ __________________
STAFF MEMBER INCHARGE HEAD OF DEPARTMENT
_______________
PRINCIPAL
(SEAL)
Practical Scheme
MOV A, #20H
This instruction uses Immediate Addressing because the Accumulator will be loaded with the value
that immediately follows; in this case 20 (hexadecimal). Notice that the immediate data must be
preceded by the pound sign, ―#‖. This addressing mode can be used to load information into any of
the registers, including the DPTR register as shown in the following examples:
Notice that we can also use immediate addressing mode to send data to 8051 ports. For example,
―MOV P1, #55H‖ is a valid instruction.
Immediate addressing is very fast since the value to be loaded is included in the instruction. However,
since the value to be loaded is fixed at compile-time it is not very flexible.
2.2 Register Addressing Mode
Register addressing mode involves the use of registers to hold the data to be manipulated. Examples
of register addressing mode are shown below:
It should be noted that the source and destination registers must match in size. In other words, coding
“MOV DPTR, A” will give an error, since the source is an 8-bit register and the destination is a16-bit
register.
Notice that we can move data between the accumulator and Rn (for n = 0 to 7) but movement of data
between "R" registers is not allowed. For example, the instruction “MOV R4, R7″ is invalid
MOV A, 30H
This instruction will read the data out of Internal RAM address 30 (hexadecimal) and store it in the
Accumulator. Further examples of the direct addressing mode are shown below:
Direct addressing is generally fast since, although the value to be loaded isn't included in the
instruction, it is quickly accessible since it is stored in the 8051s Internal RAM. It is also much more
flexible than Immediate Addressing Mode since the value to be loaded is whatever is found at the
given address. Also, it is important to note that when using direct addressing any instruction which
refers to an address between 00H and 7FH is referring to Internal Memory. Any instruction which
refers to an address between 80H and FFH is referring to the SFR control registers that control the
8051 microcontroller itself. For example, the instruction MOV 0E0,#30H is equivalent to MOV
A,#30H.
This instruction causes the 8051 to analyze the value of the R0 register. The 8051 will then load the
accumulator with the value from Internal RAM which is found at the address indicated by R0.
If the data is inside the on-chip RAM, only registers R0 and R1 are used as pointers. In other words,
R2 – R7 cannot be used to hold the address of an operand located in RAM when using this addressing
mode.
Indirect addressing mode always refers to Internal RAM; it never refers to an SFR.
2.5 External Indirect Addressing Mode
In addition to its code memory, the 8051 family also has 64K bytes of data memory space. In other
words, the 8051 has 128K bytes of address space of which 64K bytes are set aside for program code
and the other 64K bytes are set aside for data. Program space is accessed using the program counter
(PC) to locate and fetch instructions, but the data memory space is accessed using the DPTR register
and an instruction called MOVX, where X stands for external (meaning that the data memory space
must be implemented externally).
This method of addressing is used to access data stored in external data memory. There are only two
commands that use external indirect addressing mode:
MOVX A, @DPTR MOVX @DPTR, A
As you can see, both commands utilize DPTR. In these instructions, DPTR must first be loaded with
the address of external memory that you wish to read or write. Once DPTR holds the correct external
memory address, the first command will move the contents of that external memory address into the
Accumulator. The second command will do the opposite: it will allow you to write the value of the
Accumulator to the external memory address pointed to by DPTR.
2.6 Indexed Addressing Mode
Indexed addressing mode is widely used in accessing data elements of look-up table entries located in
the program ROM space of the 8051. The instruction used for this purpose is:
“MOVC A, @A+DPTR”
The 16-bit register DPTR and register A are used to form the address of the data element stored in on-
chip ROM. Because the data elements are stored in the program (code) space ROM of the 8051, the
instruction MOVC is used instead of MOV. The ―C‖ means code. In this instruction the contents of A
are added to the 16-bit register DPTR to form the 16-bit address of the needed data.
One major difference between the code space and data space is that, unlike code space, the data space
LABORATORY: MICROPROCESSOR AND MICROCONTROLLER LAB
(Permanently Affiliated to University of Mumbai)
Department of Electronics and Telecommunication Engineering
it is not, the CPU starts to fetch and execute instructions from the address of the label. If C = 1, it will
not jump but will execute the next instruction below JNC.
3.11 JC (Jump if carry)
In the JC instruction, if C = 1 it jumps to the target address. On the other hand if no carry occurs, the
processor will execute the next instruction below JC.
3.12 The CJNE Instruction
The CJNE (Compare and jump if not equal) instruction is used to compare the content of a general
purpose register with a certain value or direct memory location and jump to a certain address if the two
value are not equal. The syntax of the instruction is:
CJNE destination, source, label
The destination can be register A or the bank registers (R0-R7), and the source may be an immediate
value or a direct memory address.
3.13 The CLR Instruction
The CLR instruction is used to clear the content of the accumulator. It is a one byte logic instruction,
which has the syntax CLR A.
3.14 The CPL Instruction
The CPL (Complement) instruction is a one byte logic instruction that is used to complement (negate)
the bits of register A. After execution of this instruction, bits 1 in register A become 0 and vice versa.
It takes the syntax CPL A. It can also be used as a bitwise instruction to complement a bit.
3.15 The NOP Instruction
The NOP (No operation) instruction does not do anything. It is used only for making desired delays in
the programs.
When executing the instruction ―MOV R3, #COUNT‖, the register R3 will be loaded with the value
25 (notice the # sign). What is the advantage of using EQU? Assume that there is a constant (a fixed
value) used in many different places in the program, and the programmer wants to change its value
throughout. By the use of EQU, the programmer can change it once and the assembler will change all
of its occurrences, rather than search the entire program trying to find every occurrence
LABORATORY: MICROPROCESSOR AND MICROCONTROLLER LAB
(Permanently Affiliated to University of Mumbai)
Department of Electronics and Telecommunication Engineering
4.4 END
Another important pseudo instruction is the END directive. This indicates to the assembler the end of
the source (asm) file. The END pseudo instruction is the last line of an 8051 program, meaning that in
the source code anything after the END directive is ignored by the assembler.
A given Assembly language program (see Figure 1) is a series of statements, or lines, which are either
Assembly language instructions such as ADD and MOV, or statements called pseudo instructions.
While instructions tell the CPU what to do, pseudo-instructions (also called directives) give directions
to the assembler. For example, in the above program while the MOV and ADD instructions are
commands to the CPU, ORG and END are directives to the assembler. ORG tells the assembler to place
the opcode at memory location 0 while END indicates to the assembler the end of the source code.
In other words, one is for the start of the program and the other one for the endof the program.
Brackets indicate that a field is optional, and not all lines have them. Brackets should not be typed in.
Regarding the above format, the following points should be noted.
1. The label field allows the program to refer to a line of code by name. The label field cannot
exceed a certain number of characters. Check your assembler for the rule.
2. The Assembly language mnemonic (instruction) and operand(s) fields together perform the real
work of the program and accomplish the tasks for which the program was written. In Assembly
language statements such as
ADD A, R5
MOV A,#0
ADD and MOV are the mnemonics, which produce op-codes; and ―A, R5‖ and ―A, #0″ are the
operands. Instead of a mnemonic and an operand, these two fields could contain assembler pseudo-
instructions. Remember that pseudo-instructions do not generate any machine code (opcode) and are
used only by the assembler, as opposed to instructions that are translated into machine code (opcode)
for the CPU to execute. In Figure 1, the commands ORG (origin) and END are examples of pseudo-
instructions (some 8051 assemblers use .ORG and .END).
3. The comment field begins with a semicolon comment indicator ―;‖. Comments may be at the
end of a line or on a line by themselves. The assembler ignores comments, but they are
indispensable to programmers. Although comments are optional, it is recommended that they
be used to describe the program and make it easier for someone else to read and understand, or
for the programmers to remember what they wrote.
4. Notice the label ―HERE‖ in the label field in Figure 1. Any label referring to an instruction
must be followed by a colon symbol, ―:‖. In the SJMP (short jump instruction), the 8051 is
told to stay in this loop indefinitely. If your system has a monitor program you do not need this
line and it should be deleted from your program.
5.1 Rules for Labels in Assembly Language Programs
By choosing label names that are meaningful, a programmer can make a program much easier to read
and maintain. There are several rules that names must follow. First, each label name must be unique.
The names used for labels in Assembly language programming consist of alphabetic letters in both
uppercase and lowercase, the digits 0 through 9, and the special characters question mark (?), period
(.), at (@), underline (_), and dollar sign ($). The first character of the label must be an alphabetic
character. In other words it cannot be a number. Every assembler has some reserved words that must
not be used as labels in the program. Foremost among the reserved words are the mnemonics for the
instructions. For example, ―MOV‖ and ―ADD‖ are reserved since they are instruction mnemonics. In
addition to the mnemonics there are some other reserved words depending on the specific assembler
to be used.
5.2 Assembling an 8051 Program
The assembler is used to create a ready to run machine code file in HEX format from the entered source
code file. This generated HEX file will be burned into the program ROM of the microcontroller to do
a specific task. There are many commercial 8051 assemblers that can perform
the assembly process. The ASEM-51 assembler will be used in our lab for producing the object files
of the written assembly programs. The entered source file (asm file) should be written using an editor
like the MS-DOS EDIT program, or the windows Notepad editor. The ASEM-51 assembler will
generate two output files, the list file and the machine code HEX file as shown in Figure 2. The list
file is very useful to the programmer because it lists all the opcodes and addresses as well as errors that
the assembler may detect. The programmer uses the list file to find syntax errors in order to generate
the required HEX file. This file can be accessed by an editor and displayed on the monitor.
The source code file is created from the command prompt window after changing the path into the
ASEM51 folder containing the assembler program. To change the path into the directory ASEM51,
type the following command from the root directory:
C:\>CD ASEM51
C:\ASEM51>
In order to print the source file (mycode.asm), type the following command:
C:\ASEM51>notepad mycode.asm
Or you can use the MS-DOS EDIT program as follows:
C:\ASEM51>EDIT mycode.asm
After typing and saving the source code file, it should then be assembled by typing the command
below:
C:\ASEM51>ASEM mycode.asm
If the source file is free of syntax errors, the assembler will generate the HEX file in addition to the
list file. Otherwise, the syntax errors can be detected by displaying the list file as shown below:
C:\ASEM51>EDIT mycode.lst
To list all the created files on the screen, type the following command:
C:\ASEM51>DIR mycode.*
First, we examine the list file of the sample program presented in Figure 1 and how the code is placed
in the ROM of an 8051 chip. As we can see, the opcode and operand for each instruction are listed on
the left side of the list file as shown in Figure
After the program is burned into ROM of an 8051 family member such as 8751 or AT8951 or 87C52,
the opcode and operands are placed in ROM memory locations starting at 0000 as shown in the list
below in Figure
The list shows that address 0000 contains 7D, which is the opcode for moving a value into register R5,
and address 0001 contains the operand (in this case 25H) to be moved to R5. Therefore, the
instruction “MOV R5,#25H” has a machine code of “7D25″, where 7D is the opcode and 25 is the
operand. Similarly, the machine code “7F34″ is located in memory locations 0002 and 0003 and
represents the opcode and the operand for the instruction “MOV R7,#34H”. In the same way,
machine code “7400″ is located in memory locations 0004 and 0005 and represents the opcode and
the operand for the instruction “MOV A, #0″. The memory location 0006 has the opcode of 2D, which
is the opcode for the instruction “ADD A, R5″ and memory location 0007 has the content 2F, which is
the opcode for the “ADD A, R7″ instruction. The opcode for the instruction “ADD A, #12H”is located
at address 0008 and the operand 12H at address 0009. The memory location 000A hasthe opcode for
the SJMP instruction and its target address is located in location 000B.
EXPERIMENT NUMBER 01
Introduction to 8051 & KEIL µVision
EXPERIMENT NAME Software
DATE OF PERFORMANCE
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
EXPERIMENT NO. 1
Introduction to 8051 & KEIL µVision Software
INTRODUCTION
Earlier to Microcontrollers, Microprocessors were greatly used for each and every purpose.
Microprocessors were containing ALU, general purpose register, stack pointer, program counter,
clock counter and so many other features which the today‘s Microcontroller also possesses. But
the difference between them exists with respect to the number of instructions, access times, size,
reliability, PCB size and so on.
Microprocessor contains large instruction set called as CISC processor whereas Microcontroller
contains less number of instructions and is called as RISC processor. The access time is less in
case of microcontrollers compared to microprocessors and the PCB size reduces in case of
microcontrollers.
There are many versions of microcontrollers 8051, 80528751, AT8951 from Atmel Corporation
and many more. In this manual we will study about the 8051 architecture, its features,
programming and interfacing.
MCS 8051 is an 8-bit single chip microcontroller with many built-in functions and is the core for
all MCS-51 devices.
PINOUT DESCRIPTION
Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.
Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most registers.
In other words, the positive voltage on this pin resets the microcontroller. By applying logiczero to this
pin, the program starts execution from the beginning.
LABORATORY: MICROPROCESSOR AND MICROCONTROLLER LAB
(Permanently Affiliated to University of Mumbai)
Department of Electronics and Telecommunication Engineering
Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides,
all of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication
output.
Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication
clock output.
Pin 12: INT0 Interrupt 0 input.
Pin 13: INT1 Interrupt 1 input.
Pin 14: T0 Counter 0 clock input.
Pin 15: T1 Counter 1 clock input.
Pin 16: WR Write to external (additional) RAM.
Pin 17: RD Read from external RAM.
Pin 18, 19: X2 X1 Internal oscillator input and output. A quartz crystal which specifies operating
frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also be
used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz up to
over 50 Hz.
Pin 20: GND Ground.
Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured
as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-
A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means
that not all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it every
time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address byte
(A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external
register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and uses it as a
memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0
is now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional
(and cheap) integrated circuit. In other words, this port is used for both data and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission
with no regard to whether there is internal memory or not. It means that even there is a program written
to the microcontroller, it will not be executed. Instead, the program written to external ROM will be
executed. By applying logic one to the EA pin, the microcontroller will use both memories, first internal
then external (if exists).
Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general
inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven
high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40: VCC +5V power supply.
4. Create a source file (using File->New), type in the assembly or C program and save this
(filename.asm/filename.c) and add this source file to the project using either one of the
following two methods. (i) Project->Manage->Components, Environment Books-
>addfiles-> browse to the required file -> OK ―OR‖ ii) right click on the Source Group
in the Project Window and the Add Files to Group option.
5. Set the Target options using -> Project – Options for Target opens the μvision
Options for Target – Target configuration dialog. Set the Xtal (Crystal frequency)
frequency as 11.0592 MHz, and also the Options for Target – Debug – use either
Simulator / Keil Monitor- 51 driver.
6. If Keil Monitor- 51 driver is used click on Settings -> COM Port settings select the
COM Port to which the board is connected and select the baud rate as 19200 or 9600
(recommended). Enable Serial Interrupt option if the user application is not using on- chip
UART, to stop program execution.
7. Build the project; using Project -> Build Project. application and links. Any errors
in the code are indicated by – ―Target not created‖ in the Build window, along with the
error line. Debug the errors. After an error free, to build go to Debug mode.
8. Now user can enter into Debug mode with Debug- Start / Stop Debug session dialog.
Or by clicking in the icon.
9. The program is run using the Debug-Run command & halted using Debug-Stop
Running. Also the (reset, run, halt) icons can be used. Additional icons are
(step, step over, and step into, run till cursor).
10. If it is an interface program the outputs can be seen on the LCD, CRO, motor, led
status, etc. If it is a part-A program, the appropriate memory window is opened using View
-> memory window (for data RAM & XRAM locations), Watch window (for timer
program), serial window, etc.
11. Note: To access data RAM area type address as D: 0020h. Similarly to access the
DPTR region (XRAM-present on chip in AT89C51ED2) say 9000h location type in X:
09000H.
Result:
Result:
EXPERIMENT NUMBER 02
To simulate two 8-bit number addition,
subtraction using immediate, direct and
EXPERIMENT NAME
indirect addressing modes.
DATE OF PERFORMANCE
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Theory:
Program:
Program:
ORG 00H // This is used to set the register address during assembly. MOV
A, #05H// load #05h into accumulator
ADD A, #03H// A=A+IMMEDIATE DATA
OR SUBB, #03H//A<—A-IMMEDIATE DATA, the final value is stored in the ACC
register//
END// The END directive is used to indicate the end of the program.
Program:
ORG 0000H // This is used to set the register address during assembly
MOV A, #30H // moving #30H into accumulator
MOV R0, #10H //moving #10H in register R0 as pointer, here the value of operand
is considered as an address
MOV 10H,#04H //Moving #04H in 10H memory location
ADD A,@R0 //Performing addition operation
SUBB A, @R0// Subtraction operation
END // The END directive is used to indicate the end of the program.
Output of Programs:
1. Direct addressing mode:
Conclusion:
Through executing the assembly code on the 8051 microcontroller, we explored diverse
addressing modes and arithmetic operations, showcasing its versatility. This hands-on
experience underscored the significance of understanding the microcontroller's architecture
and instruction set for efficient embedded systems development.
EXPERIMENT NUMBER 03
DATE OF PERFORMANCE
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Theory:
Multiplication:
Division:
Division is the process of repeated subtraction. In the 8051 microcontroller, division of two
8-bit numbers is typically performed using the DIV instruction. This instruction divides the
content of the accumulator (A) by the content of another register (commonly B). After
division, the quotient is stored in the accumulator (A), and the remainder is stored in register
B.
Algorithm:
Program:
ORG 0000h // This is used to set the register address during assembly
MOV A,#25H //move #25h into accumalator
MOV B,#12H // move #12h in B
MUL AB // Perform multiplication operation
MOV 42H,A // move higher operand in 42h
MOV 43H,B // move lower operand in 43h
END // end the program
Division:
MOV A,#25H //move #25h into accumalator
MOV B,#12H// move #12h in B
DIV AB //perform division operation
MOV 44F,A //QUOTIENT MOVED TO 44H MEMORY LOCATION MOV
45H,B //REMAINDER MOVED TO 45H MEMORY LOCATION MOV A,
#25H
INC A //Increment accumalator
MOV 46H,A
DEC A // Decrement Accumalator
MOV 47H,A
END
Output of Programs:
1. Multiplication -
2. Division –
Conclusion:
In conclusion, the provided assembly code exemplifies the fundamental arithmetic operations
of multiplication and division on the 8051 microcontroller. Through instructions like MUL
and DIV, the microcontroller efficiently computes results, utilizing the accumulator and
general-purpose registers.
EXPERIMENT NUMBER 04
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Aim: To simulate using logical operation using immediate, direct and indirect
addressing.
Software Theory:
Logical operations such as AND, OR, and XOR are fundamental bitwise operations that
manipulate individual bits within binary numbers. These operations are commonly used in
digital circuitry and microcontroller programming for tasks like data manipulation, bitwise
masking, and flag setting/clearing.
AND Operation (ANL): The AND operation sets each bit of the result to 1 if both
corresponding bits of the operands are 1; otherwise, it sets the bit to 0.
OR Operation (ORL): The OR operation sets each bit of the result to 1 if at least one of
the corresponding bits of the operands is 1; otherwise, it sets the bit to 0.
XOR Operation (XRL): The XOR operation sets each bit of the result to 1 if the
corresponding bits of the operands are different; otherwise, it sets the bit to 0.
Algorithm:
1.Start the Program
2.Initialise the registers
3. Load accumalator with immediate value.
4. Perform logical operation using different addressing modes
5. Store the result in accumulator.
6. End the program.
Program:
ORL A,@R0
Output of Programs:
1. Immediate Addressing -
2. Direct Addressing -
3. Indirect Addressing -
Conclusion:
In conclusion, the assembly code exemplifies the application of logical operations (AND,
OR, XOR) utilizing immediate, direct, and indirect addressing modes on the 8051
microcontroller. By employing these operations, developers can manipulate individual bits
within binary numbers, essential for tasks like data filtering, flag manipulation, and signal
processing in embedded systems.
EXPERIMENT NUMBER 05
DATE OF PERFORMANCE
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Theory:
Converting BCD numbers to ASCII involves converting each BCD digit to its
corresponding ASCII character. ASCII (American Standard Code for Information
Interchange) is a character encoding standard where each character is represented by a
unique 7-bit binary number.
1. Extracting BCD Digits: BCD numbers are typically stored in binary format, with each
digit occupying a fixed number of bits. To convert a BCD number to ASCII, you first
need to extract each digit from the BCD representation.
2. Converting to ASCII: Once you have extracted each digit from the BCD representation,
you convert each digit to its corresponding ASCII character. This usually involves
adding an offset value to the digit's binary representation to map it to the ASCII
character set.
3. Storing ASCII Characters: After converting each BCD digit to its ASCII equivalent,
you store the ASCII characters in memory or some other storage medium for further
processing or output.
Algorithm:
Program:-
Output of Program:
Conclusion:
In summary, converting Binary-Coded Decimal (BCD) numbers to ASCII in assembly
language for the 8051 microcontroller facilitates displaying numeric data on output devices
such as LCDs or serial monitors. Utilizing bitwise operations and arithmetic instructions,
the 8051 can efficiently extract each BCD digit and map it to its corresponding ASCII
character. This conversion process is essential for generating human-readable output in
embedded systems applications, enabling users to interpret numerical data easily.
EXPERIMENT NUMBER 06
Transfer of data bytes between internal and
EXPERIMENT NAME external memory Simulation.
DATE OF PERFORMANCE
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Experiment No. 6
Aim: Transfer of data bytes between internal and external memory Simulation
Theory:
The transfer of data bytes between internal and external memory on the 8051
microcontroller involves understanding memory addressing, data movement instructions,
and memory interface configuration.
Memory Addressing:
The 8051 microcontroller has both internal and external memory spaces.
Internal memory, also known as RAM, is accessed directly through the
microcontroller's memory addressing scheme.
External memory, such as EEPROM or Flash memory, typically requires additional
interfacing components and may have different addressing requirements.
Algorithm:
1. Start the program.
2. Initialize R2 as counter
3. Load R0 and R1 with internal and external memory address.
4. Move the content at memory location into accumulator
5. Store the content of accumulator into memory pointed by R0
6. Increment value of R0and R1
7. DJNZ instruction decrements the byte indicated by the #05h and, if the resulting
value is not zero, branches to back.
8. If R2 not equals to 0, go to step 3
9. End the program
Program:
ORG 00h
MOV R2,#05H //R2 set as counter for 5
MOV R0,#20H //R0 indicates internal memory
MOV R1,#30H //R1 indicates external memory
BACK:MOV A,@RO // send the value to A
MOV @R1,A // send the value to R1
INC R0 //Increment R0
INC R1 //Increment R1
DJNZ R2,BACK //Repeat if R2 NOT=0
END // End the program
Output of Program:
Conclusion:
In conclusion, the process of transferring data bytes between internal and external memory
on the 8051 microcontroller is a critical aspect of embedded systems development. By
leveraging memory addressing capabilities and data movement instructions, developers can
efficiently move data between different memory spaces.
EXPERIMENT NUMBER 07
Arrange the given set of data in ascending
EXPERIMENT NAME and descending order
DATE OF PERFORMANCE
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Experiment No. 7
Aim: Arrange the given set of data in ascending and descending order
Theory:
In the context of the 8051 microcontroller, arranging data in ascending and descending
order involves utilizing sorting algorithms tailored to the microcontroller's architecture and
available resources. Here's the basic theory behind sorting data on the 8051:
Ascending Order:
1. Algorithm Selection: Choose a sorting algorithm suitable for the limited memory and
processing capabilities of the 8051, such as Bubble Sort, Insertion Sort, or Selection
Sort.
2. Implementation: Write assembly code to implement the selected sorting algorithm,
ensuring efficient memory usage and minimizing computational overhead.
3. Data Comparison and Swapping: Perform pairwise comparisons between elements and
swap them if they are out of order, iterating through the data until it is sorted in
ascending order.
Descending Order:
1. Algorithm Modification: Modify the selected sorting algorithm's logic to sort data in
descending order by reversing the comparison and swapping conditions.
2. Implementation: Adapt the assembly code accordingly to implement the modified
sorting algorithm for descending order.
3. Efficiency Consideration: Ensure that the sorting algorithm's efficiency is acceptable
for the size of the dataset and the available memory and processing resources of the 8051
microcontroller.
Program:
ASCENDING ORDER
ORG 00H
MOV R6,#03H
MAIN:MOV R0,#25H
MOV R2,#03H
UP:MOV A, @R0
INC R0
MOV B,@R0
CJNE A,B ,NEXT
NEXT:JC NOEXCHANGE
MOV @R0,A
DEC R0
MOV @R0,B
INC R0
NOEXCHANGE: DJNZ R2,UP
DJNZ R6,MAIN
SJMP EXIT
EXIT:END
INC R0
NOEXCHANGE:DJNZ R2,UP
DJNZ R6,MAIN
SJMP EXIT
EXIT:END
Output of Programs:
1. Ascending order-
2. Descending order-
Conclusion:
Arranging data in ascending and descending order on the 8051 microcontroller requires
adapting sorting algorithms to fit within the constraints of the microcontroller's architecture.
By selecting appropriate algorithms and optimizing their implementation, developers can
effectively manage and manipulate data within embedded systems applications, ensuring
efficient and reliable operation in real-world scenarios.
EXPERIMENT NUMBER 08
DATE OF PERFORMANCE
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Experiment No. 8
Theory:
Generating a square wave using a timer on the 8051 microcontroller involves configuring
one of the timer/counters to produce periodic interrupts. Here's the basic theory behind
generating a square wave using a timer:
Timer/Counter Modes:
The 8051 microcontroller typically has multiple timer/counters, each supporting various
modes of operation.
For generating a square wave, you'll typically use one of the timer/counters in an interval
timing mode, such as mode 1 (16-bit mode) or mode 2 (8-bit auto-reload mode).
Timer Configuration:
Configure the timer/counter mode using the TMOD (Timer Mode) register.
Set the initial values for the timer/counter using the THx (Timer High Byte) and TLx
(Timer Low Byte) registers.
Start the timer by setting the TRx (Timer Run) bit.
Interrupts:
Configure the microcontroller to generate interrupts when the timer/counter overflows.
Write an interrupt service routine (ISR) that will be executed each time the timer/counter
overflows.
Inside the ISR, toggle the output pin to generate the square wave.
Main Loop:
Implement the main program logic within a loop that continuously executes.
This loop will continue to run while the timer generates the square wave.
Program:
CLR P1.0
Output of Program:
Conclusion:
In conclusion, generating a square wave using a timer on the 8051 microcontroller is achieved
by configuring the timer/counter and utilizing interrupt-based timing. By setting appropriate
timer modes and initializing timer values, the microcontroller periodically triggers interrupts
upon timer overflow. Within the interrupt service routine, the output pin is toggled, generating
a square wave signal. This method allows for precise control over the square wave frequency
and duty cycle. Understanding timer configurations and interrupt handling is crucial for
efficiently generating square waves in embedded systems applications, enabling various
functionalities such as signal generation, timing, and synchronization.
EXPERIMENT NUMBER 09
DATE OF CORRECTION
GRADE
TIMELY LAB
ATTENDANCE ORAL TOTAL
CORRECTION PERFORMANCE
ALLOTTED 2 2 3 3 10
OBTAINED
Experiment No. 9
Theory:
When interfacing an LCD with an 8051 microcontroller, it's important to understand the
specific features and capabilities of the 8051 architecture. Here's the theory regarding
interfacing an LCD with an 8051 microcontroller:
I/O Ports:
The 8051 microcontroller features four I/O ports: P0, P1, P2, and P3.
These ports can be configured as both input and output ports.
Each port consists of 8 pins, allowing for a total of 32 I/O lines.
LCD Initialization:
Before using the LCD, it needs to be initialized to set the display parameters.
Initialization involves sending specific commands to the LCD controller, typically
through the control lines.
These commands configure the LCD, such as setting the display mode, cursor position,
and cursor blinking.
The EN line enables the LCD to latch the command or data on the falling edge of the
signal.
Timing Considerations:
Timing is crucial when interfacing with the LCD to ensure that commands and data are
properly processed.
The microcontroller needs to meet the timing requirements specified by the LCD
datasheet, especially regarding pulse widths and setup/hold times.
Program:
ORG 000H
MOV P1,#00H
MOV A,#38H
ACALL CMND
MOV A,#0EH
ACALL CMND
MOV A,#01H
ACALL CMND
MOV A,#06H
ACALL CMND
MOV A,#84H
ACALL CMND
MOV A,#3CH
ACALL CMND
MOV A,#'W'
ACALL DISP
MOV A,#'E'
ACALL DISP
MOV A,#'L'
ACALL DISP
MOV A,#'C'
ACALL DISP
MOV A,#'O'
ACALL DISP
MOV A,#'M'
ACALL DISP
MOV A,#'E'
LABORATORY: MICROPROCESSOR AND MICROCONTROLLER LAB
(Permanently Affiliated to University of Mumbai)
Department of Electronics and Telecommunication Engineering
ACALL DISP
AGAIN:SJMP AGAIN
CMND: MOV P1,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELY
CLR P2.2
DISP: MOV P1,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELY
CLR P2.2
RET
DELY: MOV R3,#50
HERE2: MOV R4,#235
HERE: DJNZ R4, HERE
DJNZ R3, HERE2
RET
END
Output of Program:
Conclusion:
In conclusion, interfacing an LCD with an 8051 microcontroller involves leveraging the
microcontroller's I/O ports to control the display through specific commands. Understanding
the 8051 architecture and the commands supported by the LCD is essential for effective
communication and display management. By configuring the I/O ports, sending initialization
commands, and transmitting data, developers can seamlessly integrate LCDs into embedded
systems using assembly language programming. This enables a wide range of applications,
from displaying real-time data to providing user interfaces in embedded devices. Mastery of
LCD interfacing with the 8051 empowers developers to create efficient and interactive
embedded systems solutions, enhancing their functionality and usability in various domains.