Also ich hab meine 3 LED Routine so gebaut:
Das Ganze auf 30 Werte erweitern und bei Wunsch noch eine Multiplexroutine einbauen und fertig ist der Hanomag (die PWM).Code:volatile unsigned char uc_tim0ovf; volatile unsigned char uc_red ; //Helligkeitswert Rot 0...255 volatile unsigned char uc_green ; //Helligkeitswert Grün 0...255 volatile unsigned char uc_blue ; //Helligkeitswert Blau 0...255 // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) { uc_tim0ovf++ ; if (uc_tim0ovf==0) { uc_tim0ovf++; } if (uc_red>=uc_tim0ovf) { # asm ("SBI PORTC,0"); //Die Rote LED Port C,0 } else # asm ("CBI PORTC,0"); if (uc_green>=uc_tim0ovf) { #asm ("SBI PORTC,1"); //Die Grüne LED Port C,1 } else #asm ("CBI PORTC,1"); if (uc_blue>=uc_tim0ovf) { #asm ("SBI PORTC,2"); //Die Blaue LED Port C,2 } else #asm ("CBI PORTC,2"); } ..... void main(void) { // Declare your local variables here // Input/Output Ports initialization // Port B initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTB=0x00; DDRB=0x00; // Port C initialization // Func6=In Func5=In Func4=In Func3=In Func2=OUT Func1=OUT Func0=OUT // State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTC=0x00; DDRC=0x07; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 8000 kHz TCCR0=0x01; TCNT0=0x00; .....
Was noch fehlt ist die Datenschnittstelle zum Datenempfang, sowie eine eventuell nötige Adressierung.
Wie das Timingmässig hinhaut kannst Du ja nochmal mit AVR Studio 4 Austesten.
Ein paar Zuweisungen fehlen in dem Code noch - ich hab CODEVISION AVR benutzt.







Zitieren
Lesezeichen