Start from Setup SimulIDE for Arduino where we setup SimulIDE to program a simulated Arduino Uno board with .ino sketches.
We configure SimulIDE to use the avra.exe compiler and locate definition files for many Atmel processors that need to be included.
Download SimulIDE_0.4.15-SR10_Win64
We already have one version of SimulIDE on the computer. 1.0 Release Candidate 3 has nifty features but it did not come with the Avra assembler toolchain and supporting files.
Unzip the SimulIDE_0.4.15-SR10_Win64.zip download. Locate the avra.exe executable in folder SimulIDE_0.4.15-SR10_Win64/bin. It is not a very large program and can be copied into other folders and executed.
Locate the include folder SimulIDE_0.4.15-SR10_Win64/share/simulide/data/codeeditor/tools/avra. You can program 50 different atmega and attiny processors from Atmel using these text files that define to the compiler how the hardware works.
You can open m328pdef.inc with notepad and see English keywords describing the atmega328p hardware. Keywords such as PORTB, DDRB and PINB are defined in this file with .equ equals statements. Example: atmega2560 hardware has a PORTE so it has an .equ statement to tell the compiler.
Close the Arduino sketch.ino and make a new file named Blink.asm. Enter this text as code and save.
.include "m328pdef.inc"
.def mask = r16 ; mask register
.def ledR = r17 ; led register
.def oLoopR = r18 ; outer loop register
.def iLoopRl = r24 ; inner loop register low
.def iLoopRh = r25 ; inner loop register high
.equ oVal = 71 ; outer loop value
.equ iVal = 28168 ; inner loop value
.cseg
.org 0x00
clr ledR ; clear led register to zero
ldi mask,(1<<PB5) ; load the mask register 00100000
out DDRB,mask ; turn on PB5 on PORTB as output
start:
eor ledR, mask ; toggle value in led register
out PORTB, ledR ; output ledR value to PORTB
ldi oLoopR,oVal ; initialize outer loop count
oLoop:
ldi iLoopRl,LOW(iVal) ; intialize inner loop count LOW
ldi iLoopRh,HIGH(iVal) ; intialize inner loop count HIGH
iLoop:
sbiw iLoopRl,1 ; decrement inner loop register
brne iLoop ; branch to iLoop if iLoop register != 0
dec oLoopR ; decrement outer loop register
brne oLoop ; branch to oLoop if oLoop register != 0
rjmp start ; jump back to start
Right now SimulIDE is still set to run Arduino sketches. Click on the Gear icon and Compiler Settings.
Find the Avra tab. Enter the locations from earlier. Click the X to close.
Click the Check mark icon to verify compile
SUCCESS!!! Compilation OK. Click the download icon with the down arrow. Remember to turn on the simulated Arduino board.
You will have to install avra on your linux computer. You can look for the avra application and the include files in these folders. I had to manually add the m328pdef.inc definitions file to the /usr/share/avra/ folder.
Tool Path: /usr/bin/
Include Path: /usr/share/avra/
Something different
Open a CMD window on your Windows computer. Type pwd for pathway directory to see where you are. Type mkdir avra to make a new directory named avra. Type cd avra to go into the new directory. Type dir to see that the directory is empty.
Go back and locate your Blink.asm file, the avra.exe executable program and the m328pdef.inc file. Put copies of these three files into the avra folder. This is a quarter of a MegaByte.
Back to the terminal cmd window and type > avra.exe Blink.asm. You should see Assembly complete with no errors.
You now have a compiled binary hex file in the intel format that you can upload to a real board or use in the simulator. Some of the other files are text files that you can open and read with notepad, they describe the software build that generated these files.
What do I do with the files I've downloaded?
Today 50MB is not a lot of space on the computer. The .zip files can be recycled. The folders with different versions of the application are all good, they each run. You can run setups saved from one in another.
The applications differ in features, menus and extras. But you are probably going to use just one, and upgrade it. But take a look at the contents before recycle.
The complete examples folder is only 6MB and there are some interesting experiments ready to go. The Arduino example folder contains sketches and compiled binaries. You can move this folder and save it, if you want.
Comments