Problem using Else


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Yes Joe that is a typo in the copy and paste. When I read all the replies with example code how are ya'll inserting the code block whereas I am just copying and pasting my code to this reply. I am assuming, which I don't like to do, that under additional options I could attach my questionable code.
    What does the DEC mean and do? In the manual I understand it to be Decimal as in MYDATA would be recieved as a decimal. After reading many post on Manchester, I would think I would only be using Binary, but it would seem in the end Binary, Decimal and Hex would all be the same.

    loop1:
    SERIN2 PortA.1,84,[DEC address1,DEC ADDRESS2,DEC MYDATA1,DEC MYDATA2]
    Return
    end

    Sayzer, in the flip/flop method you are speaking of, I can see how to turn an output on/off with the toggle command, but I do not understand how I could press the button on the tx and the output would come on the receiver but would have to release the button and press again to make it go off. As I have it using the toggle command as long as I am pressing the button on the tx the rx output just cycles on and off. Well I will keep reading the PBP manual maybe thats in there and I have missed it. By the way I am using the PBP v2.50 with the update installed.

    Many, many thanks to all for your help and patience.
    Last edited by tazntex; - 7th August 2008 at 13:56. Reason: typo

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tazntex View Post
    Yes Joe that is a typo in the copy and paste. When I read all the replies with example code how are ya'll inserting the code block whereas I am just copying and pasting my code to this reply. I am assuming, which I don't like to do, that under additional options I could attach my questionable code.
    Check out this page for all the neat stuff here on the forums:
    http://www.picbasic.co.uk/forum/misc...bbcode#imgcode

    (take out the extra spaces here)

    [ code ]This will go in a code block[ / code ]

    Code:
    This will go in a code block
    And there's a bunch more formatting type stuff listed on that page linked above.


    What does the DEC mean and do? In the manual I understand it to be Decimal as in MYDATA would be recieved as a decimal.
    It actually means that SERIN (or whatever) will wait until it receives x characters to be interpreted as a decimal.
    For instance:
    SERIN xxx,xxx,xxx, [ DEC1 x ]
    Waits for a single character between "0" and "9", preceeded by a character that's not between "0" and "9" and followed by another character that's not between "0" and "9".
    Another for instance:
    SERIN xxx,xxx,xxx, [ DEC5 x ]
    Waits for 5 consecutive characters that are each between "0" and "9", preceeded by any character that's not between "0" and "9" and followed by another character that's not between "0" and "9".
    So, the DEC (or HEX or BIN) modifier actually does 'parsing' of an input stream for you.
    HEX would wait for ASCII characters between "0" and "9" in addition to "a" (or "A") through "f" (or "F").
    BIN would only wait for "0" and "1".
    For reference..."0" = ASCII code 48 ($30), "9" = ASCII code 57 ($39), and so on. Just so we're on the same page here.

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


    Did you find this post helpful? Yes | No

    Default

    Mostly it means I have an easier time dealing with decimal numbers, than binary, as Jeremy pointed out you can use hex, binary, or decimal, it's all good.

    Quote Originally Posted by tazntex View Post
    As I have it using the toggle command as long as I am pressing the button on the tx the rx output just cycles on and off.
    Your receiver doesn't just stop because you are still holding the button, and besides your transmitter is sending a signal, not some d/c value, additionally when you go the R/F route, this is where switch debouncing comes in and should be on the transmitter I think. I think the transmitter program should send a packet of data, size determined by you, for each valid button press and not just keep sending continuously, otherwise scratchy switches will corrupt your data.
    Last edited by Archangel; - 7th August 2008 at 18:58.
    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


    Did you find this post helpful? Yes | No

    Default

    ok, how come if i use this on the receiver:

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

    And with this clip on the transmitter:

    transmit:

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

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

    Why is it that by transmiting to the receiver =%01100101 by pressing the button then once I release the button the transmitter sends keydata = %00000000 which I would think the ELSE would then turn PORTB.4 LOW, but it doesn't. Only when I press another button which activates the other three outputs which are using IF/THEN, ELSE. Then and only then will PORTB.4 go LOW, but the next output comes on and stay on like PORTB.4. Now the outputs I am toggling work just fine. Hopefully I am making some sense, and the folks with the white coats won't come get me
    Thanks again, Ya'll have been a great help

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

  6. #6


    Did you find this post helpful? Yes | No

    Default

    That is interesting, thanks so much.

  7. #7


    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.

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