Operácie

AVR ExampleT1pooled.c: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Bez shrnutí editace
Balogh (diskusia | príspevky)
Bez shrnutí editace
Riadok 9: Riadok 9:
   /* *********************** Init device ************************************ */
   /* *********************** Init device ************************************ */


     DDRB = 0x??;             // PORTB LED on PB2  is output
     DDRB = 0x??;                   // PORTB LED on PB2  is output
   PORTB = 0x??;             // LED Active low, LED off, No pull-ups
   PORTB = 0x??;                   // LED Active low, LED off, No pull-ups


   TCCR1A = 0b????????;       // T/C1 in timer mode  
   TCCR1A = 0b????????;             // T/C1 in timer mode  
   TCCR1B = 0b????????;       // prescale ck  
   TCCR1B = 0b????????;             // prescale ck  
   TCNT1 = 0x????;           // start value of T/C1 Low+High bytes
   TCNT1 = 0x????;                 // start value of T/C1 Low+High bytes
   TIFR1 = 0x01;             //(1<<TOV1);  if a 1 is written to a TOV1 bit
   TIFR1 = 0x01;                   //(1<<TOV1);  if a 1 is written to a TOV1 bit
                            //            - the TOV1 bit will be cleared
                                    //            - the TOV1 bit will be cleared


   /* *********************** Main Loop ************************************** */
   /* *********************** Main Loop ************************************** */
Riadok 22: Riadok 22:
   do {
   do {


       if ( (TIFR1 & 0x01) == 0x01) // If the overflow flag is set
       if ( (TIFR1 & 0x01) == 0x01)   // If the overflow flag is set
       {  
       {  
PORTB = PORTB ^ 0b????????; // Toggle the LED
PORTB = PORTB ^ 0b????????; // Toggle the LED
         TCNT1 = 0x????;             // Restart T/C1 - reload
         TCNT1 = 0x????;             // Restart T/C1 - reload
         TIFR1 = 0x01;               // Clear the overflow flag
         TIFR1 = 0x01;               // Clear the overflow flag
       }
       }
       else
       else
         asm("nop");                 // Do nothing
         asm("nop");                 // Do nothing


   } while(1);                       // And do this forever
   } while(1);                       // And do this forever





Verzia z 08:40, 19. november 2008

/* Example 9.1. Timer counter 1 in timer mode - pooled version  */

#include <avr/io.h>

int main( void )
{
  /* *********************** Init device ************************************ */

    DDRB = 0x??;                    // PORTB LED on PB2  is output
   PORTB = 0x??;                    // LED Active low, LED off, No pull-ups

  TCCR1A = 0b????????;              // T/C1 in timer mode 
  TCCR1B = 0b????????;              // prescale ck 
   TCNT1 = 0x????;                  // start value of T/C1 Low+High bytes
   TIFR1 = 0x01;                    //(1<<TOV1);   if a 1 is written to a TOV1 bit
                                    //             - the TOV1 bit will be cleared

  /* *********************** Main Loop ************************************** */

  do {

      if ( (TIFR1 & 0x01) == 0x01)   // If the overflow flag is set
      { 
	PORTB = PORTB ^ 0b????????;  // Toggle the LED
        TCNT1 = 0x????;              // Restart T/C1 - reload
        TIFR1 = 0x01;                // Clear the overflow flag
       }
      else
        asm("nop");                  // Do nothing

  } while(1);                        // And do this forever


 return(0);
}

Návrat na cvičenie...