16LF1824 strange problem


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: 16LF1824 strange problem

    @ Amoque - Also, I tried with () but no effect

    @ Alain - 1000X thx for your example. I'm a begginer and I see in my eyes more fog ....but was a inspiration for me and I solved . I think that is a unusually code, but work !

    Code :

    init:
    pulsin portc.2 , 1, varb
    for i = 1 to 50
    pulsin portc.2 , 1, varb
    varb = varb +1
    next i
    if varb > 60 then
    goto init2
    else
    goto init
    endif
    goto init

    init2:
    pulsin portc.2 , 1, varb
    if varb > 160 or varb <140 then goto init
    if varb > 140 and varb < 160 then goto beep
    goto init2

    beep:
    ...code...
    goto beep

    Thx to all for help!

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16LF1824 strange problem

    Quote Originally Posted by midali View Post
    @ Amoque - Also, I tried with () but no effect
    In your code () will have no effect because the simple comparisons work as expected. But using () makes the code easier to read and it is good practice to always use them.

    @ Alain - 1000X thx for your example.
    Alain's code is almost the same as yours

    Code:
    varb var byte
     varb = 0
     pause 200
    
     init:
     pulsin portc.2 , 1, varb
     if varb < 140 or varb > 160 then init
     if varb > 140 and varb < 160 then goto beep
     goto init
    Except he added a pause 100 and a retry just to make sure
    Code:
    varb var byte
     varb = 0
     pause 200
    
     init:
     pulsin portc.2 , 1, varb
     if (varb < 140) or (varb > 160) then init
     pause 100
     pulsin portc.2 , 1, varb
     if (varb < 140) or (varb > 160) then init
     if (varb > 140) and (varb < 160) then goto beep
     goto init
    Your code that works is adding delays in a complicated way and also has a retry.

    Code:
    init:
    pulsin portc.2 , 1, varb
    for i = 1 to 50
        pulsin portc.2 , 1, varb
        varb = varb +1
    next i
    if varb  > 60 then
        goto init2
     else                                                                        
        goto init
    endif
    goto init
    
    init2:
    pulsin portc.2 , 1, varb
    if varb > 160 or varb <140 then goto init
    if varb > 140 and varb < 160 then goto beep
    goto init2
    
    beep:
    ...code...
    goto beep
    It looks to me that on starting the RC a "false signal" is received that satisfies the "if varb > 140 and varb < 160 then goto beep" condition and by adding the delay and retry these "false signals" are trapped. Can you try your modified code above, the one with the added pause 100 and retry in red?

Similar Threads

  1. A strange problem
    By mombasa in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 25th January 2012, 21:08
  2. Very strange problem...
    By alanmcf in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th May 2011, 06:28
  3. strange serout2 problem
    By KaanInal in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th January 2010, 09:33
  4. Strange problem with PBP 2.50
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th October 2007, 20:45
  5. strange problem 12f675
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th July 2007, 13:47

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