1. Home
  2. /
  3. Embedded-c-cpp
  4. /
  5. PWM LED Brightness (Embedded C, AVR)

PWM LED Brightness (Embedded C, AVR) - Embedded-c-cpp Typing CST Test

Loading…

PWM LED Brightness (Embedded C, AVR) — Embedded-c-cpp Code

Generates PWM on an AVR to control LED brightness.

#include <avr/io.h>

int main(void)
{
	DDRB |= (1 << PB1); // OC1A output
	TCCR1A |= (1 << COM1A1) | (1 << WGM10);
	TCCR1B |= (1 << WGM12) | (1 << CS10); // Fast PWM, no prescaler
	while(1)
	{
		for(uint8_t i=0; i<255; i++) { OCR1A = i; for(volatile int j=0;j<1000;j++); }
	}
}

Embedded-c-cpp Language Guide

Embedded C/C++ refers to using the C or C++ programming languages for programming embedded systems. These are resource-constrained devices like microcontrollers, IoT devices, automotive controllers, and real-time systems where direct hardware control and performance are critical.

Primary Use Cases

  • ▸Microcontroller firmware
  • ▸Real-time operating systems (RTOS) tasks
  • ▸IoT devices and sensors
  • ▸Automotive ECU programming
  • ▸Industrial automation and robotics

Notable Features

  • ▸Direct memory and register access
  • ▸Low-level I/O control and peripheral interfacing
  • ▸Deterministic and high-performance execution
  • ▸Supports modular and object-oriented designs
  • ▸Rich ecosystem of compilers, toolchains, and RTOS libraries

Origin & Creator

C was created by Dennis Ritchie at Bell Labs in the 1970s, and C++ was developed by Bjarne Stroustrup in the 1980s. The embedded variant evolved as developers adapted these languages for low-level, resource-constrained systems.

Industrial Note

Embedded C/C++ dominates industries like automotive (ISO 26262), aerospace (DO-178C), industrial automation, and consumer electronics where memory, speed, and reliability are critical.

More Embedded-c-cpp Typing Exercises

Blink LED (Embedded C, AVR microcontroller)Embedded C++ Class for LED ControlRead Button Input (Embedded C)UART Transmit (Embedded C)ADC Read and LED Control (Embedded C)Timer Interrupt Toggle LED (Embedded C)Embedded C++ Motor Control ClassSPI Send Byte (Embedded C)I2C Master Send (Embedded C)

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher