Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Option Explicit
option com1speed 115200
Public const uiDelay as unsignedinteger =600
Sub Main()
Dim byMask as byte = &b00001111
Dim byRegister as byte
dim inPos as integer
dim byLoop as integer
dim byDDR as byte
byRegister = Register.Portb
'Set the pins to outputs
byDDR=Register.ddrb
Call SetBits(Register.DDRB,&b00001111,&b00001111)
'This works
for byLoop=1 to 2500
call StepperStep(Register.Portb,byMask,inPos,true)
debug.print inPos
next
'this doesn't work
for byLoop=1 to 2500
call StepperStep(byRegister,byMask,inPos,true)
debug.print inPos
next
End Sub
FFMan wrote:Does the value of register.portb change at runtime ?
It can. I can't tell what might be happening here because the routine StepperStep() isn't shown. Generally speaking, the value of Register.PORTx will be the value last written to Register.PORTx
You might alter your code to output the value of Register.PortB on each iteration of the loop to see if it is, in fact, changing.
Sub StepperStep(byRef byRegister as byte,byVal byMask as byte,byRef inStepperPos as integer,byVal blClockwise as boolean)
dim byCode(0 to 4) as byte
dim byLoop as byte
if blClockWise=true then
'byCode(0)=&b00000001
'byCode(1)=&b00000011
'byCode(2)=&b00000010
'byCode(3)=&b00000110
'byCode(4)=&b00000100
'byCode(5)=&b00001100
'byCode(6)=&b00001000
'byCode(7)=&b00001001
'byCode(8)=&b00000000
byCode(0)=&b00000001
byCode(1)=&b00000010
byCode(2)=&b00000100
byCode(3)=&b00001000
byCode(4)=&b00000000
inStepperPos=inStepperPos+1
else
'byCode(0)=&b00001000
'byCode(1)=&b00001100
'byCode(2)=&b00000100
'byCode(3)=&b00000110
'byCode(4)=&b00000010
'byCode(5)=&b00000011
'byCode(6)=&b00000001
'byCode(7)=&b00001001
'byCode(8)=&b00000000
byCode(0)=&b00001000
byCode(1)=&b00000100
byCode(2)=&b00000010
byCode(3)=&b00000001
byCode(4)=&b00000000
inStepperPos=inStepperPos-1
end if
for byLoop=0 to 4
Call SetBits(byRegister,byMask,byCode(byLoop))
Call DelayMicroSeconds(uiDelay)
next byLoop
End Sub