limiting to "no less than" zero


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Don't believe anything just because somebody said so.
    Especially when there's conflicting information.

    Check the datasheet, and test it for yourself. Then you will know the truth.

    This program will help with the testing part.

    Code:
    Volume   VAR BYTE
    Vstep    VAR BYTE
    Result   VAR BYTE
    Carry    VAR BIT
    HIGH PORTD.0     ; initialize serial line
    PAUSE 100
    FOR Volume = 5 TO 0 STEP -1
        FOR Vstep = 5 TO 0 STEP - 1
            Result = Volume - Vstep
            Carry = STATUS.0
            SEROUT2 PORTD.0,84,[DEC Volume," - ",DEC Vstep," = ",DEC Result,"   C = ",DEC Carry,13,10]
        NEXT Vstep
    NEXT Volume
    STOP
    DT

  2. #2
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Code:
    IF !STATUS.0 THEN Volume = 0
    Darrels way works with a 16F887.
    Can't vouch for any other chips...

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Darrel, what is the value of STATUS.0 at start up? I assume it should be zero (no borrow no carry) , are you going to set it at start up, in order to have your snippet @ post #12 working?
    Cheers

    Al.
    Last edited by aratti; - 18th September 2011 at 01:50.
    All progress began with an idea

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Not that Darrell needs it, but I feel compelled to jump in here and row his boat. To my knowledge, borrow/carry flag in the status reg is the same across ALL PIC's. It is not a compilier thing. It is a basic hardware reg no different then any other. It exists the same as W. That said, I believe it is cleared at POR, but it doesn't matter. it only has value directly after an addition or subtraction. Well it is also used on rotate R/L through carry, but PBP doesn't support that. Some devices even have 1 for borrow or carry between nibbles, but again only used during math.

    So startup value makes no difference for the snippet in post 12 as it follows a math operation.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Here is my test code and the debug results below...

    Code:
     DEFINE DEBUG_REGG PORTA        'set debug port to porta
     DEFINE DEBUG_BIT 0             'use pin a0 of porta for debug
     DEFINE DEBUG_BAUD 2400         'set baud rate to 2400
     DEFINE DEBUG_MODE 0            'communicate in true mode
    valA var byte
    valB var byte
    resultA var byte
    resultB var byte
    resultC var byte
    resultD var byte
       Carry var bit
       vala=51
       valb=50
    
    resulta=vala-valb
    Carry = STATUS.0
    debug "resultA : 51-50=",dec resulta," Carry=",dec carry,13,10
    
    resultb=valb-vala
    Carry = STATUS.0
    debug "resultB : 50-51=",dec resultb," Carry=",dec carry,13,10
    
    resultC=vala+valb
    Carry = STATUS.0
    debug "resultC : 51+50=",dec resultc," Carry=",dec carry,13,10
    
    vala=55
    valb=201
    
    resultD=vala+valb
    Carry = STATUS.0
    debug "resultD : 55+201=",dec resultd," Carry=",dec carry,13,10
    end
    and the Debug results...


    resultA : 51-50=1 Carry=1
    resultB : 50-51=255 Carry=0
    resultC : 51+50=101 Carry=0
    resultD : 55+201=0 Carry=1
    Last edited by Heckler; - 18th September 2011 at 03:26.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  6. #6
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    DANG EDIT TIMER...

    Therefore
    If you subtract two BYTE variables and the result is NEGATIVE, the Carry Bit will be Cleared (0)
    If you add two Byte variables and the result is >255 then the Carry Bit will be SET (1)

    HEY!! I think that's what Darrel said earlier.
    Last edited by Heckler; - 18th September 2011 at 03:51.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Sweet!
    And you made your own test program ... Perfect!

    I'm sure it all seems much clearer now.


  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,838


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Oops, sorry. I should have said borrow...

    Darrel was too polite! Thanks.

    @ Steve: I meant which audio chip are you controlling with the PIC©

    Ioannis
    Last edited by Ioannis; - 18th September 2011 at 11:23.

  9. #9
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Quote Originally Posted by Ioannis View Post
    @ Steve: I meant which audio chip are you controlling with the PIC©
    Audio chip? LM380

    Ah, you asked because I used "volume" as a variable in my question...

    Actually it's not an audio project. It's for FrankenGriddle.

    [img]http://www.weirdstuffwemake.com/blac...iddle_1450.jpg[/img]

    If anyone is really curious I guess I could start a thread about "The FrankenGriddle Project" in the OT forum.

    Hmmmm... is there a forum specifically for showcasing "Projects" that use PICs?



    Steve
    Attached Images Attached Images  

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    The Wiki could be a nice place. You can even start your personnal group in your own profile... not sure how it works though.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts