8
8051 8051 Aula 02 Aula 02 Prof Afonso Ferreira Prof Afonso Ferreira Miguel Miguel

8051 Aula 02

Embed Size (px)

DESCRIPTION

8051 Aula 02. Prof Afonso Ferreira Miguel. Microcontrolador 8051 (MCS-51). Timers do MCS51 Two 16-bit Counter/Timers: Up counters, can interrupt on overflow. Counts: CPU cycles (crystal/12). External input (max. half CPU rate). Four Operation Modes. Microcontrolador 8051 (MCS-51). - PowerPoint PPT Presentation

Citation preview

Page 1: 8051 Aula 02

80518051Aula 02Aula 02

Prof Afonso Ferreira MiguelProf Afonso Ferreira Miguel

Page 2: 8051 Aula 02

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

TimersTimers do MCS51 do MCS51 Two 16-bit Counter/Timers:Two 16-bit Counter/Timers:

Up counters, can interrupt on overflow.Up counters, can interrupt on overflow.

Counts:Counts:CPU cycles (crystal/12).CPU cycles (crystal/12).External input (max. half CPU rate).External input (max. half CPU rate).

Four Operation Modes.Four Operation Modes.

Page 3: 8051 Aula 02

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

TimersTimers do MCS51 do MCS51 Timer Mode 0 :Timer Mode 0 :

Emulates 8048 counter/timer (13-bits).Emulates 8048 counter/timer (13-bits).8-bit counter (TL0 or TL1).8-bit counter (TL0 or TL1).5-bit prescaler (TH0 or TH1).5-bit prescaler (TH0 or TH1).

Timer Mode 1 :Timer Mode 1 :Simple 16-bit counter.Simple 16-bit counter.

Timer Mode 2 :Timer Mode 2 :8-bit auto-reload.8-bit auto-reload.Counter in TL0 or TL1.Counter in TL0 or TL1.Reload value in TH0 or TH1.Reload value in TH0 or TH1.Provides a periodic flag or interrupt.Provides a periodic flag or interrupt.

Page 4: 8051 Aula 02

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51) TimersTimers do MCS51 do MCS51

Timer Mode 3 :Timer Mode 3 :• Splits timer 0 into two 8-bit counter/timers.Splits timer 0 into two 8-bit counter/timers.• First counter (TLO) acts like mode 0,First counter (TLO) acts like mode 0,• without prescaler.without prescaler.• Second counter (TH0):Second counter (TH0):

Counts CPU cycles.Counts CPU cycles. Uses TR1 (timer 1 run bit) as enable.Uses TR1 (timer 1 run bit) as enable. Uses TF1 (timer 1 overflow bit) as flag.Uses TF1 (timer 1 overflow bit) as flag. Uses Timer 1 interrupt.Uses Timer 1 interrupt.

• Timer 1 (when timer 0 is in mode 3 ):Timer 1 (when timer 0 is in mode 3 ): Counter stopped if in mode 3.Counter stopped if in mode 3. Running in mode 0, 1, or 2.Running in mode 0, 1, or 2. Has gate (INT1) and external input (T1), but no flag or interrupt.Has gate (INT1) and external input (T1), but no flag or interrupt. May be used as a baud rate generator.May be used as a baud rate generator.

Page 5: 8051 Aula 02

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

TimersTimers do MCS51 – MODO 1 do MCS51 – MODO 1Osc. ÷12 Osc.

TL18-bits

TF1 TH18-bits

Interrupt

Control

T1 (Pin)

TR1

Gate

INT1 (Pin)

The Gate input controls whether the Counter runs while gated by the interrupt signal or not.

C/T=0

C/T=1

Page 6: 8051 Aula 02

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

TimersTimers do MCS51 – MODO 2 do MCS51 – MODO 2Osc. ÷12 Osc.

TL18-bits

TF1

TH18-bits

Interrupt

Control T1 (Pin)

TR1

Gate

INT1 (Pin)

The Gate input controls whether the Counter runs while gated by the interrupt signal or not.

C/T=0

C/T=1

Page 7: 8051 Aula 02

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

TimersTimers do MCS51 – TMOD do MCS51 – TMODGATE C/T M1 M0 GATE C/T M1 M0

Timer 1 Timer 0

- GATE : Permits INTx pin to enable/disable counter.

- C/T : Set for counter operation, reset for timer operation.

- M1, M0 :

00 : Emulate 8048 counter/timer (13-bits).

01 :16-bit counter/timer.

10 : 8-bit auto-reload mode

11 :Timer 0 = two 8-bit timers.

Timer 1 Counting disabled. Timing function allowed. Can be used as Baud Rate generator.

Page 8: 8051 Aula 02

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

TimersTimers do MCS51 – TCON do MCS51 – TCON

- TF1, TF0 : Overflow flags for Timer 1 and Timer 0.

- TR1, TR0 : Run control bits for Timer 1 and Timer 0. Set to run, reset to hold.

- IE1, IE0 : Edge flag for external interrupts 1 and 0. *Set by interrupt edge, cleared when interrupt is processed.

- IT1, IT0 : Type bit for external interrupts. *Set for falling edge interrupts, reset for 0 level interrupts.

* = not related to counter/timer operation.

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0