How to use Arrays Using Pic Basic Pro(need help)


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    MrSafe's Avatar
    MrSafe Guest

    Default How to use Arrays Using Pic Basic Pro(need help)

    Hi, everybody New to the forum just wanted to give a shout out to everyone before I proceed.



    Problem: I Can not figure out how to use arrays with Pic Basic Pro

    Need: my design revolves around witlessly transferring data over the air on to a receiving unit which will then display the incoming message. Currently my program simply displays the message as it is being typed in. However I would like to store the message in an array of lets say of 48 elements in a single dimension just a single row. I would then like to send the data that is being pressed on the keypad and have it stored in an element of the array after which it will then increment to the next position or next element for the next input.

    What I have Tried: I tried declaring the array by doing the fallowing

    htxt var word[48]

    and when I try to use it after declaring it

    htxt[0] = htxt[x]
    temp[x] = htxt[x]

    and when a keypad key is pressed

    temp[x] = #key
    serout.1200.PORTD.0, [temp[x]]
    pause 100
    temp[x] = htxt[x] + 1

    when i use the fallowing method my receiving unit simply displays a blank message when ever the data is transmitted. The way I send data is after the message has been inputed and stored I then send each element by itself to the receiving unit so that I can loop the message since theres more than one receiving unit and this way if one unit is turned on after the first unit it will receive the data one the next cycle of the loop.


    *****UPDATE******

    I have uploaded my code but please understand that it does not contain the portion above simply because I could not get it to work so I used my old method to get the software working. I uploaded it so people will understand that I am using PIC Basic Pro
    Attached Files Attached Files
    Last edited by MrSafe; - 30th June 2007 at 02:35.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hello,

    Are you using PicBasic Pro?
    Doesn't appear to be the case. (wrong syntax)

    In which case, you're on the wrong forum.

    Regards,
    DT

  3. #3
    MrSafe's Avatar
    MrSafe Guest


    Did you find this post helpful? Yes | No

    Default

    Yes I am 100% sure I am using PIC Basic Pro.

    Im not sure why arrays wont work for me everything else I can manage but I would love to use arrays, can you point me in the direction or give me a example of how to use an array where if the user pushs a button on the keypad and it stores it in the element and then it increments to next element?

    I know of other methods of storing the values inputed by the user but it would require a VERY lengthy code.

    I will try and upload my current code but but please be nice :P I am still working on it as soon as i figure out the array problem it will cut my program in by 2/3.
    Last edited by MrSafe; - 30th June 2007 at 02:31. Reason: More Info

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Ok, let's see what we can do.

    First off, the brackets.
    Use square brackets when declaring the Array, and round brackets when using it.

    That's not always a requirement, but if you are using statements like SEROUT that uses square brackets, PBP gets confused with the square brackets inside other square brackets.

    And, the SEROUT syntax is different than shown ...
    Code:
    Include modedefs.bas
    
    temp  VAR BYTE[48]
    
    SEROUT PORTD.0, T1200,[temp(x)]
    Also note that you are recieving/sending BYTEs, not WORDs. So the array should be BYTE[48].
    will try and upload my current code
    Great, that'll help, cause I'm still trying to figure out what you were trying to do with the temp array.
    but please be nice :P
    I promise that even if I'm mean, I'll do it in a Nice way.
    <br>
    DT

  5. #5
    MrSafe's Avatar
    MrSafe Guest


    Did you find this post helpful? Yes | No

    Default

    What im trying to attempt is when the user decides to input a message I would like to store every keystroke in the array until he or she is satisfied with the message then I would like to send the message by using arrays I can easily loop the message so for example the user inputs "Accident near exit 101" . I would like to store that in an array and since I will be storing every keystroke the program will take "A" and store it in temp[0] then store "c" in the next array element which would be temp[1] and so on.

    Also I went and uploaded my current program to clarify that I am using PBP
    Last edited by MrSafe; - 30th June 2007 at 03:36. Reason: grammer

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Yup, that's PicBasic Pro.

    First thing to do is to change the keypad routines so that it only "gets the key's".
    This will also reduce the program size quite a bit. Sending to the LCD and SEROUT can be done later, once you know what the character is.

    There are other ways to do it, but I'm trying to keep it in the same context as your program.

    For instance, with the alpha1: routine.
    It can be reduced to ....
    Code:
    alpha1:
        gosub getkey
        LOOKUP key,[" ABCDEFGHIJ"],Char
    RETURN
    Same for the alpha2 and main getkey routines.

    The idea is that the actual character you want will be stored in the "Char" (byte sized) variable. Then you can do what you want with it later, instead of 36 different versions of what to do with it if a certain key is pressed.

    Then, once you have the kaypad routine only returning the desired characters, you can do something like this...
    Code:
    Finished VAR BIT  : Finished = 0
    StrLen   VAR BYTE : StrLen = 0
    
    while not Finished
        gosub getkey
        if Char != EOM then ' End of message key
            htxt(StrLen) = Char
            LCDOUT Char
            StrLen = StrLen + 1
        else   ; originaly post as an endif (DOH!)
            Finished = 1
        endif
    wend
    SEROUT2  PORTD.0, 813, [STR htxt\StrLen,13,10]
    Of course, this doesn't allow backspaces and the like while editing. But I gotta leave something for you to do.

    HTH,
    DT

Similar Threads

  1. Sending Commands from Visual Basic about IR to Pic
    By tne_de in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th April 2009, 06:09
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 18:05
  4. vb6 to pic basic
    By Darrenmac in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th December 2005, 01:56
  5. The Ultimate PIC Basic
    By picnaut in forum PBP Wish List
    Replies: 4
    Last Post: - 9th November 2004, 22:10

Members who have read this thread : 2

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