Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 28 → Rev 51

/IR-TX-BL/branches/LED-CTRL_V0.01/main.c
1,5 → 1,6
//############################################################################
// - LED CTRL Main
// - PWM CTRL
// - Main
// - ATMEGA8 mit 8MHz
// - Nur für den privaten Gebrauch
// - Keine Garantie auf Fehlerfreiheit
16,6 → 17,7
volatile unsigned int ppm_signal = 1500;
volatile unsigned char ppm_new = 0;
volatile unsigned char TMR1OvF = 0;
volatile unsigned int TMR1MS;
volatile unsigned char ch0;
volatile unsigned char ch1;
volatile unsigned char ch2;
22,9 → 24,8
volatile unsigned char ch3;
volatile unsigned char ch4;
volatile unsigned char ch5;
unsigned int timer;
 
 
 
SIGNAL(SIG_OVERFLOW1)
{
TMR1OvF++;
66,6 → 67,7
SIGNAL(SIG_OVERFLOW0)
{
static unsigned char counter;
static unsigned char ms1;
unsigned char PORTB_BAK;
unsigned char PORTD_BAK;
 
72,75 → 74,68
PORTB_BAK = PORTB;
PORTD_BAK = PORTD;
 
if (counter == 0)
if (counter++ == 254)
{
PORTB_BAK clrbit (CH0_B | CH1_B | CH2_B);
PORTD_BAK clrbit (CH3_D | CH4_D | CH5_D);
PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B);
PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D);
counter = 0;
}
 
if (ch0 == counter) PORTB_BAK LEDOFF CH0_B;
if (ch1 == counter) PORTB_BAK LEDOFF CH1_B;
if (ch2 == counter) PORTB_BAK LEDOFF CH2_B;
if (ch3 == counter) PORTD_BAK LEDOFF CH3_D;
if (ch4 == counter) PORTD_BAK LEDOFF CH4_D;
if (ch5 == counter) PORTD_BAK LEDOFF CH5_D;
PORTB = PORTB_BAK;
PORTD = PORTD_BAK;
 
if (ch0 == 255)
if (ms1++ == 32)
{
PORTB_BAK setbit CH0_B;
ms1=0;
TMR1MS++;
}
if (ch0 == counter)
{
PORTB_BAK setbit CH0_B;
}
if (ch0 == 0)
{
PORTB_BAK clrbit CH0_B;
}
 
 
 
}
 
 
 
if (ch1 == counter)
{
PORTB_BAK setbit CH1_B;
}
if (ch2 == counter)
{
PORTB_BAK setbit CH2_B;
}
if (ch3 == counter)
{
PORTD_BAK setbit CH3_D;
}
if (ch4_BAK == counter)
{
PORTD setbit CH4_D;
}
if (ch5_BAK == counter)
{
PORTD setbit CH5_D;
}
}
}
unsigned int SetDelay (unsigned int t)
{
unsigned char temp_hi;
unsigned char temp_lo;
 
temp_hi = (TMR1MS >> 8);
temp_lo = (TMR1MS & 0xff);
if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8);
 
counter++;
return(((temp_hi << 8) | temp_lo) + t + 1);
 
PORTB = PORTB_BAK;
PORTD = PORTD_BAK;
}
 
 
char CheckDelay(unsigned int t)
{
unsigned char temp_hi;
unsigned char temp_lo;
 
temp_hi = (TMR1MS >> 8);
temp_lo = (TMR1MS & 0xff);
if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8);
 
return(((t - ((temp_hi << 8) | temp_lo)) & 0x8000) >> 9);
 
}
 
 
 
 
 
/*##############################################################################*/
void StartPWM(unsigned char txbyte)
void StartPWM(void)
{
//Timer 0 Config for getting right timing for IR Pattern
TCCR0 = (0<<CS02)|(0<<CS01)|(1<<CS00); // (@8MHz) = 1/8us Clk = 256/8 = 32us overflow
151,9 → 146,6
 
 
 
 
 
 
/*##############################################################################*/
void StartPPM(void)
{
194,15 → 186,19
/*##############################################################################*/
int main (void)
{
unsigned int i;
unsigned char colorState;
unsigned char nextcolorState;
 
DDRC = (1<<ledred);
DDRB = (CH0_B|CH1_B|CH2_B);
PORTB = 0x00;
 
DDRC = (ledred);
PORTC = 0x00;
DDRD = (1<<ledgreen);
 
DDRD = (ledgreen|CH3_D|CH4_D|CH5_D);
PORTD = 0x00;
DDRB = (1<<1)|(1<<2)|(1<<3);
PORTB = 0x00;
 
 
ch0 = 0;
ch1 = 0;
ch2 = 0;
212,18 → 208,71
 
//StartUART();
StartPPM();
StartI2C();
//StartI2C();
StartPWM();
sei();
 
 
//rot > Violett > Blau > Türkis > Grün > Gelb >
 
 
colorState = 0;
while (1)
{
 
//printf("%d ",ppm_signal);
 
for (i=0; i<=255; i++)
{
switch(colorState)
{
case 0:
ch0 = i; //fade in (ch0) red
nextcolorState = 2;
break;
 
case 2:
ch1 = i; //fade in (ch1) blue to get 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 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 (green + red)
nextcolorState = 12;
break;
 
case 12:
ch2 = 255 - i; //fade out (ch2) green to get pure red
nextcolorState = 0;
break;
}
 
 
timer = SetDelay(1);
while (!CheckDelay(timer));
}
colorState = nextcolorState;
timer = SetDelay(3);
while (!CheckDelay(timer));
 
 
}
 
 
/IR-TX-BL/branches/LED-CTRL_V0.01/main.h
16,10 → 16,14
#define setbit |=
#define clrbit &=~
#define invbit ^=
#define ledred 3 //on Port C
#define ledgreen 7 //on Port D
#define correction -60
 
#define LEDON setbit
#define LEDOFF clrbit
 
#define ledred (1<<3) //on Port C
#define ledgreen (1<<7) //on Port D
 
#define CH0_B (1<<3)
#define CH1_B (1<<2)
#define CH2_B (1<<1)
/IR-TX-BL/branches/LED-CTRL_V0.01/twislave.c
1,5 → 1,5
//############################################################################
// - PPM2PentaxIR Uart for Debug only
// - PWM CTRL
// - ATMEGA8 mit 8MHz
// - Nur für den privaten Gebrauch
// - Keine Garantie auf Fehlerfreiheit
/IR-TX-BL/branches/LED-CTRL_V0.01/uart.c
1,5 → 1,5
//############################################################################
// - PPM2PentaxIR Uart for Debug only
// - PWM CTRL
// - ATMEGA8 mit 8MHz
// - Nur für den privaten Gebrauch
// - Keine Garantie auf Fehlerfreiheit