Problem using Else


Closed Thread
Results 1 to 40 of 47

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Tazntex,

    You are forgetting something I think.


    When you press a button, your IF statement works only WHILE you are pressing the button.

    When you do NOT press a button, your ELSE statement works continuously.

    This is why "you think" that you see no change; because it happens so fast when you hit the button down and release it.

    I think you should set an IF statement with the first button press, and keep it that way until you press it second time. Like a flip flop.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2


    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 12:56. Reason: typo

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

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

  5. #5


    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

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

  7. #7


    Did you find this post helpful? Yes | No

    Default

    That is interesting, thanks so much.

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