Saturday, April 26, 2014

4 Digit Seven Segment Up Counter Circuit - 16F628

In the past I posted a counter and timer circuit and it is used two seven segment displays to display number and it can only count 0-99. you can see it from here. This circuit was developed version of it.

This project shows cheap and accurate up counter and it can count up to 9999 and then it will start from 0. For this circuit i used PIC16F628A micro-controller and four common cathode seven segment displays. Any 7-Segment displays will work in this circuit. You need to identify the pin-out of any display you use. In Proteus schematic i used NOT gate for reduce CPU usage while simulating and you need to replace that NOT gate with NPN transistors such as BC547 and do not connect transistor's base directly with PORTA (A0-A3). Put a 1k-10k resistor for base of each transistor.

4 Digit Seven Segment Counter circuit
Schematic diagram of 4 digit up counter

Operation of Circuit

  • To start counting simply press the 'Count' button and every time you pressed that button the number will increase one by one and displayed on the seven segment displays. if you need to automatic counting, it is also possible to connect this pin with pulse generator.
  • Pressed 'Clear' button to clear the display and start from zero.
  • 'Reset' button is optional and you can omitted it. but you must add pull-up resistor. otherwise device will reset continuously. 'Reset' button is useful when the circuit was stuck or not responded.

The main problem of counter circuit was contact bounce. The contact bounce is a common problem with mechanical switches. When the contacts strike together, their momentum and elasticity act together to cause bounce. The result is a rapidly pulsed electrical current instead of a clean transition from zero to full current. It mostly occurs due to vibrations, slight rough spots and dirt between contacts. This effect is usually unnoticeable when using these components in everyday life because the bounce happens too fast to affect most equipment. However, it causes problems in some analog and logic circuits that respond fast enough to misinterpret on/off pulses as a data stream. Anyway, the whole process doesn’t last long (a few micro or milliseconds), but long enough to be registered by the microcontroller. When only a push-button is used as a counter signal source, errors occur in almost 100% of cases!

To prevent contact bounce I added some extra code. so we can get error less counting from this circuit. When you pressed and hold the Count button this circuit wont count.

PIC16F628A pin
PIC16F628A Datasheet


/******************************************************************************* 4 SSD Up Counter Copyright (C) 2015 Praneeth Kanishka This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses >> Email: scorpionzblog@gmail.com >> Web : http://scopionz.blogspot.com *******************************************************************************/ #define CLR PORTA.F4 #define ssd1 PORTA.F0 #define ssd2 PORTA.F1 #define ssd3 PORTA.F2 #define ssd4 PORTA.F3 void ssdecode(char i); int number=0; char digit1, digit2, digit3, digit4; char Loop=0; char key=0, last_key=0; void Delay_dis(){Delay_ms(5);} void main() { PCON.OSCF = 1; //4MHz CMCON |= 0x07; // Disable Comparators //INTCON = 0b10010000; TRISA = 0x10; TRISB = 0x01; PORTA = 0; PORTB = 0; Delay_ms(10); while(1){ if(!PORTB.F0) key=1; else {key=0; last_key=0;} if(key!=last_key) { if(++number>9999) number=0; last_key = key; } while(Loop <5) { ssdecode(digit1); //Display digit 1 ssd1 = 1; Delay_dis(); ssd1 = 0; ssdecode(digit2); //Display digit 2 if(number>9)ssd2 = 1; else ssd2 = 0; Delay_dis(); ssd2 = 0; ssdecode(digit3); //Display digit 3 if(number>99)ssd3 = 1; else ssd3 = 0; Delay_dis(); ssd3 = 0; ssdecode(digit4); //Display digit 3 if(number>999)ssd4 = 1; else ssd4 = 0; Delay_dis(); ssd4 = 0; Loop++; } Loop = 0; if(!CLR) number=0; digit1 = (number) %10; digit2 = (number/10) %10; digit3 = (number/100) %10; digit4 = (number/1000)%10; } } void ssdecode(char i) { switch (i) { case 0: PORTB = 0b01111110; break; case 1: PORTB = 0b00001100; break; case 2: PORTB = 0b10110110; break; case 3: PORTB = 0b10011110; break; case 4: PORTB = 0b11001100; break; case 5: PORTB = 0b11011010; break; case 6: PORTB = 0b11111010; break; case 7: PORTB = 0b00001110; break; case 8: PORTB = 0b11111110; break; case 9: PORTB = 0b11011110; break; } }

Posted By :

Please Note: All contents provided on this blog are for non-commercial purposes only.
Any question..? Feel Free to Ask!

Drop your Comments below. Please report broken links to here
  1. Where can i download the code?

    ReplyDelete
  2. hello sir would it be possible to put a button for a desired preset value let say 100 each press and stop when the count value reach...

    thnks.. mike

    ReplyDelete
    Replies
    1. You have to modify the code.

      Delete
    2. would it be possible to have the code..sir

      Delete
    3. you can able to download the code from given link

      Delete
    4. Do you done this code. If so please share with me

      Delete
  3. Where is the link..I am not able to doenload from Dowbload button

    ReplyDelete
  4. It is not having code file....I need code

    ReplyDelete
  5. Can you provide code for preset counter with power failure memory.

    ReplyDelete
  6. Please sir the would be nice. Tnx

    ReplyDelete
  7. ang also sir could you add the features With power-off memory counting
    tnx.

    ReplyDelete
  8. Thank you sir for posting this diagram. Can you modify the code to count up and down. May be, changing the clear button to count down button.

    ReplyDelete

 

on line

Labels

Recent comment

Visitors

Free counters!
Copyright © 2012 - Scorpionz™.,All rights reserved | Powered by Blogger