Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

creating a 24 hr clock using the timers 2313

2004-10-20 by emailbucky

hey guys, 

 i want to create a clock that keeps the time over a 24hr period,
below is the code i have written USING AVR GCC, whenver the timer lies
between 
22 and 23, it should write a value to the port, but its not doing
this, can anybody help? 

SIGNAL(SIG_OVERFLOW0)         /* signal handler for tcnt0 overflow
interrupt */
 {
   timer_enable_int (0);     /* disable interrupt*/
  
    
    
    
    
   switch (state){
   
   
           
         case 0:
		if (overFlow < 61)
                {
                   overFlow++;
                   state = 0;
                   
                }
		else
                {
                    overFlow = 0;
                    state = 1;
                }
		    
		break;
   
   
	case 1:
		if (seconds < 60)
                {
                    seconds++;
                    state = 0; 
                    //toggle once leds for each second
                    //toggleLeds(); 
                    
                }
		else
                { 
                    seconds = 0;
		    state   = 2;
		    
		    
                }
		break;	
	case 2:
		if (minutes < 60)
                {
                    minutes++;
                    state = 0; 
                     
                     
                   
                }
		else 
                {
                    minutes = 0;
                    state = 3;
                    
                       
                }
		    
		break;	
	case 3:
		if (hours < 24)
                {
                   
                    state = 0;
                    
                    
                    if(hours >= 22 && hours <= 23)
                    {
                       PORTB = 0x00;  /* switch charger relay on */
                        
                    }
                    
                    else 
                    {
                    
                       PORTB = 0xff;  /* keep charger relay off */
                    
                    }
                    
                   
                     hours++;    
                }
		else
                {
                    
                    //reset timer 
                      seconds = 0; 
                      hours   = 0; 
                      minutes = 0; 
                      state =   0; 
                                /*switch charger relay off*/
                }
		    
		break;
    	
	
   } 
           
    outp(0, TCNT0);   /* reset counter to get this interrupt again */
    timer_enable_int (_BV (TOIE0)); 
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.