Critique my code, please.


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: Critique my code, please.

    This seems redundant to me
    Code:
        if PIP = 0 then increment
        if PIP = 1 then display
    increment:
    It could be
    Code:
        if PIP = 1 then display
    increment:
    Another possible improvement would be to consider using an interrupt to capture the change in state of PIP. Without that, you could miss / misread the timing since the code could be updating the display and doing a pause thereby losing time before you poll the PIP pin.

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


    Did you find this post helpful? Yes | No

    Default Re: Critique my code, please.

    Hi,
    Just a quick note
    Code:
    CNT = CNT + 1
    IF CNT > 65535 then ' This adds a overload catch so it doesnt run away.
    CNT = 0
    goto no_data2
    ENDIF
    The above doesn't really work because CNT is declared as a WORD and can not contain values larger than 65535. The IF statement will never evaluate true so the program will never jump to no_data2. Once CNT is incremented "beyond" 65535 it will automatically wrap around to 0.

    /Henrik.

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Critique my code, please.

    Correct way to do that is:
    Code:
    CNT = CNT + 1
    IF CNT =0 then ' This adds a overload catch so it doesnt run away.
        CNT = 0
        goto no_data2
    ENDIF

Similar Threads

  1. Working code but my layman approach uses too much code space
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2012, 20:44
  2. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 19:51

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