Professional Documents
Culture Documents
BEE403 - MC Lab Manual 2023-24
BEE403 - MC Lab Manual 2023-24
(BEE403)
Name:
USN :
(2023-24)
PREPARED BY: APPROVED BY:
COURSE OUTCOMES:
1. Build assembly language programs for data transfer, arithmetic, Boolean and
logical instructions and code conversions.
2. Apply ALP subroutines for generation of delays, counters, configuration of
SFRs for serial communication and timers.
3. Demonstrate interfacing of LCD, stepper motor and dc motor for controlling the
speed
4. Develop different waveforms using DAC interface.
MICROCONTROLLER LAB.
Syllabus: [Use of 8051 Microcontroller and its advanced version AT89C51ED2 ]
A. Use of Simulation Software for writing programs .
8. Writing ‘c’ program for: Stepper motor speed and direction control.
9. Writing ‘c’ program for: DC Motor speed and direction control( PW M o du la tio n ).
10. Writing ‘c’ program for: Alphanumerical display on LCD Panel.
11. Writing ‘c’ program for: Gen. of Waveforms ( Sine, Triangular, Ramp ) using DAC.
12. Writing ‘c’ program for: External ADC and Temperature control.
13. Writing ‘c’ program for: Elevator Interfacing.
**************
Introduction to Microcontrollers
A microcontroller can be compared to a small standalone computer; it is a very powerful device, which is capable
of executing a series of preprogrammed tasks and interacting with other hardware devices. Being packed in a tiny
integrated circuit (IC) whose size and weight is usually negligible, it is becoming the perfect controller for robots or any
machines requiring some kind of intelligent automation. A single microcontroller can be sufficient to control a small
mobile robot, an automatic washer machine or a security system. Any microcontroller contains a memory to store the
program to be executed, and a number of input/output lines that can be used to interact with other devices, like reading
the state of a sensor or controlling a motor.
Nowadays, microcontrollers are so cheap and easily available that it is common to use them instead of simple
logic circuits like counters for the sole purpose of gaining some design flexibility and saving some space. Some
machines and robots will even rely on a multitude of microcontrollers, each one dedicated to a certain task. Most recent
microcontrollers are 'In System Programmable', meaning that you can modify the program being executed, without
removing the microcontroller from its place.
Today, microcontrollers are an indispensable tool for the robotics hobbyist as well as for the engineer. Starting
in this field can be a little difficult, because you usually can't understand how everything works inside that integrated
circuit, so you have to study the system gradually, a small part at a time, until you can figure out the whole image and
understand how the system works.
Features Of 8051
40 pin DIP
Harvard Architecture
8 bit Arithmetic and Logical unit
8 bit CPU with registers A and B
16 bit PC and DPTR
8 bit PSW
8 bit SP with SP=07h by default
Internal ROM or EPROM of 0 to 4K
Internal RAM of 128 bytes
4 banks of 8 registers(R0-R7), 8 bit each
16 bytes which can be addressed at the bit level
80 bytes of General purpose data memory
2, 16 bit timers/counters with interrupts
Four 8 bit parallel ports(P0-P3) with single line access
Oscillator and clock circuits
2 external and 3 internal interrupt sources
Full duplex serial data receiver/transmitter: SBUF
Control Registers: TCON, TMOD, SCON, PCON, IP and IE
Some basics:
1. Identify the Hexadecimal numbers:
1, 3, 5, 7, 8, A, C, D, F, FG, H, AF, FA, UG, PG.
2. What is a bit? Byte? Nibble? Word? kB = how many Bytes?
3. Convert Ch, AFh and FAh into binary. How many bit s does AFFAh has?
3. What is the difference between or “ ” or ‘ ’
and Ah?
4. ADD: i) 9h and 1h ii) 8h and 2h iii) 9h and 6h iv) Ah and Bh
5. Addition of Hexadecimal Numbers— Add 23D9h and 94BEh.
[ Note that if a carry results, the carry is always 1h(or simply 1 as 1h =
1d)]
6. Subtraction of Hexadecimal Numbers— Sub 2B8h from 59Fh. In
subtracting process if the digit to be subtracted is greater, then 16
is to be borrowed.
7. Subtraction by borrowing is complicated. Then what is the
alternative? Explain the procedure used for subtraction in
computers.
8. What is a nibble? How many nibbles make 1 byte. How many
bytes make 1 word? How many bits a word will have?
9. What is a Microprocessor?
10. What is a Microcontroller?
11. Will there be inbuilt memory in Microprocessor?
12. Why a Microcontroller is referred to as a system on chip?
13. What is likely RAM and ROM memory capacities of a Microprocessor and a
Microcontroller?
14. For the CPU to process information, the data must b e stored in RAM or ROM.
[The function of ROM is to provide information to the CPU that is fixed
and permanent. RAM is used to provide information to CPU that is not
permanent.]
15. What makes Microcontrollers to have low memory capacities?
16. A microcontroller normally has which of the following
devices on chip?
(A) RAM (B) ROM (C) I/O (D) All of these
17. A general-purpose microprocessor normally needs which of the following
devices to be attached to it?
(A) RAM (B) ROM (C) I/O (D) All of these
18. What does the term embedded system mean?
19. An embedded system is also called a dedicated system. Why?
20. Mention some of the Embedded products using microcontrollers that are
MOV R7,#34h;
MOV A,#0;
ADD A, R5; ADD
A, R7;
ADD A,#12h;
HERE: SJMP HERE
END
Run above program to understand OPCODE, INSTRUCTION, bytes per
instruction etc. Observe PSW Register and PC during execution.
36. CPU can access data in various ways. The data (i) could be in a
register, (ii) it could be in a memory location or (iii) data can be
provided as an immediate value. Observe (i) Register (ii) Direct
(iii) Immediate addressing modes below.
MOV A, R0; CPU looks into the register R0, takes the value and puts it in A
MOV A, 0h; CPU looks into the memory location oh, takes the value
that is in memory location 0h and puts it in A.
Memory location 0 or 0h belongs to which register?
What is the memory location for Register R0? (!?) Does these two
questions amounts to one and same meaning?
MOV A,#25h; the value is provided as an immediate value; no need for the
CPU to go in search-of.
Write some more examples for above.
37. There are 4 Ports, P0, P1, P2, P3 each port has got 8 pins for 8 bits of
a byte either to input data to C or to take out data from C. In order
to establish communication with the outside world these ports are used.
The Ports can be configured to receive data for the microcontroller or
send out data from the microcontroller by initialization of values.
(how to do this?)
38. Understand the difference between movement of data within internal
memory locations, movement of data within internal memory locations
and taking data to external memory locations.
39. Waveform generation in TD programs. (What is the need of Wave form in
Time delay programs? Can we generate Triangular waveforms instead of
square wave for Time delays? What is the idea behind it?)
40. Find answers for signed number/unsigned n umber ?, Type declaration ⭢
Unsigned Integer/Unsigned Char etc
these aspects into consideration (To reach a destination point, A driver may choose a
short route or a longer one; but he should have reasons for selecting a particular route
and has to justify it is it not?).
ALGORITHM:
RESULT:
BEFORE EXECUTION:
MEM. LOCATION 40h 41h 42h 43h 44h
DATA(default) 00 00 00 00 00
AFTER EXECUTION:
DATA 02 07 01 09 AC
Note that MOV instruction places a copy of the data in the new location,
keeping the original data intact .
GP_BLOCK DATA TRANSFER. docx
AFTER EXECUTION:
ALGORITHM:
1. Initialize Registers for holding source-cum-destination address.
2. Initialize Register for holding count of bytes to be exchanged.
3. Take first byte of data from BLK 2, lodge it safely in a known memory loc. R3.
4. Take first byte of data from BLK 1 and transfer it to BLK 2.
5. Take the byte of data in R3 and transfer it to BLK 1; completes 1 byte transfer.
6. Apply logic and transfer all the other data bytes, byte by byte.
; EXCHANGE DATA BETWEEN TWO MEMORY BLOCKS (say BLK 1 and BLK 2).
; Two Data blocks of 5 elements each, one start s @ 40h and another starts @ 50h.
ORG 0000h ;(Observe the use of Index Registers for
DBs ) MOV R0, #40h ;Initialize R0 with starting address of
one DB
MOV R1, #50h ;Initialize R1 with staring address of
another DB. MOV R2, #05h ;number of elements to be
exchanged.
AGAIN: MOV A, @R1 ;
MOV R3, A ;Hold this data in R3, to transfer
it later. MOV A, @R0 ;
MOV @R 1, A ;Earlier data can be overwritten.
MOV A, R3 ;note: no direct transfer between
Registers. MOV @R 0, A ;hence, roundabout procedure is
adopted.
INC R0 ;
INC R1 ;
DJNZ R2, AGAIN ; Decrement R2 first, then Jump to target if
Not ‘0’
END
RESULT:
BEFORE EXECUTION:
AFTER EXECUTION:
MEM. LOCATION 40h 41h 42h 43h 44h 45h
DATA AAh BBh CCh DDh EEh FFh
. . . . . . . . . . . . . . . . . USN :
RESULT:
After Execution:
After Execution:
Now, it is simple matter, to add any two 8 bit numbers by simply entering the
numbers in appropriate memory locations and running the program(without
bothering save, built target etc, etc).
Case 1: Case 2:
40h 41h 52h 53h
6Eh 4Ch 4Ch 6Eh
ORG 0000h ;
; Part 1: case 1. Sub. a smaller num from a larger num
CLR C ; set the Carry Flag CY to zero.
MOV A, 40h ; Minuend is taken into Register A.
MOV B, 41h ; Subtrahend is taken into Register B.
SUBB A, B ; subtract with Barrow. (SUBB B, A is not allowed).
; A (new) = [previous value of A– CY– source byte in B]
MOV R0, A ;
JNC next ; if a borrow is there,
store it. MOV R 1, #01h ;
next: NOP ;
; Part 2: case 2. Sub. a larger num from a smaller num
CLR C ; set the Carry Flag CY to zero.
MOV A, 52h ; Minuend is taken into Register A.
MOV B, 53h ; Subtrahend is taken into Register B.
SUBB A,B ; subtract with Barrow.
MOV R2, A ;
JNC next1 ;
MOV R3, #01h ;
next1 : NOP ;
END ; happen? Clarify. Use Setb C and try. Use Calc i ! M- in
It can be noted that if the data is swapped in memory locations 40h and 41h t
hen Part 2 of the program is not at all required. If the programmer says ‘
enter minuend in 40h and subtrahend in 41 h ’ problem is solved; no need to go for
2 parts in the program.
RESULT:
Given: Minuend = 6Eh , Subtrahend = 4Ch
. After Execution:
Content of R1 Content of
R0
00h 22h
RESULT:
After Execution:
3CFA 0 0 1 1 1 1 0 0 1 1 1 1 1 0 1 0
3CFA h 1 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1
1’s
+ 1
3CFA h 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0
2’s
27A5 h 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 1
3CFA 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0
Adding 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1
Invert 1 EAh ABh
CY
SJMP less
here: JC less
MOV 50h, A
less: INC R0
END
3. Modify the program to find smallest element from the array of 5 numbers.
Code Comment
ORG 00H
MOV B, A
INC R0
MOV A,@R0
CJNE A, B, notequal
SJMP SKIP
DEC R0
MOV @R0, A
INC R0
MOV @R0, B
END
3. Change the addresses of the data and carry out the programming. Indicate the address locations.
Write an assembly language program to sort the given set of numbers in descending order, starting from location 50H
Code Comment
ORG 00H
MOV B, A
INC R0
MOV A,@R0
CJNE A, B, notequal
SJMP SKIP
notequal: JC SKIP
DEC R0
MOV @R0, A
INC R0
MOV @R0, B
END
3. Change the addresses of the data and carry out the programming. Indicate the address locations.
Result: View PORT ‘0’ and observe counting(wait for the given time delay).
GP_COUNTERS_BINARY COUNTER. docx
Write an assembly language program to perform the following operations on 3 bytes of data stored from location X
onwards
(A) OR the lower nibble of location X with upper nibble of location X+1
(B)XOR the result of (A) with contents of location X+2.
Code Comment
ORG 0000h
MOV A, 40h
ANL A, #0Fh
MOV 50h, A
MOV A, 41h
SWAP A
ANL A, #0Fh
ORL A, 50h
XRL A, 42h
MOV 50h, A
END
2. How are the logical instructions used for bit manipulation? Give examples.
Write an assembly language program to perform the following operations on a given byte of data.
Set the bits 0 & 1, Reset bits 2&3, Compliment bits 6&7.
Code Comment
ORG 00H
MOV A, 40h
MOV P2,#00H
ORL A, #03h
ANL A, #0F3h
XRL A, #0C0h
MOV 50h, A
END
for:
TMOD register has a value of
20h. TH1 register has a value
of FDh.
SCON register has a value of
50h.
JNB means what? When Bit will be set? What is to be done next?
ORG 0000h ;
MOV TMOD, #20h
; MOV
TH1, #0FDh ;
MOV SCON, #50h ;
SETB TR1 ;
MOV A, #’G’ ;
ACALL SEND ;
MOV A, #’P’ ;
ACALL SEND ;
HERE: SJMP HERE ;
SJMP BACK ;
Note that this is a Time delay program which can be used in another program
to provide a specified and exact Time Delay between two operations. Waveform
generation is not the main objective. Ex: The program can be used to provide
Timing between two events like switching ON and OFF a Lamp in Traffic signal
light.
PROGRAM 18: Write an assembly language program to add a series of ‘n’ numbers stored from location X onwards.
Code Comment
ORG 0000h
CLR A
JNC nxt
INC 50h
nxt: INC R0
MOV 51h, A
END
Write an assembly language program to add a series of ‘n’ decimal numbers stored from location X onwards.
Code Comment
ORG 0000h
CLR A
DAA
JNC nxt
INC 50h
nxt: INC R0
MOV 51h, A
END
MOV A, 40h
ANL A, #0Fh
MOV 50h, A
MOV A, 40h
SWAP A
ANL A, #0Fh
MOV B, #0Ah
MUL AB
ADD A, 50h
MOV 50h, A
END
MOV A, 40h
MOV B, #64h
DIV AB
MOV 50h, A
MOV A, B
MOV B, #0Ah
DIV AB
SWAP A
ADD A, B
MOV 51h, A
END
1. Modify the program to convert a series binary numbers into BCD numbers.
MOV A, 50h
SJMP last
JC less40
SUBB A, #37h
less40: CLR C
SUBB A, #30h
END
ORG 0000h
LOGIC:
ASCII Binary
30h-39h 0-9h
41h-46h A-Fh
MOV A, 40h
ANL A, #0Fh
LCALL ascii
MOV 50h, A
MOV A, 40h
ANL A, #0F0h
SWAP A
LCALL ascii
Dept. of EEE,
MOVSapthagiri
51h, A College of Engineering, Page 49
Bangalore
ascii: CJNE A, #0Ah, nxt
IV Semester Microcontroller Lab. (BEE403)
SJMP last
nxt : JC lessA
ADD A, #37h
SJMP last
last : RET
END
LOGIC:
Binary ASCII
If binary < 0Ah Add #30h
If binary >=0Ah Add #37h
PROGRAM 20: Write an assembly language program to find the 2’s compliment of a
Dept. of EEE, Sapthagiri College of Engineering, Page 50
given 16-bit number.
Bangalore
Code Comment
ORG 0000h
IV Semester Microcontroller Lab. (BEE403)
MOV A, 41h
CPL A
MOV 51h, A
MOV A, 40h
CPL A
INC A
MOV 50h, A
END
Part B
Interfacing
1. Write a C program to generate the sinusoidal waveform and display the same on CRO
Dept. of EEE, Sapthagiri College of Engineering, Page 52
Bangalore
IV Semester Microcontroller Lab. (BEE403)
{128,132,136,141,154,150,154,158,163,167,171,175,180,184,188,192,195,199,203,206,210,213,216,
220,223,226,228,231,234,236,238,241,243,244,246,247,248,249,250,251,252,253,254,255,255,255,2
55,255,254,254,253,252,251,249,246,244,243,241,238,236,234,231,228,226,223,220,216,213,210,20
6,203,199,195,192,188,184,180,175,171,167,163,158,154,150,145,141,136,132,128,123,119,114,110,
105,101,97,92,88,84,80,75,71,67,64,60,56,52,49,45,42,39,35,32,29,27,24,21,19,17,14,12,11,9,7,6,4,3,
2,1,1,0,0,0,0,0,0,0,0,1,1,2,3,4,6,7,9,11,12,14,17,19,21,24,27,29,32,35,39,42,45,49,52,56,60,64,67,71,7
5,80,84,88,92,97,101,105,110,114,119,123,128};
P0=0X00;
while(1)
{
for(i=0;i<180;i++)
P0=table[i];
}
}
Observations:
2. Write a C program to generate the Square waveform and display the same on CRO
#include<reg52.h>
Void MSDelay ( unsigned int );
Void main ( )
{
P0 = 0 X 00;
While (1)
{
P0 = 0 X 00;
MSDelay(50);
P0 = 0 X ff;
MSDelay(50);
}
}
Void MSDelay ( unsigned int value)
{unsigned int y;
for ( y = 0 ; y < value ; y++ );
}
Observations:
3. Write a C program to generate the triangular waveform and display the same on CRO
IV Semester Microcontroller Lab. (BEE403)
#include<reg52.h>
void main ( )
{
Unsigned int i;
P0 = 0 X 00;
While (1)
{
for (i = 0; i<255; i++)
{
P0 = i;
}
Observations:
4. Write a C program to generate the Ramp waveform and display the same on CRO
IV Semester Microcontroller Lab. (BEE403)
#include<reg52.h>
void main ( )
{
Unsigned int i;
P0 = 0 X 00; set P0 as i/p port
While (1)
{
for (i = 0; i<255; i++)
{
P0 = i;
}
}
}
Observations:
5.Write a C program to generate the Rectangular waveform and display the same on CRO
IV Semester Microcontroller Lab. (BEE403)
#include<reg52.h>
Void MSDelay ( unsigned int );
void main ( )
{
P0 = 0 X 00;
While (1)
{
P0 = 0 X 00;
MSDelay(50);
P0 = 0 X ff;
MSDelay(100);
}
}
Void MSDelay (unsigned int value)
{Unsigned int y;
for ( y = 0 ; y < value ; y++ );
}
Observations:
#include<reg52.h>
void main ( )
{
Unsigned int i;
P0 = 0 X 00;
While (1)
{
for (i = 0; i<255; i = i+5)
{
P0 = i;
}
Observations:
7.Stepper motor and DC motor speed control interface with 8051 microcontroller
7a.To rotate Stepper motor in clockwise 7b.To rotate Stepper motor in anticlockwise
direction direction
#include<reg52.h>
Void MSDelay(unsigned char value); #include<reg52.h>
void main( ) Void MS Delay(unsigned char value);
{ void main( )
While (1) {
{ While (1)
P0=0X66; {
MSDelay(1); P0=0X33;
P0=0Xcc; MSDelay(1);
MSDelay(1); P0=0X99;
P0=0X99; MSDelay(1);
MSDelay(1); P0=0Xcc;
P0=0X33; MSDelay(1);
MSDelay(1); P0=0X66;
} MSDelay(1);
} }
Void MSDelay(unsigned char value) }
{ Void MSDelay(unsigned char value)
Unsigned int y,x; {
for(x=0;x<500;x++); Unsigned int y,x;
for(y=0;y<value;y++); for(x=0;x<500;x++)
} for(y=0;y<value;y++);
}
#include<reg52.h> #include<reg52.h>
Void MSDelay (unsigned char value); Void MSDelay (unsigned char value);
sbit enablr=P0^6; sbit enablr=P0^6;
sbit mtr_1=P0^7; sbit mtr_1=P0^7;
sbit mtr_2=P0^4; sbit mtr_2=P0^4;
void main( ) void main( )
{ {
while(1) while(1)
{ {
mtr_1=1; mtr_1=0;
mtr_2=0; mtr_2=1;
MSDelay(50); MSDelay(50);
mtr_1=0; mtr_1=0;
} }
} }
Void MSDelay(unsigned char value) Void MSDelay(unsigned char value)
{ {
Unsigned int y,x; Unsigned int y,x;
for(x=0;x<40;x++) for(x=0;x<40;x++)
for(y=0;y<value;y++); for(y=0;y<value;y++);
} }
9. Write a C Program to display a given message on LCD Panel using 8051 microcontroller
LCD Panel Details:
• The size of LCD is 16 characters and 2 lines.
• The address of the first line is 80H and second line is C0H.
#include<reg52.h>
Sfr ldata=0x80;
Sbit rs=P3^7;
Sbit rw=P3^6;
Sbit en=P3^5;
sbit busy=P0^7;
void MSDelay(unsigned char);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdready( );
unsigned char i;
unsigned char idatamsg[15]={"REVA University"} ;
void main( )
{
lcdcmd(0x38);
lcdcmd(0x0e);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x83);
for(i=0;i<12;i++)
lcddata(msg[i]);
while(1)
{
lcdcmd(0xc3);
}
}
Void MSDelay(unsigned char value)
{
Unsigned int x,y;
for(x=0;x<900;x++)
for(y=0;y<value;y++);
}
Void lcdcmd(unsigned char value)
{
lcdready( );
ldata=value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;
return;
}
Void lcddata(unsigned char value)
{
lcdready( );
ldata=value;
rs=1;
rw=0 ;
en=1 ;
MSDelay(1);
en=0;
return;
}
Void lcdready( )
{
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
MSDelay(1);
en=1;
}
return;
}
8051 Instructions
8051 has about 111 instructions. These can be grouped into the following categories
1. Arithmetic Instructions
2. Logical Instructions
3. Data Transfer instructions
4. Boolean Variable Instructions
5. Program Branching Instructions
The following nomenclatures for register, data, address and variables are used while write instructions.
A: Accumulator
B: "B" register
C: Carry bit
Direct: 8-bit internal direct address for data. The data could be in lower 128bytes of RAM (00 - 7FH) or it
could be in the special function register (80 - FFH).
@Ri: 8-bit external or internal RAM address available in register R0 or R1. This is used for indirect
addressing mode.
Addr11: 11-bit destination address for short absolute jump. Used by instructions AJMP & ACALL. Jump
range is 2 kbyte (one page).
Rel: 2's complement 8-bit offset (one - byte) used for short jump (SJMP) and all conditional jumps.
Arithmetic Instructions
Mnemonics Description Bytes Instruction Cycles
ADD A, Rn A A + Rn 1 1
ADD A, direct A A + (direct) 2 1
ADD A, @Ri A A + @Ri 1 1
ADD A, #data A A + data 2 1
ADDC A, Rn A A + Rn + C 1 1
ADDC A, direct A A + (direct) + C 2 1
ADDC A, @Ri A A + @Ri + C 1 1
ADDC A, #data A A + data + C 2 1
DA A Decimal adjust accumulator 1 1
DIV AB Divide A by B
A quotient 1 4
B remainder
DEC A A A -1 1 1
DEC Rn Rn Rn - 1 1 1
DEC direct (direct) (direct) - 1 2 1
DEC @Ri @Ri @Ri - 1 1 1
INC A A A+1 1 1
INC Rn Rn Rn + 1 1 1
INC direct (direct) (direct) + 1 2 1
INC @Ri @Ri @Ri +1 1 1
INC DPTR DPTR DPTR +1 1 2
MUL AB Multiply A by B
A low byte (A*B) 1 4
B high byte (A* B)
SUBB A, Rn A A - Rn - C 1 1
SUBB A, direct A A - (direct) - C 2 1
SUBB A, @Ri A A - @Ri - C 1 1
SUBB A, #data A A - data - C 2 1
Logical Instructions
Mnemonics Description Bytes Instruction Cycles
ANL A, Rn A A AND Rn 1 1
ANL A, direct A A AND (direct) 2 1
ANL A, @Ri A A AND @Ri 1 1
ANL A, #data A A AND data 2 1
ANL direct, A (direct) (direct) AND A 2 1
ANL direct, #data (direct) (direct) AND data 3 2
CLR A A 00H 1 1
CPL A A A 1 1
ORL A, Rn A A OR Rn 1 1
ORL A, direct A A OR (direct) 1 1
ORL A, @Ri A A OR @Ri 2 1
ORL A, #data A A OR data 1 1
ORL direct, A (direct) (direct) OR A 2 1
ORL direct, #data (direct) (direct) OR data 3 2
RL A Rotate accumulator left 1 1
RLC A Rotate accumulator left through 1 1
carry
RR A Rotate accumulator right 1 1
RRC A Rotate accumulator right through 1 1
carry
SWAP A Swap nibbles within Acumulator 1 1
XRL A, Rn A A EXOR Rn 1 1
XRL A, direct A A EXOR (direct) 1 1
XRL A, @Ri A A EXOR @Ri 2 1
XRL A, #data A A EXOR data 1 1
XRL direct, A (direct) (direct) EXOR A 2 1
XRL direct, #data (direct) (direct) EXOR data 3 2
All the 21 8051 Microcontroller Special Function Registers (SFRs) along with their functions and
Internal RAM Address is given in the following table.
Annexure-A
Annexure -B
8051 Special Function Registers:
1. Timer Mode Control Register (TMOD):
TMOD can be considered to be two duplicate 4-bit registers, each of which controls
the action of one of the timers. The “Timer” or “Counter” function is selected by control bits
C/T, and in different operating modes, which are selected by bit-pairs (M1, M0) in TMOD.
MSB LSB
GATE C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0
Gating control when set. Counter “x” is enabled only while “INTx” pin is
GATE high and “TRx” control pin is set. When cleared Timer “x” is enabled
whenever “TRx” control bit is set.
Timer or Counter Selector cleared for Timer operation (input from internal
C/T system clock.) Set for Counter operation (input from “Tx” input pin).
M1 M0 OPERATI0N
0 0 13-bit Timer/Counter 5-bits of “TLx” and 8-bits of “THx” are used.
0 1 16-bit Timer/Counter 8-bits of “TLx” and 8-bits of “THx” are cascaded.
8-bit auto-reload Timer/Counter “THx” holds a value which is to be
1 0
reloaded into “TLx” each time it overflows.
(Timer 0) TL0 is an 8-bit Timer/Counter controlled by the standard Timer
1 1 0 control bits. TH0 is an 8-bit timer only controlled by Timer 1 control bits.
Timer/Counter 1 stopped.
2. Interrupt Enable (IE) Register :
ET1 Enable Timer 1 interrupt. If 1, Enables the TF1 to generate the interrupt.
EX1 Enable External interrupt 1. If 1, Enables the INT1 to generate the interrupt.
ET0 Enable Timer 0 interrupt. If 1, Enables the TF0 to generate the interrupt.
EX0 Enable External interrupt 0. If 1, Enables the INT0 to generate the interrupt.
Additional Programs