Timer: 8051 Microcontroller Timers Counters 16 Timer 0 Timer 1
Timer: 8051 Microcontroller Timers Counters 16 Timer 0 Timer 1
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.
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.
• 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.