Microcontrollers have many names, such as MCU (Microcontroller Unit), and also referred to as microcontrollers.
With the popularity of the Internet of Things, the demand for microcontrollers has been increasing. At the same time, as the performance and resources of microcontrollers have improved, the number of programming languages for developing microcontrollers has also increased.
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 control hardware resources directly.
Example: A program to light up an LED using assembly language for 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, #50
DELAY_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 typically used for development.
Example: A program to light up an LED using C language for 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++ Language
Description: 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 to light up an LED using C++ language for 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 can be found in my previous article titled “Can Microcontrollers Be Developed Using C++?“.
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 to light up an LED using 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 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 LanguagesIn addition to the above assembly, C, C++, and Python, there are actually a few others that use Java, but JAVA requires a virtual machine and needs to run on high-performance microcontrollers. I have also seen a programming language called Ada, which is said to be widely used in aerospace and military applications, featuring strong static type checking and support for concurrent programming. Besides the aforementioned assembly, C, C++, and Python, what other programming languages can you think of? Or which programming languages have you used to develop microcontrollers?
END
Source: strongerHuangCopyright belongs to the original author. If there is any infringement, please contact for deletion.▍Recommended ReadingJapan’s Operating System Almost Dominated the World…VSCode vs. SourceInsight, Which is Better for Reading Source Code?No Foreign Authorization Needed! A Milestone in Fully Self-Designed Domestic CPUs is Here~
→ Follow for Updates ←