Program for counter

Sometimes we need a counter to count an event at digital scope. Counter can be made by JK flip-flop. There are some integrated chip contains two or more JK flip-flop that can be operated as a counter. A flip-flop can act as one bit counter. So, if we need 4 bit counter, that can count 0 to 16, we need four flip-flops.
A programmable counter can be made by a microcontroller. AT89S51 have two timers that can be operated as independent counter. To do this, we must set c/t bit at TMOD register. This sample will operate timer 0 as mode 2 counter. By loading 155des at TL0 and TH0, timer 0 act as 100des counter.
A simple frequency counter can be made by this counter.

This is the sample program for counting negative edge of input clock at T0 (p3.4). The number of clock will displayed at 2 digit of 7-segment LED common anode.
This program also acts as frequency divider. The clock frequency will be divided by 100 and emitted to P3.2. Press INT0 for pause and INT0 again to resume.

Here is the listing program.

No comments:

Post a Comment