| 59,9 → 59,9 |
| { |
| if (ppm > 2100) ppm = 2100; |
| if (ppm < 900) ppm = 900; |
| ppm = (ppm_signal * 3 + ppm) / 4; |
| ppm = (ppm_signal * 7 + ppm) / 8; |
| ppm_signal = ppm; |
| if (ppm_new < 50) ppm_new++; |
| ppm_new = 1; |
| } |
| |
| } |
| 109,7 → 109,6 |
| PORTB = PORTB_BAK; |
| PORTD = PORTD_BAK; |
| |
| |
| if (ms1++ == 32) |
| { |
| ms1=0; |
| 137,7 → 136,6 |
| } |
| |
| |
| |
| char CheckDelay(unsigned int t) |
| { |
| unsigned char temp_hi; |
| 183,19 → 181,20 |
| |
| |
| /*##############################################################################*/ |
| unsigned int GetPPM(void) |
| int GetPPM(void) |
| { |
| //this routines seems to be nesseccary, as reading a 16 bit value |
| //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
| //low and high byte of the 16 bit value a wrong result is possible |
| |
| unsigned char temp_hi; |
| unsigned char temp_lo; |
| unsigned char intmask; |
| unsigned int ppm_temp; |
| |
| temp_hi = (ppm_signal >> 8); |
| temp_lo = (ppm_signal & 0xff); |
| if (temp_hi != (ppm_signal >> 8)) temp_hi = (ppm_signal >> 8); |
| return( (temp_hi << 8) | temp_lo); |
| intmask = TIMSK; //backup interupt enable bits |
| TIMSK &= ~(1<<TICIE1); //disable ppm interrupt |
| ppm_temp = ppm_signal; |
| TIMSK = intmask; //restore interupt enable bits |
| return(ppm_temp); //return ppm_signal |
| |
| } |
| |
| 205,28 → 204,11 |
| /*##############################################################################*/ |
| int main (void) |
| { |
| |
| #define step 128 |
| #define mul 2 |
| |
| #define sigeepadr 0x00 |
| #define mineepadr 0x20 |
| #define maxeepadr 0x22 |
| #define eepsig 0x55aa |
| |
| |
| |
| unsigned int i; |
| unsigned int ppm; |
| unsigned int setupdly; |
| unsigned int ppmtodly; |
| unsigned int lmax; |
| unsigned int lmin; |
| unsigned int max; |
| unsigned int min; |
| unsigned int sig; |
| unsigned char setup; |
| unsigned char colorState; |
| unsigned char nextcolorState=0; |
| |
| |
| DDRB = (CH0_B|CH1_B|CH2_B); |
| PORTB = 0x00; |
| |
| 243,10 → 225,7 |
| ch4 = 0; |
| ch5 = 0; |
| |
| lmax = 0x0000; |
| lmin = 0xffff; |
| |
| StartUART(); |
| //StartUART(); |
| StartPPM(); |
| //StartI2C(); |
| StartPWM(); |
| 253,128 → 232,80 |
| sei(); |
| |
| |
| min = 1100; |
| max = 1900; |
| // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
| |
| if (eeprom_read_word(sigeepadr) != eepsig) |
| { |
| eeprom_write_word(mineepadr, min); |
| eeprom_write_word(maxeepadr, max); |
| eeprom_write_word(sigeepadr, eepsig); |
| } |
| else |
| { |
| min = eeprom_read_word(mineepadr); |
| max = eeprom_read_word(maxeepadr); |
| } |
| |
| printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
| |
| |
| setup = 0; |
| setupdly = SetDelay(3000); |
| ppmtodly = SetDelay(5000); |
| colorState = 0; |
| |
| while (1) |
| { |
| |
| if (ppm_new > 20) |
| { |
| PORTC clrbit ledred; |
| ppm = GetPPM(); |
| ppmtodly = SetDelay(500); |
| if (lmax < ppm) lmax=ppm; |
| if (lmin > ppm) lmin=ppm; |
| } |
| else |
| { |
| PORTC setbit ledred; |
| ppm = min; |
| } |
| |
| if (CheckDelay(ppmtodly)) |
| { |
| ppmtodly = SetDelay(5000); |
| ppm_new = 0; |
| } |
| /* |
| #define step 128 |
| #define mul 2 |
| |
| if ((ppm > 1600) && ((setup&1)==0)) setup++; |
| if ((ppm < 1400) && ((setup&1)==1)) setup++; |
| if (setup == 6) |
| if ((ppm >= (step * 0) && (ppm < (step * 1))) ch0 = mul * ((ppm - (step * 0))); |
| if ((ppm >= (step * 1)) && (ppm < (step * 2))) ch1 = mul * ((ppm - (step * 1))); |
| if ((ppm >= (step * 2)) && (ppm < (step * 3))) ch0 = mul * ((step - 1) - (ppm - (step * 2))); |
| if ((ppm >= (step * 3)) && (ppm < (step * 4))) ch2 = mul * ((ppm - (step * 3))); |
| if ((ppm >= (step * 4)) && (ppm < (step * 5))) ch1 = mul * ((step - 1) - (ppm - (step * 4))); |
| if ((ppm >= (step * 5)) && (ppm < (step * 6))) ch0 = mul * ((ppm - (step * 5))); |
| if ((ppm >= (step * 6)) && (ppm < (step * 7))) ch2 = mul * ((step - 1) - (ppm - (step * 6))); |
| |
| //printf("%d ",ppm); |
| */ |
| |
| for (i=0; i<=255; i++) |
| { |
| PORTD setbit ledgreen; |
| eeprom_write_word(mineepadr, lmin); |
| eeprom_write_word(maxeepadr, lmax); |
| min = lmin; |
| max = lmax; |
| setupdly = SetDelay(2000); |
| } |
| if (CheckDelay(setupdly)) |
| { |
| setup = 0; |
| PORTD clrbit ledgreen; |
| } |
| switch(colorState) |
| { |
| case 0: |
| ch0 = i; //fade in (ch0) red |
| nextcolorState = 2; |
| break; |
| |
| //printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
| |
| |
| /* |
| // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
| if ((ppm >= (step * 0)) && (ppm < (step * 1))) |
| { |
| ch0 = mul * ((ppm - (step * 0))); //fade in red > red (red only) |
| ch1 = 0; |
| ch2 = 0; |
| case 2: |
| ch1 = i; //fade in (ch1) blue to get pure purple (red + blue) |
| nextcolorState = 4; |
| break; |
| |
| case 4: |
| ch0 = 255 - i; //fade out (ch0) red to get pure blue |
| nextcolorState = 6; |
| break; |
| |
| case 6: |
| ch2 = i; //fade in (ch2) green to get pure cyan (blue + green) |
| nextcolorState = 8; |
| break; |
| |
| case 8: |
| ch1 = 255 - i; //fade out (ch1) blue to get pure green |
| nextcolorState = 10; |
| break; |
| |
| case 10: |
| ch0 = i; //fade in (ch0) red to get yellow pure (green + red) |
| nextcolorState = 12; |
| break; |
| |
| case 12: |
| ch2 = 255 - i; //fade out (ch2) green to get pure red |
| nextcolorState = 0; |
| break; |
| } |
| |
| |
| timer = SetDelay(5); //wait 10ms |
| while (!CheckDelay(timer)); |
| } |
| if ((ppm >= (step * 1)) && (ppm < (step * 2))) |
| { |
| ch0 = ((step-1) * mul); |
| ch2 = mul * ((ppm - (step * 1))); //fade in blue > purple (red + blue) |
| ch1 = 0; |
| } |
| if ((ppm >= (step * 2)) && (ppm < (step * 3))) |
| { |
| ch0 = mul * ((step - 1) - (ppm - (step * 2))); //fade out red > blue (blue only) |
| ch2 = ((step-1) * mul); |
| ch1 = 0; |
| } |
| if ((ppm >= (step * 3)) && (ppm < (step * 4))) |
| { |
| ch0 = 0; |
| ch2 = ((step-1) * mul); |
| ch1 = mul * ((ppm - (step * 3))); //fade in green > tuerkis (blue + green) |
| } |
| if ((ppm >= (step * 4)) && (ppm < (step * 5))) |
| { |
| ch0 = 0; |
| ch2 = mul * ((step - 1) - (ppm - (step * 4))); //fade out blue > green (green only) |
| ch1 = ((step-1) * mul); |
| } |
| if ((ppm >= (step * 5)) && (ppm < (step * 6))) |
| { |
| ch0 = mul * ((ppm - (step * 5))); //fade in red > yellow (green + red) |
| ch2 = 0; |
| ch1 = ((step-1) * mul); |
| } |
| if ((ppm >= (step * 6)) && (ppm < (step * 7))) |
| { |
| ch0 = ((step-1) * mul); |
| ch2 = 0; |
| ch1 = mul * ((step - 1) - (ppm - (step * 6))); //fade out green > red (red only) |
| } |
| if ((ppm >= (step * 7)) ) |
| { |
| ch0 = ((step-1) * mul); |
| ch2 = 0; |
| ch1 = 9; |
| } |
| */ |
| |
| colorState = nextcolorState; |
| |
| |
| |
| timer = SetDelay(3); //hold pure colors for additional 3ms |
| while (!CheckDelay(timer)); |
| |
| |
| |
| } |
| |
| |