Menu

set instruction

Help
Orlando D.
2017-01-28
2017-01-29
  • Orlando D.

    Orlando D. - 2017-01-28

    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

     
  • Anobium

    Anobium - 2017-01-28

    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 )

     
  • William Roth

    William Roth - 2017-01-28

    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.

    Do
         For index = 0 to 2
             if portb.7 Then
                  set temp.index on
             else
                 set temp.index off
             end if
         Next
         Wait 1 s
    Loop
    

    This is the "Contributors" Forum. In the future if you need help please post help questions to the "Help" forum.

     
  • William Roth

    William Roth - 2017-01-28

    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

     
  • Anobium

    Anobium - 2017-01-28

    Good point Bill. Sample code that works.

    '
    #chip 16f877a
    #option Explicit
    
    
    
    dim index, temp as byte
    dir portb.7 in
    
    Do
         For index = 0 to 2
              temp = temp OR FnLSL( portb.7, index )  'set a specific bit using FnLSL
              epwrite index, temp                     ' write to eeprœm to review results
         Next
         Wait 1 s
    Loop
    
     

    Last edit: Anobium 2017-01-28
  • Orlando D.

    Orlando D. - 2017-01-29

    This code work well :-)
    Thank you all for prompt support

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.