參考資訊:
https://www.microchip.com/en-us/product/attiny13#Documentation
https://nerdathome.blogspot.com/2008/04/avr-as-usage-tutorial.html
本範例使用Prescaler 1024,當Timer Overflow時,觸發中斷,在中斷裡面Toggle LED
main.s
.equ DDRB, 0x17 .equ PORTB, 0x18 .equ TIMSK0, 0x39 .equ TCNT0, 0x32 .equ TCCR0B, 0x33 .equ LED, 1 .org 0x0000 rjmp main reti reti rjmp timer_handler .org 0x0020 main: sbi DDRB, LED sbi PORTB, LED ldi r16, 0x00 out TCNT0, r16 ldi r16, 0x02 out TIMSK0, r16 ldi r16, 0x05 out TCCR0B, r16 ldi r16, 0x01 ldi r17, 0 sei loop: rjmp loop timer_handler: sbrs r17, 0 cbi PORTB, LED sbrc r17, 0 sbi PORTB, LED eor r17, r16 reti
編譯和燒錄
$ avr-as -mmcu=attiny13 -o main.o main.s $ avr-ld -o main.elf main.o $ avr-objcopy --output-target=ihex main.elf main.ihex $ sudo avrdude -c usbasp -p t13 -B 1024 -U flash:w:main.ihex:i
完成