#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define uchar unsigned char
#define uint unsigned int
void secint(void); //timer isr per second
void print_byte(char byte); //converted to binary formatted
struct{
uint delay;
uchar pattern;
} cycle[] = {
{1, 0x12}, //0
{3, 0x41}, //1
{1, 0x21}, //2
{5, 0x14}, //3
{3, 0xc1}, //4
{5, 0x1c} //5
};
const char* bit_rep[16] = {
[ 0] = "0000", [ 1] = "0001", [ 2] = "0010", [ 3] = "0011",
[ 4] = "0100", [ 5] = "0101", [ 6] = "0110", [ 7] = "0111",
[ 8] = "1000", [ 9] = "1001", [10] = "1010", [11] = "1011",
[12] = "1100", [13] = "1101", [14] = "1110", [15] = "1111",
};
uchar walk, LEDS;
void main(void){
/*initialize*/
clock_t start_t = 0, end_t = 0;
while(1){
if(end_t-start_t){
start_t = end_t;
/*inerrupt function*/
secint();
}
else{
end_t
= clock() / CLOCKS_PER_SEC
; /*main program*/
walk=2;
}
}
printf("should not be here\n"); }
void secint(void){
static uchar count;
static uchar index;
static uint countdown;
uchar i;
count++;
LEDS=cycle[i].pattern; print_byte(LEDS);
countdown = cycle[i].delay;
if(--countdown == 0){
index++;
if(index==4)index=0;
switch(index){
case 1:
if((walk&0x2) == 2){
walk = walk & 0xfd;
i=index+3;
}
break;
case 3:
if((walk&0x1) == 1){
walk= walk & 0xfe;
i=index+2;
}
break;
default: i=index;
}
}
}
void print_byte(char byte){
printf("%s %s\n", bit_rep
[byte
>>4], bit_rep
[byte
&0x0f]); }
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCiNkZWZpbmUgdWNoYXIgdW5zaWduZWQgY2hhcgojZGVmaW5lIHVpbnQgdW5zaWduZWQgaW50Cgp2b2lkIHNlY2ludCh2b2lkKTsJCQkvL3RpbWVyIGlzciBwZXIgc2Vjb25kCnZvaWQgcHJpbnRfYnl0ZShjaGFyIGJ5dGUpOwkvL2NvbnZlcnRlZCB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