Header Ads

Make Counter use multiplexing seven segment display with microcontroller (use interrupt)

Welcome to MINA TECHNOLOGY.

In this tutorial we will learn how to make 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







Mikro C Code For Counter:

# define SW1 PORTC.RC0
# define SW2 PORTC.RC1
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;
     TRISC = 0X00;
     TRISD = 0X00;
     PORTB = 0X00;
     PORTC = 0X00;
     PORTD = 0X00;
     TMR0 = 0;                    // Clear Timer0
     OPTION_REG = 0X03;
     INTCON = 0XA0;
     while(1){
              if(SW1==1){
                         i++;
                         delay_ms(20);
                         }
              if(SW2==1){
                         i--;
                         delay_ms(20);
                         }
              }



}


Click the downlaod button for Program File:
download

No comments

Theme images by 5ugarless. Powered by Blogger.