NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » C++ on the atmega168 MPU

May 24, 2011
by aibrahim9386
aibrahim9386's Avatar

All,

I have a C++ program that I would like to send it's output to the LCD but the main question is, does the MPU hangle c++ code?

Ali.

May 24, 2011
by bretm
bretm's Avatar

The MPU only runs machine language code. If you have code in any other language you first have to convert it to machine language. That's the job of a compiler.

So you could say the MPU runs any language as long as you have a compiler for it. There are C++ compilers for Atmega, but I don't recommend them. The Atmega168 is relatively limited in program capacity, and "C" is more lightweight.

If you have a C++ program on your PC that you want to use to send text to the LCD, you can write a simple "C" program to run on the MPU to read the data sent from the PC and display it on the LCD. Is that more along the lines of what you want to do?

May 24, 2011
by Hexorg
Hexorg's Avatar

aibrahim9386, to compile c++ code for ATmega168, you need avr-g++ compiler. Chances are it already came when you installed avr-gcc.

May 24, 2011
by bretm
bretm's Avatar

avr-gcc is a C++ compiler. It will compile C++ if the file extension is .cc or .C (capitalized).

May 24, 2011
by bretm
bretm's Avatar

Or .cp, .cpp, .cxx, .c++.

May 24, 2011
by Hexorg
Hexorg's Avatar

oh really? Thanks bretm! I should try it now. Do you know if there'll be much overhead in c++? with classes and all that oop stuff?

May 24, 2011
by bretm
bretm's Avatar

There will be overhead in dynamic memory usage, implicit copy constructors, virtual method tables, etc. Whether it is a lot of overhead depends on how many of those features you use. I just have a hard time picturing any app small enough to fit on an atmega and big enough to need those things. You can also do OOP in C.

October 23, 2011
by hariharan
hariharan's Avatar

I really want to apply c++ programming in mcu but i am scared that it might be a lot of memory. i think using a I2C EEPROM might help, any suggestions?

October 24, 2011
by Ralphxyz
Ralphxyz's Avatar

hariharan, how would you use an I2C EEEPROM?

Ralph

October 24, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Hari,

It is definitely possible to use C++ on the atmega168, but you are correct that there is traditionally more memory overhead when running C++. If you are careful about it, and think about your programming you can probably write some neat programs before you hit the space limits. The executable program must be in the FLASH memory, so you can't really get around that by putting stuff somewhere else.

Humberto

October 25, 2011
by hariharan
hariharan's Avatar

can't you save the program on the eeprom and make the microcontroller execute the program in the eeprom?

October 27, 2011
by Ralphxyz
Ralphxyz's Avatar

Remember harriharan you are using a MCU not a CPU comparatively speaking the micro is limited in some functions, so no I do not believe you can put executable code in the eeprom.

Ralph

October 28, 2011
by Rick_S
Rick_S's Avatar

Ralph is correct, to my knowledge none of the atmega series AVR chips support external program memory. Some do support external SRAM but not the atmega168 or atmega328p commonly used in the Nerdkit.

That is not to say you cannot connect an external eeprom or external flash, because you can. You can only use it for data storage though. All executable code must reside in program flash on the mcu itself.

Rick

Post a Reply

Please log in to post a reply.

Did you know that you can make a spooky Halloween Jack-O-Lantern with a microcontroller? Learn more...