AVR: Bare-Metal Port Control
Control ATmega pins directly without the Arduino framework.
◷ 45 minParts and tools
- ATmega328P board
- AVR programmer
- LED and resistor
Lesson
Learning objective
Control ATmega pins directly without the Arduino framework.
Procedure
- Review the circuit and confirm the board voltage.
- Build and inspect the wiring before applying power.
- Upload the example, observe the result and record your readings.
- Change one parameter, predict the result and test again.
Troubleshooting
Check power, ground, pin selection, polarity, compiler target and serial output. Use a multimeter or logic analyser where appropriate.
Example code
#include <avr/io.h>
int main(void){ DDRB|=(1<<DDB5); PORTB|=(1<<PORTB5); while(1){} }Knowledge check
Which register controls Port B direction?
