I'm playing around with some coding, I had problems with:
dim code(5) as byte
IF code(1).0=1 then ....... 'does this method work?
dim code(64) as bit 'This also doesn't work and is it correct?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why? The arrayaddress is a variable, not a constant as in the first example.
So, what are you trying to achieve? Setting a bit in a array is generates a lot of ASM. Copying the element, caching the value, setting the bit value, setting the array element.
There are ways, faster ways. Setwith(), Rotate etc.
Arrays of BITS is not supported.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I thought so... setting bits is easy. We do it all the time in the GLCD libraries where speed is really important ( and, we do not use direct assignment of array element.. it is too slow ).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is the 40bit (5byte) serial transmission I should get:
define Serial GPIO.0 ' TX serial
dir serial out
dim Temp as byte
dim Temp1,Tsel as Byte
dim Ser_byte(5) as byte
dim tempw as word
ser_byte= 170,0,255
do
tx_data
wait 2 s
loop
sub tx_data
tempw=0 'checksum
for temp=1 to 3
tempw +=Ser_byte(temp)
next
Ser_byte(4)=tempw:Ser_byte(5)= tempw_H
for temp=1 to 5
for temp1=0 to 7
if Ser_byte(temp).temp1=1 then
serial= ! serial:wait 2 mS
else
serial= ! serial:wait 1 mS
end if
next
next
serial= ! serial:wait 5 mS 'BIT di STOP TX
serial=1 ' spegne TX
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The error seems to be:
if Ser_byte(temp).temp1=1 then
it works well like this:
for temp=1 to 5
tsel= Ser_byte(temp)
for temp1=0 to 7
if tsel.temp1=1 then
serial= ! serial:wait 2 mS
else
serial= ! serial:wait 1 mS
end if
next
next
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
but this seems better to me, I haven't tried it yet but it should work.
for temp=1 to 5
repeat 8
if Ser_byte(temp).0=1 then
serial= ! serial:wait 2 mS
else
serial= ! serial:wait 1 mS
end if
Rotate Ser_byte(temp) right
end repeat
next
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
for temp=1 to 5
outbits = Ser_byte(temp)
repeat 8
if outbits.0 = 1 then
serial= ! serial:wait 2 mS
else
serial= ! serial:wait 1 mS
end if
set C off
rotate outbits right
end repeat
next
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
for temp=1 to 5
repeat 8
if Ser_byte(temp).0=1 then
serial= ! serial:wait 2 mS
else
serial= ! serial:wait 1 mS
end if
set C off
Rotate Ser_byte(temp) right
end repeat
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm playing around with some coding, I had problems with:
dim code(5) as byte
IF code(1).0=1 then ....... 'does this method work?
dim code(64) as bit 'This also doesn't work and is it correct?
Thanks
You have to be very specific about the question.
The code below will work, however, the compiler will optimise this to make a simple variable.bat assignment. Try is as look at the ASM
The code below will work, however, the compiler will optimise this to make a simple variable.bat assignment. Try is as look at the ASM
The following produces very different ASM
Why? The
arrayaddress
is a variable, not a constant as in the first example.So, what are you trying to achieve? Setting a bit in a array is generates a lot of ASM. Copying the element, caching the value, setting the bit value, setting the array element.
There are ways, faster ways. Setwith(), Rotate etc.
Arrays of BITS is not supported.
No, I summarized too much and a different problem. As soon as I can I'll post an example to help you understand better.
:-)
I thought so... setting bits is easy. We do it all the time in the GLCD libraries where speed is really important ( and, we do not use direct assignment of array element.. it is too slow ).
This is the 40bit (5byte) serial transmission I should get:
define Serial GPIO.0 ' TX serial
dir serial out
dim Temp as byte
dim Temp1,Tsel as Byte
dim Ser_byte(5) as byte
dim tempw as word
ser_byte= 170,0,255
do
tx_data
wait 2 s
loop
sub tx_data
end sub
The error seems to be:
if Ser_byte(temp).temp1=1 then
it works well like this:
for temp=1 to 5
tsel= Ser_byte(temp)
for temp1=0 to 7
if tsel.temp1=1 then
serial= ! serial:wait 2 mS
else
serial= ! serial:wait 1 mS
end if
next
next
but this seems better to me, I haven't tried it yet but it should work.
I prefer the rotate code.
Remove to
SET C OFF
to ensure you do not carry C.The following will be faster.
OK, everything works perfectly
Excellent. Please share you final solution. Be good to see.
Scusa il ritardo, I did as you advised
for temp=1 to 5
repeat 8
if Ser_byte(temp).0=1 then
serial= ! serial:wait 2 mS
else
serial= ! serial:wait 1 mS
end if
set C off
Rotate Ser_byte(temp) right
end repeat