ab 2024-10-25, uebungen, AVR Assembler
Posted: Fri Oct 25, 2024 8:14 pm
Code: Select all
.include "m8def.inc"
ldi r16, HIGH (RAMEND)
out SPH, r16
ldi r16, LOW (RAMEND)
out SPL, r16
ldi r16, 0xff
out DDRB, r16
ldi r16, 0x00
loop1:
com r16
out PORTB, r16
com r16
rcall sleep
inc r16
rjmp loop1
sleep:
push r16
push r17
push r18
ldi r16, 0x00
sleep_loop1:
ldi r17, 0x00
sleep_loop2:
ldi r18, 0x00
sleep_loop3:
inc r18
cpi r18, 0x0e
brne sleep_loop3
inc r17
cpi r17, 0x10
brne sleep_loop2
inc r16
cpi r16, 0xf0
brne sleep_loop1
pop r18
pop r17
pop r16
ret
Code: Select all
.include "m8def.inc"
.org 0x0000
rjmp RESET
.org OVF0addr
rjmp Timer0addr
RESET:
ldi r16, HIGH (RAMEND)
out SPH, r16
ldi r16, LOW (RAMEND)
out SPL, r16
ldi r16, 0xff
out DDRB, r16
ldi r16, (1<<CS02) | (1<<CS00)
out TCCR0, r16
ldi r16, (1<<TOIE0)
out TIMSK, r16
ldi r16, 0x00
ldi r17, 0x00
sei
end:
rjmp end
Timer0addr:
inc r16
andi r16, 0b00000011
cpi r16, 0b00000011
breq update
reti
update:
inc r17
com r17
out PORTB, r17
com r17
reti