I'm taking my first steps in to avr asm and I am stuck on my first endeavor.
I'm using a mega8, and trying to get PD4 to blink an LED (nothing fancy, using the internal oscillator).
If I remove my rcall delay calls from my loop:, the LED lights up fine, however, with the delays in place, the LED does not light up. The weird part is, if I swap the sbi and cbi calls in loop: the LED will light up, but not blink. I suspect this is due to a failure inside the first rcall delay call. But I can't seem to find where. I have tried to follow the AVR ASM tutorials that are available online, but clearly I am missing something (probably very simple).
Any advice would be greatly appreciated. Thank you.
.include "m8def.inc" .def delay1 = r17 .def delay2 = r18 .def delayv = r19 .equ led = 4 ; PORTD bit number to blink LED on rjmp main delay: clr delay1 clr delay2 ldi delayv, 100 delay_loop: dec delay2 brne delay_loop dec delay1 brne delay_loop dec delayv brne delay_loop ret ; go back to where we came from main: sbi DDRD, led ; connect PORTD pin 4 to LED loop: cbi PORTD, led ; turn PD4 high rcall delay ; delay for an short bit sbi PORTD, led ; turn PD4 low rcall delay ; delay again for a short bit rjmp loop ; recurse back to the head of loop