Problem using Else


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Here is the entire code with the WHILE WEND example I was trying to use for a debounce.

    Please ignore what should be upper case because when I copy and paste it changes back to lower case.

    INCLUDE "MODEDEFS.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
    CMCON=%00000111
    PORTA = 0
    PORTB = 0
    trisa = %00000010
    trisb = %10000000
    mydata1 VAR byte
    mydata2 var byte
    address1 var byte
    address2 var byte
    checksum var byte
    chk_sum var byte
    serpin VAR porta.1
    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

    if mydata1=%01010110 then toggle 0
    pause 50

    if mydata1=%01011001 then
    while mydata1=%01011001 ' trying this example for debounce
    pause 50
    wend
    high 1
    else
    low 1
    endif

    if mydata1=%01011010 then
    while mydata1=%01011010
    pause 50
    wend
    high 2
    else
    low 2
    endif

    if mydata1=%01100101 then
    while mydata1=%01100101
    pause 50
    wend
    high 3
    else
    low 3
    endif

    if mydata1=%01100101 then
    while mydata1=%01100101
    pause 50
    wend
    high 4
    else
    low 4
    endif

    if mydata1=%01101001 then toggle 5

    if mydata1=%01101010 then toggle 6

    goto loop

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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I think you're confused on the correct method of debouncing.

    The object is to check for a switch hit, wait for the bouncing to stop, then check again and see if the same switch is still hit.
    The way you are doing it, you'll catch the bouncing and kick out of your check before you get a chance to check it after the bouncing is over...

    Try this:

    Code:
    INCLUDE "MODEDEFS.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 
    CMCON=%00000111 : PORTA = 0 : PORTB = 0 : trisa = %00000010
    trisb = %10000000 : mydata1 VAR byte : mydata2 var byte : address1 var byte
     address2 var byte : checksum var byte : chk_sum var byte : serpin VAR porta.1
    PAUSE 50 
    loop:     gosub loop1 : CheckSum = (address1 + address2) + (mydata1 + mydata2)
    IF checksum != chk_sum THEN loop
    IF (mydata1) != (mydata2) THEN loop
    IF (address1) != (address2) THEN loop
    if mydata1=%01010110 then toggle 0
    pause 50
    lp1:
    if mydata1=%01011001 then
    pause 50
    if mydata1=%01011001
    high 1 
    else
    low 1
    endif 
    if mydata1=%01011010 then
    pause 50
    if  mydata1=%01011010
    high 2
    else
    low 2
    endif
    if mydata1=%01100101 then
    pause 50
    if mydata1=%01100101
    high 3
    else
    low 3
    endif
    if mydata1=%01100101 then
    pause 50
    if mydata1=%01100101
    high 4
    else
    low 4
    endif
    if mydata1=%01101001 then toggle 5
    if mydata1=%01101010 then toggle 6
    goto loop
    loop1:
    SERIN serpin,N9600,[254],address1,address2,mydata1,mydata2,chk_sum
    Return

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tazntex View Post
    Here is the entire code with the WHILE WEND example I was trying to use for a debounce.

    Please ignore what should be upper case because when I copy and paste it changes back to lower case.
    That is because you typed it in lower case and MCS changes it for it's use, when you copy it to the clipboard it reveals the truth.
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Please let us see the code you are sending to this program. Are yoy sending from a PC or a PIC?
    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.

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19: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, 08:12
  3. Microcode Studio 18f2455 problem?????
    By volkan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st May 2007, 21:04
  4. Hardware problem or what ?
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th March 2007, 21: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, 22: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