X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=kokare.c;h=b81842eceeff3431404971e481da96c5bf9c818a;hb=cd47e1a345ab3c02244ec8f09b67ac83df0c65ae;hp=38662bbd287dbf6ce0dfba6f3abd6312b440cf6e;hpb=d776f08c024659d4972e2e22f7374929dc288b99;p=kokare.git diff --git a/kokare.c b/kokare.c index 38662bb..b81842e 100644 --- a/kokare.c +++ b/kokare.c @@ -135,10 +135,10 @@ unsigned char bindisp(unsigned char num) return(ret); } -void display(char num) +void display(char num, char d0, char d1) { - dsp[0] = font[(num / 10) % 10]; - dsp[1] = font[num % 10]; + dsp[0] = font[(num / 10) % 10] | (d0?SEGP:0); + dsp[1] = font[num % 10] | (d1?SEGP:0); } void disphex(unsigned char num) @@ -263,15 +263,16 @@ void convcycle(void) int main(void) { - int state, cur, run; + int state, cur, run, rstate, delta; unsigned long utime; state = 0; cur = 100; run = 0; + rstate = 0; init(); sei(); - display(0); + display(0, 0, 0); while(1) { mnow = getticks(); @@ -288,9 +289,10 @@ int main(void) if(ktok) { ktok = 0; if((tempk >= 273) && (tempk <= 372)) { - display(tempk - 273); + display(tempk - 273, 0, run); } else { - dsp[0] = dsp[1] = SEGG; + dsp[0] = SEGG; + dsp[1] = SEGG | (run?SEGP:0); } } if(pval != 0) @@ -302,10 +304,6 @@ int main(void) else run = !run; } - if(run) - dsp[1] |= SEGP; - else - dsp[1] &= ~SEGP; } else if(state == 1) { /* Temp setting */ if(pval != 0) { @@ -315,10 +313,12 @@ int main(void) cur = 0; if(cur > 100) cur = 100; - if(cur < 100) - display(cur); - else - dsp[0] = dsp[1] = SEGG; + if(cur < 100) { + display(cur, 0, run); + } else { + dsp[0] = SEGG; + dsp[1] = SEGG | (run?SEGP:0); + } utime = mnow; } if(mnow - utime > 1000000) @@ -330,12 +330,9 @@ int main(void) } else if(state == 2) { /* Display raw temp time reading */ if(ttimea < 20000) { - display((ttimea / 100) % 100); - dsp[0] |= SEGP; - if(ttimea >= 10000) - dsp[1] |= SEGP; + display((ttimea / 100) % 100, 1, ttimea >= 10000); } else { - display(ttimea / 1000); + display(ttimea / 1000, 0, 0); } if(sstate == 2) { state = 0; @@ -346,22 +343,26 @@ int main(void) * Set Triac to match temperature */ if(run) { - if(tempk - 273 < cur) { - tron = 1; - if(cur - (tempk - 273) > 5) { - /* For some reason, the Triac currently doesn't - * trigger on one of the AC half-cycles below 0.7 - * ms. */ - trdelay = 7; - } else if(cur - (tempk - 273) >= 3) { - trdelay = 20; - } else if(cur - (tempk - 273) >= 2) { - trdelay = 40; + delta = cur - (tempk - 273); + if(rstate == 0) { + if(delta > 0) { + tron = 1; + if(delta > 8) { + /* For some reason, the Triac currently doesn't + * trigger on one of the AC half-cycles below 0.7 + * ms. */ + trdelay = 7; + } else { + trdelay = 79 - (delta * 9); + } } else { - trdelay = 70; + tron = 0; + rstate = 1; } - } else { + } else if(rstate == 1) { tron = 0; + if(delta >= 2) + rstate = 0; } } else { tron = 0;