// ************************************************************************************************ // PIC-Header einbinden #include // ************************************************************************************************ // Methodenprototypen // ************************************************************************************************ // Globale Variablen static int TimeBuffer, c, i; static int table[10] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256}; // ************************************************************************************************ // Hauptmethode void main (void) { // ******************************************************************************************** // Konfigurationsbits setzen __CONFIG(0x3F2A); // ******************************************************************************************** // Portspezifikationen #define DATA RB0 // Tristate setzen TRISB0 = 0; // ******************************************************************************************** // Zeitpuffer resetten TimeBuffer = 0; c = 0; i = 0; // ******************************************************************************************** // TIMER setzen T0CS = 0; PSA = 1; PS0 = 0; PS1 = 0; PS2 = 0; // Interrupt bei Timer-Überlauf auslösen T0IE = 1; // Interrupts aktivieren GIE = 1; // ******************************************************************************************** // Beginn der Hauptschleife while (true) { } } // ************************************************************************************************ // Interrupt-Routine für genauen 1Hz-Takt static void interrupt isr (void) { int min, max; // ******************************************************************************************** // PWM if (T0IF) { // schalte durch Modi 0 bis 10 c++; if (c > 500) { TimeBuffer = 0; c = 0; i++; if (i > 9) { i = 0; } } TimeBuffer++; if (TimeBuffer <= table[i]) { DATA = 1; } else { DATA = 0; } if (TimeBuffer >= 256) { TimeBuffer = 0; } T0IF = 0; } }