On this page
Hardware Counters
This program configures Timer 0 as a counter to count external pulses on pin T0 (P3.4).
Description
The program uses Timer 0 in counter mode to count external events. The count value is continuously displayed on Port 1.
Code
| |
Explanation
- MOV TMOD, #00000101B: Configure Timer 0 in counter mode (mode 1, 16-bit)
- Bit 2 = 1: Counter mode (counts external pulses)
- Bits 0-1 = 01: Mode 1 (16-bit timer/counter)
- SETB P3.4: Set T0 pin (P3.4) as input for external pulses
- MOV TH0/TL0, #00: Initialize counter to 0
- SETB TR0: Start Timer 0
- AGAIN loop: Continuously read TL0 and display on Port 1
The counter increments on each falling edge of the T0 input signal.