Reputation: 19847
I have the following code
#include <hcs12dp256.h>
void spinloop(int spins)
{
for (int i=0; i<spins; i++)
{
i ++;
}
}
void main(void)
{
DDRK = DDRK & 0x0F;
PORTK = PORTK & 0x00;
PORTK = PORTK | 0x01;
PORTK = PORTK | 0x02;
spinloop(100000);
PORTK = PORTK & 0x0C;
PORTK = PORTK | 0x03;
PORTK = PORTK | 0x04;
}
When I go to compile it I'm getting loads of errors, mainly around the for loop. I'm getting the following error on line 5
Syntax error found int expecting ;
followed by
Syntax error found int expecting )
Skipping int
I'm not quite sure what the issue is, I'm fairly new to this coding so I may simply be missing something simple.
Any help would be greatly appreciated.
Thanks
Upvotes: 0
Views: 1734
Reputation: 171
instead of
for (int i=0; i<spins; i++)
use
int i;
for (i=0; i<spins; i++)
Note- In c we cannot define variable inside for loop
Upvotes: 1
Reputation: 145899
Change:
for (int i=0; i<spins; i++)
with
int i;
for (i=0; i<spins; i++)
Your compiler probably doesn't support C99.
Upvotes: 2