Serout problem - Page 2


Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 95

Thread: Serout problem

  1. #41
    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

  2. #42
    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.

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

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

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

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

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

  8. #48
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I am putting an LCD to see what is coming in to be able to troubleshoot the problem , since the led dont work, I would like to see what is coming in portb.3. Sonce its giving me a value of zero, I guess my command serin is not interpretting the incoming code right.
    I just tried the following code. I realized that with 'serin' command the loop would stop at the first iteration. Now with serin2 , the led blinks, so the loops keeps going. The value coming in at portb.3 is erronous when ever it flashes once in a while on the lcd screen ( at least the erronous values are between 0 and 250). AND i get the same signal in and out on the oscilloscope
    if i dont get $55, $aa.. on the lcd screen , I suppsoe I wont be getting any leds turned on
    k

    mainloop:
    X =0
    serin2 PORTB.3,n2400,[X]
    Lcdout $fe, 1, "Value in: ", dec X

    Goto mainloop
    End
    Last edited by lerameur; - 3rd December 2006 at 20:13.

  9. #49
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    By the way I tried your code, led led lights at startup once, then i cannot get any leds to light. this is the reason why I thought it would be good to see what was going on with an LCD

    k
    Last edited by lerameur; - 3rd December 2006 at 20:52.

  10. #50
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    how about your config fuses?

    Any Schematic?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #51
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    this is the new whole program on the receiving end. If the inpu is not good, then I guess why continue making a big program making leds flash on different Pot output when the Pic cannot identify one input in the first place.

    define osc 20
    Include "modedefs.bas"
    Define LOADER_USED 1
    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD

    CMCON=7 ' Disable comparators
    'ANSEL=0 ' Set port as digital I/O
    ADCON1=7
    TrisB = %11111111 'sets all port a as input
    TrisA = %00000000 ' sets all port b as output

    X VAR BYTE 'VARIABLE TO incoming VALUE

    pause 100

    mainloop:
    X =0
    serin2 PORTB.3,n2400,[X]
    Lcdout $fe, 1, "Value in: ", dec X
    'porta.2 = 1 ' trying to see if the loop is looping
    'pause 200
    'porta.3 = 1
    'pause 200
    Goto mainloop

    End



    as far as the configuration goes, It is an F88, with portB.3 as the input and porta.2 and porta.3 as led output

  12. #52
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm, are you using the bootlader AND the LCD? If so, for sure there's some hardware problem... as the USART share the same I/O for your LCD data bits.

    Also, ANSEL should be = 0 to disable those internal ADCs, ADCON1=7 will work on some other PIC... unfortunately not this one
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #53
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I think my problem might be the sending code. I have added the output line to my lcd tosee what is sending, it says it is sending V and I's..
    here is the sending code

    define osc 20
    Include "modedefs.bas"
    Define LOADER_USED 1
    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD

    CMCON=7 ' Disable comparators
    ANSEL=0 ' Set port as digital I/O
    ADCON1=7
    TrisA = %11111111 'sets all port a as input
    TrisB = %00000000 ' sets all port b as output

    X VAR BYTE 'VARIABLE TO PUT POT VALUE
    B1 VAR BYTE
    PORTB = 0 'ALL OUTPUTS LOW
    '23

    Start:
    Pot PortA.2,49,X ' would like PortA.2,175,B0 use number to suit you
    Lcdout $fe, 1 'Clear screen
    Lcdout $FE,$80,"Pot: ", #X 'Display the numerical value
    LCDOUT $FE,$C0,"Output: ",B1
    Pause 10

    IF X <= 60 THEN LED1
    IF (X > 60) AND (X <= 120) THEN LED2
    IF (X > 120) AND (X <= 180) THEN LED1
    IF X > 180 THEN LED2
    goto Start

    LED1
    serout portb.2,n2400, [ $AA, $AA,$AA,$AA,$AA,$AA ]
    B1=$AA
    goto Start


    LED2
    serout portb.2, n2400, [ $56,$56,$56,$56,$56 ]
    B1=$56
    goto Start

    LED3
    serout portb.2,n2400, [ $55,$55,$55,$55,$55 ]
    B1=$55
    goto Start

    LED4
    serout portb.2,n2400, [ $65,$65,$65,$65,$65,$65 ]
    B1=$65
    goto Start

    end

  14. #54
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    By the way , in the receiving code you gave me, there is a Training function called, but it does not exists.

  15. #55
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I tried ansel =o all you told me, and remove the boatloader. Dont even know why it was there. There is no change in the system .
    If I am sending $aa on the tramsitter pic, shouldn'y I get that also on the LCD on the transmitter?

    I have four output on my transmitter. Here is your code to with only four values, the rest I didnot change it. None of the leds are lighting besides the initial feed:

    'RECEIVER CODE

    DEFINE OSC 20 '20Mhz Oscillator was used

    Include "modedefs.bas" ' Include serial modes

    ADCON0 = 0 '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 ledson 'manchester encoded $f
    if B0 = $55 then ledswing 'manchester encoded $0
    if B0 = $5a then led1toggle 'manchester encoded $1
    if B0 = $65 then led2toggle 'manchester encoded $2

    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

    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
    Last edited by lerameur; - 3rd December 2006 at 23:56.

  16. #56
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Would it be posible my pic at the receiver dont recognize the data in ?
    could the USART be at cause here ?

    The programs take a lot of space, I decided to post them on my web site:
    http://www3.sympatico.ca/lerameur/

    k
    Last edited by lerameur; - 4th December 2006 at 03:43.

  17. #57
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    I think my problem might be the sending code. I have added the output line to my lcd tosee what is sending, it says it is sending V
    and I's..

    -----------------because a V is ASCII code $56? and the 'I' must be a special character or something-doesn't matter
    ---------------------

    here is the sending code

    define osc 20
    Include "modedefs.bas"

    ------------------get rid of this unless you are really using a bootloader
    Define LOADER_USED 1
    -----------------------------------------------------------

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD

    CMCON=7 ' Disable comparators
    ANSEL=0 ' Set port as digital I/O
    ADCON1=7
    TrisA = %11111111 'sets all port a as input
    TrisB = %00000000 ' sets all port b as output

    X VAR BYTE 'VARIABLE TO PUT POT VALUE
    B1 VAR BYTE
    PORTB = 0 'ALL OUTPUTS LOW
    '23

    Start:
    Pot PortA.2,49,X ' would like PortA.2,175,B0 use number to suit you
    Lcdout $fe, 1 'Clear screen
    Lcdout $FE,$80,"Pot: ", #X 'Display the numerical value

    ------------------------------should be 'HEX B1' at the end
    LCDOUT $FE,$C0,"Output: ",B1
    -------------------------------
    Pause 10

    IF X <= 60 THEN LED1
    IF (X > 60) AND (X <= 120) THEN LED2
    IF (X > 120) AND (X <= 180) THEN LED1
    IF X > 180 THEN LED2
    goto Start

    LED1
    serout portb.2,n2400, [ $AA, $AA,$AA,$AA,$AA,$AA ]
    B1=$AA
    goto Start

    LED2
    serout portb.2, n2400, [ $56,$56,$56,$56,$56 ]
    B1=$56
    goto Start

    LED3
    serout portb.2,n2400, [ $55,$55,$55,$55,$55 ]
    B1=$55
    goto Start

    LED4
    serout portb.2,n2400, [ $65,$65,$65,$65,$65,$65 ]
    B1=$65
    goto Start

    end



    Does your X value change with the POT when you rotate it?
    How about this...let's break it down...again. Apparently there is too much going on here that can break the system and you're having trouble figuring out what's going on.....again...............

    1. Get rid of the transmitter................

    2. Get rid of the receiver...................

    3. Get rid of the POT.......................

    4. Put a button where the pot was....

    5. Make sure the button works...in other words, you push it and an LED connected to the same PIC on a different pin lights up on software command, not because you pushed it and made an electrical connection, then you release it and the LED goes out on software command, not because you removed an electrical connection. Then change the program around to extinguish the LED when the button is pushed, and light the LED when the button is released. That will tell you that you know how to make an LED light up on command. (or something comes up on the LCD that verifies that you are pushing and releasing the button).

    6. Then connect the other receiver PIC to the transmitter PIC through the serial port.

    7. Set up a program in the receiver to receive control data from the transmitter PIC and act on it in some fashion, and make it repeatable. For example, each press of the button on the transmitter PIC sends a command to light up a different light in the receiver PIC (4 LEDs light up, one after the other, and so on down the line, until the end is reached, then they extinguish and the process starts again.

    8. Then, after that is all working, connect the POT back into the transmitter PIC and rewrite your code to display the POT value on the LCD. When that works fine, continue...and not until it works as you want it to.

    9. When steps 1-8 all work fine, each and every time, then disconnect the PIC' serial ports and reinsert the transmitter and receiver modules (not the encoder and decoder modules).

    10. Add the code back into the transmitter that send out the various control codes for each LED at the receiver PIC. And don't forget about the receiver training code. It's the transmitter that does the training of the receiver, not the receiver itself.

    Tune in tomorrow for more...I'm tired of explaining this...
    JDG

    , connect the 2 PICs at the serial ports.

  18. #58
    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

  19. #59
    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.

  20. #60
    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.

  21. #61
    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.

  22. #62
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, Ok, Ok,.............................
    Here we go again.....................
    This is getting annoying............
    There is something getting messed up somewhere, something you aren't telling me, something you are doing ahead of time, something you aren't doing in a logical sequence, something somewhere...........so.......

    Answer these 2 questions:

    1. What hardware do you have? List the PICs, the crystals, the LEDs, the TX, the RX, the switches, the pot, etc. and so and so....

    2. What is your 'master plan'? Do you intend to transfer data between 2 PICs wirelessly? Do you intend to just control a couple of LEDs wirelessly? What?

    JDG

  23. #63
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    1. What hardware do you have? List the PICs, the crystals, the LEDs, the TX, the RX, the switches, the pot, etc. and so and so....
    Pic16F88, 20Mhz crystals, Led out on portA.0,1,2 and 3
    MCRL on PORTA.5, ground pin, Vdd on 5v. NO pot, no switch, Just a wire going from PortB3 (output of serout) going to portA.4 (serin)
    if serin.. well
    START:
    B0 =0
    serout portB.3,n2400, [ $0F, $0F, $0F, $0F, $0F, $0F, $0F ]
    serin portA.4,n2400, [B0 ]
    if (B0 = $0F) then
    porta.2 =1
    pause 100
    porta.2 =0
    else
    goto start
    endif
    GOTO START

    2. What is your 'master plan'? Do you intend to transfer data between 2 PICs wirelessly? Do you intend to just control a couple of LEDs wirelessly? What?
    I want to transfer data to about 200feet between two pics.

    Go back to my web site, I posted a picture of the circuit
    thanks for your time
    ken

  24. #64
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    1. What hardware do you have? List the PICs, the crystals, the LEDs, the TX, the RX, the switches, the pot, etc. and so and so....
    Pic16F88, 20Mhz crystals, Led out on portA.0,1,2 and 3

    2. What is your 'master plan'? Do you intend to transfer data between 2 PICs wirelessly? Do you intend to just control a couple of LEDs wirelessly? What?
    I want to transfer data to about 200feet between two pics.

    ken
    Ok, still a lot of information missing. Is the 16F88 your transmitter or receiver PIC? You posted what I assume is the 'transmitter' code, what about the receiver hardware and/or code...in fact, don't worry about the code for right now. We're going to make sure your hardware is hooked up right.
    (P.S. I'm only going to be here for the next 1/2 hour, until 10pm CST)


    And another thing, you are using a software based serial solution, also called 'bit-banging'. By the time your serout is done, all the data is transmitted. It's not buffered anywhere. It's not done in hardware. It's like trying to use 2 telephones to talk to yourself in different rooms. You talk into one phone, run to the other room and wait for your voice to come out. It isn't going to happen. Serin doesn't have anything to do but wait for nothing. Not going to work....
    Last edited by skimask; - 5th December 2006 at 03:30.

  25. #65
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    well from what you said before:
    5. Make sure the button works...in other words, you push it and an LED connected to the same PIC on a different pin lights up on software command

    I went real simple as you told me.
    So this pic is the only pic, emitting AND receiving, the yellow wire is from sending to receiving.

    k

  26. #66
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    well from what you said before:
    5. Make sure the button works...in other words, you push it and an LED connected to the same PIC on a different pin lights up on software command

    I went real simple as you told me.
    So this pic is the only pic, emitting AND receiving, the yellow wire is from sending to receiving.

    k


    Not going to work. See last thread I posted.
    JDG

  27. #67
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    just posted the unworking program ,
    nothing is coming out of the sending chip
    Last edited by lerameur; - 5th December 2006 at 03:48.

  28. #68
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    just posted the unworking program ,
    nothing is coming out of the sending chip

    I know nothing is working on your sending chip...you've got it set up wrong. Read my words a couple of posts ago. Going out of the chip back into the chip isn't going to work.

    Plug this into your sending chip, with only the LEDs and a button attached to portb.0 with a pulldown resistor:

    -------------------------------------------------------------------------
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7

    ledcount var byte

    led1 var porta.0 : output led1 'led on porta.0
    led2 var porta.1 : output led2 'and so on...
    led3 var porta.2 : output led3
    led4 var porta.3 : output led4

    key var portb.0 : input btn 'push button on portb.0
    '1K-10K resistor from portb.0 to ground (pulldown)
    'push button is wired between portb.0 and +5v

    led1 = 1 : pause 500 : led1 = 0 'initial light up to see if program is running
    led2 = 1 : pause 500 : led2 = 0
    led3 = 1 : pause 500 : led3 = 0
    led4 = 1 : pause 500 : led4 = 0

    mainloop:

    if key = 0 then 'button not pressed
    goto mainloop
    endif
    if key = 1 then
    pause 50 'wait 50ms for switch to debounce then check again
    if key = 1 then 'if it's still pressed, then increment the count
    ledcount = ledcount + 1
    endif
    endif

    if ledcount = 0 then 'all leds off
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    endif
    if ledcount = 1 then '1st led on
    led1 = 1 : led2 = 0 : led3 = 0 : led4 = 0
    endif
    if ledcount = 2 then '2nd led on and so on and so on down the line....
    led1 = 0 : led2 = 1 : led3 = 0 : led4 = 0
    endif
    if ledcount = 3 then
    led1 = 0 : led2 = 0 : led3 = 1 : led4 = 0
    endif
    if ledcount = 4 then
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 1
    endif
    if ledcount = 5 then 'reset led count, roll it back to 0
    ledcount = 0 'and turn leds off since count is back to 0
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    goto mainloop

    END




    Forget about serial code, the LCD and anything else that isn't listed above. Just do what's listed, and nothing else. If you go off on a tangent somewhere else, I don't know where you're going. Just do this. Get this to work. Then do the same basic thing on the receiver PIC. Get them both to work. We'll worry about connecting the 2 after both of these work.
    All this program is going to do is make the LED lights walk about 5 times a second as long as you hold the button down.
    JDG

  29. #69
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Ok I am going to do this, I will read and analyze your code before asking anything
    I'm off to bed now,
    thanks and see ya

    k

  30. #70
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    Ok I am going to do this, I will read and analyze your code before asking anything
    I'm off to bed now,
    thanks and see ya

    k

    There's no analyzing. You put the LEDs on PortA.0, A.1, A.2, A.3, set the pins to output. Put the switch on PortB.0, set the pin to input. Light them up in sequence for 1/2 second each.
    Then we sit in a loop waiting for the key input to go high (because it's pulled low without the button pressed).
    When it goes high, we wait 50ms. If it's still high after 50ms, then we increment the LED count.
    After that, it goes into a bunch of IF...THEN statements and sets the LEDs accordingly. If the count is 5, we reset the count back to zero and turn off all the LEDs...
    And start over again with checking the button...

    What's there to analyze? There is no analyzing. It is straight forward code, nothing hidden, no tricks of programming, no code magic, nothing. Short of
    10 PRINT"HELLO"
    20 GOTO 10
    it doesn't get much easier than this.

    JDG

  31. #71
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    well that works for both of them
    the four leds are funvtionning good on both circuits.

    k
    Last edited by lerameur; - 5th December 2006 at 11:55.

  32. #72
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    well that works for both of them
    the four leds are funvtionning good on both circuits.

    k

    You have a PIC16F88 on the transmitter and a PIC16F628A on the receiver, yes?

    When you push the button on each PIC, the LEDs cycle thru on their respective PICs with each button press, yes? (remember, 2 seperate circuits running independant programs, not tied together except for the fact they happen to be mounted to the same workbench).

    If they do, change the pause 50 to pause 1000. When you hold the button down, the LEDs should increment once a second. That will verify that the oscillator is running at the correct speed (or at least close to it).

    I just want to make sure this is all work before we got any farther (small steps).

    JDG

  33. #73
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I have two Pic16F88 ( did try a PIC16F628A once to see what would happen, how did you know, I dont think I mentioned that)

    both circuits are running independently, Just the power supply is hooked up in parallel. Two circuits, two breadboards. two are doing the same thing


    k
    Last edited by lerameur; - 6th December 2006 at 01:35.

  34. #74
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    I have two Pic16F88 ( did try a PIC16F628A once to see what would happen, how did you know, I dont think I mentioned that)

    both circuits are running independently, Just the power supply is hooked up in parallel. Two circuits, two breadboards. two are doing the same thing


    k
    Ok, I'm back. I don't think you did specifically mention you had a 16F628A except that it was in one of the headers of one of your files somewhere.

    So, you've got 2 16F88's, one will eventually be a transmitter (TXPIC), one will eventually be a receiver (RXPIC).

    Right now, both PICs right now have 4 LEDS and a push button. When you fire it up, the leds do their little power up check, then when you push the button, the leds light up in sequence about once per second.

    Release the button, the sequence stops until you hit the button again right?

    If that's correct, now we'll connect the 2 PICs, define one as TXPIC and and as RXPIC.
    On the TXPIC side:
    Select a pin for serial output. I suggest RB2.

    -------------------------------------
    Add:
    txout var portb.2
    output txout
    dataout var byte

    near the beginning of your TXPIC program, next to the rest of the variable declarations
    --------------------------------------

    -------------------------------------
    And add:
    dataout = ledcount
    serout txout, n2400, [ dataout ]
    pause 100

    on the line after 'ledcount = ledcount + 1', but before the 1st endif
    ---------------------------------------




    On the RXPIC side:
    Select a pin for serial input. I suggest RB5.

    -------------------------------------
    Add:
    rxin var portb.5
    input rxin
    datain var byte

    near the beginning of your RXPIC program, next to the rest of the variable declarations
    --------------------------------------


    ------------------------------------
    Change your RXPIC code to this (starting at mainloop):

    mainloop:
    serin rxin, n2400, 5000, nodatarx, datain
    'if no data received in 5 seconds, jump to nodatarx

    if datain = 0 then 'all leds off
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    if datain = 1 then '1st led on
    led1 = 1 : led2 = 0 : led3 = 0 : led4 = 0
    endif

    if datain = 2 then '2nd led on and so on and so on down the line....
    led1 = 0 : led2 = 1 : led3 = 0 : led4 = 0
    endif

    if datain = 3 then
    led1 = 0 : led2 = 0 : led3 = 1 : led4 = 0
    endif

    if datain = 4 then
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 1
    endif

    goto mainloop

    nodatarx: 'flash the leds 3 times
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    led1 = 1 : led2 = 1 : led3 = 1 : led4 = 1
    pause 400
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    pause 400
    led1 = 1 : led2 = 1 : led3 = 1 : led4 = 1
    pause 400
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    pause 400
    led1 = 1 : led2 = 1 : led3 = 1 : led4 = 1
    pause 400
    led1 = 0 : led2 = 0 : led3 = 0 : led4 = 0
    goto mainloop

    END
    ----------------------------------------



    Connect the PortB.2 pin on the TXPIC to the PortB.5 pin on the RXPIC, and write/burn the programs.
    This should make the TXPIC and RXPIC act in their respective roles. You push a button on the TXPIC, it sends a code to the RXPIC. Both sets of LEDs on both PICs should match. If you don't send a code for 5 seconds the RXPIC will flash the LEDs 3 times, then turn them all off. The next time you press the button on the TXPIC, the same leds should be on for both the TXPIC and RXPIC.

    Try it out, see what happens....
    JDG

  35. #75
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Ok, I tried it, everything is fine, its working, The four leds flashes if no data from sending chip after 5 seconds, everything like you said.

    ken

  36. #76
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    Ok, I tried it, everything is fine, its working, The four leds flashes if no data from sending chip after 5 seconds, everything like you said.

    ken


    GREAT!!! That's great news. I'm at work at the moment. I'll post a bit more in a few hours when I get some spare time.
    JDG

  37. #77
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    thanks alot, I wont be home till late again today so no hurry.
    I just tried putting it through the RF module just to see what would happen, but it was not going through nicely.
    Waiting for your next instruction.

    k

  38. #78
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    thanks alot, I wont be home till late again today so no hurry.
    I just tried putting it through the RF module just to see what would happen, but it was not going through nicely.
    Waiting for your next instruction.

    k
    Now go back and read thru this whole thread and see if you can tell me why that data did not go thru the RF modules correctly. The correct answer is in the thread, young grasshopper.

    Same thing. I probably won't get back to this for a few hours yet. But if you're around, we should be able to get it all working within about 4-5 thread posts.
    JDG

  39. #79
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Well a big rule I learn not long ago is to use encoding techniques. and perhaps keep on sending the data a little while longer with serout command.

    k

  40. #80
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    Well a big rule I learn not long ago is to use encoding techniques. and perhaps keep on sending the data a little while longer with serout command.

    k

    Ok, so as it stands, you have:
    TXPIC: one button, 4 leds, serial out on PortB.2
    RXPIC: 4 leds, serial in on PortB.5

    All works well, data appears to transfer from TXPIC to RXPIC, LEDs match on both, then go out on RXPIC after 5 seconds without button push on TXPIC....

    If that's all good....Read on...I'll be typing up the next post while you read this one....
    JDG

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 : 1

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