5aca

Upload: skarthikmtech

Post on 01-Mar-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/26/2019 5ACA

    1/20

    8051 timer

    MODE 0

    MODE 1

    MODE 2

    MODE 3

    MODE 0

    MODE 1

    MODE 2

    TIMER 0 TIMER 1

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    UNIT V INTERFACING MICROCONTROLLER

    1. 8051 timers

    The 8051 comes equipped with two timers, both of which may be controlled, set, read, and

    configured individually. The 8051 timers have three general functions: 1 !eeping time and"or

    calculating the amount of time between events, # $ounting the events themselves, or %

    &enerating baud rates for the serial port. one of the primary uses of timers is to measure time. 'e

    will discuss this use of timers first and will subsequently discuss the use of timers to count

    events. 'hen a timer is used to measure time it is also called an (interval timer( since it is

    measuring the time of the interval between two events.

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    2/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    TIME SFR

    TMOD REGISTER

    8051 has two timers which each function essentially the same way. )ne timer is T*+-0 and the

    other is T*+-1. The two timers share two /-s T+) and T$)2 which control the timers,

    and each timer also has two /-s dedicated solely to itself T30"T40 and T31"T41.

    GATE

    !"e# set, timer"counter is enabled, i$ *2T pin is high and T- is set.

    !"e# %&e're(, timer"counter is enabled, i$ T- bit set.

    C)T*

    !"e# set+1,, counter operation input from T input pin.

    !"e# %&e'r+0,, timer operation input from internal cloc6.

    T"e TMOD -te is #/t -it '((ress'-&e.

    007 +) 0

    017 +) 1

    107 +) #

    117 +) %

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    3/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    TCON REGISTER

    TF 1Timer 1 /er$&/2 $&'3

    TF0TR1

    Timer 1 R# %/#tr/& -it

    TR0IE1

    I#terrt 1

    IE0IT1 Timer 1 i#terrts

    IT0

    8051 TIMER)COUNTER

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    4/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    TIMER 0

    MODE 0

    17-it Time M/(e +m/(e 0,

    Timer mode (0( is a 1%7bit timer. This is a relic that was 6ept around in the 8051 to maintain

    compatibility with its predecessor, the 808. &enerally the 1%7bit timer mode is not used in new

    development. 'hen the timer is in 1%7bit mode, T4 will count from 0 to %1. 'hen T4 is

    incremented. *t will (reset( to 0 and increment T3. Thus, effectively, only 1% bits of the two

    timer bytes are being used: bits 07 of T4 and bits 079 of T3. This also means, in essence, the

    timer can only contain 81# values. *f you set a 1%7bit timer to 0, it will overflow bac6 to ;ero

    81# machine cycles later.

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    5/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    16-it Time M/(e +m/(e 1,

    Timer mode (1( is a 1

  • 7/26/2019 5ACA

    6/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    8-it Time M/(e +m/(e ,

    Timer mode (#( is an 87bit auto7reload mode. 'hat is that, you may as6> imple. 'hen a timer

    is in mode #, T3 holds the (reload value( and T4 is the timer itself. Thus, T4 starts counting

    up. 'hen T4 reaches #55 and is subsequently incremented, instead of resetting to 0 as in the

    case of modes 0 and 1, it will be reset to the value stored in T3.

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    7/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    8.5 S&it Timer M/(e +m/(e 7,

    Timer mode (%( is a split7timer mode. 'hen Timer 0 is placed in mode %, it essentially becomes

    two separate 87bit timers. That is to say, Timer 0 is T40 and Timer 1 is T30. ?oth timers count

    from 0 to #55 and overflow bac6 to 0. @ll the bits that are related to Timer 1 will now be tied to

    T30.

    'hile Timer 0 is in split mode, the real Timer 1 i.e. T31 and T41 can be put into modes 0, 1 or

    # normally77however, you may not start or stop the real timer 1 since the bits that do that are now

    lin6ed to T30. The real timer 1, in this case, will be incremented every machine cycle no matter

    what.

    . PROGRAMS IN 8051 TIMERS

    Timer +ode 1:

    *n following, we all use timer 0 as an eample.

    16-ittimer T30 and T40

    T307T40 is incremented continuously when T-0 is set to 1. @nd the 8051 stops to

    increment T307T40 when T-0 is cleared.

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    8/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    The timer wor6s with the internal system cloc6. *n other words, the timer counts up each

    machine cycle. 'hen the timer T307T40 reaches its maimum of ////3, it rolls over to 0000, and

    T/0 is raised.

    Arogrammer should chec6 T/0 and stop the timer 0.

    teps of +ode 1 1"%:

    1. $hoose mode 1 timer 0

    B MOV TMOD9:01;

    #. et the original value to T30 and T40.

    B MOV T;09:FF;

    B MOV TL09:FC;

    %. Cou had better to clear the flag to monitor: T/0D0.

    B CLR TF0

    . tart the timer.

    B SET< TR0

    teps of +ode 1 #"%

    5. The 8051 starts to count up by incrementing the T307T40.

    B T;0TL0= FFFC;9FFFD;9FFFE;9FFFF;90000;

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    9/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    teps of +ode 1 %"%

  • 7/26/2019 5ACA

    10/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    EB'm&e 1

    EB'm&e

    3e#er'te (e&' si#3 timer 0

    DELA

    SET< TR0 Jstart the timer 0

    AGAIN>N< TF09AGAIN

    CLR TR0 Jstop timer 0

    CLR TF0 Jclear timer 0 flag

    RET

    S/&ti/#

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    11/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    *n the above program notice the following steps.

    1. T+) D 0000 0001 is loaded.

    #. FFF; is loaded into T30 B T40.

    %. A1.5 is toggled for the high and low portions of the pulse.

    . The 4@C subroutine using the timer is called.

    5. *n the 4@C subroutine, timer 0 is started by the KSET< TR0L instruction.

  • 7/26/2019 5ACA

    12/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

  • 7/26/2019 5ACA

    13/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    E @synchronous serial data communication is widely used for character7oriented transmissions

    E The start bit is always a 0 low and the stop bits is 1 high

    D't' Tr'#s$er R'te

    E The rate of data transfer in serial data communication is stated in -s -its er se%/#(.

    E @nother widely used terminology for bps is -'( r'te.

    B *t is modem terminology and is defined as t"e #m-er /$ si3#'& %"'#3es er se%/#(

    8051 Seri'& P/rt

    E ynchronous and @synchronous

    E $)2 -egister is used to $ontrolE ata Transfer through TFd O -Fd pins

    E ome time 7 $loc6 through TFd Ain

    /our +odes of )peration:

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    14/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    M/(e 0 S#%"r/#/s Seri'& C/mm#i%'ti/#

    M/(e 1 8

  • 7/26/2019 5ACA

    15/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    8051

    Seri'& P/rt M/(e 0

    The erial Aort in +ode70 has the following features:

    1. erial data e#ter '#( eBits t"r/3" R?D

    #. T?D outputs the %&/%

    %. 8 bits are transmitted " received

    . The baud rate is fied at 1"1# of the oscillator frequency

    8051 Seri'& P/rt M/(e 1

    The erial Aort in +ode71 has the following features:

    1. erial data e#ters t"r/3" R?D

    #. erial data eBits t"r/3" T?D

    %. )n receive, the stop bit goes into -?8 in $)2

    4. 10 -its are transmitted " received

    1. Start bit (0)

    2. Data bits (8)

    3. Stop Bit (1)

    5. ?aud rate is determined by the Timer 1 over flow rate

    8051 Seri'& P/rt M/(e

    The erial Aort in +ode7# has the following features:

    1. erial data e#ters t"r/3" R?D

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    16/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    #. erial data eBits t"r/3" T?D

    %. th data bit T

  • 7/26/2019 5ACA

    17/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    18/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    Pr/3r'm +Tr'#s$er,

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    19/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    Pr/3r'm +Re%eie,

    !rite ' r/3r'm $/r t"e 8051 t/ tr'#s$er &etter HA seri'&& 't 4800 -'( r'te9 %/#ti#/s&.

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY

  • 7/26/2019 5ACA

    20/20

    EC 6504 MICROPROCESSORS AND MICROCONTROLLERS

    Pr/3r'm t"e 8051 t/ re%eie -tes /$ ('t' seri'&&9 '#( t t"em i# P1. Set t"e -'( r'te 't

    4800.

    KARTHIK. S SSM INSTITUTE OF ENGINEERING AND TECHNOLOGY