//common anode display
#include<pic.h>
#define _XTAL_FREQ 20000000
#define ctrl0 RD0
#define ctrl1 RD1
#define ctrl2 RD3
#define ctrl3 RD4
unsigned char digidisp=0;
static int min2,min1,sec2,sec1;
unsigned char digival[10]={0xc0,0xf9,0XA4,0xB0,0x19,0X6D,0x7D,0x07,0x7F,0X6F};
void interrupt isr()
{
TMR0IF=0;
TMR0=0X00;
ctrl0=ctrl1=ctrl2=ctrl3=0;
digidisp++;
digidisp=digidisp%4;
switch(digidisp)
{
case 0:
{
PORTB=digival[sec2];
ctrl0=1;
break;
}
case 1:
{
PORTB=digival[sec1];
ctrl1=1;
break;
}
case 2:
{
PORTB=digival[min1];
ctrl2=1;
break;
}
case 3:
{
PORTB=digival[min2];
ctrl3=1;
break;
}
}
}
void main()
{
TRISB=0X00;
PORTB=0X00;
TRISD=0X00;
PORTD=0X00;
OPTION_REG=0X00;
TMR0=0X00;
TMR0IF=0;
GIE=1;
PEIE=1;
TMR0IE=1;
min2=min1=sec2=sec1=0;
while(1) // Forward counting
{
min2=min1=sec2=sec1=0;
for(sec2=0;sec2<6;sec2++)
{
for(sec1=0;sec1<10;sec1++)
{
__delay_ms(1000);
}
}
}
}