Problem using Else


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    IT WORKS!!!!!!!!!!!!!

    Thank you very much

  2. #2


    Did you find this post helpful? Yes | No

    Default

    can I put a pause in for debounce?
    IF i=%00000001 THEN
    HIGH 1
    pause 50
    ELSE
    LOW 1
    ENDIF

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tazntex View Post
    can I put a pause in for debounce?
    IF i=%00000001 THEN
    HIGH 1
    pause 50
    ELSE
    LOW 1
    ENDIF
    debounce?

    Code:
    IF i=%00000001 THEN
    
     WHILE i=%00000001
      PAUSE 50 
     WEND
    
     HIGH 1
    
    ELSE
    
     LOW 1
    
    ENDIF
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4


    Did you find this post helpful? Yes | No

    Default

    I have tried the:
    IF i=%00000001 THEN

    WHILE i=%00000001
    PAUSE 50
    WEND

    HIGH 1

    ELSE

    LOW 1

    ENDIF

    using this on four outputs my program does nothing with these four. If I take out the while statement and use the :
    If i=%00000001 THEN
    HIGH 1
    ELSE
    LOW 1
    ENDIF
    then my outputs for these four comes on and stays on, forever.
    I been experimenting with SELECT CASE and what I am trying to accomplish is if I am pressing the button on the transmitter, the output selected comes on and stays on until I release the button instead of cycling on/off. So here is my latest rx version which does nothing, what am I doing wrong?

    INCLUDE "bs2defs.bas"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, MCLR_ON
    @ DEVICE pic16F628a, BOD_ON
    @ DEVICE pic16F628a, LVP_OFF
    @ DEVICE pic16F628a, CPD_OFF
    @ DEVICE pic16F628a, PROTECT_OFF
    DEFINE OSC 4
    mydata1 VAR byte
    mydata2 var byte
    address1 var byte
    address2 var byte
    checksum var byte
    chk_sum var byte
    serpin VAR porta.1
    PORTA = 0
    PORTB = 0
    trisa = %00000010
    trisb = %10000000
    CMCON=%00000111
    PAUSE 50

    loop:
    gosub loop1
    CheckSum = (address1 + address2)
    CheckSum = CheckSum + (mydata1 + mydata2)
    IF checksum != chk_sum THEN loop
    IF (mydata1) != (mydata2) THEN loop
    IF (address1) != (address2) THEN loop

    select case mydata1
    case 0
    mydata1=%01010110
    toggle 0
    pause 50

    case 1
    mydata1=%01011001
    high 1
    pause 50
    case else
    low 1

    case 2
    mydata1=%01011010
    high 2
    pause 50
    case else
    low 2

    case 3
    mydata1=%01100101
    high 3
    pause 50
    case else
    low 3

    case 4
    mydata1=%01100110
    high 4
    pause 50
    case else
    low 4

    case 5
    mydata1=%01101001
    toggle 5
    pause 50

    case 6
    mydata1=%01101010
    toggle 6
    pause 50
    end select
    goto loop

    loop1:
    SERIN serpin,N9600,[254],address1,address2,mydata1,mydata2,chk_sum
    Return

    One more thing when I copy and paste my code to this forum everything becomes lower case. I have been reminded as a courtesy of DEFINE OSC 4 just wanted to let ya'll know
    why everything appears in the lower case. Many Thanks

  5. #5
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default

    FineLine Viewer was created to sort out the if - endif statements by drawing brackets between the if and endif's.

    See IDE FineLine Viewer.
    Scroll down to and download v1.3

    Be sure to have "Hide extensions for known file types"
    unchecked in Any folder>Tools>Folder options>View to see
    the ".TXT" to remove.


    Norm
    Attached Images Attached Images  

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Order of operations, I dunno maybe the compiler sorts this out, but . . . logic dictates, cmcon goes before anything portA, then tris registers dictate input or output, then port dictates hi or low status. Unless you are writing this for a basic stamp, why INCLUDE "bs2defs.bas" I would and always do use INCLUDE "MODEDEFS.BAS", as I haven't the foggiest as to what makes a stamp tick. Now having said this , someone will explain to me why I am all wrong
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Ok, I am seeing some light, hopefully it isn't attached to a train. Thanks for pointing out the CASE ELSE, never thought about that. I started with sample code from RENTRON's site and that why I had INCLUDE "bs2defs.bas" up there, and the CMCON=%00000111 never saw exactly where that should be placed in the manual. One thing is for certain I have learned a lot from this forum. And thanks for the FINE LINE link.

    I still have a problem with:
    'This will do nothing

    IF mydata1=%01011001 THEN
    WHILE mydata1=%01011001
    pause 50 ' pause for debounce
    WEND
    HIGH 1
    ELSE
    LOW !
    ENDIF

    or
    'This works, to turn on but will not turn off

    IF mydata1=%01011001 THEN
    HIGH 1
    ELSE
    LOW !
    ENDIF

    Thanks again
    Last edited by tazntex; - 6th August 2008 at 21:37.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    For one thing, you've got more than one CASE ELSE inside the SELECT CASE block.
    Check your manual...

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 20:52
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 09:12
  3. Microcode Studio 18f2455 problem?????
    By volkan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st May 2007, 22:04
  4. Hardware problem or what ?
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th March 2007, 22:39
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 23:59

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