Z
Z
ZombFS2020-06-20 00:34:12
Programming
ZombFS, 2020-06-20 00:34:12

In what language are microcontrollers most often programmed?

When I was just starting to get into programming, I read in a book about the history of Java and about its approach to how programs work. I learned that with the help of the JVM, the language achieves cross-platform and due to this, Java has become so popular. Those. in my understanding, the language was then just the same for microcontrollers, but now when I look for information about programming for microcontrollers, I find that they mostly do it in the C language. The question is: what language is now the most popular for developing software for microcontrollers and why for this purpose (as I read on other sources) is the C language chosen more often than its more developed counterpart - Java?

Answer the question

In order to leave comments, you need to log in

10 answer(s)
V
Victor Bomberow, 2020-06-20
@ZombFS

Java ME has minimum system requirements for target devices.
Looking at them, it becomes clear that this is not for microcontrollers in the general case. Of course, an embedded system is different for an embedded system, but microcontrollers are still used not only for embedded systems, but directly into hardware, for example, a radio transceiver designed to work with a physical layer protocol. Such controllers can have kilobytes of memory of all kinds. Often, such devices offer not so many assembler instructions that it makes sense to make a C compiler for them. In more universal microcontrollers, there is a compiler, so this is quite a reason for joy.
Where JME can be deployed, there is already a Linux kernel, so the answer to the question of why there is more C than Java is what the company does, what its business is, and what its market is. Quantitatively, there are simply fewer solutions that need JME compared to those that don't need an OS layer.

V
Vladimir Kuts, 2020-06-20
@fox_12

why for this purpose (as I read on other sources) the C language is chosen more often than its more developed counterpart - Java

Controller example - ATTiny13:
- 1 KB ISP Flash program memory
- 64 bytes ISP EEPROM data memory
- 64 bytes onboard SRAM
Good luck locating the Java virtual machine + code of the program itself, given the available resources...

0
0x131315, 2020-06-21
@0x131315

It's pure economics.
Controllers are placed mainly in mass devices.
This means that every dollar saved is tens or even hundreds of millions of profits out of the blue.
Such amounts more than cover the time of programmers, so they are given the task of putting the functionality on the cheapest controller that is still somehow able to pull this functionality.
Hence - a high degree of code optimization when working with controllers.
It is necessary to use all the features of a particular controller as much as possible - programmers work a lot with the datasheet.
The language should allow the maximum use of the command system of a particular controller, and flexibly manage the registers and memory of the controller.
Therefore, assembler is mainly used - you can write the most compact code with it.
But the functionality is often large enough to be written entirely in assembler.
Therefore, in order to save time, they write in C using libraries, and the most important places are implemented using assembler inserts.
Thanks to this, it is possible to realize almost all the advantages of both assembler and C: fast and fairly fully controlled development, with fairly compact and fast code.
With SIM cards, the situation is different - it was important to implement cross-platform code there. Therefore, they use java, regardless of the resources.
In more powerful controllers, it is no longer a specific language that is in use, but entire operating systems. Basically, in the firmware, Linux is simply sewn up, and individual parts for controlling the controller are implemented in C as drivers.
Where performance is important, they do not use program code at all, but switch to iron logic - pluses. This is mainly signal processing equipment, incl. all kinds of radio modules, modems, video equipment, etc.
So it all comes down to common sense and cost.
It's just silly to shove java everywhere.

E
evgeniy_lm, 2020-06-20
@evgeniy_lm

I knew that with the help of the JVM, the language achieves cross-platform and due to this, Java became so popular. Those. in my understanding, the language then was just the same for microcontrollers

I don’t know from what ceiling you took such an understanding, but it is precisely because of the JVM that JAVA is completely unacceptable for microcontrollers. JAVA is cross-platform at the cost of high memory consumption and low performance.
PS Some Ampere controllers that are programmed in JavaScript on ARM Cortex, but that's another story (not a very good one in my opinion)

R
regsmic, 2020-06-20
@regsmic

You can also write in Java, only for this case the compiler is needed in order to translate the code into machine codes understandable to the processor.
No matter what language the code is written in, it will still be converted by the compiler. It so happened historically that Xi was chosen.

�
âš¡ Kotobotov âš¡, 2020-06-20
@angrySCV

languages ​​well, C, Rust, because usually controllers are required not only to process data, but to process it in real time, that is, to perform specific actions, exactly at the appointed time, and the Java machine does not work in real time.

T
Terranz, 2020-06-21
@Terranz

I'll just leave this here for anyone who hasn't seen this before and doesn't know about java processors.

A
Alexander Buliterov, 2020-06-25
@bullitufa

It all depends on the task!
C, C++, Rust, asm. Approximately such distribution of use I see.
I use C++ more like "C with classes". I note that C ++ does not eat much resources compared to C. You need to "be able to cook" (-fno-exceptions, -fno-rtti, virtual functions, inheritance, etc.).
C++ allowed writing drivers for peripherals (timers, spi, i2c, uart). And when moving from platform to platform, minimize changes, or even avoid them. Naturally, it was not without the use of STL (mostly containers), but do not use methods with an exception.
But the whole low-level part is in Xia.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question