Counter


Closed Thread
Results 1 to 7 of 7

Thread: Counter

  1. #1
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187

    Default Counter

    Anyone have a simple example of how I can do something like this but with larger numbers then 65535?

    Counter VAR WORD

    Loop:

    Counter = Counter + 1
    lcdout $FE, line1,"Counter:", #Counter
    PAUSE 100

    Goto Loop

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Counter

    Well, the obvious, if using an 18F part
    Code:
    Counter VAR LONG
    Main:   ' Don't use Loop as a label, it's a reserved word.
    
    Counter = Counter + 1
    lcdout $FE, line1,"Counter:", DEC Counter    ' I think there's a problem with using # with LONG
    PAUSE 100
    
    Goto Main
    If you don't have an 18F part and all you want is a simple counter then perhaps something like this might work (not tested), it should count to 655 milions and a bit beyond:
    Code:
    TenThousands VAR WORD
    Ones VAR WORD
    
    Ones = Ones + 1
    If Ones = 10000 THEN
      Ones = 0
      TenThousands = TenThousands + 1
    ENDIF
    
    LCDOUT $FE, line1, Counter: "
    IF TenThousands > 0 THEN
      LDCOUT DEC TenThousands, DEC4 Ones
    ELSE
      LCDOUT DEC Ones
    ENDIF
    /Henrik.

  3. #3
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187


    Did you find this post helpful? Yes | No

    Default Re: Counter

    The code works perfect on a 16F886, thank you Henrik!

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Counter

    I'll bet that even if you own PBP3 and a 18F series chip, the code Henrik posted, will be using less memory and will be much faster than using Long variables.

    Ioannis

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Counter

    Thanks for the feedback Fredrick!
    Just a note, you don't need PBP3 to use LONGs, support for that were added in v2.5.
    You do need an 18F part though. But, as Ioannis said, for a simple counter like that it's probably not worth the "cost" having them enabled.

    /Henrik.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Counter

    Right, my error. Its been too long, right?

    Ioannis

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Counter

    It does work for display, I did 15 digit numbers with a 16F628 the same way it was done on paper in school
    with allowance for 16 digit result for a character LCD
    Just a shame if you wanted the result in a variable, but you could probably write a good & proper calculator.
    Code:
    123456789012345 *
    012345678901234
    _______________
    
    _______________

Similar Threads

  1. counter
    By daydream in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd May 2012, 04:52
  2. Counter
    By brenda in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2008, 08:57
  3. counter
    By jankraak in forum General
    Replies: 1
    Last Post: - 11th October 2008, 15:37
  4. Counter
    By ALI_ALVANDPOUR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th October 2007, 19:49
  5. Replies: 1
    Last Post: - 27th September 2007, 19:15

Members who have read this thread : 1

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