AVR-GCC is the compiler toolchain suite that generates software for Atmel microcontroller units. Atmel is now part of MicroChip and we will use a simulated Atmega328p chip with the WinAVR package.
Setup WinAVRWe can install a C compiler in a number of ways. We will discuss XC8 and arduino but WinAVR is one of the original softwares, easy to install and easy to use. Go to the project Program Uno with WinAVR and setup your computer.
Arduino IDE uses an updated version of AVR-GCC. There is an organization that maintains the software. Atmel Studio uses XC8 compiler from MicroChip which contains a release. If we can locate any working version of the compiler we can use it to program Atmel Chips.
We will need to know where WinAVR is installed in the PC. MPLab X performs a scan and finds compilers for the Atmega328. Some are installed with Atmel Studio.
We can open a CMD command screen and type which avr-gcc.exe and see that the default version of avr-gcc running in this computer is located in C:\WinAVR-20100110\bin\avr-gcc.exe. Type PATH and we see several folders that will be searched for recognized commands.
In project Simulated Blinky we installed SimulIDE circuit simulator. In Blink LED Manually we acquired some hands-on with the software.
Open a new circuit.
With your cursor you can move the windows around right to the edge of the screen. If you have a mouse with scroll wheel you can zoom in and out. There are menus for opening and saving. Hover over the icons and the commands are displayed.
Look in File Explorer Data/arduino/uno/Uno.sim1 double-click or drag-and-drop onto the blank circuit. We are looking at the Simulated Arduino Uno and the Atmega328p circuit. We can add more components from the menu on the left of the screen.
DevBoard is the name of the electronic board we will run our program on. SimulIDE has example circuits for a number of boards. The Uno contains the Atmega328p microcontroller.
Software written for the Uno can run on many other AVR chips such as the Atmega8 which differs in flash and SRAM size. We can setup SimulIDE to program our Uno with Arduino IDE sketches or AVRA Assembler .asm.
Right click on the board and you see this menu
Check and uncheck the little box for Board mode. Two views of your simulated Arduino Uno board and the components inside. Our Uno devboard is the microcontroller chip and a few components.
Right click on the chip and you see this menu. A hardware Uno board has a programmer circuit we talk to with avrdude.exe. We'll use the Load firmware command to do this.
There are a lot of useful commands here. If you have a hex file for Uno, Nano or any atmega328 MCU you can manually Load firmware.
Arduino IDE has an export compiled binary command that generates a hex file that will work here. SimulIDE samples come with hex files that you can load, look for them in File Explorer.
The hex file can be from Atmel Studio / MicroChip Studio, CodeBlocks or WinAVR. Serial Monitor is like on real Arduino board you can execute serial.print( ) commands. MCU Monitor is a debugging tool that lets you look inside the processor.
main.cUse the edit menu to open a new main.c file and save the file.
Put this code into the file
// PORTB is an 8bit number at address 0x25
#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
int main(void){ DDRB = 0xFF; // turn PORTB on
while(1) {PORTB++; // increment PORTB
_delay_ms(100); }}
It tells the processor to use all 8 outputs on PORTB as outputs and to use the port to count a binary number. The C compiler uses PORTB as a variable identifier.
Compiler SettingsOpen Compiler Settings from the gear menu and choose
Compiler: Avrgcc
Tool Path: C:/WinAVR-20100110/bin/
Include Path C:/WinAVR-20100110/lib/gcc/avr/
Device atmega328p.
Look for Avrgcc Compiler successfully loaded in lower right. Close Compiler Settings window.
CompileClick the compile check mark command. Watch for Success!!! Compilation ok
UploadClick the Upload command. Watch for Mapping Flash to Source...
ON/OFFAs a safety feature SimulIDE shuts down our circuit when we change wires or software. Click on the red ON/OFF button.
The LED will blink and you will see flashes as wires receive voltage.
MCU MonitorRight click on the processor chip and select MCU Monitor. Type in PORTB and you will see the count tick off.
Comments