Shop OBEX P1 Docs P2 Docs Learn Events
I can't write to RA or RE — Parallax Forums

I can't write to RA or RE

Armored CarsArmored Cars Posts: 172
edited 2005-09-28 01:15 in General Discussion
In this program in the debugger RA and RE stay at 0.· I can't figure it out.

device sx52,OSC4MHZ
device turbo,stackx,optionx
IRC_CAL IRC_SLOW
reset RSPO
freq 4_000_000
org $0A
fsrcounter·ds·1
rcounter·ds·1
loop1var·ds·1
dloop1var·ds·1
;
RESET POINT ONLY
RSPO
mov·!ra,#0
mov·!re,#0
;
IDLE
mov·FSR,#$30
mov·IND,#%00000001
inc·FSR
mov·IND,#%00000010
inc·FSR
mov·IND,#%00000100
inc·FSR
mov·IND,#%00001000
IdleLoop
mov·loop1var,#4
clr·rcounter
mov·fsrcounter,#$30
loop1
call·xaxis
mov·FSR,fsrcounter
mov·re,IND
call·delay
clr·re
inc·fsrcounter
djnz·loop1var,loop1
jmp·IdleLoop
xaxis
call·xtable
mov·ra,w
inc·rcounter
ret
xtable
mov·w,rcounter
jmp·pc+w
retw·%01111111
retw·%11011111
retw·%10111111
retw·%11101111

delay
··clr ·dloop1var
dloop1··djnz ·dloop1var,dloop1
ret

Comments

  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-09-26 15:36
    Following

    call xaxis

    you do a

    mov FSR, fsrcounter
    mov re, IND

    and then do a

    call delay

    where the delay subroutine modifies the dloop1 variable in bank $10 but you can't take for granted that bank $10 is selected because you have modified the FSR before. Therefore you should add an instruction like

    bank dloop1

    at the very beginning of the subroutine.

    I'm not sure if this fixes your problem but - at least - I noticed this when quickly scanning over your code. There are also other places in your code that might fail because of a modified FSR, like the code following the label "IdleLoop". Here, loop1var is referred without setting up FSR before (FSR contains $33 here).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • Armored CarsArmored Cars Posts: 172
    edited 2005-09-27 15:30
    I fixed the above program. I have expanded on it and moved all the variables into bank 2. (org $0A changed to org $25) Everything works, except for RA and RE. I have tried clearing FSR before writing to RA but that hasn't worked ethier.
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-09-27 18:09
    In your code, you use

    RSPO
    mov !ra,#0
    mov !re,#0

    to configure port A and E bits to all be outputs. By default the M register is set to $1F in order to have the mov !rx, w instructions modify the port direction bits but you can never be sure. Therefore, I suggest to insert

    mov w, #$1f
    mov m, w

    or

    mode $1f

    before these instructions. Maybe, this helps.

    To make sure if port bits are defined as outputs, you can also use the debugger. Set a breakpoint to some code line following the

    mov !ra,#0
    mov !re,#0

    instructions, run to this breakpoint, and then click on any of the port bits in the debugger's binary representation of the port registers. The bit should toggle when it has been defined as an output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • Armored CarsArmored Cars Posts: 172
    edited 2005-09-28 01:15
    Thats it!

    In the new program I write to !RA and !RE but then change M to set pull ups on a different port afterwords.· I've noticed how registors will carry over if not modified and that is probably what happened with M.

    BTW, I just found your book (I never really knew there was any other books for the SX) and will be ordering it soon.
Sign In or Register to comment.