MC Lab Manual-2024
MC Lab Manual-2024
MICROCONTROLLER
LAB MANUAL
B20EE0407
2023-2024
NAME : _______________________
SRN : _______________________
MICROCONTROLLER
LAB MANUAL
B20EE0407
2023-2024
NAME : _______________________
SRN : _______________________
INDEX
Particulars of the Experiment Performed
Marks Staff
Sl N0 Title of Experiment Date
Obtained Signature
SYLLABUS
Course Outcomes
After the completion of the course the student shall be able to:
1. Write the codes using Assembly Level Program and C language for the 8051
microcontrollers.
2. Debug the given code using KEIL software.
3. Interface the microcontroller with peripheral devices for simple electrical and electronic
circuits.
4. Apply the logic to implement the real time applications.
PART-A
I. PROGRAMMING
1. Data Transfer - Block move, Exchange, Sorting, Finding largest element in an array.
2. i) Arithmetic Instructions -Addition/subtraction, multiplication and division (16 bits Arithmetic
operations – bit addressable).
ii) Boolean & Logical Instructions (Bit manipulations).
3. i) Code conversion: BCD – ASCII ; Decimal - HEX.
ii) Counters.
4. Programs on Serial Communication.(Transfer data serially).
5. Stack Operation.
II. INTERFACING
Write C programs to interface 8051 chip to Interfacing modules to develop single chip
solutions.
2. Students should take prior permission from the concerned faculty before availing the Leave.
3. Students should come with formals with apron and must be present on time in the laboratory.
4. Students will not be permitted to attend the laboratory unless they bring the practical Record
fully completed in all respects pertaining to the experiment conducted in the previous lab.
5. Students should obtain the signature of the staff-in-charge in the observation book after
completing each experiment.
7. All the students must enter their system numbers in the system log book.
8. Once the lab is over, students should shut down the systems and keep the system chairs properly
in order.
CONTENTS
Sl.No Name of the Experiment Page No.
Introduction to Microcontroller 1
Steps to create and compile Keil µvision -3/4 project 4
Execution steps using Keil µvision 6
PART A- PROGRAMMING (Assembly Language Program)
1a To copy a block of 10 Numbers from one location to other location 13
1b To Exchange a block of 10 numbers from one location to other location 15
1c To sort the given set of number in ascending order starting from location X 17
1d To find the largest number from array starting from location X & store the 19
result in location Y
2a Addition of two 8 bit hexadecimal numbers 21
2b Subtraction of two 16 bit hexadecimal numbers 23
2c To perform the following operation on given byte 25
i). Set the bits 0 & 1, Reset bits 2 & 3,Complement bits 6 & 4
2d To find the 2’s complement of a given 16 bit number. 26
2e Write an assembly language program to perform the following operations on 27
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
3a To convert BCD to ASCII 29
3b To convert Decimal to HEX 31
3c To display the decimal up/ down counter 32
4 To transfer the data “ELECTRICAL ROCKS” Serially 34
5 Stack Operation 36
PART B – INTERFACING (C Program)
6 To Generate Sine, Square, Triangular, Ramp, Rectangular, Sawtooth 38
waveform using DAC interface to 8051 (With modifications).
7 To control the speed of stepper motor with interfacing to 8051 44
8 To control the speed of DC motor with interfacing to 8051 45
9 To display a given message(REVA University) on LCD Panel using 8051 46
Microcontroller LCD panel details
10 LED Interfacing to 8051 47
Challenging / Critical thinking Questions 49
Sample VIVA Questions 50
Microcontroller Question Bank 53
Annexure – I (8051 Instruction Sets) 55
Annexure – II (Special function registers of 8051) 63
Additional programs 66
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
MCS 8051 is an 8-bit single chip microcontroller with many built-in functions and is the core for
all MCS-51 devices.
2. Close any previous projects that were opened using – Project -> Close
3. Start Project – New Project, and select the CPU from the device database (Database-
Atmel- AT89S592as per the board).On clicking ‘OK’, the following option is displayed.
Choose ‘Yes’.
4. Click on file in the menu bar and select new to get text window (to type the code). Add
this file to the project by Right clicking 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 μ Vision2
Options for Target – Target configuration dialog. Set the XTAL (Crystal frequency)
frequency as 11.0592 MHz, and also the Options for Target – Debug – use Simulator.
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. µVision translates all the user 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
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.
Program -1(a)
Write an assembly language program to copy a block of ten numbers from one location to
other location.
Code Comment
ORG 00H
MOV R2,#0AH
MOV R0,#20H
MOV R1,#50H
MOV @R1,A
INC R0
INC R1
DJNZ R2,NEXT
END
Observations:
3. Change the source address and destination address and carry out the programming.
Indicate the address locations.
Program -1(b)
Write an assembly language program to exchange a block of 10 numbers from one location
to other location.
Code Comment
ORG 00H
MOV R2,#0AH
MOV R0,#20H
MOV R1,#50H
NEXT:MOV A,@R0
XCH A,@R1
MOV @R0,A
INC R0
INC R1
DJNZ R2,NEXT
END
Observations:
3. Change the addresses of the data and carry out the programming. Indicate the address
locations.
Program -1(c)
Write an assembly language program to sort the given set of numbers in ascending order,
starting from location X.
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
Observations:
3. Change the addresses of the data and carry out the programming. Indicate the address
locations.
Program -1(d)
Write an assembly language program to find the largest number from array starting from
location X and store the result in location Y.
Code Comment
ORG 0000h
SJMP less
here: JC less
MOV 50h, A
less: INC R0
END
Observations:
3. Modify the program to find smallest element from the array of 5 numbers.
Program -2(a)
Write a program to Add two 8 bit hexadecimal numbers
Code Comments
ORG 00H
MOV A,#04H
MOV B,#02H
ADD A,B
MOV R1,A
MOV 30H,A
END
Observations:
2. Change the internal register location and store the result. Indicate the location.
3. Change the internal memory location and store the result. Indicate the location.
Program -2(b)
Write a program to Subtract of two 16 bit hexadecimal numbers
Code Comment
ORG 00H
CLR C
MOV A,#50H
SUBB A,#30H
MOV R0,A
MOV A,#55H
SUBB A,#35H
MOV R1,A
CLR A
SUBB A,#00H
MOV R2,A
END
Observations:
4. Change the internal register location and store the result. Indicate the location.
Program -2(c)
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
Observations:
Program -2(d)
Write an assembly language program to find the 2’s compliment of a given 16 bit number.
Code Comment
ORG 0000h
MOV A, 41h
CPL A
ADD A,#01H
MOV 51h, A
MOV R1,A
MOV A, 40h
CPL A
ADDC A,#00H
MOV 50h, A
MOV R2,A
END
Observations:
Program -2(e)
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
Observations:
2. How are the logical instructions used for bit manipulation? Give examples.
Program -3(a)
Write an assembly language program to convert Binary to ASCII.
Code Comment
MOV DPTR,#9000H
MOVX A,@DPTR
MOV R0,A
SWAP A
MOV DPTR,#900DH
ACALL ASCII
MOV A,R0
ACALL ASCII
SJMP $
ADD A,#30H
MOVX @DPTR,A
INC DPTR
RET
END
Observations:
LOGIC:
Binary ASCII
If binary < 0Ah Add #30h
If binary >=0Ah Add #37h
Program -3(b)
Write an assembly language program to convert Decimal to HEX.
Code Comment
MOV DPTR,#9000H
MOVX A,@DPTR
MOV R0,A
ANL A,#0F0H
SWAP A
MOV B,#0AH
MUL AB
MOV R1,A
MOV A,R0
ANL A ,#0FH
ADD A,R1
MOVX @DPTR,A
END
Observations:
Program -3(c)
Code Comment
ORG 00H
CLR A
UP:ADD A,#01H
MOV 30H,A
DA A
MOV P0,A
MOV A,30H
CJNE A,#99H,UP
DOWN:SUBB A,#01H
MOV 40H ,A
DA A
MOV P0,A
MOV A,40H
CJNE A,#00,DOWN
END
Observations:
1. Mention the counting range of the program (up counter and down counter)
3. Write an assembly language program to display the decimal down counter in PORT 0
Program - 4
Code Comment
ORG 00H
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON ,#50H
SETB TR1
AGAIN: MOV A,#'E'
ACALL TRANS
MOV A,#'L'
ACALL TRANS
MOV A,#'E'
ACALL TRANS
MOV A,#'C'
ACALL TRANS
MOV A,#'T'
ACALL TRANS
MOV A,#'R'
ACALL TRANS
MOV A,#'I'
ACALL TRANS
MOV A,#'C'
ACALL TRANS
MOV A,#'A'
ACALL TRANS
MOV A,#'L'
ACALL TRANS
MOV A,#20H
ACALL TRANS
MOV A,#'R'
ACALL TRANS
MOV A,#'O'
ACALL TRANS
MOV A,#'C'
ACALL TRANS
MOV A,#'K'
ACALL TRANS
MOV A,#'S'
ACALL TRANS
MOV A,#9
ACALL TRANS
AGAIN1: SJMP AGAIN1
TRANS: MOV SBUF,A
HERE: JNB TI,HERE
CLR TI
RET
END
Observations:
Program - 5
Write an assembly language program to transfer the data on to the stack and Retrieve the
data from stack
Code Comment
ORG 0000h
MOV R1,#24H
MOV R2,#11H
MOV R3,#0F2H
PUSH 1
PUSH 2
PUSH 3
POP 2
POP 1
POP 3
END
Observations:
1. Find the contents of stack before and after execution of the given instructions?
MOV R2,#30H
MOV R3,#40H
MOV R4,#50H
PUSH 2
PUSH 3
PUSH 4
Part B
Interfacing
Program -6(i)
Write a C program to generate the sinusoidal waveform and display the same on CRO
#include <reg52.h>
void main( )
{
unsigned char i;
unsigned char idata table[180]=
{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,255,255,254,254,253,252,251,249,246,244,243,241,238,236,234,231,228,226,223,220,
216,213,210,206,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,3
5,39,42,45,49,52,56,60,64,67,71,75,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:
Program – 6(ii)
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:
Program – 6 (iii)
Write a C program to generate the triangular waveform and display the same on CRO
#include<reg52.h>
void main ( )
{
Unsigned int i;
P0 = 0 X 00;
While (1)
{
for (i = 0; i<255; i++)
{
P0 = i;
}
Observations:
Program – 6(iv)
Write a C program to generate the Ramp waveform and display the same on CRO
#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:
Program – 6(v)
Write a C program to generate the Rectangular 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(100);
}
}
Void MSDelay (unsigned int value)
{Unsigned int y;
for ( y = 0 ; y < value ; y++ );
}
Observations:
Program -6 (vi)
Write a C program to generate the Saw tooth waveform and display the same on CRO
#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:
Program -
44
Write a C program for Stepper 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> #include<reg52.h>
Void MSDelay(unsigned char value); Void MS Delay(unsigned char value);
void main( ) void main( )
{ {
While (1) While (1)
{ {
P0=0X66; P0=0X33;
MSDelay(1); MSDelay(1);
P0=0Xcc; P0=0X99;
MSDelay(1); MSDelay(1);
P0=0X99; P0=0Xcc;
MSDelay(1); MSDelay(1);
P0=0X33; P0=0X66;
MSDelay(1); MSDelay(1);
} }
} }
Void MSDelay(unsigned char value) Void MSDelay(unsigned char value)
{ {
Unsigned int y,x; Unsigned int y,x;
for(x=0;x<500;x++); for(x=0;x<500;x++)
for(y=0;y<value;y++); for(y=0;y<value;y++);
} }
Observations:
Program -8
Write a C program for DC motor speed control interface with 8051 microcontroller
#include<reg52.h>
Void MSDelay (unsigned char value); #include<reg52.h>
sbit enablr=P0^6; Void MSDelay (unsigned char value);
sbit mtr_1=P0^7; sbit enablr=P0^6;
sbit mtr_2=P0^4; sbit mtr_1=P0^7;
void main( ) sbit mtr_2=P0^4;
{ void main( )
while(1) {
{ while(1)
mtr_1=1; {
mtr_2=0; mtr_1=0;
MSDelay(50); mtr_2=1;
mtr_1=0; MSDelay(50);
} mtr_1=0;
} }
Void MSDelay(unsigned char value) }
{ Void MSDelay(unsigned char value)
Unsigned int y,x; {
for(x=0;x<40;x++) Unsigned int y,x;
for(y=0;y<value;y++); for(x=0;x<40;x++)
} for(y=0;y<value;y++);
}
Observations:
Program - 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 ;
MICROCONTROLLERS LAB B20EE0407 47
REVA UNIVERSITY SCHOOL OF EEE
MSDelay(1);
en=0;
return;
}
Void lcdready( )
{
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
MSDelay(1);
en=1;
}
return;
}
Observations:
96. What is the use of the serial communication mode 0 in the 8051?
97. Explain in detail the Serial Data Mode 1 in the 8051.
98. Explain how the Baud rate is calculated for the Serial Data Mode 1.
99. How is the Baud rate for the Multiprocessor communication Mode calculated?
100. Explain in detail the Multiprocessor communication Mode in the 8051.
101. Explain the significance of the 9th bit in the Multiprocessor communication Mode.
102. Explain the Serial data mode 3 in the 8051.
103. What are interrupts and how are they useful in Real Time Programming?
104. Briefly describe the Interrupt structure in the 8051.
105. Explain about vectored and non-vectored interrupts in general.
106. What are the five interrupts provided in the 8051?
107. What are the three registers that control and operate the interrupts in 8051?
108. Describe the Interrupt Enable (IE) special function register and its various bits.
109. Describe the Interrupt Priority (IP) special function register and its need.
110. Explain in detail how the Timer Flag interrupts are generated.
111. Explain in detail how the Serial Flag interrupt is generated.
112. Explain in detail how the External Flag interrupts are generated.
113. What happens when a high logic is applied on the Reset pin?
114. Why the Reset interrupt is called a non-maskable interrupt?
115. Why do we require a reset pin?
116. How can you enable/disable some or all the interrupts?
117. Explain how interrupt priorities are set? And how interrupts that occur simultaneously are
handled.
118. What Events can trigger interrupts, and where do they go after getting triggered?
119. What are the actions taken when an Interrupt Occurs?
110. What are Software generated interrupts and how are they generated?
111. What is RS232 and MAX232?
112. What is the function of RS and E pins in an LCD?
113. What is the use of R/W pin in an LCD?
114. What is the significance of DA instruction?
115. What is packed and unpacked BCD?
116. What is the difference between CY and OV flag?
117. When will the OV flag be set?
118. What is an ASCII code?
2. a) Write an ALP to find cube of given 8-bit data using 8051 /MSP430.
b) Write a C program to interface stepper motor to 8051.
4. a) Write an ALP to find the largest / smallest element in an array using 8051.
b) Write a C program to interface stepper motor to 8051.
8. a) Write an ALP to convert two digit BCD number to its equivalent ASCII
value using 8051 /MSP430.
b) Write a C program to generate square wave of amp = (1V-5V)
using DAC. Display the waveform on CRO.
9. a) Write an ALP to find whether the given number is palindrome or not using
8051.
Annexure- I
8051 Instruction Sets
The 8051 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
1. A: Accumulator
2. B: "B" register
3. C: Carry bit
4. Rn: Register R0 - R7 of the currently selected register bank
5. 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).
6. @Ri: 8-bit external or internal RAM address available in register R0 or R1. This is used
for indirect addressing mode.
7. #data8: Immediate 8-bit data available in the instruction.
8. #data16: Immediate 16-bit data available in the instruction.
9. Addr11: 11-bit destination address for short absolute jump. Used by instructions AJMP &
ACALL. Jump range is 2 Kbyte (one page).
10. Addr16: 16-bit destination address for long call or long jump.
11. Rel: 2's complement 8-bit offset (one - byte) used for short jump (SJMP) and all conditional
jumps.
12. bit: Directly addressed bit in internal RAM or SFR
Arithmetic Instructions
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
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
Data Transfer Instructions
All the 21 8051 Microcontroller Special Function Registers (SFRs) along with their functions and Internal
RAM Address is given in the following table
Instruction Sets
Annexure - II
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
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.
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.
Mov dptr,#9000h
Mov r1,#04h
Mov r2,#90h
Mov r3,#91h
Mov r4,#92h
clr c
Mov dph,r2
Back: Movx a, @dptr Mov r5,a
Mov dph,r3
Movx a,@dptr
Addc a,r5 //Note: For multibyte subtraction
subb a,r5
Mov dph,r4
Movx @dptr,a
Inc dptr
Djnz r1,back
Jnc end1
Mov a,#01h
Movx @dptr, a
End1: lcall 0003h
End