Menu

portb.0=val always turns off first

2013-05-06
2013-05-30
  • Jim giordano

    Jim giordano - 2013-05-06

    the following code

    ptst=1
    portb.0=ptst
    

    compiles to

    ;ptst=1
        movlw   1
        banksel PTST
        movwf   PTST
    ;portb.0=ptst
        bcf PORTB,0
        movf    PTST,F
        btfss   STATUS,Z
        bsf PORTB,0
    

    I'm not that great on pic assembly language yet, so I could be reading this wrong, but
    it seems it always turns portb.0 to zero first, then sets it to ptst.  bcf sets it to zero, right?
    This seems to be causing my problems.
    If it was already = 1, and ptst is = 1,  I don't want it turned to zero and then back to one.
    For a normal variable, this behavior would be irrelevant, and indeed, probably more efficient.
    But for a physical port output, it matters.  Is there some way to override this behavior?

     
  • Chuck Hellebuyck

    I agree, that is a glitch.
    The end result is correct but you can get a quick low pulse on the port pin.
    I've seen this before on other compilers and it caused issues.       

     
  • Chuck Hellebuyck

    It's best to declare a variable as a bit if you plan to use it that way (i.e. Dim PTST as bit).
    Otherwise any bit set within the 8 bits of PTST can make the PORTB,0 get set to a 1.

    When I declared PTST as a bit the code still had the issue though a little different code.
    ;portb.0 = ptst
      bcf PORTB,0
      btfsc SYSBITVAR0,0
      bsf PORTB,0

    This would work fine if one more line was added
    ;portb.0 = ptst
      btfss SYSBITVAR0,0  ;Add this line
      bcf PORTB,0
      btfsc SYSBITVAR0,0
      bsf PORTB,0

    So applying that same logic to the original code:
    ;portb.0=ptst
    movf  PTST,F        ;move this up
            btfss  STATUS,Z   ;move this up
            bcf PORTB,0
    btfsc STATUS,Z    ;add this
    bsf PORTB,0

    I believe this will fix it.
    Again I don't know where that is to fix but I'm sure Hugh will consider this for the next release.

     

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.