6
\$\begingroup\$

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.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ In general, you will use C or Assembly to program an MCU. However, there may be compilers for other languages that can produce executables for the MCU you choose. Some educational tools provide BASIC compilers, for example. \$\endgroup\$
    – Keegan Jay
    Sep 7, 2013 at 20:35
  • \$\begingroup\$ If you're just starting, take a look at Arduino which is a very simple framework for running ATMega devices. Very user friendly. \$\endgroup\$ Sep 7, 2013 at 20:36
  • \$\begingroup\$ You could try PICAXE (uses some Microchip PIC devices). You program it with BASIC - which is easier to grasp than C when you're just starting out. \$\endgroup\$
    – aja
    Sep 8, 2013 at 1:15
  • \$\begingroup\$ Gustavo Litovsky, I know i think i will start with arduino, thanks. \$\endgroup\$ Sep 8, 2013 at 9:28
  • \$\begingroup\$ What arduino board is best for beginners ? \$\endgroup\$ Sep 8, 2013 at 9:33

5 Answers 5

17
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ I'd say basic is more common then fortran, but I don't have any particular evidence for that belief. \$\endgroup\$ Sep 7, 2013 at 23:14
  • \$\begingroup\$ You're probably right. It seems that there are flavors of BASIC out there for most architectures, I'll edit my answer accordingly. \$\endgroup\$
    – us2012
    Sep 7, 2013 at 23:27
  • \$\begingroup\$ Do i get any instruction with the microcontroller ? \$\endgroup\$ Sep 8, 2013 at 9:20
  • \$\begingroup\$ All microcontrollers come with data sheets and some form of toolchain, available on their manufacturer's website. However, if you are a beginner, this material might be overwhelming for you. Look for a kit that is explicitly targeted at beginners. An Arduino is a reasonable choice, there are lots of beginner tutorials and community forums out there. \$\endgroup\$
    – us2012
    Sep 8, 2013 at 10:31
4
\$\begingroup\$

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).

\$\endgroup\$
4
\$\begingroup\$

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...

\$\endgroup\$
3
  • \$\begingroup\$ playground.arduino.cc/Code/AVR-Ada - New project on my to do list: Program the blink example on an ATtiny with Ada. \$\endgroup\$
    – jippie
    Sep 8, 2013 at 10:16
  • \$\begingroup\$ Basically if you can get the tools installed and working, the actual project is easy! If building from scratch, make sure you have AVR-Ada 1.2.x based around gcc4.7 or later. gcc4.5 had a bug that prevented the most elegant approach from working... \$\endgroup\$
    – user16324
    Sep 8, 2013 at 10:25
  • \$\begingroup\$ @BrianDrummond, I've been looking into setting myself up with an Ada for AVR toolchain, but all of the ones that I can find are either defunct github repositories or no longer supported or available from the vendors. Do you know of any current Ada compiler toolchains for AVR micros? (preferably free or open-source ones)? \$\endgroup\$
    – user98663
    Sep 5, 2019 at 13:24
1
\$\begingroup\$

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.":

enter image description here

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Amusing Note: That uC does not natively execute Java. It is a standard uC that just happens to have a Java interpreter pre-loaded into it's Flash. The uC executes "machine code", just like any other uC. \$\endgroup\$
    – user3624
    Sep 8, 2013 at 6:19
  • \$\begingroup\$ This is no less an answer than those that mention Basic interpreters however. As for the device itself, it's the sort of project which will live or die on the capability of its software stack, and it appears that there is an unsupported release which one can try to get running on the discovery boards which are both already available and cheaper than the kickstarter proposal. \$\endgroup\$ Sep 8, 2013 at 7:16
  • \$\begingroup\$ @ChrisStratton I didn't say it was "less of an answer", I didn't downvote it. I called it an "amusing note". Don't be so argumentative. Also, if you do an At-Username when you reply then the person you are replying to will get a notification. Otherwise, your comments could easily get overlooked. \$\endgroup\$
    – user3624
    Sep 9, 2013 at 0:36
  • 3
    \$\begingroup\$ @David Kessner: This is about "JavaScript", not "Java". Both are quite different languages. \$\endgroup\$
    – Curd
    Sep 9, 2013 at 8:50
0
\$\begingroup\$

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.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.