0% found this document useful (0 votes)
3 views8 pages

Timer: 8051 Microcontroller Timers Counters 16 Timer 0 Timer 1

Uploaded by

itssam4577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Timer: 8051 Microcontroller Timers Counters 16 Timer 0 Timer 1

Uploaded by

itssam4577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Timers and

Counters
In the 8051 microcontroller, Timers and Counters are important peripherals that allow the
microcontroller to measure time intervals, generate time delays, and count external events. The
8051 has two 16-bit timers/counters: Timer 0 and Timer 1, and each can function as either a timer
or a counter, depending on how they are configured.
Timer
Clock Source: Internal clock of the 8051 microcontroller
Purpose: To measure time or generate delays.

Counter
Clock Source: External pulses from pins T0 (for Timer 0)
or T1 (for Timer 1).
Purpose: To count external events such as the number of
pulses from a sensor or external clock source.

• TCON register controls the start/stop operation of


the timers.
• TMOD register is an 8-bit register used to select
the mode of operation for Timer 0 and Timer 1.
Timer Modes in 8051:
The 8051 timers can operate in the following modes:
1.Mode 0 (13-bit Timer):
1. Timer operates as a 13-bit timer with 8192 counts.
2.Mode 1 (16-bit Timer):
1. Timer operates as a 16-bit timer with 65536 counts.
3.Mode 2 (8-bit Auto-Reload Timer):
1. Timer operates as an 8-bit timer with auto-reload.
2. Only TLx is used as an 8-bit timer. After an overflow, the TLx register is
automatically reloaded with the value stored in THx.
4.Mode 3 (Split Timer Mode):
1. Timer 0 is split into two 8-bit timers: TL0 and TH0 work independently.

In the 8051 microcontroller, the timers are driven by the system clock, but their input clock is
divided by 12 internally. This means that the timer increments or decrements its value once
every 12 machine cycles.
The 8051 microcontroller's timers operate at 1/12 of the oscillator frequency due to the architecture
and design of the chip. For every instruction executed, the microcontroller effectively counts 12
clock cycles.
The 8051 uses a crystal oscillator to generate the clock signal. For a typical 11.0592 MHz crystal,
the 8051 microcontroller generates a clock signal that is 1/12 of the crystal frequency.

Effective Frequency=11.0592 MHz/12 ​≈ 921.6 kHz

Example: Count 10 external pulses using 8051's counter mode


You need to load the appropriate initial values into the THx and TLx registers, where x can be either
0 (for Timer 0) or 1 (for Timer 1).
The 8051 counter is a 16-bit register, so it can count from 0000h to FFFFh (65536 counts in total).
To count 10 pulses, you need to load an initial value that will result in the counter reaching the
overflow (i.e., 0xFFFF) after exactly 10 pulses.
Initial Value=65536−Desired

Converting 65526 to hexadecimal:6552610=𝐹𝐹𝐹6H.​


Initial Value =65536−10=65526
Serial Communication

• 8051 connected to other circuits and I/O devices via four ports P0, P1, P2 and P3. Each port having 8 pins and
totally 32 pins used for data transfer.
• In serial communication data transfer takes place bit wise. i.e. one bit at a time.
• 8051 uses register SBUF to hold the data to be either transferred or received.
• The data to be transmitted is loaded to SBUF only and transmitted out via pin TXD(P3.1) of 8051. During
reception, the data available at pin RXD(P3.0) is loaded to SBUF only.
• This register SCON controls the serial data communication. It is an 8-bit register and bit addressable.

Parallel communication in the 8051 uses the I/O ports (P0, P1, P2, P3) to transfer multiple
bits of data at once.
Interrupts in 8051
Types of Interrupts in 8051
The 8051 microcontroller supports five interrupts:
1.External Interrupt 0 (INT0): Triggered by an external signal.
2.Timer 0 Overflow Interrupt (TF0): Triggered when Timer 0 overflows.
3.External Interrupt 1 (INT1) Triggered by an external signal.
4.Timer 1 Overflow Interrupt (TF1) : Triggered when Timer 1 overflows.
5.Serial Communication Interrupt (RI/TI) : Triggered by serial communication events,
either when:
1.RI (Receive Interrupt): Data has been received.
2.TI (Transmit Interrupt): Data has been transmitted.

• IE register controls whether


specific interrupts are enabled or
disabled.

• IP register is used to assign


priority to interrupts.
Power modes in 8051
8051 microcontroller has two power-saving
modes
• Power Down Mode
•In Power
Idle ModeDown mode, CPU and peripherals clock
remains inactive in this mode.
In Idle Mode, only the clock provided to the CPU gets
deactivated, whereas the peripherals clock will remain
active in this mode.

PCON Register: Power control register

PCON (Power Control) register is used to force the


8051 microcontrollers into power-saving mode.
Example: LCD display using 8051

You might also like