Q1Microprocessor
Question
Q.1. Explain various timers and interrupts and their functions of 8051.
Answer
The 8051 has two 16-bit timers (Timer 0 and Timer 1) configurable in four operating modes for timing/counting/baud-rate generation, and five interrupt sources (two external, two timer overflow, one serial port) each individually enabled and prioritized via the IE and IP special function registers.
Timers in 8051: the 8051 has two 16-bit timer/counter units, Timer 0 and Timer 1, each formed from a pair of 8-bit registers (TH0/TL0 for Timer 0, TH1/TL1 for Timer 1) that increment automatically with each machine cycle (in timer mode, counting internal clock pulses) or with each external pulse on the T0/T1 pins (in counter mode). Timer operation is configured via the TMOD (Timer Mode) register, which selects one of four operating modes independently for each timer: Mode 0 (13-bit timer/counter, for backward compatibility), Mode 1 (16-bit timer/counter, the most commonly used mode for general timing/delay generation), Mode 2 (8-bit auto-reload, where TL reloads automatically from TH on overflow, ideal for generating precise, repetitive baud-rate clock pulses), and Mode 3 (split timer mode, where Timer 0 splits into two independent 8-bit timers, primarily used when Timer 1 is needed exclusively for serial baud rate generation while Timer 0 handles two separate timing tasks). Starting/stopping a timer is controlled via the TR0/TR1 control bits in the TCON register, and timer overflow (when the timer register rolls over from all-1s back to 0) sets the corresponding overflow flag (TF0/TF1) in TCON, which can trigger an interrupt if enabled.
Interrupts in 8051: the 8051 supports five interrupt sources — External Interrupt 0 (INT0), Timer 0 overflow, External Interrupt 1 (INT1), Timer 1 overflow, and Serial Port interrupt (RI/TI) — each individually enabled/disabled via the Interrupt Enable (IE) special function register (with a global interrupt enable/disable bit, EA, also in IE, controlling all interrupts simultaneously), and each individually assignable to high or low priority via the Interrupt Priority (IP) register. Each interrupt source has a fixed vector address in program memory to which execution jumps automatically when that interrupt is serviced (e.g., 0003H for External Interrupt 0, 000BH for Timer 0), and the external interrupts (INT0, INT1) can be individually configured (via bits in TCON) to respond either to a low level or to a falling edge on their respective input pins, providing flexibility in interfacing with different types of external interrupt-triggering hardware. Timers and interrupts together are fundamental to virtually all real-time embedded control applications, enabling the 8051 to generate precise time delays, measure external event durations/frequencies, generate accurate serial communication baud rates, and respond promptly to asynchronous external events without needing to continuously poll for them in software.