Nun dann hier einmal mein Hauptprogramm.
[code]void main(void)
{
//Variablendefinition ohne Vorzeichen
uint16_t result1;
uint16_t result2;
uint16_t result3;
uint16_t result4;
uint16_t result5;
uint16_t result6;
uint16_t j;
DDRB=0xff; // alle B-Pins als Ausgänge definiert
DDRC=0b11110000; // Bit 0 und 1 in Port C Eingänge da ADC[1:0]
DDRD=0b11111000; //Alle D-Pins als Ausgänge definiert
//Endlosschleife
while(1)
{
PORTD=0b00000111;
//alle ADC Eingänge der Reihe nach wandeln
result1=readADC(1); //Poti3
result2=readADC(0); //Poti2
result3=readADC(7); //Poti1
//Hardware PWM für J34 bis J38
if(result3>10)
{
TCCR1A |=(1<<COM1A1)|(1<<WGM10)|(1<<WGM12); // 8-Bit Fast-PWM <-dito
TCCR1B |=(1<<CS10)/*| (1<<CS11)*/; //kein Prescaling
OCR1A = (result3/4);
}
if(result3<=10)
{
TCCR1A = (0<<COM1A1);
}
//Hardware PWM für J49 bis J53
if (result1>10)
{
TCCR0A|=(1<<COM0A1)|(1<<WGM00)|(1<<WGM01); // 8-Bit Fast-PWM
TCCR0B|=(1<<CS00);//Kein Prescaling
OCR0A = (result1/4); // result2/4 da 8 Bit
}
if (result1<=10)
{
TCCR0A = (0<<COM0A1);
}
//Software PWM für J39 bis J48
if (result2>10)
{
// 512 Stufen da Frequenz damit höher und kein Sprung in der Helligkeit zu sehen
for (j=0; j<511; j++)
{
if (j<result2/2)
{
PORTB |= (1<<PINB0);
PORTD |= (1<<PIND7);
}
if (j>=result2/2)
{
PORTD &= ~(PORTD);
PORTB &= ~(PORTB);
}
}
}
if (result2<=10)
{
PORTD &= ~(PORTD);
PORTB &= ~(PORTB);
}
}
}[\code]
Lesezeichen