In this tutorial we will learn how to make auto decrease counter use Timer / Counter Overflow Interrupt. Here I am use PIC16F877A Micrcocontroller and 3 digit multiplexing seven segment display.

 

You can watch the video or read the written tutorial below.

 

Circuit Diagram of counter circuit

 

Source code 

char display[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int i;
char digit1,digit2,digit3;
void interrupt(){
     if(i==1000)i=0;
     //if(i==-1)i=0;
     digit1 = i/100;
     digit2 = (i/10)%10;
     digit3 = i %10;
     
     PORTB = display[digit1];
     PORTD = 0X01;
     delay_ms(5);
     PORTD = 0X00;
     
     PORTB = display[digit2];
     PORTD = 0X02;
     delay_ms(5);
     PORTD = 0X00;
     
     PORTB = display[digit3];
     PORTD = 0X04;
     delay_ms(5);
     PORTD = 0X00;
     T0IF_bit = 0;
     }
     
void main() {
     TRISB = 0X00;
     TRISD = 0X00;
     PORTB = 0X00;
     PORTD = 0X00;
     TMR0 =0;
     OPTION_REG = 0X06;
     INTCON = 0XA0;
     while(1){
              for(i=0;i<1000;i++) delay_ms(50);
              }
}

 

 

 

Download free source code

 

download