Serial from PC into an Array


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    andyf's Avatar
    andyf Guest

    Default Serial from PC into an Array

    I have managed to make a really cool design that is perfect for testing the PIC16F877-20/P is getting what I send it. it simply echo's back to the PC what Is recieved at 19,200 on a 20MHZ clock.

    ok, so this is great and runs sweat, even have several subroutines to act upon the data/codes I send the PIC.

    Now I have a short and simple problem and am sure the answer will be very obvious so here goes.

    HSERIN [WAIT("*TEST"),STR in_ctl\11\"*"]

    in-ctl is an array that can contain upto 24 characters, the question is how can I know if it only has 6, 7 10 20 etc...

    input string examples:
    TESTABCDEF! in-ctl contains 7 characters
    TESTABCDEFGHI! in-ctl contains 10 characters
    TESTABC! in-ctl contains 3 characters

    I want to do this so I can have a loop similar in practice to this syntax:

    AR = arreycount(in-ctl)
    do
    .
    . some code
    .
    X=X+1
    loop until X = AR


    Andy

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    andyf, What I used to do is make sure the receiving array is all null by clearing it in a sort of loop. Then using the HSERIN options of "STR arrayname/maxumum characters/13" will load the array with no more than the maximum characters and terminate the input or, any number of characters until a carriage return is encountered. Then within some sort of loop look for the last character to be null and that is the last received character. Something simillar to this code:
    Counter = 0
    While counter <= maxcharacters
    in_ctl(counter) = 0
    Counter = Counter + 1
    wend
    HSERIN [WAIT("*TEST"),STR in_ctl\Maxcharacters\13]
    Counter = 0
    While (in_ctl(Counter) <> 0) and (Counter < Maxcharacters)
    Counter = Counter + 1
    wend
    'At this point Counter has the number of characters in the received array -1

    Dave Purola,
    N8NTA

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


    Did you find this post helpful? Yes | No

    Default

    Good idea Dave.

    If you want to have another way,
    Here's is another way
    Steve

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

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    You could send a single byte containing the length of the string.
    Send this byte right after the "SYNC" string (*TEST)

    STR in_ctl[0] would then tell you how many valid chars are in this array.
    Last edited by NavMicroSystems; - 13th May 2005 at 17:02.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Mister-e, That is an OK way to do it at a slower baud rate but at 9600+ baud I would be concerned with loosing characters especially at lower osc frequency's.

    Dave Purola,
    N8NTA

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


    Did you find this post helpful? Yes | No

    Default

    Dave,

    you're 100% right on that, was just an example snip. For faster Baudrate I'll for sure prefer using an other way like yours or Ralph's suggestion. Well, serial communication handling is an endless story and depend of too much thing to have an single solution
    Steve

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

Similar Threads

  1. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  2. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35
  3. PC serial port funny
    By nicjo in forum Serial
    Replies: 13
    Last Post: - 6th February 2007, 05:34
  4. Replies: 2
    Last Post: - 28th April 2006, 12:10
  5. Interrupt and Serial communication to PC.
    By obaskirt in forum mel PIC BASIC
    Replies: 2
    Last Post: - 17th June 2005, 20:01

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