Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ for 8051 microcontroller?

Could someone please tell me if it's possible to burn an 8051 microcontroller with a C++ program? I've tried searching about it online but can't seem to find out for sure if it's possible or not. Keil uses C, but the program I need to write is very string-intensive and C is quite string-unfriendly as compared to C# which is what I'm used to using. At the moment, I'm trying my hand at writing the code in C but it's getting really messy, so I'd be extremely relieved if I could write it in C++ instead.

I would need a C++ compiler that creates a Hex output file that can then be burnt onto the microcontroller. Anyone heard of something I could use? And also, C uses a header file that lets you refer to ports, but when I tried to find out if this header file is used in C++ as well I couldn't find any information on it.

Addition: The microcontroller I'm using is an Atmel AT89C51 with 4K Bytes of Reprogrammable Flash Memory, and 128 x 8-bit Internal RAM. This is actually for a Robot for a project at university and the coding does not actually require OOP. It just has a lot of look up tables that are in 2D string array format. The only reason I wanted to consider C++ was because of how messy manipulating strings seemed to be getting (due to MY lack of expertise in C).

And does anyone know about the header file? C uses #include reg51.h but I tried to find out if this works for C++ and couldn't find anything on it.

like image 377
CodeConfused Avatar asked May 22 '09 19:05

CodeConfused


People also ask

Can 8051 be programmed in C?

Program the 8051 in C to receive bytes of data serially and put them in P1. Set the baud rate at 9600, 8-bit data, and 1 stop bit.

Why is C use for microcontroller?

Microcontrollers are memory and bandwidth constrained processing units. C programming language generates tight code that is close to assembly language in terms of size and speed. C++ usually carries an overhead in memory and speed.

Which programming language is used in 8051 microcontroller?

Assembly Language is a pseudo-English representation of the Machine Language. The 8051 Microcontroller Assembly Language is a combination of English like words called Mnemonics and Hexadecimal codes. It is also a low level language and requires extensive understanding of the architecture of the Microcontroller.


1 Answers

I would question whether this is really a good idea in the first place. I understand the reasoning behind wanting to use c++ over C in the general case but in the case of an 8-bit Harvard architecture microcontroller I would warn against this.

Things to bear in mind include:

  • Source-level debugging support will be somewhere between poor and impossible.
  • Runtime overhead of OOP on an 8-bit machine. I would strongly recommend doing some serious benchmarking before committing to a tool.
  • Memory isn't cheap in embedded systems and you will no doubt have some address space limitations.

Also, if you really are going to be doing some serious string handling I would recommend using the C standard library rather than a string object library simply because you have better control over in-place substitution and so string copies become glaringly obvious in the code.

Please post a little about the microcontroller you plan to use (Data Memory, Program Memory) and whether there are any performance requirements that must be met so we can help a little more concretely.

like image 127
4 revs Avatar answered Sep 19 '22 01:09

4 revs