AVR ExampleT1pooled.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
(2 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.) | |||
Riadok 24: | Riadok 24: | ||
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 | |||
TCNT1 = 0x????; // Restart T/C1 - reload | TCNT1 = 0x????; // Restart T/C1 - reload | ||
TIFR1 = 0x01; // Clear the overflow flag | TIFR1 = 0x01; // Clear the overflow flag | ||
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);
}