I can't write to RA or RE
Armored Cars
Posts: 172
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
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
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
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
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.