AVR ExampleT1pooled.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
(4 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.) | |||
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 | |||
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 | ||
Riadok 39: | Riadok 39: | ||
</source> | </source> | ||
[[ | [[MMP Cvičenie 4|Návrat na cvičenie...]] |
Aktuálna revízia z 13:22, 4. október 2010
/* 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);
}