Serout problem


Closed Thread
Results 1 to 40 of 95

Thread: Serout problem

Hybrid View

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

  2. #2
    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 21:13.

  3. #3
    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 21:52.

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

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

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

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

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

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

Similar Threads

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