/***************************************************************************/ /* Das Programm zur Diesel-Ente */ /* -------------------------------------------------------------------- */ /* copyright (c) 2002 by Hubersoft Corp. All rights reserved. */ /***************************************************************************/ #include #include #include #include //#TARGET AT90S2213 volatile unsigned int drossel=15; volatile unsigned int randseed=33797; //Zufallszähler volatile unsigned char unicount=0; volatile unsigned char gaspointer=0; volatile unsigned char motoran=0; const unsigned char gasschema[3][10]={{10, 40, 7, 40, 15, 40, 20, 10, 40, 40}, {0, 50, 3, 50, 100, 50, 20, 150, 100, 255}, {0, 0, 0, 0, 1, 0, 2, 2, 0, 0}}; unsigned char i,w; /***********************************************************************************/ void delay(unsigned int ms) { register unsigned int a; register unsigned char b, c; for (a=ms; a>0; --a) for (b=27; b>0; --b) for (c=91; c>0; --c); } /***********************************************************************************/ void mdelay(unsigned int ms) { register unsigned int a, b; for (a=ms; a>0; --a) for (b=7; b>0; --b); } /***********************************************************************************/ unsigned int random(unsigned int max) { unsigned char temp; randseed=randseed*33797+1; temp=randseed; randseed>>=8; randseed=randseed+256*temp; return randseed%max; } /***********************************************************************************/ void duckforward(void) {cbi(PORTD,0);cbi(PORTD,1); sbi(PORTD,2);sbi(PORTD,3);} void duckbackward(void) {sbi(PORTD,0);sbi(PORTD,1); cbi(PORTD,2);cbi(PORTD,3);} void duckstop(void) {sbi(PORTD,0);cbi(PORTD,1); sbi(PORTD,2);cbi(PORTD,3);} /***********************************************************************************/ SIGNAL(SIG_OVERFLOW0) { unsigned char i; if (!unicount) { if (gasschema[0][gaspointer]>drossel) drossel++; for(i=0;i<2;i++) if (gasschema[0][gaspointer]8) d=1; sbi(PORTD,6); delay(2);cbi(PORTD,6); delay(d); sbi(PORTD,6); delay(1);cbi(PORTD,6); for(w=0;w<10;w++) {sbi(PORTD,6); mdelay(5);cbi(PORTD,6); mdelay(d*120);} } motoran=1; drossel=15; gaspointer=0; unicount=0; outp(5, TCCR0); // Timer 0 prescaler 1024 outp(2, TIMSK); // Timer 0 overflow int enable (38.14697266) sei(); // Enable Interrupts } /***********************************************************************************/ void motoraus(void) { unsigned char i; cli(); for(i=0;i<4;i++) { sbi(PORTD,6); delay(i*2+1);cbi(PORTD,6); delay(2); sbi(PORTD,6); delay(10);cbi(PORTD,6); delay(i*20+40); } } /***********************************************************************************/ void umdrehung(void) { unsigned char i=0; for(i=0;i<4;i++){ sbi(PORTD,6); if (i==3) delay(2); else delay(1); cbi(PORTD,6); delay(2); sbi(PORTD,6); delay(4); cbi(PORTD,6); delay(drossel); if (i==3) {sbi(PORTD,6); delay(random(2)+1); cbi(PORTD,6); delay(random(2)+1);} } } /***********************************************************************************/ int main( void ) { outp(255, DDRD); //Port D pullups enable cbi(PORTD,6); //Lautsprecher aus duckstop(); //Motor aus sbi(ACSR,2); outp(0, DDRB); outp(0, PORTB); for(;;) { delay(1000); sbi(ACSR,4); delay(100); while (!(inp(ACSR)&16)); anlasser(); while (motoran) umdrehung(); motoraus(); } } /***********************************************************************************/