Manipulation of string array


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    3

    Smile Manipulation of string array

    Hi,
    This is my first post but I have been checking out the site for a while using code examples to learn different ways to manipulate data e.c.t
    I am currently playing with a serial GPS mouse and I have programmed the pic with different routines and code to learn what can be achieved.
    My current project is based on a pic 16-F-628A and it reads the GPS data stream that I have set up and I can print out the saved arrays in any location from the array using the array based address system, but I am having trouble understanding how the data is saved as when I save the portions of the array to a variable and manipulate the data - I get unexpected results.

    Here is a sample of my code

    POS_STAT VAR BYTE
    LAT var byte [9]
    LON var byte [10]
    LAT_N_S VAR BYTE
    SPEED VAR BYTE

    READ_GPS:
    SERIN2 portb.4,16572,2000,FAULT,[WAIT("$GPRMC,"),wait (","),POS_STAT,wait (","),STR LAT\9,wait (","),LAT_N_S, wait (","), STR LON\10, wait (","),LON_E_W, wait (","), DEC3 SPEED]

    When I send the data from the program as follows :

    SEROUT2 portb.2,84,[LAT_N_S,STR LAT\9,LON_E_W,STR LON\10,"SPEED", DEC3 SPEED,10,13]

    It prints out fine.
    When I goto manipulate the data I get unexpected results.
    DEGLAT = LAT[0]
    I = LAT[1]

    SEROUT2 portb.2,84,[LAT_N_S,DEGLAT,I,LON_E_W,STR LON\10,"SPEED", DEC3 SPEED,10,13]
    DELGAT = 3 --- I = 6 INSTEAD OF 8

    THE STRING CONTAINS FROM 0 TO 9 ...(3810.7890)
    I am wondering if the array has signed integer e.g 38 10 . 7890 or 3,8,1,0,.,7,8,9,0 ??????

    Any help would be appreciated.
    Thanks in advance Benny007

  2. #2
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Each byte of the array should contain a single ascii character only. There are no unsigned integers. So, the 3 in the first position actually looks like $33 instead of $03. This way it will print the ascii number "3". What are you trying to manipulate? Also, if you post your code, put ; or ' in front of your comments. It will make your code easier to read and help us troubleshoot it.

    Ron

  3. #3
    Join Date
    Apr 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Post

    Thanks for the reply Ron.
    I have tried to print out 38 from the string which I can if I use
    SEROUT2 portb.2,84,[LAT[0],LAT[1],10,13] ' PRINTS OUT 38 FROM THE STRING (3810.7890)
    IF I GO
    DEGLAT = LAT[0] * 10 + LAT[1] 'DEGLAT IS DEFINED AS DEGLAT VAR BYTE
    I would have thought I would have got an output of 38 when I used the following
    ' Instead I got 36
    If I use the following:
    DEGLAT = LAT[0] ' (DEGLAT) IS DEFINED AS (DELGAT VAR BYTE)
    I = LAT[1] ' (I) IS DEFINED AS (I VAR BYTE):
    SEROUT2 portb.2,84,[DEGLAT,I,10,13] ' I get 3€ Instead of 38

    Thanks Benny007
    Last edited by Benny007; - 23rd April 2008 at 13:56.

  4. #4
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    OK. My first question is, why did you do this?

    DEGLAT = LAT[0] * 10 + LAT[1] 'DEGLAT IS DEFINED AS DEGLAT VAR BYTE
    I would have thought I would have got an output of 38 when I used the following
    ' Instead I got 36
    Keep in mind that if you are sending these numbers out as their ascii characters to be read on a screen, or printed, you just need to send them out as is. Are you trying to pack the numbers $33,$38 into a single hex byte $38 ? If so, it will not print as "38", but you can do real math to them.
    You need to subtract $30 from the first character and shift it 4 places to the left...
    DEGLAT = (LAT[0] - $30) <<4
    I = LAT[1]& %00001111 ; This keeps the lower 4 bits only. ie.. I becomes $08.
    DEGLAT = DEGLAT + I ; Will make DEGLAT $38

    Is this what you want?

  5. #5
    Join Date
    Apr 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks for the reply Ron.
    I am purely doing this to learn different way's of basically doing the same thing.
    I have made several routines to read and print out a GPS string array but I would like to learn how to change the degrees and minutes e.c.t with my own code and this seems to be the best example for me to learn from.
    It seems that you have hit the nail on the head with the HEX modifier.
    I have not tried it as yet but I am sure that this is what I need to know.
    I have never done math with HEX characters so I am interested to learn.
    I will hit the search button and find some references to HEX math examples as it looks puzzling to me at first glance. I need to get it right in my head before going any further.
    Ron I am the sort of bloke that likes to make simple things difficult and then further simplify them in order to learn. Being self taught - for me this is reasoning !!!!!!
    Thank you for taking the time to reply Ron.
    Regards Benny007

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 05:46
  3. Replies: 1
    Last Post: - 28th January 2010, 23:15
  4. String Manipulation
    By Darrenmac in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th April 2008, 15:39
  5. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 05:39

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