Menu

Read/write BIT

jackjames
2018-05-29
2018-05-29
  • jackjames

    jackjames - 2018-05-29

    Hello,
    I find myself with a strange problem:
    I would like to use the bits of a variable to set flags.
    I can not write the bit on the variable using another variable as a pointer:
    Example:
    dim Pippo as byte
    dim NBit as byte

    NBit = 4
    Pippo.NBit = 1

    When I go to read the Pippo variable, it has not changed.
    The revision of compiler is the last.

    I enclose an example I wrote for proof:

        Dim Pippo1 As Byte
        Pippo1 = 0
        Cls
        Do ForEver
           For Tmp = 0 to 7
              Pippo1.Tmp = 1
              Locate 0,1
              Print "   "
              Locate 0,1
              Print Pippo1
              Locate 0,12
              Print Tmp
              Dsp_TimersAb2 (Pippo1)
              Wait 3 s
           Next Tmp
           Pippo1 = 0
        Loop
    

    Sub Dsp_TimersAb2 (In Dato As Byte)
    Dim nTmrA2 As Byte
    Locate 1,0
    For nTmrA2 = 0 to NUMTIMERS -1
    If Dato.nTmrA2 Then
    Print nTmrA2 +1
    Else
    Print "-"
    End If
    Next nTmrA2
    End Sub

    If I call the routine sending it other variables it works perfectly.
    Seeing the assembled listing does not seem to be a problem.

    banksel PIPPO1
    clrf    PIPPO1
    

    ;Cls
    banksel STATUS
    pagesel CLS
    call CLS
    pagesel $
    ;Do ForEver
    SysDoLoop_S1
    ;For Tmp = 0 to 7
    movlw 255
    banksel TMP
    movwf TMP
    SysForLoop1
    incf TMP,F
    ;Pippo1.Tmp = 1
    bsf PIPPO1,TMP
    ;Locate 0,1
    banksel LCDLINE
    clrf LCDLINE
    movlw 1
    movwf LCDCOLUMN
    pagesel LOCATE
    call LOCATE
    pagesel $
    ;Print " "
    movlw low StringTable3
    banksel SYSPRINTDATAHANDLER
    movwf SysPRINTDATAHandler
    movlw (high StringTable3) | 128
    movwf SysPRINTDATAHandler_H
    banksel STATUS
    pagesel PRINT232
    call PRINT232
    pagesel $
    ;Locate 0,1
    clrf LCDLINE
    movlw 1
    movwf LCDCOLUMN
    pagesel LOCATE
    call LOCATE
    pagesel $
    ;Print Pippo1
    banksel PIPPO1
    movf PIPPO1,W
    banksel LCDVALUE
    movwf LCDVALUE
    pagesel PRINT233
    call PRINT233
    pagesel $
    ;Locate 0,12
    clrf LCDLINE
    movlw 12
    movwf LCDCOLUMN
    pagesel LOCATE
    call LOCATE
    pagesel $
    ;Print Tmp
    banksel TMP
    movf TMP,W
    banksel LCDVALUE
    movwf LCDVALUE
    pagesel PRINT233
    call PRINT233
    pagesel $
    ;Dsp_TimersAb2 (Pippo1)
    banksel PIPPO1
    movf PIPPO1,W
    banksel DATO
    movwf DATO
    pagesel DSP_TIMERSAB2
    call DSP_TIMERSAB2
    pagesel $
    ;Wait 3 s
    movlw 3
    movwf SysWaitTempS
    pagesel Delay_S
    call Delay_S
    pagesel $
    ;Next Tmp
    movlw 7
    banksel TMP
    subwf TMP,W
    btfss STATUS, C
    goto SysForLoop1
    ENDIF1
    SysForLoopEnd1
    ;Pippo1 = 0
    clrf PIPPO1
    ;Loop
    goto SysDoLoop_S1
    SysDoLoop_E1

     
  • stan cartwright

    stan cartwright - 2018-05-29

    For Tmp = 0 to 7
    Pippo1.Tmp = 1

    see set-
    Set
    Syntax:
    Set variable.bit {On | Off}

    set Pippo.Tmp On

     
  • jackjames

    jackjames - 2018-05-29

    I Tested ... NOT WORKING

     
  • Anobium

    Anobium - 2018-05-29

    In the Help we used to say 'you cannot set a bit with a variable' but now see the Help.

    See Can I specify the bit of a variable to alter using another variable? on page https://sourceforge.net/p/gcbasic/discussion/596084/thread/52cb9ffc/?limit=50#0044

    Does the resolve the issue?

     
  • stan cartwright

    stan cartwright - 2018-05-29

    doh me for trying to help.
    BitsOut = FnLSL(BitsIn, NumBits)

      For Tmp = 0 to 7
          Pippo1.Tmp = 1
    

    For Tmp = 0 to 7
    Pippo1= FnLSL( 1,Tmp) or Pippo1

     

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.