This post provides the implementation of free running counter ( using c language ) for PIC16F84A micro-controller. This code is written in such a way that, the counter starts from a value of β0β ( displayed on the seven segment ) and then increments this value after every second. So, the seven segment display starts from β0β and then displays β1β, β2β, β3β, β4β, β5β, β6β, β7β, β8β, β9β, βAβ, βbβ, βCβ, βdβ, βEβ, and in the end βFβ. After displaying βFβ, counter starts from β0β again and this pattern repeats forever.
The code andΒ ProteusΒ simulation is given in the βDownloadsβ section at the bottom of this page. It is assumed that you know how to make an LED blink withΒ PIC16F84AΒ micro-controller. If you donβt, then please readΒ this postΒ first.
The following figure shows the circuit of free running counter inΒ Proteus.
A crystal of 20 MHz is used here. You can use any crystal value from 0 to 20MHz withΒ PIC16F84A.Β As we know thatΒ PIC16F84AΒ microcontroller has an architecture which executes an instruction in 4 CPU cyclesΒ [1], hence this 20Mhz crystal makes thisΒ PIC16F84AΒ run at 5.0 MIPS (MillionΒ of instructions per second).
PORTB is used here to connectΒ PIC16F84AΒ with the seven segment display. RB0 pin is attached with the βaβ segment of the seven segment display. Similarly, RB1 pin is connected with βbβ segment, RB2 pin is connected with βcβ segment and so on.
Common cathodeΒ seven segment display is used in this example. You can easily modify this circuit and code for the common anode seven segment display as well.
Code
The following function is used in the code to display values on the seven segment display.
Downloads
Free running counter code usingΒ PIC16F84AΒ was compiled inΒ MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10.Β To download code andΒ ProteusΒ simulationΒ click here.
For more detail: How to implement free running counter in PIC16F84A using seven segment display