Bare-metal AVR projects from my second-year college study, rebuilt for the Arduino Uno R3 / ATmega328P.
The important point is that the Arduino Uno is only being used as an ATmega328P development board. The projects do not use Arduino functions such as digitalWrite(), pinMode(), or Serial.begin(). They use AVR registers directly with AVR-GCC, just like normal AVR development.
Each project uses the same simple layout:
Project XX - Project Name/
├── main.c
├── README.md
└── images/
└── .gitkeep
After rebuilding a circuit, add your own real photo as:
images/breadboard.jpg
Useful Arduino Uno / ATmega328P mappings:
| Arduino pin | AVR pin |
|---|---|
| D0 | PD0 / RXD |
| D1 | PD1 / TXD |
| D2 | PD2 / INT0 |
| D3 | PD3 / INT1 |
| D8 | PB0 |
| D9 | PB1 |
| D10 | PB2 |
| D11 | PB3 / MOSI |
| D12 | PB4 / MISO |
| D13 | PB5 / SCK / built-in LED |
| A0 | PC0 / ADC0 |
| A1 | PC1 / ADC1 |
| A4 | PC4 / SDA |
| A5 | PC5 / SCL |
Target:
MCU: ATmega328P
Clock: 16 MHz
Compiler: AVR-GCC
Board: Arduino Uno R3
Example compilation:
avr-gcc -mmcu=atmega328p -DF_CPU=16000000UL -Os main.c -o main.elf
avr-objcopy -O ihex -R .eeprom main.elf main.hexUpload through the Uno bootloader by replacing COM3 with the correct serial port:
avrdude -c arduino -p atmega328p -P COM3 -b 115200 -D -U flash:w:main.hex:iProjects containing additional .c files must compile those files too. For example, the UART library project can be built with:
avr-gcc -mmcu=atmega328p -DF_CPU=16000000UL -Os main.c uart.c -o main.elf
avr-objcopy -O ihex -R .eeprom main.elf main.hexThe project sequence is based on Simply AVR (ببساطة AVR) by Abdallah Ali Abdallah.
The source book is published under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0). No book circuit diagrams or long passages are included here. Project descriptions and code were rewritten for the ATmega328P.
Project 01 - Blinking the On-Board LEDProject 02 - Four Blinking LEDsProject 03 - Using PORTB and PORTD as OutputsProject 04 - 7-Segment LED CounterProject 05 - Digital Input with PushbuttonProject 06 - Pushbutton with Internal Pull-UpProject 07 - Three Buttons and Three LEDsProject 08 - Pushbutton DebouncingProject 09 - DC Motor On-Off ControlProject 10 - DC Motor Direction ControlProject 11 - External Interrupt INT0Project 12 - External Interrupts INT0 and INT1Project 13 - UART TransmitterProject 14 - UART ReceiverProject 15 - UART Transmit and ReceiveProject 16 - UART String TransmissionProject 17 - Reusable UART Driver LibraryProject 18 - ADC Potentiometer ReadingProject 19 - FreeRTOS - Three LED Tasks