Serout problem


Closed Thread
Results 1 to 40 of 95

Thread: Serout problem

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Anyway here is the code I am using at the receiver:
    I will be putting a lcd on the circuit to see how the pic is reading the input.
    Beside the test led input at the begining the rest is not functioning, I suppose it has to do with the data coming is in one format and I am treating it in another.

    DEFINE OSC 20 '20Mhz Oscillator was used

    Include "modedefs.bas" ' Include serial modes

    ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT
    ADCON1=7
    CMCON = 7 'COMPARATORS OFF
    TRISA = 0 'outpu
    TRISB = 1 'input

    B0 var byte

    porta.0 =1 'testing leds output
    pause 500
    porta.1 =1
    pause 500
    porta.2 =1
    pause 500
    porta.3 =1
    pause 500

    start:
    serin PORTB.3,n2400,[B0]
    pause 1
    if B0 = $aa then led1
    if B0 = $aa then led2
    if B0 = $5a then led3
    if B0 = $5a then led4

    goto loop

    led1:
    porta.0 =1
    pause 200
    goto start

    led2:
    porta.1 =1
    pause 200
    goto start

    led3:
    porta.2 =1
    pause 200
    goto start

    led4:
    porta.3 =1
    pause 200
    goto start

    loop:
    porta.0 =1
    pause 200

    goto start
    end

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    A couple of notes:

    TRISA = 0 'outpu <------ might only set porta.0 as an output(?)
    use TRISA = %00000000 to make sure

    TRISB = 1 'input <------ will only set portb.0 as an input
    use TRISB = %11111111 to make sure all
    of port B is set to input

    start:
    serin PORTB.3,n2400,[B0]
    pause 1 <------ don't pause here, you want to read the serial
    and get done what you want done and get
    back to reading the serial port as quick as
    possible

    if B0 = $aa then led1
    if B0 = $aa then led2
    if B0 = $5a then led3
    if B0 = $5a then led4

    goto loop

    led1:
    porta.0 =1
    pause 200 <----------- take out all these pause 200 lines
    goto start

    led2:
    porta.1 =1
    goto start

    led3:
    porta.2 =1
    goto start

    led4:
    porta.3 =1
    goto start

    loop:
    porta.0 =1

    goto start
    end[/QUOTE]


    And you last post, 'where is the serin command?'. I'm using the hardware serial port driven by the 'on interrupt' command. Read the PBP manual a bit on it, then read the datasheets on the serial port and interrupts.
    Give me a few minutes. I'll rework your code into something useful.
    JDG
    Last edited by skimask; - 2nd December 2006 at 16:53.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    wow, ok some improvements to be done.
    I will try this tonight when I get home, I might leave early...

    ken

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default serial wireless receiver code

    Ok, this should work. Ingest the code, understand the manchester encoding method.
    And your other program only turned LEDs on, it never turned them off. And it never cleared B0.

    'RECEIVER CODE

    DEFINE OSC 20 '20Mhz Oscillator was used

    Include "modedefs.bas" ' Include serial modes

    ADCON0 = 0 : ADCON1 = 7 'AD MODULE OFF & CONSUMES NO CURRENT
    CMCON = 7 'COMPARATORS OFF
    TRISA = $00 : TRISB = $FF 'all porta is outputs, all portb is inputs

    B0 var byte

    'testing led outputs
    porta.0 = 1 : pause 200 : porta.0 = 0
    porta.1 = 1 : pause 200 : porta.1 = 0
    porta.2 = 1 : pause 200 : porta.2 = 0
    porta.3 = 1 : pause 200 : porta.3 = 0

    start:
    B0 = 0 'empty B0 because the program doesn't
    serin PORTB.3,n2400,[B0] 'if n2400 doesn't work, try t2400
    if B0 = $aa then training 'manchester encoded $f
    if B0 = $55 then training 'manchester encoded $0
    if B0 = $56 then led1toggle 'manchester encoded $1
    if B0 = $59 then led2toggle 'manchester encoded $2
    if B0 = $5A then led3toggle 'manchester encoded $3
    if B0 = $65 then led4toggle 'manchester encoded $4
    if B0 = $66 then ledson 'manchester encoded $5
    if B0 = $69 then ledsoff 'manchester encoded $6
    if B0 = $6A then ledswing 'manchester encoded $7
    'still have $8-$e free to use
    goto start

    led1toggle:
    if porta.0 = 1 then
    porta.0 = 0
    else
    porta.0 = 1
    endif
    goto start

    led2toggle:
    if porta.1 = 1 then
    porta.1 = 0
    else
    porta.1 = 1
    endif
    goto start

    led3toggle:
    if porta.2 = 1 then
    porta.2 = 0
    else
    porta.2 = 1
    endif
    goto start

    led4toggle:
    if porta.3 = 1 then
    porta.3 = 0
    else
    porta.3 = 1
    endif
    goto start

    ledson:
    porta.0 = 1 : porta.1 = 1 : porta.2 = 1 : porta.3 = 1
    goto start

    ledsoff:
    porta.0 = 0 : porta.1 = 0 : porta.2 = 0 : porta.3 = 0
    goto start

    ledswing:
    porta.0 = 1 : pause 10 : porta.0 = 0
    porta.1 = 1 : pause 10 : porta.1 = 0
    porta.2 = 1 : pause 10 : porta.2 = 0
    porta.3 = 1 : pause 10 : porta.3 = 0
    goto start

    end


    Redo your transmitter code to match the receiver code. Put a few buttons on it to transmit the codes above needed to turn your leds on and off, etc.

    Do you have a couple of buttons on the transmitter or is it just a free running PIC without any outside input?

    JDG

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I just have a pot command as input, from memory
    port portb.1,50,bo
    if bo >0 and bo <150 then output1
    if bo > 150 and bo <255 the output 2
    output1
    serout ......

    something like that , just two different outputs for now,
    I will use the a/d converter when I get the first working.

    k

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default wireless transmitter code

    'posted to the wrong thread!!!!
    didn't realize this thread has gone to 2 pages!
    Last edited by skimask; - 2nd December 2006 at 17:40.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default serial wireless transmitter code

    'after you've got everything else set up

    led1toggle = $56 : led2toggle = $59 : led3toggle = $5a : led4toggle = $65
    ledson = $66 : ledsoff = $69
    ledswing = $6a

    START:
    gosub trainreceiver : serout portb.2, n2400, [ ledsoff ] : pause 1000
    gosub trainreceiver : serout portb.2, n2400, [ ledson ] : pause 1000

    goto start

    trainreceiver:
    serout portb.2, n2400, [ $aa, $aa, $aa, $aa, $aa ] : return

    end



    See that? Every time you send a command you have to train the receiver because there is more than about 5ms between commands. If you were to continuously send commands or data, you probably wouldn't need to train the receiver. But in any case, you MUST use manchester encoding! You'll get garbage at the output if you don't!
    As this code is setup, all your LEDs should come on for a second, turn off for a second, come on for a second, etc.etc...
    Let me know what happens...
    JDG

    Ok, I just saw the post about using the pot. So use the pot to turn the LEDs on and off. Then after that works, use the POT to turn the LEDs on in sequence to match the pot's rotation.

    gosub trainreceiver : serout portb.2, n2400, [ ledsoff ]
    if b0 < 64 then gosub trainreceiver : serout portb.2, n2400, [ led1toggle ]
    if ( b0 > 63 ) and ( b0 < 128 ) then gosub trainreceiver : serout portb.2, n2400, [ led2toggle ]
    if ( b0 > 127 ) and ( b0 < 192 ) then gosub trainreceiver : serout portb.2, n2400, [ led3toggle ]
    if ( b0 > 191 ) then gosub trainreceiver : serout portb.2, n2400, [ led4toggle ]
    Last edited by skimask; - 2nd December 2006 at 17:44.

  8. #8
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I had time to analyze the code:
    A few questions came up:
    For the ledtoggle, why would you want to bit the pin high to low and then put it high, why not put it high right away. The way you have it, if its high, you put it to low, then to high, there must be a reason why and its flying 100 feet over my head.
    Also, the led will stay on until you call the ledsoff right?
    as far as the manchester coding goes, I understand, but there is decoder done here, you are simply pointing the coded values to their function. right?

    k

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    I had time to analyze the code:
    A few questions came up:
    For the ledtoggle, why would you want to bit the pin high to low and then put it high, why not put it high right away. The way you have it, if its high, you put it to low, then to high, there must be a reason why and its flying 100 feet over my head.
    Also, the led will stay on until you call the ledsoff right?
    as far as the manchester coding goes, I understand, but there is decoder done here, you are simply pointing the coded values to their function. right?

    k

    LedToggle --- It's not the way describe it.
    Read the IF...ELSE....ENDIF statement... work it through in your head.
    If it's on, turn it off, otherwise turn it on (implying that it was off in the first place).

    Encoder/Decoder - yes, I am assuming you don't have either the encoder or the decoder in the circuit. As far as I'm concerned, you don't need it. Yes, it's a handy piece of hardware to have around. The sooner you figure out how to do things without it, the better.

    JDG

  10. #10
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    HI

    I was not refering to the hardware encoder and decoder.
    The program I have below works, but always gives me zero on the lcd.
    k
    By the way , the command gosub trainreceiver :... gives an eror while compiling , wrong Label..


    X VAR BYTE 'VARIABLE TO incoming VALUE
    pause 100
    mainloop:
    X =0
    serin PORTB.3,n2400,[X]
    Lcdout $fe, 1, "Value in: ", dec X
    pause 100
    Goto mainloop
    End
    Last edited by lerameur; - 3rd December 2006 at 19:37.

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    HI

    I was not refering to the hardware encoder and decoder.
    The program I have below works, but always gives me zero on the lcd.
    k
    By the way , the command gosub trainreceiver :... gives an eror while compiling , wrong Label..


    X VAR BYTE 'VARIABLE TO incoming VALUE
    pause 100
    mainloop:
    X =0
    serin PORTB.3,n2400,[X]
    Lcdout $fe, 1, "Value in: ", dec X
    pause 100
    Goto mainloop
    End



    Now, what are you trying to do here....Make LEDs light up on command or make an LCD work.

    If you can't make LEDs do what you want them to, when you want them to do it, how do you expect to make an LCD work correctly?

    When you get a good hack on your priorities, let me know, I'm not going anywhere.

    Until then, start with the basics and work your way up...

    And as far as your program not working, you've got a 100ms pause between checking the serin. Get rid of the pause and use the timeout. If you get a timeout, no data has been received. If you don't get a timeout, you probably got some data. A 100ms is too long of a time to be missing characters. The receiver doesn't store them for you until you're ready to take them.

    (On another note, the trainreceiver gosub, try putting that above the main program, but below the setup, it should work correctly then, unless I had a typo or something)

    JDG

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask


    if B0 = $aa then training 'manchester encoded $f
    if B0 = $55 then training 'manchester encoded $0

    that was wrong, it was supposed to be this:

    if B0 = $aa then start 'manchester encoded $f
    if B0 = $55 then start 'manchester encoded $0

    $F and $0 are for 'training' the receiver and aren't to be used for sending data until the receiver is trained....

    Also in your RX4.bas (maybe it was RX6.bas), you have
    Serin PortB.3, 16780, [B0]
    ----shouldn't that be serin2?

    JDG

  13. #13
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    O k starting from scratches..
    I manages to do 2 different programs which dont work.
    here: http://www3.sympatico.ca/lerameur/
    do I need to configure SSPCON, or the RCSTA registers ?

    Also in your RX4.bas (maybe it was RX6.bas), you have
    Serin PortB.3, 16780, [B0]
    ----shouldn't that be serin2?
    I tried both , so many combinations....

    k
    Last edited by lerameur; - 5th December 2006 at 01:51.

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    O k starting from scratches..
    I manages to do 2 different programs which dont work.
    here: http://www3.sympatico.ca/lerameur/
    do I need to configure SSPCON, or the RCSTA registers ?

    Also in your RX4.bas (maybe it was RX6.bas), you have
    Serin PortB.3, 16780, [B0]
    ----shouldn't that be serin2?
    I tried both , so many combinations....

    k


    Did you get the LEDs to light up in sequence as described in the earlier post?
    And if you didn't, then why are you worried about the SSPCON or RCSTA registers... and why are you worried about those 2 registers in the first place? You're using a software-based serial commands, not hardware.
    Priorities, man, priorities....

    And after further checking.....................
    If you'd check your ttt program and read the PIC datasheet, you'll notice that RA.4 is an open-drain output...you'll never get a high logic level from it...
    If you'd check your rrr program and read the PIC datasheet, you'll notice that the TRIS statements are wrong...

    Don't assume something is broke when you just plain haven't looked hard enough... Come on,,, get on it... Get this thing working by tomorrow!!! or else!!!
    Last edited by skimask; - 5th December 2006 at 02:05.

  15. #15
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Nothing is working,
    Well the testing led part in the program works. thats it.
    The loop is looping, but as soon as I put the wire to the input port, then the signal disappear. AND no leds lighting

    k
    Last edited by lerameur; - 5th December 2006 at 02:06.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Strange SerOut Problem
    By masosi in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 23rd April 2007, 06:06
  5. Replies: 11
    Last Post: - 13th July 2005, 19:26

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