I have a problem with SET instruction i use it for serial input of bit on port b.7 and i want to use it
with a variable index in for cicle "set TEMP.index on/off" but it don't work.
--- this sample work ---
if portb.7 Then
set temp.0 on
else
set temp.0 off
end if
wait routine
if portb.7 Then
set temp.1 on
else
set temp.1 off
end if
wait routine
if portb.7 Then
set temp.2 on
else
set temp.2 off
end if
--- this same littlest sample whit for cicle don't work ---
For index = 0 to 2
do
if portb.7 Then
set temp.index on
else
set temp.index off
end if
wait routine
loop
Where i'm wrong ?
Thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your code structure is incorrect. There is a FOR with no NEXT. Even if you added a Next you will have have a DO LOOP nested inside the FOR that will never exit. Try this instead.
Even with the code strucure corrected, the code above will not work as GCB does not support or allow substituting var_name.bit with var_name.variable. With PORT.x or VARIABLE.x the valu for X MUST be a constant and cannot be a variable such as "index"
I know of no workaround for this limitation as it certainly would be nice to be able to use a variable
@Evan, I you know of a way to get setwith to work with the OP code can you provide an example ? I see no way to use variable "index" as the bit marker for variable "temp"
William
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'#chip 16f877a#option Explicitdim index, temp as bytedir portb.7 inDo For index = 0 to 2temp=tempORFnLSL(portb.7,index)'set a specific bit using FnLSLepwriteindex,temp' write to eeprœm to review results Next Wait 1 sLoop
Last edit: Anobium 2017-01-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a problem with SET instruction i use it for serial input of bit on port b.7 and i want to use it
with a variable index in for cicle "set TEMP.index on/off" but it don't work.
--- this sample work ---
if portb.7 Then
set temp.0 on
else
set temp.0 off
end if
wait routine
if portb.7 Then
set temp.1 on
else
set temp.1 off
end if
wait routine
if portb.7 Then
set temp.2 on
else
set temp.2 off
end if
--- this same littlest sample whit for cicle don't work ---
For index = 0 to 2
do
if portb.7 Then
set temp.index on
else
set temp.index off
end if
wait routine
loop
Where i'm wrong ?
Thanks in advance
See https://sourceforge.net/p/gcbasic/discussion/579126/thread/b1d3c9ee/ first.
So, I am assuming you have the latest build. The HELP is clear on setting bits of a variable.
Please use SetWith. SetWith ( temp.index, off )
Hi Orlando,
Welcome to Great Cow Basic.
Your code structure is incorrect. There is a FOR with no NEXT. Even if you added a Next you will have have a DO LOOP nested inside the FOR that will never exit. Try this instead.
This is the "Contributors" Forum. In the future if you need help please post help questions to the "Help" forum.
Even with the code strucure corrected, the code above will not work as GCB does not support or allow substituting var_name.bit with var_name.variable. With PORT.x or VARIABLE.x the valu for X MUST be a constant and cannot be a variable such as "index"
I know of no workaround for this limitation as it certainly would be nice to be able to use a variable
@Evan, I you know of a way to get setwith to work with the OP code can you provide an example ? I see no way to use variable "index" as the bit marker for variable "temp"
William
Good point Bill. Sample code that works.
Last edit: Anobium 2017-01-28
This code work well :-)
Thank you all for prompt support