I'll show you a bit of how to use avr-as in Linux. I'm using Ubuntu 6.06 while writing this blog and doing my experiment with avr-as.
# Installing avr-as
avr-as is part of avr-binutils package, and if you have installed avr-gcc in your Linux before it means you've installed this software too.
If you haven't install avr-gcc, these are the links to help you:
- Building AVR GCC The process is applicable for most of Linux distribution.
- For debian / ubuntu:
- apt-get install avr-binutils avr-gcc avr-libc avrdude
- For SLED 10 / OpenSUSE:
- Use Yast to find avr-gcc. For SLED 10, you need to install OpenSUSE repo first
The demo is simple: Set PORTB0 mode to output, and set its value to HIGH. Here's the demo program:
.equ PORTB,0x18
.equ DDRB, 0x17
.org 0x00
reset:
rjmp main;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
rjmp defaultInt;
defaultInt:
reti;
main:
sbi DDRB, 0;
cbi DDRB, 0;
end:
rjmp end;
The .equ syntax assign PORTB and DDRB to 0x18 and 0x17. The syntax makes the code easier to read. The rest of the program is the standard avr assembly. You can view the datasheet for the complete assembly syntax and its meaning.
# Compiling Demo Program
- Save into *.s file (in this demo we call it: simpleIo.s)
- Assembly the file using:
avr-as -mmcu=attiny15 -o simpleIo.o simpleIo.s
- Link the file using:
avr-ld -o simpleIo.elf simpleIo.o
- Generate hex file:
avr-objcopy --output-target=ihex simpleIo.elf simpleIo.ihex
- Program the hex file
No comments:
Post a Comment