10-Second Counter

I have made a 10-Second Counter by using a PIC16F627a and a CD4543 BCD to 7-Segment decoder. This circuit and source code are just a demonstration of using MCU to drive an LED 7-Segment Display via CD4543. The 7-Segment displays from 0 to 9 and the number will roll over to 0 again. The interval between change is 1 second. So, this circuit counts 10 seconds between the roll over. I use TIMER1 module and 32.768KHz crystal to make 1 second timebase (see Clock with 32.768KHz Crystal for more info ).

The schematic of the 10-Second counter
Schematic of 10-Second counter
Project setting of MikroC for using internal oscillator of the PIC16f627a.
Setting MikroC for Internal Oscillator

The firmware is written in MikroC and you can find it below.

//PIC16F627A
//4MHz Internal OSC // One Digit Counter // 06/11/2008 //Punkky unsigned short counter;
unsigned short tick;
void interrupt ()
{

        PIR1.TMR1IF = 0;        // clears TMR1IF         TMR1H = 0x80;
        tick = 1;
}

void main(){
        CMCON = 0x07;   //Digital I/O for PORTA   TRISA = 0x00;
  PORTA = 0x00;
  TRISB = 0x00;
  PORTB = 0x00;
  T1CON = 0x0F;
        
  // Prescaler 1:1   external clock   PIE1.TMR1IE = 1;  // enable interupt to start the clock   INTCON = 0xC0;   // Set GIE, PEIE   TMR1L = 0x00;
  TMR1H = 0x80;
  PCON.OSCF = 1//Internal Clock 4MHz   //PCON.OSCF = 0; //Internal Clock 48KHz doesn't work well   counter = 0;
  tick = 0;
  PORTA.F0 = 1// Enable 4345 BCD to 7-Segment   while(1){
    if(tick){
       tick = 0;
       counter++;
       PORTB = counter;
       if(counter>9){
       counter = 0;
    }
   }
  }
}

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Engr.Arif Naseem | Bloggerized by Naseem - | Affiliate Network Reviews