Software apps and online services
MicroChip makes avrasm2.exe assembler for Atmel AVR chips like the ATtiny. On Linux we can use AVRA assembler. This project looks closely at the include file tn13def.inc.Install AVRA
Open CLI terminal and type
sudo apt install avra avrdude
You will be prompt to install software modules. Installed software remains unchange. Click enter to agree.
When installation is complete we will have an application named AVRA. Type which avra to see where the command is located. Type $PATH and you will see directories where Linux will look for commands.
Software is modular. Assemblers use definition files that map out what features a given processor will have. 49 files for forty nine different processor modules. m8def.inc for the ATmega8, tn45def.inc for the ATtiny45.
They are text files with assembly language. Lots of comments, most of the active lines of code are definitions that explain what number to substitute for PORTB, for example. We can open them with a text editor and change text if we need.
Create a text file named tinyCount.asm. You can download it as an attachment to this project, you may need to change the name.
This is assembly code that will program the ATtiny to perform a binary count on PORTB. Change delay by change oVal and iVal. Notice how the first command is to include the contents of the definition file tn13def.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 = 80 ; outer loop value
.equ iVal = 800 ; inner loop value
clr ledR ; clear led register to zero
ldi mask,0xFF ; load the mask register 11111111
out DDRB,mask ; set PORTB to all 8 bits OUT
out PORTB,ledR ; write led register to PORTB
inc ledR ; increment ledR from 0 to 255
ldi oLoopR,oVal ; initialize outer loop count
ldi iLoopRl,LOW(iVal) ; intialize inner loop count in inner
ldi iLoopRh,HIGH(iVal) ; loop high and low registers
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 outer loop register != 0
rjmp start ; jump back to start
Open a CLI terminal screen in the directory with the assembly source file.
avra -I /usr/share/avra tinyCount.asm
This command is telling avra to perform assembly on the source file tinyCount.asm. -I tells it to look in the folder /usr/share/avra for any extra files to include.
Assembly complete with no errors. Let's look in the project folder. New files generated and there is a hex file containing hexadecimal numbers.
Connect an ATtiny development board or chip with a USBasp or USBtiny programming device.
Enter the command
avrdude -p t13 -c usbasp -U flash:w:tinyCount.hex:i
Progress bars cross your computer screen. You may see lights blink on your programmer.
LED D2 is on pin PB3 LED D3 is on pin PB4.
You got error messages? Pragma warnings? Most likely it is the includes file that prevents compilation. Check and see if a new hex file is generated. Delete old generated files.
Most of this project is about the include file and where it is located. Wrong location in our command $ avra -I /usr/share/avra tinyCount.asm. You are telling avra to look in the directory /usr/share/avra for any included files. Avra needs to find tn13def.inc. Spell it wrong and avra will not find it.
You can copy the definitions file into your project folder. Change the cli terminal instruction to $ avra tinyCount.asm.
Look on the internet for different versions of tn13def.inc. Newer ones come with MicroChip Studio. Try modifying the file with a text editor.
Try other processors. I wanted to use AVRA on an ATmega32 and now we have this tiny project. Look at the files in /usr/share/avra and you don't see m328pdef.inc for the Arduino.
So, obtain a copy of m328pdef.inc and do this project with your Uno board.