Scampy,
I'm pretty sure the issue you are having with I2CWRITE vs LCDOUT is two-fold.
1. Using Output String Modifiers
2. The use of Brackets "[ ]" with I2CWRITE
First and foremost, PBP does not support "ALL TYPES" of Output String Modifiers for use with the I2CWRITE command.
It only supports one type of modifier with this command, the "STR" modifier.
From the PBP Manual for Output Modifiers:
I2CWRITE is not listed above.2.11 Output Modifiers for Formatting Strings
The following information applies to output commands ARRAYWRITE, DEBUG, SEROUT2, HSEROUT, HSEROUT2, and LCDOUT.
Continuing from the PBP Manual for Output Modifiers for Formatting Strings:
So trying to use DEC, BIN, HEX or REP with I2CWRITE will fail to compile.All of these commands accept an item list to determine output.
Numeric data included in this item list can be converted to ASCII strings using the following modifiers.
Output Modifiers for Formatting Strings
Modifier Operation
{I}{S}DEC{1..10} Send decimal digits
{I}{S}BIN{1..32} Send binary digits
{I}{S}HEX{1..8} Send hexadecimal digits
REP char\count Send character c repeated n times
STR ArrayVar{\count} Send string of n characters
The "Bad expression" compile error you get is due to the fact you are trying to use the "dec1" Output String Modifier with I2CWRITE, which is not supported.
However I2CWRITE does support the "STR" modifier.
From the PBP Manual for I2CWRITE:
I2CWRITE
"A modifier, STR, may be included before the variable name. This can be used to write an entire array (string) at once..."
"... If STR is specified, the following variable must be the name of a word or byte array, followed by a backslash (\) and a count:"
What you can possibly do is use ARRAYWRITE to store all of your "String" data into an array (with modifiers) and then
use I2CWRITE with the "STR x\n" modifier to output your formatted string, which is supported.
e.g.
Lastly, the issue of when to use brackets "[ ]" with I2CWRITE.Code:myOutArray var byte[8] ARRAYWRITE myOutArray, ["TT", dec1 (Pid_channel + 1), 0] I2CWRITE SDA, SCL, I2CSlaveAddress, [STR myOutArray\4] ' \4 for "TT10" 4 bytes, which is what ["TT", dec1 Pid_channel+1, 0] would be assuming Pid_channel = 0.
Although sometimes you can compile without errors when not using brackets.
I have found this seems to be for simple cases.
If you have complex statements in you variable list, then you need to use brackets.
Which is what you are seeing the "Expected '['" and "Expected ']'" compile errors from.
It think it is trying to parse the complexity of the input to the I2CWRITE command and gets lost, so errors out.
Then once you put the brackets around your list of data variables it errors out due to the unsupported "dec1" modifier.
I always surround my data variable list in this and other commands with brackets and do not have problems.
Hope this helps.
Bookmarks