PDA

View Full Version : Syntax Question



Squibcakes
- 8th October 2003, 05:35
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

Melanie
- 8th October 2003, 10:29
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

Squibcakes
- 27th November 2003, 04:46
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.

Melanie
- 27th November 2003, 09:08
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