for loop never
Posted: Wed Jul 02, 2008 4:23 am
Hi
I have recently embarked on the C4AVR course and almost imediately ran into a stone wall. I was following along with the tutorial, though using different hardware. I had the LED's turning off and turning on, but when it came to the part where you add a 'for loop' to create a time delay, in order that the LED's flash slowly, I ran into difficulty. The time delay loop did not work for some reason. The LED's just flashed away at full speed and half power. I was able, using a multimeter on the output pin, to see that adding additional PORTA = ??; statements, I was able to change the mark to space ratio of the output, so the code I was writing was affecting the action. All that appears to be wrong is that the 'for loops' in the code appear to be being ignored.
Initially I tried this code on a Tiny13 based board, but when I ran into the problems as outlined above, I changed to a Mega128 board (Futurelec) that I also have. But exactly the same problem arose.
What I would note is that the Mega128 board has its clock set to 1MHz, so is compatible with the code in the tutorial.
I even changed the delay to a while loop, but that had the same result..Jack.
Hardware:
Futurelec Mega128 board
AVRISP Mk2 Programmer
Software:
XP Proffesional
AVR Studio 4
Win AVR
C4AVR
Any help appreciated
Ian
NZ
/* Ex 1.4 Flash one LED with delay */
/* (c) Rob Miles August 2005 */
#include <AVR\io.h>
void main(void)
{
unsigned int i;
DDRC=0x01;
while (1)
{
PORTC = 0x01;
for ( i=0 ; i < 65000 ; i= i + 1 ) ;
PORTC = 0x00;
for ( i=0 ; i < 65000 ; i= i + 1 ) ;
}
}
I have recently embarked on the C4AVR course and almost imediately ran into a stone wall. I was following along with the tutorial, though using different hardware. I had the LED's turning off and turning on, but when it came to the part where you add a 'for loop' to create a time delay, in order that the LED's flash slowly, I ran into difficulty. The time delay loop did not work for some reason. The LED's just flashed away at full speed and half power. I was able, using a multimeter on the output pin, to see that adding additional PORTA = ??; statements, I was able to change the mark to space ratio of the output, so the code I was writing was affecting the action. All that appears to be wrong is that the 'for loops' in the code appear to be being ignored.
Initially I tried this code on a Tiny13 based board, but when I ran into the problems as outlined above, I changed to a Mega128 board (Futurelec) that I also have. But exactly the same problem arose.
What I would note is that the Mega128 board has its clock set to 1MHz, so is compatible with the code in the tutorial.
I even changed the delay to a while loop, but that had the same result..Jack.
Hardware:
Futurelec Mega128 board
AVRISP Mk2 Programmer
Software:
XP Proffesional
AVR Studio 4
Win AVR
C4AVR
Any help appreciated
Ian
NZ
/* Ex 1.4 Flash one LED with delay */
/* (c) Rob Miles August 2005 */
#include <AVR\io.h>
void main(void)
{
unsigned int i;
DDRC=0x01;
while (1)
{
PORTC = 0x01;
for ( i=0 ; i < 65000 ; i= i + 1 ) ;
PORTC = 0x00;
for ( i=0 ; i < 65000 ; i= i + 1 ) ;
}
}