Embedded C Part 7: LED ON with 2 lines of registers
// WHAT YOU WILL LEARN
DDRB |= (1<<5); PORTB |= (1<<5); lights D13 (= PB5) without digitalWrite.
// LESSON NOTES
Turn on an LED with NO Arduino functions — just 2 lines of C! 💡
The Uno's pin 13 LED is really PB5: port B, pin 5 on the ATmega328P.
DDRB |= (1 << DDB5); // bit 5 = 1 → outputPORTB |= (1 << PORTB5); // bit 5 = 1 → HIGH, LED on ✅
Why |= and not = ?
'=' overwrites all 8 bits (wipes the others) ❌
'|=' sets only bit 5 and keeps the rest ✅
No digitalWrite — just the chip's own switches: registers.
TESTED CODE · ec07_led_on_registers.c · avr-gcc
// EC L07 - LED on D13 with 2 lines, no digitalWrite
#include <avr/io.h>
int main(void) {
DDRB |= (1 << DDB5); // PB5 -> output
PORTB |= (1 << PORTB5); // PB5 -> HIGH, LED ON
while (1) { }
}Read the voiceover (transcript)
- No Arduino functions. Just two lines!
- The Uno's pin thirteen LED is really port B, pin five.
- Line one: DDRB bit five becomes one. Now it's an output.
- Line two: PORT B, bit five, becomes one. The pin goes high!
- And the LED lights up!
- The or-equals changes only bit five. The rest stay.
- No digital write, just the chip's own switches!
- Next, Part eight: the bit shift trick. Follow for Part eight!
Related lessons
// NEWSLETTER · FREE
Get new lessons + early access to the full course
One email when new lessons drop. No spam, unsubscribe any time.
✓ You're on the list! We'll email you when new lessons drop.
By joining you agree to the privacy policy.




