Elektronische Visitenkarte

 

 

    Schaltplan       Stückliste        Layout    
          
// Elektronischer Würfel  Version 1.0
// Version 1.1 wenn Taste betätigt wird kein Power Down ausgeführt
// Version 1.2 Analogcomperator aus wegen Strom sparen  16.12.2002
 #include <iot2313v.h>
 #include <macros.h>
 #define MAX    30
 #define Z1    5000     //
 #define Z2    10000     //
 #define Z3    15000     //
 #define Z4    20000     //
 #define Z5    25000     //
 #define Z6    30000     //
 // Function prototypes
 void setLeds(unsigned char val);
 void delay(unsigned int c);
 flash unsigned char led[7] = {0xF7,0xDE,0xD6,0x9C,0x94,0x88,0x80};
 void main()
 {
    unsigned char j; 
    unsigned char runner = 0x01;
    DDRB = 0xff; // Set all pins on port B as outputs
    PORTB = 0xff; // Alle Leds aus  
    ACSR  = 0x80; // Analog Comperator aus   15uA bei 3V
    runner = 3;
    PORTD = 0x04; // PD2 Input mit Pullup
    GIMSK |= 0x40; // Int0 ativ
    _asm("sei"); // Enable global interrupt
    while(1)
    {
      if (!(PIND & 0x04))       // PD2 = 0 dann Zählen
      {
        runner++;    // +1
        if(runner >7) //unser Würfel geht bis 7
           runner = 1;
      }
      else
      {
         setLeds(2);    // Set the LED's
         delay(Z1);     // Wait a moment
         setLeds(4);    // Set the LED's
         delay(Z2);     // Wait a moment
         setLeds(3);    // Set the LED's
         delay(Z3);     // Wait a moment
         setLeds(5);    // Set the LED's
         delay(Z4);     // Wait a moment
         setLeds(1);    // Set the LED's
         delay(Z6);     // Wait a moment
         setLeds(runner); // Set the LED's
         for(j = 0;j<max;j++)< body="">
         delay(Z1);
         PORTB = 0xff;        // alle Leds aus 
         delay(100);
         if(PIND & 0x04)     // Taste wieder frei
         {                   // Wir gehen schlafen
            GIMSK |= 0x40;    // Int0 ativ
            MCUCR = 0x30;     // PowerDown Wake up at low Int0
           _asm("sleep");     // Power down
         }
       }

     }

  }

 void setLeds(unsigned char val)
 {
   val--;
   PORTB = led[val];
 }
 void delay(unsigned int count)
 {
   while(--count) // Decrease to zero
      ; // Empty
 }
 #pragma interrupt_handler int0_handler:iv_INT0
 // handles INT0 interrupt
 void int0_handler(void)
 {
      GIMSK = 0; // Int0 deaktiv
 }