#include <io.h>
#include <delay.h> 

void main(void)
{      
    unsigned char delayCnt = 0;
    unsigned char digitSelect = 0;
    unsigned char i = 0;
    unsigned long num = 1234;   
    unsigned long temp;
    unsigned char sevenSegDigit[8];
    unsigned char sevenSegNum[10] = {
        0xC0,0xF9,0xA4,0xB0,0x99,
        0x92,0x82,0xF8,0x80,0x90
    };        

    DDRC = 0xFF;
    DDRD = 0xFF;               
                    
    temp = num;
    for(i = 0; i < 8; i++)
    {
        sevenSegDigit[i] = sevenSegNum[temp % 10];
        temp /= 10;
    }
       
    while(1)
    {      
        PORTC = 0xFF;               
        PORTD = 1 << digitSelect;  
        PORTC = sevenSegDigit[digitSelect];
        digitSelect++;
        if(digitSelect >= 8)
        {                  
            digitSelect = 0;
        }   
                    
        if(++delayCnt >= 100)
        {                 
            delayCnt = 0;  
            if(++num > 9999)
            {            
                num = 0;
            } 
            temp = num;
            for(i = 0; i < 8; i++)
            {
                sevenSegDigit[i] = sevenSegNum[temp % 10];
                temp /= 10;
            }  
        }      
                   
        delay_ms(5);    
        
    }
}
   