ATtiny13 >> Assembly

Sleep


本練習使用Power-down模式


main.s

  .equ PCMSK, 0x15
  .equ PINB,  0x16
  .equ DDRB,  0x17
  .equ PORTB, 0x18
  .equ GIMSK, 0x3b
  .equ MCUCR, 0x35
  
  .equ BTN,   0
  .equ LED,   1
  
  .org 0x0000
  rjmp main
  reti
  rjmp pcint0_handler
  
  .org 0x0010
main:
  sbi DDRB, LED
  cbi DDRB, BTN
  sbi PORTB, LED
  sbi PORTB, BTN
  ldi r16, 0x20
  out GIMSK, r16
  ldi r16, 0x01
  out PCMSK, r16
  ldi r16, 0x30
  out MCUCR, r16
  sei
  sleep
  cbi PORTB, 1

loop:
  rjmp loop

pcint0_handler:
  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

完成


返回上一頁