Conditions

Anobium
2013-07-05
2013-08-18
  • Anobium

    Anobium - 2013-07-05

    A question on the correct usage of conditions. Can someone validate my results please? And, what is the correct usage and what are the limitations?

    Anobium

    A few tests. Variable bcdval is 127 and SEG_A is b'00000001'

    1) Works: As the conditional test returns 1.
    ~~~~~~~~~~~~

    if bcdval AND SEG_A then
    SET A1 ON
    end if

    2) Works. The conditional test ensures the values tested. 
    


    if (bcdval AND SEG_A) = SEG_A then
    SET A1 ON
    end if

    3) Fails.  However, I thought this should work (after many hours of testing I discovery this may not). 
    


    if !(bcdval AND SEG_A) then
    SET A1 ON
    end if

    ~~~~~~~~~~~~

    What is the correct convention?

    Anobium

     
    Last edit: Anobium 2013-07-05
  • Chuck Hellebuyck

    What is the 3rd line not doing?
    It looks like it should work based on the assembly code.

    By looking at the assembly code they look the same except for the Compliment of the AND result.
    In both cases, the BCDVAL and SEG_A are ANDed together and then the result tested. The only difference is the result is complimented in the second one.

    I'm assuming the banksel line is to reset the address pointer to the proper bank where the the BCDVAL is stored so I'm ignoring that affect.

    --------#1)----------

    ;if bcdval AND SEG_A then

    banksel BCDVAL        <--- This may be caused by previous code
    movf    BCDVAL,W      <--- load BCDVAL
    andwf   SEG_A,W       <--- AND with SEG_A
    movwf   SysTemp1      <--- Move Result into SysTemp1 variable
    btfsc   SysTemp1,0    <--- Test if Status.Z bit is set indicating zero
    

    ;SET PORTB.0 ON
    bsf PORTB,0
    ;end if

    --------#3)------------
    ;if !(bcdval AND SEG_A) then

    movf    BCDVAL,W      <--- load BCDVAL
    andwf   SEG_A,W       <--- AND with SEG_A
    movwf   SysTemp1      <--- Move Result into SysTemp1 variable
    comf    SysTemp1,W    <--- Compliments the result
    movwf   SysTemp2      <--- Move result to SysTemp2 variable
    btfsc   SysTemp2,0    <--- Test if Status.Z bit is set indicating zero
    

    ;SET PORTB.0 ON
    bsf PORTB,0
    ;end if

     
  • Anobium

    Anobium - 2013-07-08

    Sorry, posted to wrong forum!

    I am still not certain of the syntax. Results of tonights testing are shown below with the code and ASM below. So, bcdval = 2 and the SEGB results are not valid... correct? As the only condition that should be true is the first result.

    The only condition I can trust is TRUE: ( variable1 AND variable2 ) = variable1 or FALSE: ( variable1 AND variable2 ) <> variable1.

    Anobium

    Terminal results

    bcdval = 2
    SEG_A = 1
    SEG_B = 2

    FALSE: !(bcdval AND SEG_A)

    TRUE: (bcdval AND SEG_B) = SEG_B
    FALSE: !(bcdval AND SEG_B)

    Code
    bcdval = 2

                ANSIERASECREEN
                    ANSI 0 , 2
          HSerPrint "bcdval = "
          HSerPrint str(bcdval):crlf
          HSerPrint "SEG_A = "
          HSerPrint str(SEG_A):crlf
          HSerPrint "SEG_B = "
          HSerPrint str(SEG_B):crlf
    
          ANSI 0 , 8
    
          if bcdval AND SEG_A  then
                HSerPrint "TRUE: bcdval AND SEG_A": CRLF
            End if
    
          if (bcdval AND SEG_A) = SEG_A then
                HSerPrint "(TRUE: bcdval AND SEG_A) = SEG_A": CRLF
            End if
    
          if !(bcdval AND SEG_A)  then
                HSerPrint "FALSE: !(bcdval AND SEG_A)": CRLF
            End if
    
                    ANSI 0 , 10
          if bcdval AND SEG_B  then
                HSerPrint "TRUE: bcdval AND SEG_B": CRLF
            End if
    
          if (bcdval AND SEG_B) = SEG_B then
                HSerPrint "TRUE: (bcdval AND SEG_B) = SEG_B": CRLF
            End if
    
          if !(bcdval AND SEG_B) then
                HSerPrint "FALSE: !(bcdval AND SEG_B)": CRLF
            End if
    

    ASM

    ;if bcdval AND SEG_A then
    movlw 1
    andwf BCDVAL,W
    banksel SYSTEMP1
    movwf SysTemp1
    clrf SysTemp1_H
    btfss SysTemp1,0
    goto ENDIF12
    ; HSerPrint "TRUE: bcdval AND SEG_A": CRLF
    movlw low SYSSTRINGPARAM1
    movwf FSR1L
    movlw high SYSSTRINGPARAM1
    movwf FSR1H
    movlw low StringTable24
    movwf SysStringA
    movlw high StringTable24
    movwf SysStringA_H
    banksel STATUS
    pagesel SysReadString
    call SysReadString
    pagesel $
    movlw low SYSSTRINGPARAM1
    banksel SYSPRINTDATAHANDLER
    movwf SysPRINTDATAHandler
    movlw high SYSSTRINGPARAM1
    movwf SysPRINTDATAHandler_H
    banksel STATUS
    call HSERPRINT169
    movlw 1
    movwf NUM
    movlw 1
    movwf NPORT
    pagesel FN_CRLF
    call FN_CRLF
    pagesel $
    ; End if
    ENDIF12
    ;if (bcdval AND SEG_A) = SEG_A then
    movlw 1
    banksel BCDVAL
    andwf BCDVAL,W
    banksel SYSTEMP1
    movwf SysTemp1
    clrf SysTemp1_H
    movf SysTemp1,W
    movwf SysCalcTempA
    movf SysTemp1_H,W
    movwf SysCalcTempA_H
    movlw 1
    movwf SysCalcTempB
    clrf SysCalcTempB_H
    banksel STATUS
    pagesel SysCompEqual16
    call SysCompEqual16
    pagesel $
    btfss SysCalcTempX,0
    goto ENDIF13
    ; HSerPrint "(TRUE: bcdval AND SEG_A) = SEG_A": CRLF
    movlw low SYSSTRINGPARAM1
    movwf FSR1L
    movlw high SYSSTRINGPARAM1
    movwf FSR1H
    movlw low StringTable25
    movwf SysStringA
    movlw high StringTable25
    movwf SysStringA_H
    pagesel SysReadString
    call SysReadString
    pagesel $
    movlw low SYSSTRINGPARAM1
    banksel SYSPRINTDATAHANDLER
    movwf SysPRINTDATAHandler
    movlw high SYSSTRINGPARAM1
    movwf SysPRINTDATAHandler_H
    banksel STATUS
    call HSERPRINT169
    movlw 1
    movwf NUM
    movlw 1
    movwf NPORT
    pagesel FN_CRLF
    call FN_CRLF
    pagesel $
    ; End if
    ENDIF13
    ;if !(bcdval AND SEG_A) then
    movlw 1
    andwf BCDVAL,W
    banksel SYSTEMP1
    movwf SysTemp1
    clrf SysTemp1_H
    comf SysTemp1,W
    movwf SysTemp2
    comf SysTemp1_H,W
    movwf SysTemp2_H
    btfss SysTemp2,0
    goto ENDIF14
    ; HSerPrint "FALSE: !(bcdval AND SEG_A)": CRLF
    movlw low SYSSTRINGPARAM1
    movwf FSR1L
    movlw high SYSSTRINGPARAM1
    movwf FSR1H
    movlw low StringTable26
    movwf SysStringA
    movlw high StringTable26
    movwf SysStringA_H
    banksel STATUS
    pagesel SysReadString
    call SysReadString
    pagesel $
    movlw low SYSSTRINGPARAM1
    banksel SYSPRINTDATAHANDLER
    movwf SysPRINTDATAHandler
    movlw high SYSSTRINGPARAM1
    movwf SysPRINTDATAHandler_H
    banksel STATUS
    call HSERPRINT169
    movlw 1
    movwf NUM
    movlw 1
    movwf NPORT
    pagesel FN_CRLF
    call FN_CRLF
    pagesel $
    ; End if
    ENDIF14
    ;ANSI 0 , 10
    banksel XPOS
    clrf XPOS
    movlw 10
    movwf YPOS
    banksel STATUS
    pagesel ANSI
    call ANSI
    pagesel $
    ;if bcdval AND SEG_B then
    movlw 2
    andwf BCDVAL,W
    banksel SYSTEMP1
    movwf SysTemp1
    clrf SysTemp1_H
    btfss SysTemp1,0
    goto ENDIF15
    ; HSerPrint "TRUE: bcdval AND SEG_B": CRLF
    movlw low SYSSTRINGPARAM1
    movwf FSR1L
    movlw high SYSSTRINGPARAM1
    movwf FSR1H
    movlw low StringTable27
    movwf SysStringA
    movlw high StringTable27
    movwf SysStringA_H
    banksel STATUS
    pagesel SysReadString
    call SysReadString
    pagesel $
    movlw low SYSSTRINGPARAM1
    banksel SYSPRINTDATAHANDLER
    movwf SysPRINTDATAHandler
    movlw high SYSSTRINGPARAM1
    movwf SysPRINTDATAHandler_H
    banksel STATUS
    call HSERPRINT169
    movlw 1
    movwf NUM
    movlw 1
    movwf NPORT
    pagesel FN_CRLF
    call FN_CRLF
    pagesel $
    ; End if
    ENDIF15
    ;if (bcdval AND SEG_B) = SEG_B then
    movlw 2
    banksel BCDVAL
    andwf BCDVAL,W
    banksel SYSTEMP1
    movwf SysTemp1
    clrf SysTemp1_H
    movf SysTemp1,W
    movwf SysCalcTempA
    movf SysTemp1_H,W
    movwf SysCalcTempA_H
    movlw 2
    movwf SysCalcTempB
    clrf SysCalcTempB_H
    banksel STATUS
    pagesel SysCompEqual16
    call SysCompEqual16
    pagesel $
    btfss SysCalcTempX,0
    goto ENDIF16
    ; HSerPrint "TRUE: (bcdval AND SEG_B) = SEG_B": CRLF
    movlw low SYSSTRINGPARAM1
    movwf FSR1L
    movlw high SYSSTRINGPARAM1
    movwf FSR1H
    movlw low StringTable28
    movwf SysStringA
    movlw high StringTable28
    movwf SysStringA_H
    pagesel SysReadString
    call SysReadString
    pagesel $
    movlw low SYSSTRINGPARAM1
    banksel SYSPRINTDATAHANDLER
    movwf SysPRINTDATAHandler
    movlw high SYSSTRINGPARAM1
    movwf SysPRINTDATAHandler_H
    banksel STATUS
    call HSERPRINT169
    movlw 1
    movwf NUM
    movlw 1
    movwf NPORT
    pagesel FN_CRLF
    call FN_CRLF
    pagesel $
    ; End if
    ENDIF16
    ;if !(bcdval AND SEG_B) then
    movlw 2
    andwf BCDVAL,W
    banksel SYSTEMP1
    movwf SysTemp1
    clrf SysTemp1_H
    comf SysTemp1,W
    movwf SysTemp2
    comf SysTemp1_H,W
    movwf SysTemp2_H
    btfss SysTemp2,0
    goto ENDIF17
    ; HSerPrint "FALSE: !(bcdval AND SEG_B)": CRLF
    movlw low SYSSTRINGPARAM1
    movwf FSR1L
    movlw high SYSSTRINGPARAM1
    movwf FSR1H
    movlw low StringTable29
    movwf SysStringA
    movlw high StringTable29
    movwf SysStringA_H
    banksel STATUS
    pagesel SysReadString
    call SysReadString
    pagesel $
    movlw low SYSSTRINGPARAM1
    banksel SYSPRINTDATAHANDLER
    movwf SysPRINTDATAHandler
    movlw high SYSSTRINGPARAM1
    movwf SysPRINTDATAHandler_H
    banksel STATUS
    call HSERPRINT169
    movlw 1
    movwf NUM
    movlw 1
    movwf NPORT
    pagesel FN_CRLF
    call FN_CRLF
    pagesel $
    ; End if
    ENDIF17
    ;do while
    SysDoLoop_S4
    ;loop
    goto SysDoLoop_S4

     
  • Anobium

    Anobium - 2013-08-18

    Resolved:

    I changed the code extensively to resolve the issue. I have changed the code to use 3 bytes for each of the LCD characters and I update the three bytes which reflect the state required for each specific number. It is much faster and saves a lot of code space.

     

Log in to post a comment.