Counters - Timers C++ - NEED HELP

Thread Starter

blank

Joined Apr 26, 2008
13
I try to program STK500 microcontroller and have a timer in my program.

I have the following program:

#include <avr/io.h>

int main (void)
{
unsigned char ElapsedSeconds = 0; // Make a new counter variable and initialize to zero

DDRB |= (1 << 0); // Set LED as output

TCCR1B |= ((1 << CS10) | (1 << CS11)); // Set up timer at Fcpu/64

for (;

{
// Check timer value in if statement, true when count matches 1 second
if (TCNT1 >= 15625)
{
TCNT1 = 0; // Reset timer value
ElapsedSeconds++;

if (ElapsedSeconds == 60) // Check if one minute has elapsed
{
ElapsedSeconds = 0; // Reset counter variable

PORTB ^= (1 << 0); // Toggle the LED
}
}
}
}


Is there an other way to write the command
TCCR1B |= ((1 << CS10) | (1 << CS11));
because when I compile it it shows an error that CS10 and CS11 are undefined.
 

hgmjr

Joined Jan 28, 2005
9,027
I try to program STK500 microcontroller and have a timer in my program.

I have the following program:
Rich (BB code):
#include <avr/io.h> 
 
int main (void) 
{ 
   unsigned char ElapsedSeconds = 0; // Make a new counter variable and initialize to zero 
 
   DDRB |= (1 << 0); // Set LED as output 
 
   TCCR1B |= ((1 << CS10) | (1 << CS11)); // Set up timer at Fcpu/64 
 
   for (;

	
	
		
		
	


	
{ // Check timer value in if statement, true when count matches 1 second if (TCNT1 >= 15625) { TCNT1 = 0; // Reset timer value ElapsedSeconds++; if (ElapsedSeconds == 60) // Check if one minute has elapsed { ElapsedSeconds = 0; // Reset counter variable PORTB ^= (1 << 0); // Toggle the LED } } } }
Is there an other way to write the command
TCCR1B |= ((1 << CS10) | (1 << CS11));
because when I compile it it shows an error that CS10 and CS11 are undefined.
Code cleanup for readability using the CODE tags.

The labels CS10 and CS11 are defined in the .h header file for the AVR device you are using. The header file must not be located in the folder in which the compiler is looking.

What AVR device are you using in your project?

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
As a point of reference, I cut and pasted your code into my AVRSTUDIO/WINAVR application and it compiled without any errors.

That confirms my suspicion that your problem is a directory or path specification problem.

hgmjr
 
Top