I want to start making devices and I read about microcontrollers and other stuff on the Internet. I wonder if there are other languages to program microcontrollers with in addition to C.
|
Chips do not directly use C at all. They have instruction sets that vary greatly between different architectures. As a very low level abstraction of these instruction sets, most manufacturers provide an assembler, through which you can translate programs written in the relevant assembly language (which is roughly a more human-readable form of the machine instructions) into binary form that you can upload to your chip. At the next higher level, there are languages like C. C is by far the most dominant language for microcontroller programming at this level. For some architectures, you will also find the odd Pascal, BASIC or maybe Fortran compiler. In theory, the only thing that you need to use a given language on a given architecture is a suitable compiler (although some, like Java, C#, etc usually depend on runtime environments, and these are prohibitively resource-hungry for most uCs). In practice, there aren't that many compilers available. |
|||||||||||||||||
|
As one of the other users commented below your question, Arduino is very popular and versatile in terms of projects and uses. It has its own language that is very similar to C... for example declaring libraries, variables, and making function calls. However, it has some of its own inherent functions that you will have to learn the syntax for. |
|||||
|
Another candidate language for programming microcontrollers is Ada. It offers very good facilities for low level programming, as well as better detection of certain types of error before you get to the stage of running the program, which I find helps me develop considerably faster than in C. The resultant executable can be just as small as C, not so surprising when you realise that most of the Gnat Ada compiler is the same optimiser and code generator as the commonest C compiler (gcc). Another benefit is that the code can be much more readable than C; another way to make problems easier to eliminate. Beyond the smallest microcontrollers, it also offers good.object oriented and multitasking facilities; the equivalent of an RTOS is built into the language. Two downsides: Ada has an undeservedly poor reputation inherited from a 30 year old version that you are unlikely to encounter nowadays - you may hear quite emotional reactions against it. Ada-2005 is a very different language... And not every microcontroller has an Ada compiler and toolchain. Two popular ones that do, are the Atmel AVR (so you can program your Arduino boards in Ada) and the Texas Instruments MSP430 series. There are also Gnat builds available for many varieties of the ARM processor, including the Raspberry Pi Debian distribution. Any other GCC target can potentially support Ada, though building GCC is not usually a trivial project... |
|||||||||
|
As the other answers say, most uC's come with toolchains that support C and some other similar languages, because larger languages, especially those with garbage collection, are very resource hungry. But, in the spirit of Atwood's Law: "Everything will eventually be ported to Javascript", I give you the Espruino, "The world's first JavaScript microcontroller for beginners or experts.": |
|||||||||||||||||
|
As us2012 said, a µc does not actually run the C language at all. It instead runs machine language which is a binary representation of the instruction set of the µc, with fields for an opcode (what to do), and either register specifiers and/or addresses (where the data is fetched from and/or stored.) Assembly language is a symbolic representation of this binary machine language. In the case of the C language, these machine instructions are generated by a C compiler, which almost always runs on a computer separate from the µc (an exception is embedded Linux, which includes the gcc compiler, running on a µc with sufficient resources to run a compiler). When the compiler is run on a PC, this is known as cross-compiling. Each separate source file containing the C language statements is compiled separately, and the output of each is combined into a single downloadable file by linker program. This downloadable file contains the machine language instructions mentioned above, and can be directly run on the µc. If you want to run a different language on the µc, you would need a different compiler for that language. However there are a number of languages that are not compiled to machine code, but instead are compiled to bytecodes; these cannot be directly executed by the µc but instead have to be executed by an interpreter running on the µc (a variation is to compile the bytecodes into machine language the first time they are executed by the interpreter). |
|||
|