Another Newbe That Can't Complile The LED Program - Help!!!

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone,

This is my first post to the forum and I guess I have to start out with a stupid question that probably been asked 100 times before, but I tried searching the forum and came up with nothing. :cry:

My problem is just trying to get a simple LED program to compile with out warnings. For the life of me I don't see what I am missing here???

Every time I compile the code in AVR GCC through AVR 4's interface I am receiving the following warning:

C:\Documents and Settings\William L. Scheffer\My Documents\AVR Studio\ATmega168\..\..\..\..\..\WinAVR-20090313\avr\include/util/delay.h:123: warning: overflow in implicit constant conversion

#include 
#include 

int main()
{
	PORTC &= 0xC0;
	DDRC |= 0x00;

	while(1)
	{
		PINC &= 0x01;
		_delay_ms(100);

		PINC ^= 0x01;
		_delay_ms(400);

	}

	return 1;

}

Am I missing a statement here? :?

The AVR is a 168 and they have been around awhile, so the header files should be ok. Right???

I just can not see what the problem is if someone could please enlighten me to what I'm doing wrong.

Thanks,

Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It compiles OK for me? As I can't simulate your conditions, I can't help any further!

BTW, FWIW
DDRC |= 0x00; is a currently a redundant instruction.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Line 123 in delay.h reads:

			_delay_loop_2(((F_CPU) / 4e3) / 10);

As this is code that many people have used with success, let's guess that it's a variable part of that code that is the problem. The only variable thing in there is F_CPU. So...

How did you specify F_CPU?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I set F_CPU from AVRStudio to 8000000 hz. & it compiles OK. When I set the frequency to null, I get the following Warning:-
c:/winavr/lib/gcc/../../avr/include/util/delay.h:85:3: warning: #warning "F_CPU not defined for "
When I set the frequency to either 0 Hz., 1 Hz. or 999999999999 Hz., it compiles without error.

I wonder if OP has inadvertantly modified something in delay.c ????

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the OP needs to tell us exactly how he IS defining F_CPU for use by

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think with DDRC=0 there are no outputs.
Using PINC with &= is probably not
what the OP wants.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let me start by saying thanks to everyone for their quick response, and that I never programmed in C before.

I come from an object oriented background. It's been awhile so please bare with me.

Quote:
clawson: I think the OP needs to tell us exactly how he IS defining F_CPU for use by

I tried to use a define statement for this variable. I placed the following statement into my code:

#define F_CPU = 16000000

But upon doing so the compiler threw a warning that F_CPU is being defined twice. I sort of expected this would be the case.

Quote:
LDEVRIES: When I set the frequency to null, I get the following Warning:-
c:/winavr/lib/gcc/../../avr/include/util/delay.h:85:3: warning: #warning "F_CPU not defined for "
...

Since, I am not generating this error the variable F_CPU must have a value by default.

Quote:
LDEVRIES: I wonder if OP has inadvertently modified something in delay.c ????

All software being used are fresh installations currently off the internet. I did not modify any of the source files.

Quote:
JohanEkdahl: let's guess that it's a variable part of that code that is the problem.

I too feel this is where my fault lies.

Quote:
JohanEkdahl: How did you specify F_CPU?

Well that's the million dollar question. How do I define it's value. Should my code also have a statement like this included in it?

#include 
#include 


 int main()
 {
    F_CPU = 16000000;
    PORTC &= 0xC0;
    DDRC |= 0x00;

    while(1){
...

I am currently not at my computer or I would just try this instead of asking. But I don't feel this is the correct way to set the value for F_CPU or even if the compiler would allow me to do that?

LDEVRIES wrote:

Quote:
I set F_CPU from AVRStudio to 8000000 hz. & it compiles OK.

How do you set the CPU speed in AVRStudio?

Quote:
ossi: I think with DDRC=0 there are no outputs.
Using PINC with &= is probably not
what the OP wants.

You're probably right but for now all I am concerned with is trying to get everything to compile correctly, but thank you for you're input.

Thanks again,

Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In a avr-gcc project controlled by AVR Studio 4 you set F_CPU in the project options dialogue:

Project menu, Configuration Options item. In the dialogue that follows there is a field for Frequency. State the frequency in Herz (no "L" or "UL").

Example:

Attachment(s): 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks John,

I thought I set that when I first set up the project, but I guess my settings did not take. :cry:

I should have noticed it when I had trouble with the optimization setting earlier. I corrected this problem by going to Configuration Options - Custom Options and manually set it to O3. Which I also noticed that could be set from the drop menu right below the Frequency Edit Box.

Boy I knew it would be a simple resolve, but I feel really stupid now! :oops:

Again, thank you for your time in directing me in the right direction.

Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Boy I knew it would be a simple resolve, but I feel really stupid now! :oops:

Don't. We've all been there.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]