14,7 → 14,7 |
#include "uart.h" |
#include "twislave.h" |
|
volatile unsigned int PPM_SIGNAL = 1500; |
volatile unsigned int PPM_SIGNAL = 1520; |
volatile unsigned char PPM_NEW = 0; |
volatile unsigned char TMR1OvF = 0; |
volatile unsigned int TMR1MS; |
228,6 → 228,9 |
|
#define EEPSIGNATURE 0x55aa |
|
#define inimin 1200 |
#define inimax 1800 |
|
unsigned int ppm; |
signed int color; |
unsigned int setupdly; |
238,8 → 241,8 |
unsigned int lmin; |
unsigned int max; |
unsigned int min; |
signed long temp1; |
signed long temp2; |
signed long temp1; |
signed long temp2; |
|
DDRB = (CH0_B|CH1_B|CH2_B); |
PORTB = 0x00; |
260,16 → 263,17 |
lmax = 0x0000; |
lmin = 0xffff; |
|
StartUART(); |
// StartUART(); |
StartPPM(); |
//StartI2C(); |
StartPWM(); |
sei(); |
|
if (eeprom_read_word(&EEPSIG) != EEPSIGNATURE) //check eep if signature is there |
min = inimin; //default min |
max = inimax; //default max |
|
if (eeprom_read_word(&EEPSIG) != EEPSIGNATURE) //check eep if signature is there |
{ |
min = 1100; //default min |
max = 1900; //default max |
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 |
276,10 → 280,12 |
} |
else |
{ |
|
min = eeprom_read_word(&EEPMIN); //signature ok |
max = eeprom_read_word(&EEPMAX); //read min and max |
} |
|
|
setup = 0; //reset setup toggle counter |
setupdly = SetDelay(5000); |
ppmtodly = SetDelay(5000); |
355,22 → 361,27 |
PORTD clrbit ledgreen; |
} |
|
printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
|
|
|
if (setup == 8) |
{ |
|
temp1 = (STEP * (signed long)30000 * (signed long)6) / ((max-REDUCE) - (min+REDUCE)); |
temp2 = ((ppm - (min+REDUCE)) * temp1); |
color = temp2 / 30000; |
|
|
|
temp1 = ((long)STEP * 6 * 20000) / ((max-REDUCE) - (min+REDUCE)); |
temp2 = (((int)ppm - ((int)min+REDUCE)) * temp1); |
color = temp2 / 20000; |
|
if (color < 0) color = 0; |
if (color > (STEP * 6)) color = (STEP * 6); |
if (color > ((STEP*6)+1)) color = ((STEP*6)+1); |
|
|
printf("color: %d\n",color); |
//printf("p %u ",ppm); |
//printf("pm %u ",(min+REDUCE)); |
//printf("t1 %li ",temp1); |
//printf("t2 %li ",temp2); |
//printf("c %i\n ",color); |
|
|
// Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
if ((color >= (STEP * 0)) && (color < (STEP * 1))) |
{ |