Microcontrollers LAB Manual: LAB CODE: EC - 607, EE - 410
Microcontrollers LAB Manual: LAB CODE: EC - 607, EE - 410
LAB
MANUAL
LIST OF EXPERIMENTS
EXPERIMENT NO: 01
Description:
o The microcontroller incorporates all the features that are found in
microprocessor.
o The microcontroller has built in ROM, RAM, Input Output ports, Serial Port,
o timers, interrupts and clock circuit. A microcontroller is an entire computer
o manufactured on a single chip. Microcontrollers are usually dedicated
devices
o embedded within an application.
o For example, microcontrollers are used as engine controllers in automobiles
and as exposure and focus controllers in cameras.
o In order to serve these applications, they have a high concentration of onchip facilities such as serial ports, parallel input output ports, timers,
counters, interrupt control, analog-to-digital converters, random access
memory, read only memory, etc.
o The I/O, memory, and on-chip peripherals of a microcontroller are selected
depending on the specifics of the target application. Since microcontrollers
are powerful digital processors, the degree of control and programmability
they provide significantly enhances the effectiveness of the application.
FEATURES OF 8051 MICROCONTROLLER:
8-bit ALU, Accumulator, 8-bit Registers and 8-bit data bus; hence it is an 8bitmicrocontroller
Boolean processor
Multiply, divide and compare instructions
4 register banks with 8 registers each (memory mapped)
Fast interrupt with register bank switching
Interrupts and threads with selectable priority supporting basic multitasking up to
hardware assisted, small real-time operating systems (RTOS) with preemptive
multitasking
Dual 16-bit address bus It can access 2 x 216 memory locations 64 kB (65536
locations) each of RAM and ROM
128 bytes of on-chip RAM (IRAM)
4KB ROM:
In 8051, 4KB read only memory (ROM) is available for program storage.
This is used for permanent data storage. Or the data which is not changed
during the processing like the program or algorithm for specific
applications.
This is volatile memory the data saved in this memory does not disappear
after power failure.
Serial Port:
There are two pins available for serial communication TXD and RXD.
Normally TXD is used for transmitting serial data which is in SBUF register,
RXD is used for receiving the serial data.
SCON register is used for controlling the operation
Port 2 can be used as I/O port as well as higher order address bus A8 to A15.
Port 3 also have dual functions it can be worked as I/O as well as each pin
of P3 has specific function.
P3.0 RXD
P3.1 TXD Serial data transmit.
P3.2 INT0 External Interrupt 0.
P3.3 INT1 External Interrupt 1.
P3.4 T0 Clock input for counter 0.
P3.5 T1 Clock input for counter 1.
P3.6 WR Signal for writing to external memory.
P3.7 RD Signal for reading from external memory.
When external memory is interfaced with 8051 then P0 and P2 cant be
worked as I/O port they works as address bus and data bus, otherwise they
can be accessed as I/O ports.
Oscillator:
It is used for providing the clock to MC8051 which decides the speed or
baud rate of MC.
We use crystal which frequency vary from 4MHz to 30 MHz, normally we
use 11.0592 MHz frequency.
Interrupts:
Interrupts are defined as requests because they can be refused (masked) if
they are not used, that is when an interrupt is acknowledged. A special set
of events or routines are followed to handle the interrupts. These special
routines are known as interrupt handler or interrupt service routines (ISR).
These are located at a special location in memory.
INT0 and INT1 are the pins for external interrupts.
EXPERIMENT NO: 02
PIN DESCRIPTION :
Pins 1 to 8(Port 1): The Pins 1.0 to 1.7 are 8 Pins of port 1. Each of them can be
configured as input or output pin.
Pin 9: It is used to Reset Microcontroller 8051. A positive pulse is given on this Pin to
reset Microcontroller.
Pin 10 to 17(Port 3): These Pins are similar to Pins of Port 1. These Pins can be used as
universal Input or output. These are dual function Pins.
Pin 11:
Pin 12:
Pin 13:
Pin 14:
Pin 15:
Pin 16:
Pin 17:
Interrupt 0 input.
Interrupt 1 input.
Counter 0 clock input.
Counter 1 clock input.
Writing Signal for Writing content on external RAM.
Reading Signal to read contents of external RAM.
Pin 18 and 19: These are input output PINS for oscillator. An internal oscillator is
connected to Micro controller through these PINS.
Pin 29: If we uses an external ROM then it should has a logic 0 which indicates
Micro controller to read data from memory.
Pin 30: This Pin is used for ALE that is Address Latch Enable. If we uses multiple
memory chips then this pin is used to distinguish between them. This Pin
also gives program pulse input during programming of EPROM.
Pin 31: If we have to use multiple memories then by applying logic 1 to this pin
instructs Micro controller to read data from both memories first internal
and afterwards external.
Pin 32 to 39(Port 0): Similar to port 2 and 3, these pins can be used as input
EXPERIMENT NO: 03
Arithmetic Instructions
Branch Instructions
Data Transfer Instructions
Logic Instructions
Bit-oriented Instructions
INSTRUCTIONS
BYTES
INSTRUCTIONS
BYTES
MOV @R0,#data
MOV @R1,#data
MOV @R0,A
MOV @R1,A
MOV A,#data
MOV A,@R0
MOV A,@R1
MOV A,R0
MOV A,R1
MOV A,R2
MOV A,R3
MOV A,R4
MOV A,R5
MOV A,R6
MOV A,R7
MOVX @DPTR,A
MOVX @R0,A
MOVX @R1,A
MOVX A,@DPTR
MOV DPTR,#data16
MOVX A,@R0
MOV R0,#data
MOVX A,@R1
MOV R1,#data
MOV R4,A
MOV R2,#data
MOV R5,A
MOV R3,#data
MOV R6,A
MOV R4,#data
MOV R7,A
MOV R5,#data
MOV R6,#data
MOV R7,#data
MOV R0,A
MOV R1,A
MOV R2,A
MOV R3,A
XCH A,R3
XCH A,@R0
XCH A,R4
XCH A,@R1
XCH A,R5
XCH A,R0
XCH A,R6
XCH A,R1
XCH A,R7
XCH A,R2
SWAP A
Arithmetic instructions
Arithmetic instructions perform several basic operations such as addition, subtraction,
division, multiplication etc. After execution, the result is stored in the first operand.
Instructions
Bytes
Flags
ADD A,#data
C, AC, OV
C, AC, OV
ADD A,@RI
C, AC, OV
ADD A, Rn
C, AC, OV
ADDC A,#data
C, AC, OV
C, AC, OV
ADDC A,@Ri
C, AC, OV
ADDC A, Rn
C, AC, OV
SUBB A,#data
C, AC, OV
C, AC, OV
SUBB A,@Ri
C, AC, OV
SUBB A,Rn
C, AC, OV
INC A
None
None
INC @Ri
None
INC Rn
None
INC DPTR
None
DEC A
None
None
DEC @Ri
None
DEC Rn
None
DIV AB
C, OV
MUL AB
C, OV
DA A
Bytes
Flags
None
None
ANL A,#data
None
None
ANL A,@R0
None
ANL A,@R1
None
ANL A,R0
None
ANL A,R1
None
ANL A,R2
None
ANL A,R3
None
ANL A,R4
None
ANL A,R5
None
ANL A,R6
None
ANL A,R7
None
None
None
ORL A,#data
None
None
ORL A,@R0
None
ORL A,@R1
None
ORL A,R0
None
ORL A,R1
None
ORL A,R2
None
ORL A,R3
None
ORL A,R4
None
ORL A,R5
None
ORL A,R6
None
ORL A,R7
None
None
None
XRL A,#data
None
None
XRL A,@R0
None
XRL A,@R1
None
XRL A,R0
None
XRL A,R1
None
XRL A,R2
None
XRL A,R3
None
XRL A,R4
None
XRL A,R5
None
XRL A,R6
None
XRL A,R7
None
CPL A
None
CPL C
CLR C
CLR A
None
RL A
RLC A
RR A
None
RRC A
Bytes
Flags
SETB C
None
None
None
NONE
Bytes
Flags
ACALL page0
None
ACALL page1
None
ACALL page2
None
ACALL page3
None
ACALL page4
None
ACALL page5
None
ACALL page6
None
ACALL page7
None
AJMP page0
None
AJMP page1
None
AJMP page2
None
AJMP page3
None
AJMP page4
None
AJMP page5
None
AJMP page6
None
AJMP page7
None
CJNE A,#data,reladdr
CJNE @R0,#data,reladdr
CJNE @R1,#data,reladdr
CJNE R0,#data,reladdr
CJNE R1,#data,reladdr
CJNE R2,#data,reladdr
CJNE R3,#data,reladdr
CJNE R4,#data,reladdr
CJNE R5,#data,reladdr
CJNE R6,#data,reladdr
CJNE R7,#data,reladdr
None
DJNZ R0,reladdr
None
DJNZ R1,reladdr
None
DJNZ R2,reladdr
None
DJNZ R3,reladdr
None
DJNZ R4,reladdr
None
DJNZ R5,reladdr
None
DJNZ R6,reladdr
None
DJNZ R7,reladdr
None
JB bit addr,reladdr
None
None
JC reladdr
None
JMP @A+DPTR
None
None
JNC reladdr
None
JNZ reladdr
None
JZ reladdr
None
None
None
RET
None
RETI
None
SJMP reladdr
None
NOP
None
EXPERIMENT NO: 04
MOV A, # data
MOV B, # data
ADD A, B
INT O3
Output:
Test data:
A = 08H
B = 02H
AFTER ADDITION OPERATION
A = 0AH
B = 02H
EXPERIMENT NO : 05
MOV A, # data
MOV B, # data
SUBB A, B
INT O3
Output:
Test data:
A = 08H
B = 02H
AFTER SUBTRACTION OPERATION
A = 06H
B = 02H
EXPERIMENT NO : 06
MOV A, # data
MOV F0, # data
MUL AB
INT O3
Output:
Test data:
A = 08H
B = 02H
AFTER MULTIPLICATION OPERATION
A = 16H (LOWER 8 BITS)
B = 00H (HIGHER 8 BITS)
EXPERIMENT NO: 07
MOV A, # data
MOV F0, # data
DIV AB
INT O3
Output :
Test data:
A = 08H
B = 02H
AFTER DIVISION OPERATION
A = 04H (QUOTIENT)
B = 00H (REMAINDER)
EXPERIMENT NO: 08
MOV A, #data
CPL A
INC A
INT 03
Output :
Test data:
EXPERIMENT NO: 09
Program :
MOV A, # data (last 8 bits of A data)
MOV B, # data (last 8 bits of B data)
ADD A,B
MOV R0, A
MOV A,# data (first 8 bits of A data)
MOV B, # data (first 8 bits of B data)
ADDC A,B
INT 03
Output :
Test data :
EXPERIMENT NO: 10
EXPERIMENT NO: 11
A = 0402H
B = 0204H
RI = 00
A = 08
B = 00
EXPERIMENT NO: 12
Output :
Test data :
A = 84 H = 1000 0100
R0 = 12 H = 0001 0010
AFTER ORL
A = 1001 0110 = 96 H
EXPERIMENT NO: 13
Output :
Test data :
A = 84 H = 1000 0100
R0 = 92 H = 1001 0010
AFTER ANL
A = 1000 0000 = 80 H
EXPERIMENT NO: 14
Output :
Test data :
A = 84 H = 1000 0100
R0 = 12 H = 0001 0010
AFTER XRL
A = 1001 0110 = 96 H