/*************************************** Project : Fensterheber Version : Chip type : AT90S2343 Clock frequency : 1.000000 MHz, Internal XO ***************************************/ /*************************************** Declarationen ***************************************/ #include <90s2343.h> #define FB_OPEN PINB.1 #define FB_CLOSE PINB.2 #define LED PORTB.0 #define UP PORTB.3 #define DOWN PORTB.4 #define R_TIME 2000 #define D_TIME 3000 #define S_TIME 500 #define A_TIME 3500 #define ON 1 #define OFF 0 /*************************************** Variablen ***************************************/ int timer_count, abbruch; /*************************************** Funktionen ***************************************/ interrupt [TIM0_OVF] void timer0_ovf_isr(void) // Timer 0 Ueberlauf interrupt routine { #asm ("wdr") // Watchdog reset timer_count++; // Timer Counter incrementieren if (timer_count > A_TIME) // Ueberlauf abfangen { timer_count=D_TIME; // Counter verkleinern abbruch=0;}; // Algemeiner Timeoff } // /*************************************** Hauptprogram ***************************************/ void main(void) { WDTCR=0x0E; // Watchdog initialisieren OSC/2048 DDRB=0x19; // Port B initialisieren PORTB=0x00; // TCCR0=0x02; // Timer 0 initialisieren TCNT0=0x00; // System Clock, 500,000 kHz TIMSK=0x02; // Timer Interrupt initialisieren #asm("sei") // Interrupts einschalten LED=ON; // Beim einschalten blinken: timer_count=0; // Zeichen für gelungene Programmierung while (timer_count < S_TIME){}; // und Start. LED=OFF; // Der µC hat Problemme beim Start timer_count=0; // mit internen Oscilator. while (timer_count < S_TIME){}; // Kein Blinken -> Start nicht erfolgt. LED=ON; // Einfach neu einschalten. timer_count=0; // while (timer_count < S_TIME){}; // LED=OFF; while (1) // Ewige Schleife, horchen und handeln :) { if (FB_OPEN) // FB_O gedrueckt { timer_count=0; // ab die Lutzi :) abbruch=1; while ((FB_OPEN)&(abbruch)) {}; // Taste losgelassen timer_count=0; // Falls Death lock aktiv, ueberhoeren while ((timer_count < S_TIME)&(abbruch)){}; timer_count=0; // warten auf FB_O while ((timer_count < R_TIME)&(abbruch)) { if (FB_OPEN) // FB_O gedrueckt { while (FB_OPEN) {}; // FB_O losgelassen while ((timer_count < R_TIME)&(abbruch)) // warten auf FB { if (FB_OPEN) // FB_O gedrueckt { while ((FB_OPEN)&(abbruch)) {}; // FB_O losgelassen timer_count=0; // DOWN=ON; LED=ON; // Fenster runter an while ((timer_count < D_TIME)&(abbruch)) // Ende mit Timeoff oder FB { if (FB_CLOSE) abbruch=0; // abbruch, FB_C Taste if (FB_OPEN) abbruch=0; // abbruch, FB_O Taste }; DOWN=OFF;LED=OFF; // Fenster runter aus abbruch=0; // Ab in Grundschleiffe }; if (FB_CLOSE) // FB_O Taste gedrueckt { while ((FB_CLOSE)&(abbruch)) {}; // Taste FB_C losgelassen timer_count=0; // Death lock Behandlung, quic und dirty while ((!FB_CLOSE)&(abbruch)&(timer_count < S_TIME)) {}; timer_count=0; while ((FB_CLOSE)&(abbruch)&(timer_count < S_TIME)) {}; timer_count=0; UP=ON; LED=ON; // Fenster hoch an while ((timer_count < D_TIME)&(abbruch)) // Ende mit Timeoff oder FB { if (FB_CLOSE) abbruch=0; // abbruch, FB_C Taste if (FB_OPEN) abbruch=0; // abbruch, FB_O Taste }; UP=OFF;LED=OFF; // Fenster runter aus abbruch=0; // Ab in Grundschleiffe }; }; if (FB_CLOSE) abbruch=0; // Kombination FB_O / FB_C führt zu nix }; }; // Zur sicherheit: UP=OFF; // Fenster hoch aus DOWN=OFF; // Fenster runter aus }; }; }