AVR ExampleT1pooled.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 9: | Riadok 9: | ||
/* *********************** Init device ************************************ */ | /* *********************** Init device ************************************ */ | ||
DDRB = 0x??; | DDRB = 0x??; // PORTB LED on PB2 is output | ||
PORTB = 0x??; | PORTB = 0x??; // LED Active low, LED off, No pull-ups | ||
TCCR1A = 0b????????; | TCCR1A = 0b????????; // T/C1 in timer mode | ||
TCCR1B = 0b????????; | TCCR1B = 0b????????; // prescale ck | ||
TCNT1 = 0x????; | TCNT1 = 0x????; // start value of T/C1 Low+High bytes | ||
TIFR1 = 0x01; | TIFR1 = 0x01; //(1<<TOV1); if a 1 is written to a TOV1 bit | ||
// - the TOV1 bit will be cleared | |||
/* *********************** Main Loop ************************************** */ | /* *********************** Main Loop ************************************** */ | ||
Riadok 22: | Riadok 22: | ||
do { | do { | ||
if ( (TIFR1 & 0x01) == 0x01) | if ( (TIFR1 & 0x01) == 0x01) // If the overflow flag is set | ||
{ | { | ||
PORTB = PORTB ^ 0b????????; // Toggle the LED | PORTB = PORTB ^ 0b????????; // Toggle the LED | ||
TCNT1 = 0x????; | TCNT1 = 0x????; // Restart T/C1 - reload | ||
TIFR1 = 0x01; | TIFR1 = 0x01; // Clear the overflow flag | ||
} | } | ||
else | else | ||
asm("nop"); | asm("nop"); // Do nothing | ||
} while(1); | } 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);
}