mci_8

Upload: het-patel

Post on 01-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 MCI_8

    1/7

    Subject:

    Microcontroller &

    Interfacing

    Title:

    8051 Micro controller Timers and counters 8.6

    Experiment No.

    08 DATE:D!. !D"

    AITS/ECD/EXPT

    #e$. %o.

    1.00

    im: ' To study timers nd !ounters

    T(eor): ' "ny mi!ro!ontroller ppli!tions re#uire !ountin$ o% externl e&ents' su!( s t(e %re#uen!y

    o% pulse trin' or t(e $enertion o% pre!ise internl time delys )et*een !omputer 

    !tions. +ot( o% t(ese ts,s !n )e !!omplis(ed usin$ so%t*re te!(ni#ues' )ut so%t*re

    loops %or !ountin$ or timin$ ,eep t(e pro!essor o!!upies so t(t ot(er' per(ps more

    importnt' %un!tions re not done.

    To relie&e t(e pro!essor o% t(is )urden' t*o 1-)it up !ounters' nmed T0 nd T1' re pro&ided

    %or t(e $enerl use o% t(e pro$rmmer. E!( !ounter my )e pro$rmmed to !ount internl !lo!, pulses'

    !tin$ s timer' or pro$rmmed to !ount externl pulses s !ounter.

    T(e !ounters re di&ided into t*o 8)it re$isters !lled t(e timer lo* T0' T1 nd (i$( T20'

    T21 )ytes. All !ounters !tion is !ontrolled )y )it sttes in t(e timer mode !ontrol re$isterT"3D' t(e

    timer/!ounter !ontrol re$ister TC3N' nd !ertin pro$rm instru!tions.

    1. T!%: Timer Control S45 Address 6 882' )it ddress)le:

    *it S)mbol +unction7 T41 Timer1 o&er%lo* %l$. Set *(en timer rolls %rom 1s to 0.!lered *(en pro!essor 

    &e!tors to exe!ute interrupt ser&i!e routine lo!ted t pro$rm ddress 001+2.

    - T51 Timer1 run !ontrol )it. Set to1 )y pro$rm to en)le timer to !ount. Clered to 0 )y

     pro$rm to (lt timer.

    T40 Timer0 o&er%lo* %l$. Set *(en timer rolls %rom 1s to 0.Clered *(en pro!essor 

    &e!tors to exe!ute interrupt ser&i!e routine lo!ted t pro$rm ddress 000+2.

    9 T50 Timer0 run !ontrol )it. Set to1 )y pro$rm to en)le timer to !ount. Clered to 0 )y

     pro$rm to (lt timer.

    IE1 Externl interrupt 1 Ed$e %l$. Set to 1 )y *(en (i$(tolo* ed$e si$nl is

    re!ei&ed on port pin . INT1. Clered *(en pro!essor &e!tors to interruptser&i!e routine lo!ted t pro$rm ddress 0012. Not relted to timer opertions

    ; IT1 Externl interrupt 1 si$nl type !ontrol )it. Set to 1 )y pro$rm to en)le externl

    interrupt 1 to )e tri$$ered )y %llin$ ed$e si$nl. Set to 0 )y pro$rm to en)le

    lo*le&el si$nl on externl interrupt 1 to $enerte n interrupt.

    1 IE0 Externl interrupt 0 Ed$e %l$. Set to 1 )y *(en (i$(tolo* ed$e si$nl is

    re!ei&ed on port pin .; INT0. Clered *(en pro!essor &e!tors to interrupt

    ser&i!e routine lo!ted t pro$rm ddress 0002. Not relted to timer opertions

    0 IT0 Externl interrupt 0 si$nl type !ontrol )it. Set to 1 )y pro$rm to en)le externl

    interrupt 0 to )e tri$$ered )y %llin$ ed$e si$nl. Set to 0 )y pro$rm to en)le

    lo*le&el si$nl on externl interrupt 0 to $enerte n interrupt.

    AT"I

  • 8/9/2019 MCI_8

    2/7

    Subject:

    Microcontroller &

    Interfacing

    Title:

    8051 Micro controller Timers and counters 8.6

    Experiment No.

    08 DATE:D!. !D"

    AITS/ECD/EXPT

    #e$. %o.

    1.00

    ;. TMD: Timer "ode Control S45 Address 6 8B(: 

    Timer 1 Timer 0

     

    *it S)mbol +unction

    7/ >te 35 $te en)le )it' *(i!( !ontrols 5=N/Stop o% time 1/0. Set to 1 )y pro$rm to

    en)le timer to run i% )it T51/0 in TC3N is set nd si$nl on externl interrupt

    INT1/0 pin is (i$(. Clered to 0 )y pro$rm to en)le timer to run i% )it T51/0 in

    TC3N is set.

    -/; C/T Set to 1 )y pro$rm to m,e timer 1/0 !t s !ounter )y !ountin$ pulses %rom

    externl input pins .T1 or .9T0. Clered to 0 )y pro$rm to m,e timer !t s

    timer )y !ountin$ internl %re#uen!y.

    /1 "1 Timer/!ounter opertin$ mode sele!t )it 1. Set/!lered )y pro$rm to sele!t mode.

    9/0 "0 Timer/!ounter opertin$ mode sele!t )it 1. Set/!lered )y pro$rm to sele!t mode.

    M1 M0 Mode

    0 0 0

    0 1 1

    1 0 ;1 1

    Timer !ounter Interru,ts:

    (en pro$rm *is(es to !ount !ertin num)er o% internl pulses or externl e&ents' num)er 

    is pl!ed in one o% t(e !ounters. T(e num)er represents t(e mximum !ount less t(e desired !ount' plus

    1. T(e !ounter in!rements %rom t(e initil num)er to t(e mximum nd t(en rolls o&er to 0 on t(e %inl

     pulse nd n lso sets timer %l$. T(e %l$ !ondition my )e tested )y n instru!tion to tell t(e pro$rm

    t(t t(e !ount (s )een !!omplis(ed' or t(e %l$ my )e used to interrupt t(e pro$rm.

    Timing:

    I% !ounter is pro$rmmed to )e timer' it *ill !ount t(e internl !lo!, %re#uen!y o% t(e 801os!illtor di&ided )y 1;d. As n exmple' i% t(e !rystl %re#uen!y is 1; "2' t(en t(e timer !lo!, *ill

    (&e %re#uen!y o% 1"2.

    T(e resultnt timer !lo!, is $ted to t(e timer )y mens o% t(e !ir!uit s(o*n in %i$ure . In order 

    %or os!illtor !lo!, pulses to re!( t(e timer' t(e C/ T  )it in t(e T"3D re$ister must )e set to 0timer 

    opertion. +it T5X in t(e TC3N re$ister must )e set to 1timer run' nd t(e $te )it in t(e T"3D

    re$ister must )e 0' or

    externl pin INTX must )e 1. In ot(er *ords' t(e !ounter is !on%i$ured s timer' nd t(en t(e timer 

     pulses re $ted to t(e !ounter )y t(e run )it nd t(e $te )it or t(e externl input )its INTX.

    AT"I

  • 8/9/2019 MCI_8

    3/7

    Subject:

    Microcontroller &

    Interfacing

    Title:

    8051 Micro controller Timers and counters 8.6

    Experiment No.

    08 DATE:D!. !D"

    AITS/ECD/EXPT

    #e$. %o.

    1.00

    Timer 

    C/T  6 0Timer

      To timer st$es

    C/T  6 1Counter

    T1/0 Input Pin

      T51/0 +it In TC3N

    >te +it in T"3D

     

    INTX Pin

    Timer Modes of ,eration

    1. Timer Mode 0:

    Settin$ timer X mode )it to 00+ in t(e T"3D re$ister results in suin$ t(e T2X re$ister s n 8

     )it !ounter nd TX s )it !ounter.

    Pulse Interrupt

    Input

     

    Timer "ode 0 1 F +it Timer/Counter 

    -. Timer Mode 1:

    In mode 1 TX is !on%i$ured s %ull 8)it nd T2X is lso !on%i$ured s %ull 8)it !ounter.

    2ere *e !n $et mximum time dely usin$ s timer.

    Pulse

    Input Interrupt

    Timer "ode 1 1- F +it Timer/Counter 

    AT"I

  • 8/9/2019 MCI_8

    4/7

    Subject:

    Microcontroller &

    Interfacing

    Title:

    8051 Micro controller Timers and counters 8.6

    Experiment No.

    08 DATE:D!. !D"

    AITS/ECD/EXPT

    #e$. %o.

    1.00

    . Timer Mode -:

    TX is 8)it !ounter. T2X is used to (old s &lue t(t is loded into TX e&ery time TX

    o&er%lo*s %rom 0%% to 00(. T(e timer %l$ is lso set *(en TX o&er%lo*s.

    T(is mode ex(i)its n utorelod %eture: TX *ill !ount up %rom t(e num)er in T2X'

    o&er%lo*' nd )e initilied $in *it( t(e !ontents o% T2X. 4or exmple' pl!in$ B!( in T2X *ill

    result in dely o% ex!tly .000; se!onds )e%ore t(e o&er%lo* %l$ is set i% - "e$(ert !rystl is

    used.

    Pulse

    Input Interrupt

      5elod TX

    Timer "ode ; Auto5elod o% T %rom T2

    /. Timer Mode 1:

    Timers 0 nd 1 my )e pro$rmmed to )e in mode 0'1' or ; independently o% similr mode %or 

    t(e ot(er timer. T(is is not true %or mode G t(e timers do not operte independently i% mode is !(osen

    %or timer 0. Pl!in$ timer 1 in mode !uses it to stop !ountin$G t(e !ontrol )it T51 nd timer 1 %l$

    T41 re t(en used )y timer 0.

     

    Pulse

    Input Interrupt

     

    4/1; Interrupt

    T51 +it

    in TC3N

    Timer "ode T*o 8+it Timers =sin$ Timer 0

    AT"I

  • 8/9/2019 MCI_8

    5/7

    Subject:

    Microcontroller &

    Interfacing

    Title:

    8051 Micro controller Timers and counters 8.6

    Experiment No.

    08 DATE:D!. !D"

    AITS/ECD/EXPT

    #e$. %o.

    1.00

    Timer 0 in mode )e!omes t*o !ompletely seprte 8)it !ounters. T0 is !ontrolled )y t(e $terrn$ement o% %i$. +elo*. And sets timer %l$ T40 *(en e&er it o&er%lo*s %rom 044( to 00(. T20

    re!ei&es t(e timer !lo!, t(e os!illtor di&ided )y 1;under t(e !ontrol o% T51 only nd sets t(e T41 %l$

    *(en it o&er%lo*s.

      Timer 1 my still )e used in modes 0'1 nd ; *(ile timer 0 is in mode *it( one

    importnt ex!eption: timer 1 *ill $enerte No interrupts *(ile timer 0 is usin$ t(e T41 o&er%lo* %l$.

    S*it!(in$ timer 1 to mode *ill stop it. Timer 1 !n )e used %or )ud rte $enertion %or t(e seril port'

    or ny ot(er mode 0' 1 nd ; %un!tion t(t does not depend on n interrupt %or proper opertion.

    !ounting:

    T(e only di%%eren!e )et*een !ountin$ nd timin$ is t(e sour!e o% t(e !lo!, pulses to t(e !ounters.

    (en used s timer t(e !lo!, pulses re sour!ed %rom t(e os!illtor t(rou$( t(e di&ide)y1;d !ir!uit.

    (en used s !ounter' pin T0P.9 supplies pulses to !ounter 0' nd pin T1P. to !ounter 1. T(e C/

    T  )it in T"3D must )e set to 1.

    T(e input pulse on TX is smpled durin$ P; o% stte e&ery m!(ine !y!le. A !(n$e on t(e

    input %rom (i$( to lo* )et*een smples *ill in!rement t(e !ounter. E!( (i$( nd lo* stte o% t(e input

     pulse must t(us )e (eld !onstnt %or t lest one m!(ine !y!le to ensure reli)le !ountin$. Sin!e t(is

    t,es ;9 pulses' t(e mximum input %re#uen!y t(t !n )e !!urtely !ounted is t(e os!illtor %re#uen!y

    di&ide )y ;9. 4or 1; "2 !rystl' t(e mximum externl %re#uen!y is 002.

    rade ab'In'!(arge 2..D.

    AT"I

  • 8/9/2019 MCI_8

    6/7

    Subject:

    Microcontroller &

    Interfacing

    Title:

    8051 Micro controller Timers and counters 8.6

    Experiment No.

    08 DATE:D!. !D"

    AITS/ECD/EXPT

    #e$. %o.

    1.00

    "3"#!IS"

    4rogramming in ssembl)

    1. 4ind t(e dely $enerted )y Timer 0 in t(e %ollo*in$ !ode. Do not in!lude t(e o&er(ed due to

    instru!tions.

    3r$ 0000(

    Clr p;.

    "o& tmod'H01(

    2ere: mo& tl0'H!(

    "o& t(0'H0)8(

    Set) p;.

    Set) tr0

    A$in: n) t%0'$in

    Clr tr0

    Clr t%0

    Clr p;.

    ;. rite AP to $enerte ; ms dely usin$ timer 1 ? (&in$ !rystl %re#uen!y 1; "2 usin$ mode.

    pollin$ nd interrupt met(od

    . Cl!ulte t(e lr$est possi)le dely in mode 1 i% !rystl %re#uen!y is 11.0B; "2.

    9. T(e %ollo*in$ pro$rm $enertes s#ure *&e on pin P1. !ontinuously usin$ Timer 1 %or time

    dely. 4ind t(e %re#uen!y o% t(e s#ure *&e i% XTA 6 11.0B; "2. Do not in!lude t(e o&er(ed

    due to instru!tions.

    3r$ 0000(

    A$in: mo& tl1'H9(

    "o& t(1'H7-(

    Set) tr1+!,: n) t%1')!,  

    Clr tr1

    Cpl p1.

    Clr t%1

    Smp $in

    . rite pro$rm to $enerte s#ure *&e o% 0J duty !y!le o% 102

    %re#uen!y on pin P1.. =se XTA 6 1;"2. use timer 0 in mode1 pollin$ nd

    interrupt met(od

    -. rite pro$rm to $enerte s#ure *&e o% 70J duty !y!le o% ;2 %re#uen!y

    AT"I

  • 8/9/2019 MCI_8

    7/7

    Subject:

    Microcontroller &

    Interfacing

    Title:

    8051 Micro controller Timers and counters 8.6

    Experiment No.

    08 DATE:D!. !D"

    AITS/ECD/EXPT

    #e$. %o.

    1.00

    on pin P1.0. =se XTA 6 1;"2. use timer 1 in mode 1 pollin$ only

    7. rite pro$rm to $enerte 100us o% dely usin$ timer 0 in mode ;. use XTA

    6 1;"2. interrupt met(od only

    8. rite pro$rm to !ount %re#uen!y o% s#ure *&e )ein$ %ed to T1 pin. =se

    timer 1 s !ounter in mode 1.

    4rogramming in ! 3T 1-M27

    1. rite 801 C pro$rm to to$$le ll t(e )its o% port P1 !ontinuously *it( 10

    mse! o% dely in )et*een. =se timer 0' in mode 1.

    ;. rite n 801 C pro$rm to to$$le ll )its o% P; !ontinuously e&ery 00 ms. =se

    timer 1 in mode 1.

    . rite n 801 C pro$rm to !rete %re#uen!y o% ;.2 on pin P;.. =se

    timer 1 in mode ;.

    AT"I