Flashing Lights


C Program to make LEDs flash in a particular pattern


#include "hc12.h"

#define LEN 9

/* Program to imlement a flashing pattern on Port A */

void delay(int num);

main()
{
 const unsigned char table[] = {0x00,0x80,0xc0,0xe0,0xf0,
                                   0xf8,0xfc,0xfe,0xff};
    int i;

    i = 0;

    DDRA = 0xff;             /* Make Port A output */
    while (1)
    {
        PORTA = table[i];    /* Binary counter */
        delay(1);            /* Wait for slow human */
        i = i+1;
        if (i >= LEN) i = 0;
    }
}

void delay(int num)
{
    int i;

    while (num>0)       /* Out loop delays num ms */
    {
        i = 1333;       /* Inner loop takes 6 cycles */
        while (i > 0)   /* 1333 times 6 = 1 ms */
        {
            i = i-1;
        }
        num = num - 1;
    }
}