SEGA | SEGE | SEGF | SEGG,
};
/* LED */
-#define LCDELAY 1000
uint8_t dsp[2] = {0, 0};
char leda = 0;
char ledc = 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;
TCCR1A = 0;
TCCR1B = 1;
TIMSK1 = 1;
+ OCR2A = 16;
+ TCCR2A = 2;
+ TCCR2B = 4;
+ TIMSK2 = 2;
/*
* B0..2 = Pulse sensor
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)
while(1) {
mnow = getticks();
- ledcycle();
tempcycle();
calcavg();
convcycle();
}
}
+ISR(SIG_OUTPUT_COMPARE2A)
+{
+ ledcycle();
+}
+
ISR(SIG_OVERFLOW1)
{
of = 1;