Syntax Question


Closed Thread
Results 1 to 4 of 4

Thread: Syntax Question

  1. #1
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257

    Unhappy Syntax Question

    Hi I'm just learing the Basics here.. sorry if these questions seem too easy for you smarties out there....

    1.
    I can't explain why I can not assign a string of text to a variable... eg


    MyText VAR BYTE ' Assign the Variable
    MyText = "X" ' Place Letter X into MyText

    Above compiles Ok.. But,

    MyText VAR BYTE[5] ' Assign the Variable
    MyText = "HELLO" ' Place Text 'HELLO' into MyText

    Doesn't compile. Any Ideas???

    2.
    If I use SERIN2 to get a line of serial data into an array, is each character stored in the array as one string (like in a LOOKUP table), or as a group seperate elements?

    eg
    MyText VAR BYTE
    SERIN2 PININ, 188, [STR MyText\5]

    MyText = "HELLO" OR "H","E","L","L","O"

    Thanks if you can help

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Aw c'mon folks... somebody else answer some questions for a change...

    PBP doesn't handle strings... unless they're one byte long... so you have to be creative.

    1. Assigning a longer string...

    MyText var byte [5]

    MyText[0]="H"
    MyText[1]="E"
    MyText[2]="L"
    MyText[3]="L"
    MyText[4]="O"

    2. Serin will save to an array if you so tell it to. The result will be as per my example in 1 above.

    Melanie

  3. #3
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    How about using a binary number? How many bits can be allocated to a Constant? I know that there are 8 bits in a byte.

    I would like to use 10 bits if it works.

    eg

    MyNumber_0 CON %0000000111
    MyNumber_128 CON %1111111000

    Seems to compile ok.

    Would it work? I am using a 16F628 which is an 8 bit controller, but has 2048x14 program space....or doesn't matter because PBP compilies for 8 bits only? Your advice is much appreciated.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If you spill out of eight bits then it becomes a word and you have up to sixteen bits to play with.

    Remember, you have three types of data element to play with, a bit, a byte and a word. Whatever you're doing must fit one of these.

    Melanie

Similar Threads

  1. Math operations & Syntax?
    By kevj in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 23rd February 2008, 01:40
  2. IF..THEN syntax
    By scaenix in forum mel PIC BASIC Pro
    Replies: 52
    Last Post: - 20th February 2007, 12:10
  3. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  4. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  5. Syntax error PIC16F684
    By milestag in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st September 2005, 18:54

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