Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino - tutorijali, pitanja, primjeri i projekti
Makso, evo programa:
Code:
#define    START    1
#define    STOP    0

// ***** Definisanje korisnickih promenljivih *****
unsigned int    Sec_Counter = 0;
unsigned char    Sequence = 0;
// ***** Definisanje korisnickih flagova *****
         bool    KB_Start_Stop_Old = false;                    // Flag za izvlacenje ivice tastera
volatile bool    Current_State = STOP;                        // Trenutno stanje masine

ISR(TCC1_OVF_vect)
{    
    // TMR1 Reload na 1s
    TCNT1H = 0xC2;                
    TCNT1L = 0xF7;
    
    if(Current_State == START)
    {    Sec_Counter++;                                        // Inkrement brojaca na svaku sekundu
        switch(Sequence)
        {    case    0    :    Izlaz1 = true;                    // Ukljuci izlaz
                            if(Sec_Counter >= 3600)            // Da li je proslo 60min
                            {    Sec_Counter = 0;
                                Izlaz1 = false;                // Iskljuci izlaz
                                Sequece = 1;
                            }            
                            break;
            case    1    :    if(Sec_Counter >= 600)            // Da li je proslo 10 min
                            {    Sec_Counter = 0;
                                Izlaz2 = true;                // Ukljuci drugi izlaz
                                Sequence = 2;    
                            }            
                            break;
            case    2    :    if(Sec_Counter >= 3600)            // Da li je proslo 60min
                            {    Sec_Counter = 0;
                                Izlaz2 = false;                // Iskljuci izlaz
                                Sequece = 3;
                            }        
                            break;
            case    3    :    if(Sec_Counter >= 600)            // Da li je proslo 10 min
                            {    Sec_Counter = 0;
                                Izlaz2 = false;                // Ukljuci drugi izlaz
                                Izlaz1 = true;
                                Sequence = 0;    
                            }            
                            break;                
            case     default:Sequence = 0;
                            break;
        }        
    }    
    else
    {    Sec_Counter = 0;
        Sequence = 0;
    }
}

// ***** Inicijalizacija TMR1 *****
void TMR1_Init(void)
{    TCCR1A = 0b00000000;
    TCCR1B = 0b00000101;                                    // Prescaler deli ucestanost sa 1024
    TIMSK1 = 0x01;                                            // Timer 1 overflow interrupt
    TCNT1H = 0xC2;                                            // Interrupt on every 1s
    TCNT1L = 0xF7;
    SREG |= 0x80;                                            // Globalna dozvola interapta
}
void main(void)
{    TMR1_Init();
    while(1)
    {    // Ukljucivanje uredjaja i iskljucivanje uredjaja
        if(KB_Start_Stop && !KB_Start_Stop_Old)
        {    if(Current_State == STOP))                        // Ukljucivanje
            {    Current_State = START;}
            else                                            // Iskljucivanje
            {    Current_State = STOP;}                        // Iskljucivanje
        }
        KB_Start_Stop_Old = KB_Start_Stop;
        
        // Ispitivanje uslova motora
        if(Current_State == STOP)                            
        {    motor1 = false;                                    // Ako je masina u STOP modu, iskljuci motor1
            motor2 = false;                                    // Ako je masina u STOP modu, iskljuci motor2
            motor3 = false;                                    // Ako je masina u STOP modu, iskljuci motor3
            motor4 = false;                                    // Ako je masina u STOP modu, iskljuci motor4
        }
    }    
}

Pozdrav
Reply


Messages In This Thread
RE: Arduino - tutorijali, pitanja, primjeri i projekti - by vojinilic - 12-27-2016, 10:45 AM

Forum Jump:


Users browsing this thread: 47 Guest(s)