ABC of Electronics cosycom.com
EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 6

C: The Standard Language for Firmware

Fast, small and close to the hardware.

C is the most common firmware language because it compiles to compact, fast machine code and lets you reach hardware registers directly through pointers. Compilers exist for PIC, AVR, ARM and nearly every other family.

Key habits: use fixed-size types such as uint8_t, mark hardware-shared variables volatile so the compiler re-reads them, and keep interrupt routines short.

The volatile keyword matters. Without it, the compiler may cache a flag in a CPU register and never notice an interrupt changed it.

EXAMPLE
#include <stdint.h>

volatile uint8_t button_pressed = 0;   /* set inside an interrupt */

int main(void) {
    for (;;) {
        if (button_pressed) {
            button_pressed = 0;
            /* handle the press */
        }
    }
}