Program Coding for a 6 hour toggle switch

Thread Starter

renderix

Joined Jun 3, 2018
2
Hello guys!
I need a code for a 6 hour toggle for an in-house project between two pins preferably PC1 and PC2.If any has a code please post!
Thanks in advance.
 

hexreader

Joined Apr 16, 2011
619
Code:
//  EasyPIC7 code for PIC18F45K22 8MHz xtal x4 PLL gives 32MHz


// 6 hour delay
void del6(){
unsigned long n;
    for(n=21600 ; n > 0 ; n--){                         // 6 hours in seconds is 21600
        Delay_ms(1000);                                 // 1 second delay
    }
}

void main(){
    ANSELC = 0;                                         // all digital
    TRISC = 0;                                          // all output
    PORTC = 2;                                          // start with PC1 high, PC2 low

    while(1){
        PORTC = 2;                                      // PC1 high, PC2 low
        del6();
        PORTC = 4;                                      // PC1 low, PC2 high
        del6();
    }
}
 

Thread Starter

renderix

Joined Jun 3, 2018
2
hiii @hexreader ,I was looking for a counter overflow kind of code using a 8-bit timer for Atmega 328 without using any delay functions as there's some other sensors working in this too
 

Picbuster

Joined Dec 2, 2013
1,058
don't not use delay . A delay will stop all other actions in a single treading system.
Use the 32.768 xtal set overflow in an interrupt @ one second
Use a counter. Count up to seconds you want and do what you want to do.
Like :
Reset counter.
Create a pulse.
Fill the bath tube.
Switch radio or tv on.
Play a melody.
Code is very simple and easy to figure out.

Picbuster
 
Top