25,7 → 25,33 |
volatile unsigned char CH4; |
volatile unsigned char CH5; |
|
uint16_t EEMEM EEPMIN=0x0000; |
uint16_t EEMEM EEPMAX=0xffff; |
uint16_t EEMEM EEPSIG=0xffff; |
|
|
//led kennlinie, (noch nicht implementiert, nur vorbereitet) |
unsigned char kl[256]={ |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 |
}; |
|
|
|
/*##############################################################################*/ |
SIGNAL(SIG_OVERFLOW1) |
{ |
198,12 → 224,9 |
|
#define STEP 256 |
#define MUL 1 |
#define REDUCE 5 |
#define REDUCE 2 |
|
#define EEPADRSIG 0x00 |
#define EEPADRMIN 0x20 |
#define EEPADRMAX 0x22 |
#define EEPSIGATURE 0x55aa |
#define EEPSIGNATURE 0x55aa |
|
unsigned int ppm; |
signed int color; |
215,11 → 238,9 |
unsigned int lmin; |
unsigned int max; |
unsigned int min; |
unsigned long temp1; |
unsigned long temp2; |
signed long temp1; |
signed long temp2; |
|
|
|
DDRB = (CH0_B|CH1_B|CH2_B); |
PORTB = 0x00; |
|
245,26 → 266,24 |
StartPWM(); |
sei(); |
|
|
|
if (eeprom_read_word(EEPADRSIG) != EEPSIGATURE) //check eep if signature is there |
if (eeprom_read_word(&EEPSIG) != EEPSIGNATURE) //check eep if signature is there |
{ |
min = 1100; //default min |
max = 1900; //default max |
eeprom_write_word(EEPADRMIN, min); //no, write initial min |
eeprom_write_word(EEPADRMAX, max); //and max values |
eeprom_write_word(EEPADRSIG, EEPSIGATURE); //along with eep signature |
eeprom_write_word(&EEPMIN, min); //no, write initial min |
eeprom_write_word(&EEPMAX, max); //and max values |
eeprom_write_word(&EEPSIG, EEPSIGNATURE); //along with eep signature |
} |
else |
{ |
min = eeprom_read_word(EEPADRMIN); //signature ok |
max = eeprom_read_word(EEPADRMAX); //read min and max |
min = eeprom_read_word(&EEPMIN); //signature ok |
max = eeprom_read_word(&EEPMAX); //read min and max |
} |
|
setup = 0; //reset setup toggle counter |
setupdly = SetDelay(3000); |
setupdly = SetDelay(5000); |
ppmtodly = SetDelay(5000); |
flashdly = SetDelay(100); |
flashdly = SetDelay(1000); |
|
while (1) |
{ |
296,7 → 315,7 |
if ((ppm > 1600) && ((setup&1)==0)) setup++; // |
if ((ppm < 1400) && ((setup&1)==1)) setup++; // |
|
if (CheckDelay(flashdly)) //setup timeout reached |
if (CheckDelay(flashdly)) |
{ |
CH0 = CH0 ^ 0xff; |
CH1 = CH1 ^ 0xff; |
303,19 → 322,24 |
CH2 = CH2 ^ 0xff; |
flashdly = SetDelay(250); |
} |
|
} |
|
if (setup == 6) //if stick is toggled 6 times |
{ //within setup timeout |
PORTD setbit ledgreen; //store ppm min and max |
eeprom_write_word(EEPADRMIN, lmin); //in eeprom |
eeprom_write_word(EEPADRMAX, lmax); |
setupdly = SetDelay(3000); //for 2000ms |
eeprom_write_word(&EEPMIN, lmin); //in eeprom |
eeprom_write_word(&EEPMAX, lmax); |
min = lmin; |
max = lmax; |
setupdly = SetDelay(2000); |
setup = 7; //enter PWM toggle mode |
|
if (CheckDelay(flashdly)) //setup timeout reached |
} |
|
|
if (setup == 7) |
{ |
if (CheckDelay(flashdly)) //each 25ms toggle PWM's |
{ |
CH0 = CH0 ^ 0xff; |
CH1 = CH1 ^ 0xff; |
322,29 → 346,31 |
CH2 = CH2 ^ 0xff; |
flashdly = SetDelay(25); |
} |
|
|
} |
|
if (CheckDelay(setupdly)) //setup timeout reached |
{ |
setup = 7; //lockdown setup |
setup = 8; //lockdown setup |
PORTD clrbit ledgreen; |
} |
|
//printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
|
|
|
if (setup = 7) |
if (setup == 8) |
{ |
|
temp1 = (STEP * (long)40000 * (long)6) / ((max-REDUCE) - (min+REDUCE)); |
temp1 = (STEP * (signed long)30000 * (signed long)6) / ((max-REDUCE) - (min+REDUCE)); |
temp2 = ((ppm - (min+REDUCE)) * temp1); |
color = temp2 / 40000; |
color = temp2 / 30000; |
|
if (color < 0) color = 0; |
if (color > (STEP * 6)) color = (STEP * 6); |
|
printf("color: %d\n",color); |
|
// Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
if ((color >= (STEP * 0)) && (color < (STEP * 1))) |
{ |