Gast
#587694
Irgendwie will mein Timer einfach nicht funktionieren (16Bit Timer an ATMega16). Ich dachte eigentlich das wäre ganz einfach, aber es tut sich rein garnichts (eigentlich sollte alle 1000ms eine LED blinken). Da ich das ganze zum ersten mal mache (Timer + Interrupts) habe ich wahrscheinlich einen ganz blöden Fehler gemacht. Sieht vielleicht jemand was? Danke! //-------------- INCLUDES ------------------------------------------------ #include <avr\io.h> // Input/output an den Pins #include <avr\interrupt.h> // Interrupts #include "Structs.h" //-------------- GLOBALS ------------------------------------------------ struct strTime curTime; char msFlag = 1; //---------------------------------------------------------------------- -------------------- //---------------------------------------------------------------------- -------------------- // //---------------------------------------------------------------------- -------------------- int main(void) { // Timer initialisieren OCR1A = 0x002B; // Wert im compare register (sollte bei 11,0592MHZ Quarz eine MS bedeuten??) TIMSK |= (1<<OCIE1A); // Bitte Interrupt auslösen TCCR1B = (1<<CS12); // Prescaler (256?) // Init time curTime.ms = 0; curTime.s = 0; curTime.m = 0; curTime.h = 0; // Interrupts AN sei(); // MainLoop while(1) { if( msFlag == 1 ) { msFlag = 0; doAction(); }//end if }//end while return 1; }//end main /* ====================================================================== */ /* Interrupt Service Routine */ /* ====================================================================== */ // Uhrzeit-Timer-Interrupt ISR(TIMER1_COMPA_vect) { // Zählregister resetten TCNT1 = 0; // Um 1 ms weiterlaufen curTime.ms++; if( curTime.ms > 1000 ) { curTime.ms = 0; msFlag = 1; curTime.s++; if( curTime.s > 59 ) { curTime.s = 0; curTime.m++; if( curTime.m > 59 ) { curTime.m = 0; curTime.h++; if( curTime.h > 23 ) { curTime.h = 0; }//end if }//end if }//end if }//end if }