Mainstream Development Languages for Microcontrollers

Follow+Star Public Account Number, don’t miss exciting content
Mainstream Development Languages for Microcontrollers
Author | strongerHuang
WeChat Official Account | strongerHuang
Microcontrollers have many names, MCU (Microcontroller Unit), also called microcontroller, etc.
With the popularity of the Internet of Things, the demand for microcontrollers is increasing. At the same time, with the enhancement of microcontroller performance and resources, the languages used for developing microcontrollers are also increasing.
So, do you know which mainstream development languages are currently supported by microcontrollers?
1. Assembly Language
Description:Assembly language is a low-level programming language that is closely related to hardware. It directly maps to machine language, allowing programmers to directly control hardware resources.
Example:Write a lighting program for the 51 microcontroller (AT89S52) in assembly language.
ORG 0x0000  ; Program start address
MOV P1, #0x00  ; Initialize P1 port to low level
MAIN:    MOV P1.0, #1  ; Light up LED, set P1.0 to high level    ACALL DELAY   ; Call delay subroutine    MOV P1.0, #0  ; Turn off LED, set P1.0 to low level    ACALL DELAY   ; Call delay subroutine    SJMP MAIN     ; Infinite loop
DELAY:    ; Delay subroutine    MOV R2, #50DELAY_LOOP:    DJNZ R2, DELAY_LOOP    RET
2. C Language
Description:C language is the most commonly used development language for microcontrollers and is a high-level programming language with good portability and readability. For microcontrollers, embedded C is usually used for development.
Example:Write a lighting program for the STM32 microcontroller in C language.
#include "stm32f4xx_hal.h"
int main(void){  HAL_Init();
  SystemClock_Config();
  __HAL_RCC_GPIOA_CLK_ENABLE();  // Enable GPIOA clock
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  // Configure GPIO pin  GPIO_InitStruct.Pin = GPIO_PIN_5;      // Assume LED is connected to pin 5 of GPIOA  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Push-pull output  GPIO_InitStruct.Pull = GPIO_NOPULL;       // No pull-up or pull-down  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; // Low speed  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  while (1)  {    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); // Light up LED    HAL_Delay(1000); // Delay 1 second
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); // Turn off LED    HAL_Delay(1000); // Delay 1 second  }}
3. C++ Language
Description:C++ is an object-oriented programming language based on C, and although it is relatively less used in the microcontroller field, some modern microcontrollers are starting to support C++.
Example:Write a lighting program for the STM32 microcontroller in C++ language.
int main(void){  LED_Class LED1(GPIOF, GPIO_Pin_7, RCC_APB2Periph_GPIOF);  LED_Class LED2(GPIOF, GPIO_Pin_8, RCC_APB2Periph_GPIOF);
  LED1.Init();  LED2.Init();
  while(1)  {    LED1.Open();    LED2.Open();    Delay(10);
    LED1.Close();    LED2.Close();    Delay(10);  }}
Of course, the classes and function interfaces defined here can be found in my previous article titled “Can Microcontrollers Be Developed with C++?“.
4. Python Language
Description:Although Python is not commonly used for traditional microcontroller programming, some microcontrollers like MicroPython and CircuitPython support Python, making development easier.
Example:Write a lighting program for the microcontroller in MicroPython.
import machine
import time
led_pin = machine.Pin(2, machine.Pin.OUT)  # Assume LED is connected to pin 2
while True:    led_pin.on()   # Light up LED    time.sleep(1)  # Delay 1 second
    led_pin.off()  # Turn off LED    time.sleep(1)  # Delay 1 second
Note that the code uses MicroPython, not standard Python. Ensure that your development board supports MicroPython and is correctly installed and configured. In actual embedded development, you may also need to consider hardware configuration, clock settings, and other low-level details.
5. Other Programming Languages
In addition to the above Assembly, C language, C++, Python language, there are actually a few that use Java, but JAVA requires a virtual machine and needs to run on high-performance microcontrollers.
I’ve also seen a programming language called Ada, which is said to be widely used in some aerospace and military applications, with powerful static type checking and support for concurrent programming.

Besides the assembly, C language, C++, and Python language mentioned above, what else can you think of? Or what programming languages have you used to develop microcontrollers?

———— END ————

Mainstream Development Languages for Microcontrollers

● Column “Embedded Tools”

● Column “Embedded Development”

● Column “Keil Tutorial”

● Selected Tutorials from the Embedded Column

Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Mainstream Development Languages for Microcontrollers

Mainstream Development Languages for Microcontrollers

Click “Read the Original” to see more shares.

Leave a Comment