From: Fredrik Tolf Date: Mon, 2 Jul 2007 21:24:50 +0000 (+0000) Subject: Cycle the display from the Timer2 interrupt. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=8c536798197a233e09c8d146581b434cb7c954e5;p=kokare.git Cycle the display from the Timer2 interrupt. --- diff --git a/kokare.c b/kokare.c index 35e5a01..131015d 100644 --- a/kokare.c +++ b/kokare.c @@ -31,7 +31,6 @@ uint8_t font[16] = { SEGA | SEGE | SEGF | SEGG, }; /* LED */ -#define LCDELAY 1000 uint8_t dsp[2] = {0, 0}; char leda = 0; char ledc = 0; @@ -67,8 +66,9 @@ volatile char trdelay = 0; void init(void) { /* Timer init - * Timer 0 cycles timing sensitive subsystems + * Timer 0 cycles the Triac * Timer 1 is used for global timing + * Timer 2 cycles the LED display */ OCR0A = 100; TCCR0A = 2; @@ -77,6 +77,10 @@ void init(void) TCCR1A = 0; TCCR1B = 1; TIMSK1 = 1; + OCR2A = 16; + TCCR2A = 2; + TCCR2B = 4; + TIMSK2 = 2; /* * B0..2 = Pulse sensor @@ -151,33 +155,27 @@ unsigned long getticks(void) void ledcycle(void) { - static uint16_t last = 0; uint8_t c, d, v; - if(TCNT1 - last > LCDELAY) { - last = TCNT1; - if(++leda >= 8) { - leda = 0; - if(++ledc >= 2) - ledc = 0; - } - if(dsp[ledc] & (1 << leda)) { - if(leda < 6) { - c = 1 << leda; - d = 0; - } else { - c = 0; - d = 0x10 << (leda - 6); - } - d |= ledc?0x40:0x80; + if(++leda >= 8) { + leda = 0; + if(++ledc >= 2) + ledc = 0; + } + if(dsp[ledc] & (1 << leda)) { + if(leda < 6) { + c = 1 << leda; + d = 0; } else { - c = d = 0; + c = 0; + d = 0x10 << (leda - 6); } - cli(); - PORTC = c; - PORTD = (PORTD & 0x0f) | d; - sei(); + d |= ledc?0x40:0x80; + } else { + c = d = 0; } + PORTC = c; + PORTD = (PORTD & 0x0f) | d; } void tempcycle(void) @@ -268,7 +266,6 @@ int main(void) while(1) { mnow = getticks(); - ledcycle(); tempcycle(); calcavg(); convcycle(); @@ -453,6 +450,11 @@ ISR(SIG_OUTPUT_COMPARE0A) } } +ISR(SIG_OUTPUT_COMPARE2A) +{ + ledcycle(); +} + ISR(SIG_OVERFLOW1) { of = 1;