Microcontrollers have many names, such as MCU (Microcontroller Unit) and microcontroller. With the popularity of the Internet of Things, the demand for microcontrollers is increasing. At the same time, as the performance and resources of microcontrollers improve, the number of programming languages for developing microcontrollers is also growing. So, do you know which mainstream development languages are currently supported by microcontrollers?1. Assembly LanguageDescription: Assembly language is a low-level programming language that is closely related to hardware. It directly maps to machine language, allowing programmers to control hardware resources directly.Example: A program written in assembly language to light up an LED on the 51 microcontroller (AT89S52).
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    RET2. C LanguageDescription: 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 typically used for development.Example: A program written in C language to light up an LED on the STM32 microcontroller.
#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++ LanguageDescription: C++ is an object-oriented programming language based on C. Although it is relatively less used in the microcontroller field, some modern microcontrollers have started to support C++.Example: A program written in C++ language to light up an LED on the STM32 microcontroller.
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.4. Python LanguageDescription: Although Python is not commonly used for traditional microcontroller programming, some microcontrollers like MicroPython and CircuitPython support Python, simplifying development.Example: A program written in MicroPython to light up an LED on a microcontroller.
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 this code uses MicroPython, not standard Python. Ensure 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-mentioned assembly, C, C++, and Python, there are also very few instances of Java being used, but Java requires a virtual machine and needs to run on high-performance microcontrollers. There are also reports of a programming language called Ada, which is said to be widely used in aerospace and military applications, with strong static type checking and support for concurrent programming.
Besides the assembly, C, C++, and Python mentioned above, what other languages can you think of?