Program to use Port A to implement a binary counter with an appropriate delay



#define PORTA (*(unsigned char *) 0x0000)
#define PORTB (*(unsigned char *) 0x0001)
#define DDRA  (*(unsigned char *) 0x0002)
#define DDRB  (*(unsigned char *) 0x0003)

#define NUM   

/* Program to imlement a binary counter on Port A */

void delay(int num);

main()
{
    DDRA = 0xff;             /* Make Port A output */
    while (1)
    {
        PORTA = PORTA + 1;   /* Binary counter */
        delay(100);          /* Wait for slow human */
    }
}

void delay(int num)
{
    int i;

    while (num>0)       /* Outer loop delays num ms */
    {
        i = 1000;       /* Inner loop delays for 1 ms */
        while (i > 0)
        {
            i = i-1;
        }
        num = num - 1;
    }
}