i~.
MCS@-51PROGRAMMER’SGUIDE AND INSTRUCTION SET
USING TIMER/COUNTER 1 TO GENERATE BAUD RATES:
For this purpose,Timer 1is usedin mode2 (Aut@Reload).Refer to TimerSetupsectionof this chapter.
BaudRate=
KxOscillatorFreq.
32X12x [256– (THI)]
If SMOD = O,then K = 1.
If SMOD = 1,then K = 2. (SMODis the PCONregister).
Most of the time the user knowsthe baud rate and needsto knowthe reloadvaluefor TH1.
Therefore,the equationto calculateIT-Hcan be writtenas:
TH1 mustbean integer value.RoundingoffTHl to the neareatintegermaynot producethe desiredbaud rate. In
this casejthe user may haveto chooseenother crystal frequency.
Sincethe PCONregisteris not bit addressable,onewayto set the bit is logicalORingthe PCON register.(ie,ORL
PCON,#80H). The addressof PCONis 87H.
USING TIMER/COUNTER 2 TO GENERATE BAUD RATES:
For this purpose,Timer 2 must be used in the baud rate generatingmode.Refer to Timer 2 SetupTable in this
chapter. If Timer2 is beingclockedthroughpin T2 (P1.0)the baud rate is:
BaudRate= Timer2Overflow
Rate
16
And if it is beingclockedinternallythe baud rate is:
BaudRate=
OscFraq
32X [65536- (RCAP2H,RCAP2L)]
To obtainthe reloadvaluefor RCAP2Hand RCAP2Lthe aboveequationcan be rewrittenas:
RCAP2H,RCAP2L= 65536– 32;:a::ate
SERIAL PORT IN MODE 2:
The
baudrate is fixedin thismodeandis 7,, or%. ofthe oscillatorfrequencydpding on the v~ue ofthe SMOD
bit in the PCONregister.
In this modenoneof the Timersare usedand the clockcomesfromthe internalphase2 clock.
SMOD = 1,BaudRate = YWOsc Frcq.
SMOD = O,Baud Rate = yWw FrMI.
To set the SMODbit: ORL
pcON, #80H. The addressof PCONis 87H.
I
SERIAL PORT IN MODE 3:
The
baud rate in mode3 is variableand sets up exactlythe same as in mode 1.
2-20