You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Example projects & code for Atmel ATMega8.
Notifications You must be signed in to change notification settings
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go to fileThis repository is intended to contain detailed instructions on how to get started with programming Atmel AVR microcontrollers. It also contains a bunch of thoroughly documented and explained example projects.
First, you need to compile a C source file to an .elf object file.
avr-gcc -mmcu=atmega8 -Wall -Os -o blink.elf blink.c -DF_CPU=1000000UL
DF_CPU=1000000UL sets F_CPU to 1MHz.
To flash the MCU using USBasp programmer, you need a .hex file. It can be created out of the .elf file you generated in the previous step.
avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex
Now it's time to run the code
avrdude -c usbasp -p m8 -e -U flash:w:blink.hex
First things first: you need Homebrew.
It prints a list which contains:
/usr/local/Cellar/avr-gcc//avr/include/
Copy that line, replacing with your version.
Now, in project root, create a .vscode folder. In it, create settings.json file with the following content:
Example (for avr-gcc v9.3.0 and using headers for ATmega8A)
< "C_Cpp.default.includePath": [" /usr/local/Cellar/avr-gcc@9/9.3.0_2/avr/include/"], "C_Cpp.default.defines": ["__AVR_ATmega8A__"] >
Voilà, IntelliSense should work now.
Example (using headers for ATmega8A)
.vscode/settings.json
< "C_Cpp.default.includePath": ["C:\\Users\\Bartek\\avr-gcc\\avr\\include"], "C_Cpp.default.defines": ["__AVR_ATmega8A__"] >
This is almost enough, but chances are, if you use sei() or ISR functions for interrupts, your IntelliSense will show errors. To fix them, create a new file named c_cpp_properties.json in .vscode directory in this project's root with the following content:
.vscode/c_cpp_properties.json
< "configurations": [ < "name": "Win32", "includePath": ["$"], "cStandard": "c99", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" > ], "version": 4 >
Voilà, IntelliSense should work just fine.