Need help on using AVR CodeVision C compiler

Electronics Computer Programming Q&A
Post Reply
eddylau
Posts: 7
Joined: Thu Sep 20, 2007 1:25 am
Contact:

Need help on using AVR CodeVision C compiler

Post by eddylau »

Dear all,

Is it possible to pass a variable parameter to the function delay_us( )
which accept only constant expression?

If it's impossible, I think this function has no great use.

Thanks a lot

Eddy Lau :x
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi there,

If you think that is bad, you should try doing it in assembler :smile:
LEDs vs Bulbs, LEDs are winning.
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

I don't know that compiler but if delay_us( ) is truly a C function then it should be able to take a variable as a parameter. C uses call-by-value which means the expression parameter is evaluated, pushed onto the stack and the function called.
eddylau
Posts: 7
Joined: Thu Sep 20, 2007 1:25 am
Contact:

Post by eddylau »

the function was declared as void delay_us(unsigned int n) in the header
file delay.h

I need to pass a variable to this function to control the delay according
to my actual need. But when I pass a variable to this function, it produce
an error saying that it only accept constant expression!

Just can't understand why another function delay_ms( ) can accept variable parameter while the function delay_us() cannot?

What's the reason of making this limitation?

Does anybody know and can provide a positive solution?

Really thanks a lot
:?
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

what's the prototype from delay.h? please post it.
eddylau
Posts: 7
Joined: Thu Sep 20, 2007 1:25 am
Contact:

Post by eddylau »

the content of delay.h is as follows:

// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.

#ifndef _DELAY_INCLUDED_
#define _DELAY_INCLUDED_

#pragma used+

void delay_us(unsigned int n);
void delay_ms(unsigned int n);

#pragma used-

#endif

I wonder whether this is compiler bug or not?
Who can tell me the answer?

Thanks
:sad:
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

show us the code you call it with.
eddylau
Posts: 7
Joined: Thu Sep 20, 2007 1:25 am
Contact:

Post by eddylau »

the sample coding per your request is as follows:

#include <delay>
#include <mega8515>

unsigned int origin = 1200;
unsigned int base= 18800;

void main(void)
{
unsigned char i;
for( i = 0; i < 100; i ++)
{
PIND = 1;
delay_us(origin);
PIND = 0;
delay_us(base);
}
}
eddylau
Posts: 7
Joined: Thu Sep 20, 2007 1:25 am
Contact:

Post by eddylau »

sorry for the typo error,

it shoule be:

#include <delay>
#include <mega8515>
redrocker
Posts: 87
Joined: Fri Oct 29, 2004 1:01 am
Location: Pennsylvania
Contact:

Post by redrocker »

There is a space between the 'i' and the '++' in the for-loop declaration. Maybe that is giving the compiler fits.
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

the space doesn't matter.

I assume the PIND is defined.

The code looks ok. The only thing that comes to mind is what does the pragma do in the context of declaring the prototype. Is there documentation for delay_us()?

Try removing the delay include and declaring a dummy delay_us. see if it compiles.

does this error come from the compiler or the linker phase?
eddylau
Posts: 7
Joined: Thu Sep 20, 2007 1:25 am
Contact:

Post by eddylau »

I just got the answer from the support team of the CodeVision.

Anyway, thanks for all your kind concern to my problem.

:grin: :razz: :lol:
User avatar
GoingFastTurningLeft
Posts: 163
Joined: Wed Sep 06, 2006 7:33 pm
Contact:

Post by GoingFastTurningLeft »

Thats why I stick with WinAVR and AVRstudio :)
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

so what was the problem????
eddylau
Posts: 7
Joined: Thu Sep 20, 2007 1:25 am
Contact:

Post by eddylau »

According to their info, the time needed to handle parameter passing in a function call
is longer than the delay provided by the function delay_us( ). So it only accept constant expression for that function to work correctly.

Although they didn't help to solve my programming need, at least I know the limitation of that function.

May be I will try to stick with WinAVR and AVRstudio as an alternative!
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests