Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Newbie rcall question

2004-12-04 by Andrew Lim

Geert,
 
U need to initialise the stack pointer.
 
Add these few lines after ur MAIN.
 
;==============================================
Main:
 
ldi Temp,  Low(Ramend)
out SPL, Temp
ldi Temp, High(Ramend)
out SPH, Temp
;==============================================

These 4 lines of code will initialise ur stack pointer. U will be able to use rcall now.
 
 
 
Cheers,
Andrew Lim
Geert De Pecker <geert.de.pecker@skynet.be> wrote:
Hi,

I am about to start with the fascinating world of AVR and, although
I do not have the STK500 for real tests, I'm playing around with the
AVR Studio.

I made a small test program to simulate, but run into the following 
problem: when I run it and the subroutine "doStep" comes at the "ret"
instruction, the program counter jumps back to the "main" label instead
of the instruction after the "rcall" instruction.

What am I doing wrong?

Regards,

Geert

.include "8515def.inc"
;
;       Stepper output ports and pins
;
.equ sPort = PORTB
.equ sVertStep = 0
.equ sVertDir = 1
.equ sHorStep = 2
.equ sHorDir = 3
;
;       Position registers
;
.def moveH = r18
.def moveL = r19
.def posVertL = r20
.def posVertH = r21
.def posHorL = r22
.def posHorH = r23
;
;       Steps per count
;
.equ stepsPerCount = 8

;
;       General vars
;
.def tmp1 = r10
.def tmp2 = r11
.def tmp3 = r12
;
;       Org
;
.org 0x0000
;
;       Interrupts
;
;rjmp   main
;--------------------------------------------------
;       Start of program
;
main:
;
;       Init counters
;
         ldi     posVertH, 0x00
         ldi     posVertL, 0x00
         ldi     posHorH, 0x00
         ldi     posHorL, 0x00
;
;       Test
;
         ldi moveH, 0x00
         ldi moveL, 0x0A
         rcall doStep
         ldi r17, 0x00
         ldi r17, 0x00
         ldi r17, 0x00
         ldi moveH, 0x01
         ldi moveL, 0x03
         rcall doStep
;--------------------------------------------------
;       doStep
;
doStep:
         cpi moveL, 0x00
         brne doStepLow
         cpi moveH, 0x00
         breq doStepEnd
         dec moveH
         ldi moveL, 0xFF
doStepLow:
         dec moveL
         rjmp doStep
doStepEnd:
         ldi r17, 0x00
         ret

Yahoo! Groups SponsorADVERTISEMENT


---------------------------------
Yahoo! Groups Links

   To visit your group on the web, go to:
http://groups.yahoo.com/group/AVR-Chat/
  
   To unsubscribe from this group, send an email to:
AVR-Chat-unsubscribe@yahoogroups.com
  
   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


		
---------------------------------
Do you Yahoo!?
 Yahoo! Mail - Helps protect you from nasty viruses.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.