Problem using Else


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    On the receiver end change to SERIN2.

    Have it wait for the "synch" and use the time out modifier. The time out modifier will take place of the "else".

    So the reciever is "waiting" for the synch, if it does not get in in the specified time, the program will jump to where ever.

    You do not need to send keydata = %00000000 . Once the receiver does not see the synch it will time out and go on.

    I agree with Joe, debounce on the receiver end. Here is a simple but not so efficient way one of my kids debounced with a radio using SERIN.

    The code waits for the number 9 and writes the next bit to a variable. 9 is the synch in this case. Then if the variable = 3 enough times then another piece of code executes. You will see the the next piece is called "send". He was doing a relay project. If the 9 was not seen the program went back to looping, if the 9 and 3 was seen the program sends something out to the next receiver.

    He debounced the heck out of it I was told there is to much noise in the shop.

    Code:
    LOOP: 
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D1
    GOTO LOOP
    
    D1:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D2
    GOTO LOOP
    
    D2:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D3
    GOTO LOOP
    
    D3:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D4
    GOTO LOOP
    
    D4:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D5
    GOTO LOOP
    
    D5:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN SEND
    GOTO LOOP
    
    D6:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D7
    GOTO LOOP
    
    D7:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D8
    GOTO LOOP
    
    D8:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D9
    GOTO LOOP
    
    D9:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D10
    GOTO LOOP
    
    D10:
    PAUSE 50
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN SEND
    GOTO LOOP
    
    D11:
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D12
    GOTO LOOP
    
    D12:
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN D13
    GOTO LOOP
    
    D13:
    SERIN PORTC.4,T2400,[9],net
    IF net = 3 THEN SEND
    GOTO LOOP
    Dave
    Always wear safety glasses while programming.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    That is interesting, thanks so much.

  3. #3


    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 04:01.

  4. #4
    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...

  5. #5
    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

  6. #6
    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...

  7. #7


    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

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