why isn't my avr working?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i have tried to make a led flasher with many programs but none seems to work.I compiled them into avrstudio. my atmega 8535 has connected some leds, the hardware is ok, but the leds(diferent types) they just light continousl.i give here one of the programs.what's wrong?

.include "m8535def.inc"

.def Temp = R16

.org 0x0000

init:
ldi temp, 0b00000001 ;
out DDRD, temp ;

main:
ldi temp, 0b00000001 ;
out portd, temp ;

rcall delay ;

ldi temp, 0x00 ;
out portd, temp ;

rcall delay ;

rjmp main ;

delay: ;
; =============================
;
; 499998 cycles: about 1/2 seconds
; -----------------------------
; delaying 499995 cycles:
ldi R29, $0F
WGLOOP0: ldi R30, $37
WGLOOP1: ldi R31, $C9
WGLOOP2: dec R31
brne WGLOOP2
dec R30
brne WGLOOP1
dec R29
brne WGLOOP0
; -----------------------------
; delaying 3 cycles:
ldi R29, $01
WGLOOP3: dec R29
brne WGLOOP3
; =============================
ret

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You haven't initialised the stack pointer! You'd have probably found the mistake if you had simulated the program.

Leon

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have to load the stack pointer with RAMEND so that program can return correctly from the delay routine
add
ldi temp, low(RAMEND)
out SPL,temp
ldi temp, High(RAMEND)
out SPH,temp as part of your init sequence

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Leon
Programs simulates "correctly" without setting stack pointer

Gerry

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GerryKeely wrote:
Leon
Programs simulates "correctly" without setting stack pointer
Gerry

I think the simulator often defaults the SP to RAMEND and while some of the modern AVRs do this in real life too I'm not sure that it's correctly simulating the behvaiour of some of the older AVRs.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it finaly worked,,you were right with the stack pointer,

thank you very much for help