problem in c programme

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

Hello everyone,
Please can you explain why i am getting this errors and how to fix these problems...

error 1: invalid operands to binary << (have 'int' and 'char (*)(void)')
error 2: invalid operands to binary << (have 'char (*)(void)' and 'int')
error 3: 'bit' undeclared (first use in this function)
error 4: 'array' undeclared (first use in this function)
error 5: 'nothing' undeclared (first use in this function)

MY CODE:

int main(void)
{

  extern char TCCROB(void);
  extern char OCROA(void);
  extern char TCNTO(void);
  extern char TIMSKO(void);
  extern char OCIEOA(void);
  extern char TOIEO(void);

unsigned char i=1;

//unsigned char temp[5];
//unsigned char i[3];

// Prescaler = FCPU/1024
    TCCR0B|= (1<<WGM02)|(1<<CS02)|(0<<CS01)|(1<<CS00);

// Ecah byte is increment for 1ms
	OCROA|= (1<<OCROA);

// Initialize timer/counter register 
    TCNTO << 1;

// Data direction register
	DDRF = 0xF0;


// Enable the o/p compare A interrupt and over flow interrupt enable
    TIMSKO|= (1<<OCIEOA)|(1<<TOIEO);

	SetupHardware();

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
	while(1)
	{
        if (bit==1)
		{
		array[i] = OCROA;

		i=i+1;
		else
		  do nothing;
		}

// Increment the variable
        i++;
        if (i==15.625)
		{
         PORTF ^= 0xF0;
		 i=1;
		}
	}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You cannot assign a value to a function's return value.

Further you should not declare hardware registers as functions (e.g. "extern char TCCROB(void);").

"'array' undeclared (first use in this function)" - means just what it says.

"else do nothing" - huh?! This does not look like valid C code.

/Jakob Selbing

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

i++;
if (i==15.625) ...

...what situation are you expecting such that an incremented integer variable (i = 1, 2, 3, etc) becomes equal to 15.625?

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

Quote:

You cannot assign a value to a function's return value.

what i need to assign for that....

Quote:

Further you should not declare hardware registers as functions (e.g. "extern char TCCROB(void);").

if i didn't declare that,it was showing the warnings..
Quote:

'array' undeclared (first use in this function)" - means just what it says.

can you give me the example for that...

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

There are several c compilers for AVRs with slight differences in the area of the names of the include files and the directory that they are kept in. Look at a couple of AVR c programs in the project section here. AVRstudio/WINAVR/GCC compiler always has #include as the first include. The makefile for the program lists all the c files and library files to be compiled and linked to form the hex file, and it also tells the compiler which AVR you are using so it knows which io.h file to include. Does this explanation make any sense at all, or should I have started the explanation at a much lower level?

Imagecraft compiler user

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

Quote:
unsigned char i=1;

how can char be equal to 1?

Apart from that, there is no valid register like TCCR0B and many others. Which device are you using?

Where did you copy the code from?

AVR Guide and Tutorials
http://maxembedded.wordpress.com

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

Quote:

Apart from that, there is no valid register like TCCR0B and many others. Which device are you using?

for that you can follow these two links:
http://extremeelectronics.co.in/...
http://www.atmel.com/dyn/resourc... (SEE PAGE.NO:91)

FINALLY I AM ASKING 1 THING :
i am using the atmega32u4,but how can i start code for interfacing from pc to controller..please don't ignore this thread help me step by step....

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

maxmiaggi wrote:
Quote:
unsigned char i=1;

how can char be equal to 1?

maxmiaggi, what is wrong with that statement? Do you understand what that statement does or what an unsigned char is?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Hello,
ok ok i can change that 'i' value..
Please tell me how to fix these errors....

error 1: invalid operands to binary << (have 'int' and 'char (*)(void)')
error 2: invalid operands to binary << (have 'char (*)(void)' and 'int')
error 3: 'bit' undeclared (first use in this function)
error 4: 'array' undeclared (first use in this function)
error 5: 'nothing' undeclared (first use in this function)

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

madhu.b wrote:
FINALLY I AM ASKING 1 THING :
i am using the atmega32u4,but how can i start code for interfacing from pc to controller..please don't ignore this thread help me step by step....

madhu.b, Using all caps is considered shouting and is rude. You'll get help here that is proportional to the amount of effort that we see you putting in to solve the problem yourself.

What compiler are you using and on what OS?

Are you using AVR Studio?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

madhu.b wrote:
error 1: invalid operands to binary << (have 'int' and 'char (*)(void)')
error 2: invalid operands to binary << (have 'char (*)(void)' and 'int')
error 3: 'bit' undeclared (first use in this function)
error 4: 'array' undeclared (first use in this function)
error 5: 'nothing' undeclared (first use in this function)
But those are pretty much the same errors as before. You have already been given pointers to what is wrong!

To be able to use a variable in C code, you must first declare it, like:

char array[100];
...
array[i] = OCR0A;

Compiler complains about "nothing" because it does not know of anything called "nothing". Also you seem to use "{" and "}" incorrectly. Your code should look something like:

if (bit==1) 
{ 
array[i] = OCROA;
i=i+1;
}
else 
{
// Do nothing here (completely unnecessary though)
}

To assign values to hardware registers, just write the name of the register, e.g.

OCR0A = 42;

/Jakob Selbing

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

madhu.b, I've just looked back over your previous posts and one thing is very clear... I don't mean to be rude, but, you don't have the first clue about what you are doing.
If you want to make any progress with embedded system design and programming, you are going to have to learn for yourself, not just keep asking for help.

Please, please, please, get a good book on C programming and once you've read it a few times, go to the tutorials forum on this site and work your way through the lessons. You can't just keep copy and pasting stuff from around the internet and expect it to work.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Quote:

i am using the atmega32u4,but how can i start code for interfacing from pc to controller..

Do you mean using it's USB facilities to link it to a PC as a CDC-ACM or HID or MSD or something? If so then you will want to use "LUFA" which is a supprt library for all the USB enabled AVRs. However I agree with Greg, I'd say you are six months to a year of experience from being able to use something so complex. Start with simple projects like flashing an LED and ignore the USB nature of the 32U4 for the time being.

Lines such as this:

// Ecah byte is increment for 1ms
   OCROA|= (1<<OCROA); 

are utter nonsense. Maybe tell us exactly what YOU think that line is going to achieve. (apart from anything else the zeros in that code are capital letter O's!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
// Initialize timer/counter register 
    TCNTO << 1; 

This does nothing.

  extern char TCCROB(void); 
  extern char OCROA(void); 
  extern char TCNTO(void); 
  extern char TIMSKO(void); 
  extern char OCIEOA(void); 
  extern char TOIEO(void); 

You don't want these, you want to include the proper header file (which one depends on what compiler you are using). That will take care of the first two errors. The other three errors are simply what they say, you are using variables that are not defined, so define them.

Regards,
Steve A.

The Board helps those that help themselves.

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

Koshchi wrote:
...You don't want these, you want to include the proper header file (which one depends on what compiler you are using). That will take care of the first two errors. The other three errors are simply what they say, you are using variables that are not defined, so define them.

Exactly! That is why I asked these simple questions.

larryvc wrote:
What compiler are you using and on what OS?

Are you using AVR Studio?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Hello Larry,
well.......
As Koshchi said(in the above),that need the header files for fix the first two errors. So, what type of header files i have to use...
yes,i am using the AVR studio,gcc compiler and
OS-windows7..

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

Quote:

So, what type of header files i have to use

In GCC it's pretty safe to simply start every .c file with:

#include 

Also in the Studio project you will specify the device to build for and this setting ultimately filters down and is used within io.h to then select the correct device header file to use.

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

Hello clawson,

Yes, i was use that header file,but again it was showing the these errors.

error1: 'OCROA' undeclared (first use in this function)
error2: (Each undeclared identifier is reported only once
error3: for each function it appears in.)
error4: 'TIMSKO' undeclared (first use in this function)
error5: 'OCIEOA' undeclared (first use in this function)
error6: 'TOIEO' undeclared (first use in this function)

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

You've already been told that you are using the letter 'o' instead of the number 0.
Eg TIMSK0 where the last char is a zero not an 'o'
OCIE0A. The last chars are zero A
TOIE0 timer overflow interrupt enable zero

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

It may help to say the name of the registers out-loud. i.e Timer Mask Zero and Output Compare Interrupt Enable Zero Ay. (and finally, Timer Overflow Interrupt Enable Zero).
Oh, I missed one... Output Compare Register Zero Ay.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

I don't think you've even told us which AVR this is - so maybe they shouldn't be the zero suffixed register names anyway?

How about you tell us which AVR and post your complete code. I'll then edit it so it compiles without error.

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

Quote:
I'll then edit it so it compiles without error.
Now thats an offer I could not refuse :)
However, just because it compiles without error, does not mean it will perform the intended function if the program logic is faulty.

Cliff must really think you've got potential, I've not seen this sort of offer here before ;)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Quote:

However, just because it compiles without error, does not mean it will perform the intended function if the program logic is faulty.


Ever heard the term "LEER" ? ;-)

EDIT: Actually when I typed "leer left easy exercise" into Google it points back here to Freaks - maybe I'm the only one who had lecturers who used this phrase?

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

Quote:
Ever heard the term "LEER" ?
Um, can't say I have, sorry.
So... 'leer left easy exercise'????

I've a collegue, who shall remain nameless (Lets call him Matt :) ) who's idea of fixing a program which fails to compile, is to keep removing lines, until it does.

Magic!

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Mr. Madhu.b: You should read and respond to each reply to your question. I see you have asked about which header file to include, and this information was presented in message number five. No reply was ever made to this message.

Imagecraft compiler user

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

Quote:
Timer Mask Zero and Output Compare Interrupt Enable Zero Ay.
Greg, I didn't know you were Canadian (though they usually spell it Eh, must be the British in you). ;)

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:
must be the British in you
Eh? or should that be Ay?

:)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

EIGH

Imagecraft compiler user

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

bobgardner wrote:
EIGH
That's Bristolian :)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Bristol - where's that to then, my luvver?

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

Sover ear init!

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!