C for AVR Ex 1.4 Delay Routine
Posted: Tue Jul 22, 2014 10:41 am
I am trying to get the following code to work from the C for AVRs MATRIX course.
/* Ex 1.4 Flash one LED with delay */
/* (c) Rob Miles August 2005 */
#include <AVR\io.h>
void main(void)
{
unsigned int i;
DDRD=0x01;
while (1)
{
PORTD = 0x01;
for (i=0; i<65000; i=i+1);
PORTD = 0x00;
for (i=0; i<65000; i=i+1) ;
}
}
The 'for' delay lines do not create a delay. I have tried reducing this number and nothing seems to happen. Looking at pin 14 (PD0) the signal is not stable. This type of delay is used many time in exercises following this one so I would like to understand why it does not appear to work. The same code has been compiled for a PIC and works fine.
The hardware is the AVR EB019-00-2 ATMEL Board with the EB-004-00-2 LED on Port D. The processor is a ATMEGA324P running on internal clock 8Mhz.
Can anyone suggest a way forward?
Many thanks,
Chris
/* Ex 1.4 Flash one LED with delay */
/* (c) Rob Miles August 2005 */
#include <AVR\io.h>
void main(void)
{
unsigned int i;
DDRD=0x01;
while (1)
{
PORTD = 0x01;
for (i=0; i<65000; i=i+1);
PORTD = 0x00;
for (i=0; i<65000; i=i+1) ;
}
}
The 'for' delay lines do not create a delay. I have tried reducing this number and nothing seems to happen. Looking at pin 14 (PD0) the signal is not stable. This type of delay is used many time in exercises following this one so I would like to understand why it does not appear to work. The same code has been compiled for a PIC and works fine.
The hardware is the AVR EB019-00-2 ATMEL Board with the EB-004-00-2 LED on Port D. The processor is a ATMEGA324P running on internal clock 8Mhz.
Can anyone suggest a way forward?
Many thanks,
Chris