8051 Microcontroll
8051 Microcontroll
T M1
T M
MODE
DESCRI PTI ON
0 0 0 13-bit timer
0 1 1 16-bit timer
1 0 2 8-bit auto-reload
1 1 3 Split mode
TMER 0 N MODE 0 (13-BT TMER)
Thi8 i8 one of the raritie8 being kept only for the purpo8e of compatibility with the previuo8 ver8ion8 of
microcontroller8. Thi8 mode configure8 timer 0 a8 a 13-bit timer which con8i8t8 of all 8 bit8 of TH0 and the
lower 5 bit8 of TL0. 8 a re8ult, the Timer 0 u8e8 only 13 of 16 bit8. How doe8 it operate? Each coming
pul8e cau8e8 the lower regi8ter bit8 to change their 8tate8. fter receiving 32 pul8e8, thi8 regi8ter i8
loaded and automatically cleared, while the higher byte (TH0) i8 incremented by 1. Thi8 proce88 i8
repeated until regi8ter8 count up 8192 pul8e8. fter that, both regi8ter8 are cleared and counting 8tart8
from 0.
TMER 0 N MODE 1 (16-BT TMER)
Mode 1 configure8 timer 0 a8 a 16-bit timer compri8ing all the bit8 of both regi8ter8 TH0 and TL0. That'8
why thi8 i8 one of the mo8t commonly u8ed mode8. Timer operate8 in the 8ame way a8 in mode 0, with
difference that the regi8ter8 count up to 65 536 a8 allowable by the 16 bit8.
TMER 0 N MODE 2 (&TO-RELOD TMER)
Mode 2 configure8 timer 0 a8 an 8-bit timer. ctually, timer 0 u8e8 only one 8-bit regi8ter for counting and
never count8 from 0, but from an arbitrary value (0-255) 8tored in another (TH0) regi8ter.
The following example 8how8 the advantage8 of thi8 mode. Suppo8e it i8 nece88ary to con8tantly count
up 55 pul8e8 generated by the clock.
f mode 1 or mode 0 i8 u8ed, t i8 nece88ary to write the number 200 to the timer regi8ter8 and con8tantly
check whether an overflow ha8 occured, i.e. whether they reached the value 255. When it happen8, it i8
nece88ary to rewrite the number 200 and repeat the whole procedure. The 8ame procedure i8
automatically performed by the microcontroller if 8et in mode 2. n fact, only the TL0 regi8ter operate8 a8
a timer, while another (TH0) regi8ter 8tore8 the value from which the counting 8tart8. When the TL0
regi8ter i8 loaded, in8tead of being cleared, the content8 of TH0 will be reloaded to it. Referring to the
previou8 example, in order to regi8ter each 55th pul8e, the be8t 8olution i8 to write the number 200 to the
TH0 regi8ter and configure the timer to operate in mode 2.
TMER 0 N MODE 3 (SPLT TMER)
Mode 3 configure8 timer 0 8o that regi8ter8 TL0 and TH0 operate a8 8eparate 8-bit timer8. n other word8,
the 16-bit timer con8i8ting of two regi8ter8 TH0 and TL0 i8 8plit into two independent 8-bit timer8. Thi8
mode i8 provided for application8 requiring an additional 8-bit timer or counter. The TL0 timer turn8 into
timer 0, while the TH0 timer turn8 into timer 1. n addition, all the control bit8 of 16-bit Timer 1 (con8i8ting
of the TH1 and TL1 regi8ter), now control the 8-bit Timer 1. Even though the 16-bit Timer 1 can 8till be
configured to operate in any of mode8 (mode 1, 2 or 3), it i8 no longer po88ible to di8able it a8 there i8 no
control bit to do it. Thu8, it8 operation i8 re8tricted when timer 0 i8 in mode 3.
The only application of thi8 mode i8 when two timer8 are u8ed and the 16-bit Timer 1 the operation of
which i8 out of control i8 u8ed a8 a baud rate generator.
TMER CONTROL (TCON) REGSTER
TCON regi8ter i8 al8o one of the regi8ter8 who8e bit8 are directly in control of timer operation.
Only 4 bit8 of thi8 regi8ter are u8ed for thi8 purpo8e, while re8t of them i8 u8ed for interrupt control to be
di8cu88ed later.
O TF1 bit i8 automatically 8et on the Timer 1 overflow.
O TR1 bit enable8 the Timer 1.
o 1 - Timer 1 i8 enabled.
o - Timer 1 i8 di8abled.
O TF bit i8 automatically 8et on the Timer 0 overflow.
O TR bit enable8 the timer 0.
o 1 - Timer 0 i8 enabled.
o - Timer 0 i8 di8abled.
HOW TO &SE THE TMER 0 ?
n order to u8e timer 0, it i8 fir8t nece88ary to 8elect it and configure the mode of it8 operation. Bit8 of the
TMOD regi8ter are in control of it:
Referring to figure above, the timer 0 operate8 in mode 1 and count8 pul8e8 generated by internal clock
the frequency of which i8 equal to 112 the quartz frequency.
Turn on the timer:
The TR0 bit i8 8et and the timer 8tart8 operation. f the quartz cry8tal with frequency of 12MHz i8
embedded then it8 content8 will be incremented every micro8econd. fter 65.536 micro8econd8, the both
regi8ter8 the timer con8i8t8 of will be loaded. The microcontroller automatically clear8 them and the timer
keep8 on repeating procedure from the beginning until the TR0 bit value i8 logic zero (0).
HOW TO 'RED' TMER?
Depending on application, it i8 nece88ary either to read a number 8tored in the timer regi8ter8 or to
regi8ter the moment they have been cleared.
- t i8 extremely 8imple to read a timer by u8ing only one regi8ter configured in mode 2 or 3. t i8 8ufficient
to read it8 8tate at any moment. That'8 all!
- t i8 8omehow complicated to read a timer configured to operate in mode 2. Suppo8e the lower byte i8
read fir8t (TL0), then the higher byte (TH0). The re8ult i8:
TH0 = 15 TL0 = 255
Everything 8eem8 to be ok, but the current 8tate of the regi8ter at the moment of reading wa8:
TH0 = 14 TL0 = 255
n ca8e of negligence, 8uch an error in counting (255 pul8e8) may occur for not 8o obviou8 but quite
logical rea8on. The lower byte i8 correctly read (255), but at the moment the program counter wa8 about
to read the higher byte TH0, an overflow occurred and the content8 of both regi8ter8 have been changed
(TH0: 1415, TL0: 2550). Thi8 problem ha8 a 8imple 8olution. The higher byte 8hould be read fir8t,
then the lower byte and once again the higher byte. f the number 8tored in the higher byte i8 different
then thi8 8equence 8hould be repeated. t'8 about a 8hort loop con8i8ting of only 3 in8truction8 in the
program.
There i8 another 8olution a8 well. t i8 8ufficient to 8imply turn the timer off while reading i8 going on (the
TR0 bit of the TCON regi8ter 8hould be cleared), and turn it on again after reading i8 fini8hed.
TMER 0 OVERFLOW DETECTON
&8ually, there i8 no need to con8tantly read timer regi8ter8. t i8 8ufficient to regi8ter the moment they are
cleared, i.e. when counting 8tart8 from 0. Thi8 condition i8 called an overflow. When it occurr8, the TF0 bit
of the TCON regi8ter will be automatically 8et. The 8tate of thi8 bit can be con8tantly checked from within
the program or by enabling an interrupt which will 8top the main program execution when thi8 bit i8 8et.
Suppo8e it i8 nece88ary to provide a program delay of 0.05 8econd8 (50 000 machine cycle8), i.e. time
when the program 8eem8 to be 8topped:
Fir8t a number to be written to the timer regi8ter8 8hould be calculated:
Then it 8hould be written to the timer regi8ter8 TH0 and TL0:
When enabled, the timer will re8ume counting from thi8 number. The 8tate of the TF0 bit, i.e. whether it i8
8et, i8 checked from within the program. t happen8 at the moment of overflow, i.e. after exactly 50.000
machine cycle8 or 0.05 8econd8.
HOW TO MES&RE P&LSE D&RTON?
Suppo8e it i8 nece88ary to mea8ure the duration of an operation, for example how long a device ha8
been turned on? Look again at the figure illu8trating the timer and pay attention to the function of the
GTE0 bit of the TMOD regi8ter. f it i8 cleared then the 8tate of the P3.2 pin doe8n't affect timer
operation. f GTE0 = 1 the timer will operate until the pin P3.2 i8 cleared. ccordingly, if thi8 pin i8
8upplied with 5V through 8ome external 8witch at the moment the device i8 being turned on, the timer will
mea8ure duration of it8 operation, which actually wa8 the objective.
HOW TO CO&NT &P P&LSES?
Similarly to the previou8 example, the an8wer to thi8 que8tion again lie8 in the TCON regi8ter. Thi8 time
it'8 about the CT0 bit. f the bit i8 cleared the timer count8 pul8e8 generated by the internal o8cillator, i.e.
mea8ure8 the time pa88ed. f the bit i8 8et, the timer input i8 provided with pul8e8 from the P3.4 pin (T0).
Since the8e pul8e8 are not alway8 of the 8ame width, the timer cannot be u8ed for time mea8urement and
i8 turned into a counter, therefore. The highe8t frequency that could be mea8ured by 8uch a counter i8
124 frequency of u8ed quartz-cry8tal.
TMER 1
Timer 1 i8 identical to timer 0, except for mode 3 which i8 a hold-count mode. t mean8 that they have the
8ame function, their operation i8 controlled by the 8ame regi8ter8 TMOD and TCON and both of them can
operate in one out of 4 different mode8.
2.7 &RT (&NVERSL SYNCHRONO&S RECEVER ND TRNSMTTER)
One of the microcontroller feature8 making it 8o powerful i8 an integrated &RT, better known a8 a 8erial
port. t i8 a full-duplex port, thu8 being able to tran8mit and receive data 8imultaneou8ly and at different
baud rate8. Without it, 8erial data 8end and receive would be an enormou8ly complicated part of the
program in which the pin 8tate i8 con8tantly changed and checked at regular interval8. When u8ing
&RT, all the programmer ha8 to do i8 to 8imply 8elect 8erial port mode and baud rate. When it'8 done,
8erial data tran8mit i8 nothing but writing to the SB&F regi8ter, while data receive repre8ent8 reading the
8ame regi8ter. The microcontroller take8 care of not making any error during data tran8mi88ion.
Serial port mu8t be configured prior to being u8ed. n other word8, it i8 nece88ary to determine how many
bit8 i8 contained in one 8erial "word, baud rate and 8ynchronization clock 8ource. The whole proce88 i8 in
control of the bit8 of the SCON regi8ter (Serial Control).
SERL PORT CONTROL (SCON) REGSTER
O SM - Serial port mode bit 0 i8 u8ed for 8erial port mode 8election.
O SM1 - Serial port mode bit 1.
O SM2 - Serial port mode 2 bit, al8o known a8 multiproce88or communication enable bit.
When 8et, it enable8 multiproce88or communication in mode 2 and 3, and eventually
mode 1. t 8hould be cleared in mode 0.
O REN - Reception Enable bit enable8 8erial reception when 8et. When cleared, 8erial
reception i8 di8abled.
O TB8 - Tran8mitter bit 8. Since all regi8ter8 are 8-bit wide, thi8 bit 8olve8 the problem of
tran8miting the 9th bit in mode8 2 and 3. t i8 8et to tran8mit a logic 1 in the 9th bit.
O RB8 - Receiver bit 8 or the 9th bit received in mode8 2 and 3. Cleared by hardware if 9th
bit received i8 a logic 0. Set by hardware if 9th bit received i8 a logic 1.
O TI - Tran8mit nterrupt flag i8 automatically 8et at the moment the la8t bit of one byte i8
8ent. t'8 a 8ignal to the proce88or that the line i8 available for a new byte tran8mite. t
mu8t be cleared from within the 8oftware.
O RI - Receive nterrupt flag i8 automatically 8et upon one byte receive. t 8ignal8 that byte
i8 received and 8hould be read quickly prior to being replaced by a new data. Thi8 bit i8
al8o cleared from within the 8oftware.
8 8een, 8erial port mode i8 8elected by combining the SM0 and SM2 bit8:
SM SM1 MODE DESCRI PTI ON BUD RT E
0 0 0 8-bit Shift Register 1/12 the quartz frequency
0 1 1 8-bit UART Determined by the timer 1
1 0 2 9-bit UART 1/32 the quartz frequency (1/64 the quartz frequency)
1 1 3 9-bit UART Determined by the timer 1
n mode 0, 8erial data are tran8mitted and received through the RXD pin, while the TXD pin output clock8.
The bout rate i8 fixed at 112 the o8cillator frequency. On tran8mit, the lea8t 8ignificant bit (LSB bit) i8
8entreceived fir8t.
TRNSMIT - Data tran8mit i8 initiated by writing data to the SB&F regi8ter. n fact, thi8 proce88 8tart8
after any in8truction being performed upon thi8 regi8ter. When all 8 bit8 have been 8ent, the T bit of the
SCON regi8ter i8 automatically 8et.
RECEIVE - Data receive through the RXD pin 8tart8 upon the two following condition8 are met: bit REN=1
and R=0 (both of them are 8tored in the SCON regi8ter). When all 8 bit8 have been received, the R bit of
the SCON regi8ter i8 automatically 8et indicating that one byte receive i8 complete.
Since there are no STRT and STOP bit8 or any other bit except data 8ent from the SB&F regi8ter in the
pul8e 8equence, thi8 mode i8 mainly u8ed when the di8tance between device8 i8 8hort, noi8e i8
minimized and operating 8peed i8 of importance. typical example i8 O port expan8ion by adding a
cheap C (8hift regi8ter8 74HC595, 74HC597 and 8imilar).
MODE 1
n mode 1, 10 bit8 are tran8mitted through the TXD pin or received through the RXD pin in the following
manner: a STRT bit (alway8 0), 8 data bit8 (LSB fir8t) and a STOP bit (alway8 1). The STRT bit i8 only
u8ed to initiate data receive, while the STOP bit i8 automatically written to the RB8 bit of the SCON
regi8ter.
TRNSMIT - Data tran8mit i8 initiated by writing data to the SB&F regi8ter. End of data tran8mi88ion i8
indicated by 8etting the T bit of the SCON regi8ter.
RECEIVE - The STRT bit (logic zero (0)) on the RXD pin initiate8 data receive. The following two
condition8 mu8t be met: bit REN=1 and bit R=0. Both of them are 8tored in the SCON regi8ter. The R bit
i8 automatically 8et upon data reception i8 complete.
The Baud rate in thi8 mode i8 determined by the timer 1 overflow.
MODE 2
n mode 2, 11 bit8 are tran8mitted through the TXD pin or received through the RXD pin: a STRT bit
(alway8 0), 8 data bit8 (LSB fir8t), a programmable 9th data bit and a STOP bit (alway8 1). On tran8mit,
the 9th data bit i8 actually the TB8 bit of the SCON regi8ter. Thi8 bit u8ually ha8 a function of parity bit. On
receive, the 9th data bit goe8 into the RB8 bit of the 8ame regi8ter (SCON).The baud rate i8 either 132 or
164 the o8cillator frequency.
TRNSMIT - Data tran8mit i8 initiated by writing data to the SB&F regi8ter. End of data tran8mi88ion i8
indicated by 8etting the T bit of the SCON regi8ter.
RECEIVE - The STRT bit (logic zero (0)) on the RXD pin initiate8 data receive. The following two
condition8 mu8t be met: bit REN=1 and bit R=0. Both of them are 8tored in the SCON regi8ter. The R bit
i8 automatically 8et upon data reception i8 complete.
MODE 3
Mode 3 i8 the 8ame a8 Mode 2 in all re8pect8 except the baud rate. The baud rate in Mode 3 i8 variable.
The parity bit i8 the P bit of the PSW regi8ter. The 8imple8t way to check correctne88 of the received byte
i8 to add a parity bit to it. Simply, before initiating data tran8mit, the byte to tran8mit i8 8tored in the
accumulator and the P bit goe8 into the TB8 bit in order to be "a part of the me88age. The procedure i8
oppo8ite on receive, received byte i8 8tored in the accumulator and the P bit i8 compared with the RB8
bit. f they are the 8ame- everything i8 OK!
B&D RTE
Baud Rate i8 a number of 8entreceived bit8 per 8econd. n ca8e the &RT i8 u8ed, baud rate depend8
on: 8elected mode, o8cillator frequency and in 8ome ca8e8 on the 8tate of the SMOD bit of the SCON
regi8ter. ll the nece88ary formula8 are 8pecified in the table:
BUD RT E BI TSMOD
ode 0 Fosc. / 12
ode 1
1 Fosc.
16 12 (256-TH1)
BitSD
ode 2
Fosc. / 32
Fosc. / 64
1
0
ode 3
1 Fosc.
16 12 (256-TH1)
TMER 1 S CLOCK GENERTOR
Timer 1 i8 u8ually u8ed a8 a clock generator a8 it enable8 variou8 baud rate8 to be ea8ily 8et. The whole
procedure i8 8imple and i8 a8 follow8:
O Fir8t, enable Timer 1 overflow interrupt.
O Configure Timer T1 to operate in auto-reload mode.
O Depending on need8, 8elect one of the 8tandard value8 from the table and write it to the
TH1 regi8ter. That'8 all.
BUD RT E
FOSC. MHZ)
BI T SMOD
11.0592 12 14.7456 16 20
150 40 h 30 h 00 h
0
300 A0 h 98 h 80 h 75 h 52 h 0
600 D0 h CC h C0 h BB h A9 h 0
1200 E8 h E6 h E0 h DE h D5 h 0
2400 F4 h F3 h F0 h EF h EA h 0
4800
F3 h EF h EF h
1
4800 FA h
F8 h
F5 h 0
9600 FD h
FC h
0
9600
F5 h 1
19200 FD h
FC h
1
38400
FE h
1
76800
FF h
1
M<PROCESSOR COMM&NCTON
8 you may know, additional 9th data bit i8 a part of me88age in mode 2 and 3. t can be u8ed for
checking data via parity bit. nother u8eful application of thi8 bit i8 in communication between two or
more microcontroller8, i.e. multiproce88or communication. Thi8 feature i8 enabled by 8etting the SM2 bit
of the SCON regi8ter. 8 a re8ult, after receiving the STOP bit, indicating end of the me88age, the 8erial
port interrupt will be generated only if the bit RB8 = 1 (the 9th bit).
Thi8 i8 how it look8 like in practice:
Suppo8e there are 8everal microcontroller8 8haring the 8ame interface. Each of them ha8 it8 own
addre88. n addre88 byte differ8 from a data byte becau8e it ha8 the 9th bit 8et (1), while thi8 bit i8
cleared (0) in a data byte. When the microcontroller (ma8ter) want8 to tran8mit a block of data to one of
8everal 8lave8, it fir8t 8end8 out an addre88 byte which identifie8 the target 8lave. n addre88 byte will
generate an interrupt in all 8lave8 8o that they can examine the received byte and check whether it
matche8 their addre88.
Of cour8e, only one of them will match the addre88 and immediately clear the SM2 bit of the SCON
regi8ter and prepare to receive the data byte to come. Other 8lave8 not being addre88ed leave their SM2
bit 8et ignoring the coming data byte8.
8051 MCROCONTROLLER NTERR&PTS
There are five interrupt 8ource8 for the 8051, which mean8 that they can recognize 5 different event8 that
can interrupt regular program execution. Each interrupt can be enabled or di8abled by 8etting bit8 of the
E regi8ter. Likewi8e, the whole interrupt 8y8tem can be di8abled by clearing the E bit of the 8ame
regi8ter. Refer to figure below.
Now, it i8 nece88ary to explain a few detail8 referring to external interrupt8- NT0 and NT1. f the T0 and
T1 bit8 of the TCON regi8ter are 8et, an interrupt will be generated on high to low tran8ition, i.e. on the
falling pul8e edge (only in that moment). f the8e bit8 are cleared, an interrupt will be continuou8ly
executed a8 far a8 the pin8 are held low.
IE Reglster
(Interrupt
Enuble)
O E - global interrupt enabledi8able:
o 0 - di8able8 all interrupt reque8t8.
o 1 - enable8 all individual interrupt reque8t8.
O ES - enable8 or di8able8 8erial interrupt:
o 0 - &RT 8y8tem cannot generate an interrupt.
o 1 - &RT 8y8tem enable8 an interrupt.
O ET1 - bit enable8 or di8able8 Timer 1 interrupt:
o 0 - Timer 1 cannot generate an interrupt.
o 1 - Timer 1 enable8 an interrupt.
O EX1 - bit enable8 or di8able8 external 1 interrupt:
o 0 - change of the pin NT0 logic 8tate cannot generate an interrupt.
o 1 - enable8 an external interrupt on the pin NT0 8tate change.
O ET - bit enable8 or di8able8 timer 0 interrupt:
o 0 - Timer 0 cannot generate an interrupt.
o 1 - enable8 timer 0 interrupt.
O EX - bit enable8 or di8able8 external 0 interrupt:
o 0 - change of the NT1 pin logic 8tate cannot generate an interrupt.
o 1 - enable8 an external interrupt on the pin NT1 8tate change.
NTERR&PT PRORTES
t i8 not po88ible to for8een when an interrupt reque8t will arrive. f 8everal interrupt8 are enabled, it may
happen that while one of them i8 in progre88, another one i8 reque8ted. n order that the microcontroller
know8 whether to continue operation or meet a new interrupt reque8t, there i8 a priority li8t in8tructing it
what to do.
The priority li8t offer8 3 level8 of interrupt priority:
1. Re8et! The ap8olute ma8ter. When a re8et reque8t arrive8, everything i8 8topped and the
microcontroller re8tart8.
2. nterrupt priority 1 can be di8abled by Re8et only.
3. nterrupt priority 0 can be di8abled by both Re8et and interrupt priority 1.
The P Regi8ter (nterrupt Priority Regi8ter) 8pecifie8 which one of exi8ting interrupt 8ource8 have higher
and which one ha8 lower priority. nterrupt priority i8 u8ually 8pecified at the beginning of the program.
ccording to that, there are 8everal po88ibilitie8:
O f an interrupt of higher priority arrive8 while an interrupt i8 in progre88, it will be
immediately 8topped and the higher priority interrupt will be executed fir8t.
O f two interrupt reque8t8, at different priority level8, arrive at the 8ame time then the
higher priority interrupt i8 8erviced fir8t.
O f the both interrupt reque8t8, at the 8ame priority level, occur one after another, the one
which came later ha8 to wait until routine being in progre88 end8.
O f two interrupt reque8t8 of equal priority arrive at the 8ame time then the interrupt to be
8erviced i8 8elected according to the following priority li8t:
1. External interrupt NT0
2. Timer 0 interrupt
3. External nterrupt NT1
4. Timer 1 interrupt
5. Serial Communication nterrupt
P REGSTER (NTERR&PT PRORTY)
The P regi8ter bit8 8pecify the priority level of each interrupt (high or low priority).
O PS - Serial Port nterrupt priority bit
o Priority 0
o Priority 1
O PT1 - Timer 1 interrupt priority
o Priority 0
o Priority 1
O PX1 - External nterrupt NT1 priority
o Priority 0
o Priority 1
O PT - Timer 0 nterrupt Priority
o Priority 0
o Priority 1
O PX - External nterrupt NT0 Priority
o Priority 0
o Priority 1
HNDLNG NTERR&PT
When an interrupt reque8t arrive8 the following occur8:
1. n8truction in progre88 i8 ended.
2. The addre88 of the next in8truction to execute i8 pu8hed on the 8tack.
3. Depending on which interrupt i8 reque8ted, one of 5 vector8 (addre88e8) i8 written to the
program counter in accordance to the table below:
4.
I NTERRUPT SOURCE VECTOR DDRESS)
E0 3 h
TF0 B h
TF1 1B h
R T 23 h
All addresses are in hexadecimal format
5. The8e addre88e8 8tore appropriate 8ubroutine8 proce88ing interrupt8. n8tead of them,
there are u8ually jump in8truction8 8pecifying location8 on which the8e 8ubroutine8 re8ide.
6. When an interrupt routine i8 executed, the addre88 of the next in8truction to execute i8
poped from the 8tack to the program counter and interrupted program re8ume8 operation
from where it left off.
From the moment an interrupt i8 enabled, the microcontroller i8 on alert all the time. When an interrupt
reque8t arrive8, the program execution i8 8topped, electronic8 recognize8 the 8ource and the program
"jump8 to the appropriate addre88 (8ee the table above). Thi8 addre88 u8ually 8tore8 a jump in8truction
8pecifying the 8tart of appropriate 8ubroutine. &pon it8 execution, the program re8ume8 operation from
where it left off.
RESET
Re8et occur8 when the RS pin i8 8upplied with a po8itive pul8e in duration of at lea8t 2 machine cycle8
(24 clock cycle8 of cry8tal o8cillator). fter that, the microcontroller generate8 an internal re8et 8ignal
which clear8 all SFR8, except SB&F regi8ter8, Stack Pointer and port8 (the 8tate of the fir8t two port8 i8
not defined, while FF value i8 written to the port8 configuring all their pin8 a8 input8). Depending on
8urrounding and purpo8e of device, the RS pin i8 u8ually connected to a power-on re8et pu8h button or
circuit or to both of them. Figure below illu8trate8 one of the 8imple8t circuit providing 8afe power-on re8et.
Ba8ically, everything i8 very 8imple: after turning the power on, electrical capacitor i8 being charged for
8everal milli8econd8 throgh a re8i8tor connected to the ground. The pin i8 driven high during thi8 proce88.
When the capacitor i8 charged, power 8upply voltage i8 already 8table and the pin remain8 connected to
the ground, thu8 providing normal operation of the microcontroller. Pre88ing the re8et button cau8e8 the
capacitor to be temporarily di8charged and the microcontroller i8 re8et. When relea8ed, the whole
proce88 i8 repeated.
THRO&GH THE PROGRM- STEP BY STEP...
Microcontroller8 normally operate at very high 8peed. The u8e of 12 Mhz quartz cry8tal enable8
1.000.000 in8truction8 to be executed per 8econd. Ba8ically, there i8 no need for higher operating rate. n
ca8e it i8 needed, it i8 ea8y to built in a cry8tal for high frequency. The problem ari8e8 when it i8
nece88ary to 8low down the operation of the microcontroller. For example during te8ting in real
environment when it i8 nece88ary to execute 8everal in8truction8 8tep by 8tep in order to check O pin8'
logic 8tate.
nterrupt 8y8tem of the 8051 microcontroller practically 8top8 operation of the microcontroller and enable8
in8truction8 to be executed one after another by pre88ing the button. Two interrupt feature8 enable that:
O nterrupt reque8t i8 ignored if an interrupt of the 8ame priority level i8 in progre88.
O &pon interrupt routine execution, a new interrupt i8 not executed until at lea8t one
in8truction from the main program i8 executed.
n order to u8e thi8 in practice, the following 8tep8 8hould be done:
1. External interrupt 8en8itive to the 8ignal level 8hould be enabled (for example NT0).
2. Three following in8truction8 8hould be in8erted into the program (at the 03hex. addre88):
What i8 going on? 8 8oon a8 the P3.2 pin i8 cleared (for example, by pre88ing the button), the
microcontroller will 8top program execution and jump to the 03hex addre88 will be executed. Thi8 addre88
8tore8 a 8hort interrupt routine con8i8ting of 3 in8truction8.
The fir8t in8truction i8 executed until the pu8h button i8 reali8ed (logic one (1) on the P3.2 pin). The
8econd in8truction i8 executed until the pu8h button i8 pre88ed again. mmediately after that, the RET
in8truction i8 executed and the proce88or re8ume8 operation of the main program. &pon execution of any
program in8truction, the interrupt NT0 i8 generated and the whole procedure i8 repeated (pu8h button i8
8till pre88ed). n other word8, one button pre88 - one in8truction.
8051 MCROCONTROLLER POWER CONS&MPTON CONTROL
Generally 8peaking, the microcontroller i8 inactive for the mo8t part and ju8t wait8 for 8ome external 8ignal
in order to take8 it8 role in a 8how. Thi8 can cau8e 8ome problem8 in ca8e batterie8 are u8ed for power
8upply. n extreme ca8e8, the only 8olution i8 to 8et the whole electronic8 in 8leep mode in order to
minimize con8umption. typical example i8 a TV remote controller: it can be out of u8e for month8 but
when u8ed again it take8 le88 than a 8econd to 8end a command to TV receiver. The T89S53 u8e8
approximately 25m for regular operation, which doe8n't make it a pover-8aving microcontroller. nyway,
it doe8n't have to be alway8 like that, it can ea8ily 8witch the operating mode in order to reduce it8 total
con8umption to approximately 40u. ctually, there are two power-8aving mode8 of
operation:Idle and Power Down.
DLE MODE
&pon the DL bit of the PCON regi8ter i8 8et, the microcontroller turn8 off the greate8t power con8umer-
CP& unit while peripheral unit8 8uch a8 8erial port, timer8 and interrupt 8y8tem continue operating
normally con8uming 6.5m. n dle mode, the 8tate of all regi8ter8 and O port8 remain8 unchanged.
n order to exit the dle mode and make the microcontroller operate normally, it i8 nece88ary to enable
and execute any interrupt or re8et. t will cau8e the DL bit to be automatically cleared and the program
re8ume8 operation from in8truction having 8et the DL bit. t i8 recommended that fir8t three in8truction8 to
execute now are NOP in8truction8. They don't perform any operation but provide 8ome time for the
microcontroller to 8tabilize and prevent8 unde8ired change8 on the O port8.
POWER DOWN MODE
By 8etting the PD bit of the PCON regi8ter from within the program, the microcontroller i8 8et to Power
down mode, thu8 turning off it8 internal o8cillator and reduce8 power con8umption enormou8ly. The
microcontroller can operate u8ing only 2V power 8upply in power- down mode, while a total power
con8umption i8 le88 than 40u. The only way to get the microcontroller back to normal mode i8 by re8et.
While the microcontroller i8 in Power Down mode, the 8tate of all SFR regi8ter8 and O port8 remain8
unchanged. By 8etting it back into the normal mode, the content8 of the SFR regi8ter i8 lo8t, but the
content of internal RM i8 8aved. Re8et 8ignal mu8t be long enough, approximately 10mS, to enable
8table operation of the quartz o8cillator.
PCON REGSTER
The purpo8e of the Regi8ter PCON bit8 i8:
O SMOD Baud rate i8 twice a8 much higher by 8etting thi8 bit.
O GF1 General-purpo8e bit (available for u8e).
O GF1 General-purpo8e bit (available for u8e).
O GF0 General-purpo8e bit (available for u8e).
O PD By 8etting thi8 bit the microcontroller enter8 the Power Down mode.
O DL By 8etting thi8 bit the microcontroller enter8 the Idle mode.