Problem using Else


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Still trying

    After many tries I am about to take a hammer to my processor and just put it out of its misery. I have tried several different versions of this an they always do the same thing. I press a button on the transmitter data link works great on the the receiver the bits that I am toggling works good, but no matter what I try the outputs on portb 1-4 just come on but they won't go off. I've added a few lines to make sure the receiver knows keydata=%00000000 when no key is pressed, even add a little delay to hear it on my service monitor.
    transmit:

    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    if keyin = nokey then pause 10
    if keyin = nokey then x2
    goto findkey

    x2: 'I have taken this out as suggested but then what tells the Rx mydata1,mydata2 to equal %00000000 other than CLEAR or mydata1=%00000000?
    high dgood
    keydata = %00000000
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    goto findkey

    On the receiver side:
    loop1:
    SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
    Return
    when I am sending data everything checks out fine using the checksum then continues on, but for whatever reason even though when I release the key on the transmitter, and it sends keydata=%00000000 , I would think mydata1,mydata2 being (%00000000 + %00000000) would match and continue on so the ELSE command would return the outputs back to their low state but it doesn't.

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



    Anyone know what I am doing wrong?
    Last edited by tazntex; - 14th August 2008 at 05:01.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Read thru your code very very carefully again! And again....and again....and again....
    Use a piece of paper or something to keep track of what your program is doing if you have to.
    Your transmit program is doing EXACTLY what you are writing it to do, like I was trying to explain in the other thread.
    YOU aren't doing anything wrong, your program isn't doing anything wrong. Again, it's doing exactly what you programmed it to do.
    What you have to do is program it to do what you WANT it to do...
    The problem is in your program, your logic flow. Read it...You'll get it...

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You know, the idea of this forum is to provide asnwers for peoples questions.

    If you see something helpfull that you can provide, by all means, speak up and point it out.

    Telling someone to re-read their own program over and over, as if (ha ha, I know what's wrong and you don't).

    Does not help.
    <br>
    DT

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I would, and I will, eventually, maybe. The O/P is seeming to have difficulty in realizing that PICs do only what they are programmed to do...nothing more, nothing less, and just because a programmer wants the PIC to do something, doesn't mean it's going to do it, at least not without proper program and logic flow and hardware to back it up. Feeding, fishing, teaching, learning, all that stuff... He'll get it eventually. He's already figured out a few things for himself. It's only a matter of time before a light bulb goes on...

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Ya'll are great, I will go back through this, print it and try to figure it out. Will be back after awhile and let ya'll know what I have or haven't found.



    Thanks again

  6. #6


    Did you find this post helpful? Yes | No

    Default

    INCLUDE "bs2defs.bas"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    ' Watchdog Timer
    @ DEVICE pic16F628a, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628a, MCLR_ON
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628a, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic16F628a, LVP_OFF
    ' Low-Voltage Programming
    @ DEVICE pic16F628a, CPD_OFF
    ' Data Memory Code Protect
    ' Set to CPD_OFF for Development Copy
    ' Set to CPD_ON for Release Copy
    @ 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 'serial input pin
    PORTA = 0
    PORTB = 0
    trisa = %00000010
    trisb = %10000000
    CMCON=%00000111
    PAUSE 50 ' settle time

    loop:
    clear 'Do I really need to do this? I tried to make sure everything is back to 0
    gosub loop1 'After button is released on tx mydata1=%00000000
    CheckSum = (address1 + address2) 'address sent %00000001 added together in this case this = 10
    CheckSum = CheckSum + (mydata1 + mydata2) '10 + (%00000000 +%00000000)= 10
    IF checksum != chk_sum THEN loop 'checksum = chk_sum because of above
    IF (mydata1) != (mydata2) THEN loop '(mydata1) = (mydata2)
    IF (address1) != (address2) THEN loop '(address1) != (address2)
    'Since everything should be a match We move on
    if mydata1=%01010110 then rly1 'this works so I will go to the next one

    if mydata1=%01011001 then rly2 '1st case will turn portb.1 on
    if mydata1=%00000000 then rly2 '2nd case appears to do nothing but as I stated above the check
    'should be correct and mydata1=%00000000
    if mydata1=%01011010 then rly3 'I will skip the rest of this area because it
    if mydata1=%00000000 then rly3 'behaves the same as rly2 the rly6 rly7 ok.

    if mydata1=%01100101 then rly4
    if mydata1=%00000000 then rly4

    if mydata1=%01100110 then rly5
    if mydata1=%00000000 then rly5

    if mydata1=%01101001 then rly6
    if mydata1=%01101010 then rly7

    rly1:
    if mydata1=%01010110 then pause 10
    if mydata1=%01010110 then toggle 0
    pause 10
    goto loop
    rly2:
    if mydata1=%01011001 then pause 10 'Down here the fun begins
    if mydata1=%01011001 then high 1 '1st case will turn portb.1 on
    if mydata1=%00000000 then low 1 'Since the checksum is correct why didn't I get here
    'mydata1=%00000000 so this should go low but doesn't
    goto loop 'here we go back to loop so I will goto loop1
    rly3:
    if mydata1=%01011010 then pause 10
    if mydata1=%01011010 then high 2
    if mydata1=%00000000 then low 2
    goto loop
    rly4:
    if mydata1=%01100101 then pause 10
    if mydata1=%01100101 then high 3
    if mydata1=%00000000 then low 3
    goto loop
    rly5:
    if mydata1=%01100101 then pause 10
    if mydata1=%01100110 then high 4
    if mydata1=%00000000 then low 4
    goto loop
    rly6:
    if mydata1=%01101001 then pause 10
    if mydata1=%01101001 then TOGGLE 5
    pause 10
    goto loop
    rly7:
    if mydata1=%01101010 then pause 10
    if mydata1=%01101010 then TOGGLE 6
    pause 10
    GOTO loop


    loop1:
    SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
    Return
    'loop1 receives the following
    'transmit:

    ' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    ' if keyin = nokey then pause 10
    ' if keyin = nokey then x2
    ' goto findkey

    'x2:
    ' high dgood
    ' keydata = %00000000
    ' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    ' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    ' serout serpin,N2400,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    ' goto findkey

    'on the GOSUB loop1 after the tx button is released I should move on to x2
    'x2 sends the preamble, and I am still getting my synch plus address,data an chk_sum
    'so I should pass through the checksum area of my receiver code and on to the rest of
    'my program. When the program arrives at "if mydata1=%00000000 then rly2 " it should
    'ask "if mydata1=%00000000 then low 1" and respond and portb.0 should go low but it
    'never seems to get there. I switch from the If/Then/Else to make it simpler for me
    'to break it down.

    'I've been over the tx side and I feel confident everything there is working correctly

    ' Am I heading in the right direction?

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    So between post #34 and #39, that is your entire code for both TX and RX?

    And is it possible for you to connect an LCD to the RX for troubleshooting? Or at least replace those relays with LEDs.

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