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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
ORG 0000H
	
	MOV TMOD , #00000101B
	SETB P3.4
	
	MOV TH0,#00;
	MOV TL0,#00;
	
	SETB TR0
	AGAIN:
	MOV A , TL0
	MOV P1 , A
	
	SJMP AGAIN
END

Explanation

  1. 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)
  2. SETB P3.4: Set T0 pin (P3.4) as input for external pulses
  3. MOV TH0/TL0, #00: Initialize counter to 0
  4. SETB TR0: Start Timer 0
  5. AGAIN loop: Continuously read TL0 and display on Port 1

The counter increments on each falling edge of the T0 input signal.