Strange Serout Behaviour


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2008
    Posts
    16

    Default Strange Serout Behaviour

    I have been experiencing strange behaviour with Serout. The short version is this: I have a number of Serout commands (to hyperterminal on my laptop) in my code and my 16f88 would always skip the first Serout and start with the second Serout.

    Here's an example of what I see on my laptop:

    This is a test 2
    This is a test 3
    This is a test 4
    etc....

    When it should read:

    This is a test 1
    This is a test 2
    This is a test 3
    etc...

    I added the huge pause thinking that it might 'settle down' the pic. It didn't.
    I'm running a 1k resistor between the serout pin and the Com1 port on the laptop.

    Here's an example of the code:

    Include "modedefs.bas"

    @ __config _config1, _INTRC_IO & _WDT_OFF & _MCLR_OFF & _LVP_OFF
    'Interal Oscillator, WDT off, MCLR off, LVP off
    'For use with Microchip Assembler

    Define OSC4

    i VAR Byte

    OSCCON = %01101000 'OSC4, internal

    'DEFINE CHAR_PACING 1000 'For leaving slight spacing between Serout characters

    CMCON = 7 'Comparators Off

    ' Set the port directions
    ' 0=output 1=input
    TRISA = %11111111 'Need to set A.0 as Input
    TRISB = %11111011 'Set B.2 as output

    ANSEL = %00000000 ' Set digital

    Pause 5000

    i = 0

    for i = 1 to 10

    High PortB.1 'Turn on LED
    Pause 1000

    Low PortB.1 'Turn off LED
    Pause 1000

    Serout PortB.2,N2400,["This is a test ", #i,10,13]
    Pause 500

    Next i

    END

  2. #2
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default RS232 Missing Output

    Here is the reply I go from Melanie on this subject:

    When you first power-up, your hardware, registers, buffers can have all kinds of crap lurking. There's no real way of flushing this out, so the best thing I do is send a dummy line containg a dozen Nulls ($00) or so and terminate that with a CR LF. From then onwards, we're open for business.

    Now, it all depends what is connected to what... if at the receiving end you've got an ANSI Terminal, then the next thing you'll send is a Clear-Screen, if it's an Invoicing printer, then you'd send a Page-Feed, POS Terminal you'd eject a couple of inches of paper along with a paper-cut command, etc etc...

    If one PIC is connected to another, then I tend to send things in packets, and I always prefix the packet with some NULLs and a CR LF. The packet always has to have a valid header and a Checksum, otherwise it's dumped.

    Generally, I've found that the first thing out of the SEROUT business in wrong/odd/missing and so design your code accordingly.

    Regards Bill Legge

  3. #3


    Did you find this post helpful? Yes | No

    Default Condition the line first

    I find it pays to condition the TxData line first. For true RS232, i.e. using a MAX232 for example, the following works a treat.

    HIGH PortB.2 : Pause 5
    Serout PortB.2,N2400,["This is a test ", #i,10,13]

    This forces the RS232 interface into the correct MARK state where the external line to the terminal device idles low at negative 6~12 volts. The Start bit, a SPACE, is then seen as a positive going bit.

    HTH
    BrianT

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. Strange SerOut Problem
    By masosi in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 23rd April 2007, 06:06
  4. Strange behaviour from PIC16F877 on TMR0
    By mikebar in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 19th August 2006, 01:31
  5. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04: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