Modulus Question


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382

    Default Modulus Question

    In a basic stamp the following will increment to 60 then roll over:

    mins = mins + 1 // 60 ' inc with rollover

    The same command just keeps incrementing beyond 60 in picbasic. This is what I end up doing:

    Minutes=Minutes+1
    IF Minutes>60 Then Minutes=0

    Although the above works, I'm squished for space. Thoughts?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Try this; mins = (mins + 1) // 60 to force the add before the divide.

    If you're really "squished" for space, this will do the same thing, and save
    you around 10 words or so code space.

    Code:
    asm
      incf _Mins,f
      movf _Mins,w
      sublw D'60'
      btfss STATUS,2
      goto _NotOver
      clrf _Mins    
    endasm
    NotOver:
    Just be sure to keep Mins in bank0.
    Last edited by Bruce; - 2nd March 2006 at 01:28.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Bruce as usual a big thanks to you for the suggestion. However that seems to take up more code space than the method I'm using.

    I'm doing my best to stay away from ASM.

    I'm at 3762 or 4K I haven't run out of space yet but I'm getting close.

    Every little bit counts.
    Last edited by DynamoBen; - 2nd March 2006 at 01:58.

Similar Threads

  1. Crystals & Caps - Super noob question??
    By kevj in forum General
    Replies: 4
    Last Post: - 24th September 2007, 17:11
  2. Remote PIC input question
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2007, 15:44
  3. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49

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