I am moving from Parallax SX/B to AVR ATmega128 (BigAVR2) and MikroBasic Pro. I would like to see commands such as READ and DATA and SHIFTIN and SHIFTOUT. I have what I thought are work arounds in MikroBasic PRO but can't get them to work correctly until I figure it all out better.
Just my 2 cents.
Thanks.
Wishlist - Parallax SX chips SX/B
-
- mikroElektronika team
- Posts: 265
- Joined: 25 Nov 2008 09:09
Below is an excerpt from the HELP page for READ and READINC (e.g. READ with increment):
READ | READINC Examples
READ | READINCBase {+ Offset}, Variable {, Variable, ...}
Function
Read one or more bytes from a table.
Base is the base address of data to be read which may be specified as a DATA or WDATA statement label, or as a string-pointer variable created by the compiler (see below).
Offset is an optional variable indicating the relative position (to Base) for the READ operation. This may be specified when Base is a label, or can be created by the compiler when strings are used (see below).
Variable is a byte or word variable.
Explanation
The DATA directive can be used to create [read-only] tables for SX/B programs. The READ instruction is used to move one or more table values into the specified byte variable(s)
If READINC is used, the Offset wil be automatically incremented to to point to the next DATA item. If Offset is not used the Base will be incremented.
Start:
OUTPUT RB
Main:
FOR idx = 0 TO 3
READ Pattern + idx, RB ' move pattern to LEDs
PAUSE 100
NEXT idx
FOR idx = 4 TO 1 STEP -1
READ Pattern + idx, RB
PAUSE 100
NEXT idx
GOTO Main ' do it again
' -------------------------------------------------------------------------
Pattern: ' LED patterns
DATA %00000000
DATA %00011000
DATA %00111100
DATA %01111110
DATA %11111111
As of version 1.4, SX/B can handle inline strings (of two or more characters) and z-strings (of any length) stored in DATA statements. Using READ, the following subroutine will send a string to a defined serial port:
' Use: TX_STR [ string | label ]
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
SUB TX_STR
tmpW1 = __WPARAM12 ' get offset/base
DO
READ tmpW1, tmpW3 ' read a character
IF tmpW3 = 0 THEN EXIT ' if 0, string complete
SEROUT SOut, Baud, tmpW3 ' send the byte
INC tmpW1 ' point to next character
LOOP
ENDSUB
This subroutine expects two parameters: the base address and the character offset of the string. The subroutine uses a word variable to accept the base+offset string pointer that is passed as a parameter. When a literal string or DATA label is specified as the TX_STR parameter, the compiler inserts the appropriate values that form a pointer to the string. Using the subroutine above strings can be transmitted like this:
TX_STR SUB 2 ' strings use two parameters
' -------------------------------------------------------------------------
Main:
TX_STR "Version " ' inline string (compiles to z-string)
TX_STR VerNum
END
' -------------------------------------------------------------------------
VerNum:
DATA "1.0", 0 ' defined z-string
Note that when using a label as a subroutine parameter it must be defined before use, and the SX/B compiler adds the terminating zero to inline strings when there are two are more characters. If the following syntax is used:
TX_STR "X" ' character passed by value
an error will be raised as single characters are passed by value (one parameter), not by string pointer reference (two parameters). The solution is to create a subroutine for sending a single character that is also used by the TX_STR subroutine. See the examples page for details.
--------------------------------------------------------------------------------
Related instructions: DATA/WDATA and LOOKUP
READ | READINC Examples
READ | READINCBase {+ Offset}, Variable {, Variable, ...}
Function
Read one or more bytes from a table.
Base is the base address of data to be read which may be specified as a DATA or WDATA statement label, or as a string-pointer variable created by the compiler (see below).
Offset is an optional variable indicating the relative position (to Base) for the READ operation. This may be specified when Base is a label, or can be created by the compiler when strings are used (see below).
Variable is a byte or word variable.
Explanation
The DATA directive can be used to create [read-only] tables for SX/B programs. The READ instruction is used to move one or more table values into the specified byte variable(s)
If READINC is used, the Offset wil be automatically incremented to to point to the next DATA item. If Offset is not used the Base will be incremented.
Start:
OUTPUT RB
Main:
FOR idx = 0 TO 3
READ Pattern + idx, RB ' move pattern to LEDs
PAUSE 100
NEXT idx
FOR idx = 4 TO 1 STEP -1
READ Pattern + idx, RB
PAUSE 100
NEXT idx
GOTO Main ' do it again
' -------------------------------------------------------------------------
Pattern: ' LED patterns
DATA %00000000
DATA %00011000
DATA %00111100
DATA %01111110
DATA %11111111
As of version 1.4, SX/B can handle inline strings (of two or more characters) and z-strings (of any length) stored in DATA statements. Using READ, the following subroutine will send a string to a defined serial port:
' Use: TX_STR [ string | label ]
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
SUB TX_STR
tmpW1 = __WPARAM12 ' get offset/base
DO
READ tmpW1, tmpW3 ' read a character
IF tmpW3 = 0 THEN EXIT ' if 0, string complete
SEROUT SOut, Baud, tmpW3 ' send the byte
INC tmpW1 ' point to next character
LOOP
ENDSUB
This subroutine expects two parameters: the base address and the character offset of the string. The subroutine uses a word variable to accept the base+offset string pointer that is passed as a parameter. When a literal string or DATA label is specified as the TX_STR parameter, the compiler inserts the appropriate values that form a pointer to the string. Using the subroutine above strings can be transmitted like this:
TX_STR SUB 2 ' strings use two parameters
' -------------------------------------------------------------------------
Main:
TX_STR "Version " ' inline string (compiles to z-string)
TX_STR VerNum
END
' -------------------------------------------------------------------------
VerNum:
DATA "1.0", 0 ' defined z-string
Note that when using a label as a subroutine parameter it must be defined before use, and the SX/B compiler adds the terminating zero to inline strings when there are two are more characters. If the following syntax is used:
TX_STR "X" ' character passed by value
an error will be raised as single characters are passed by value (one parameter), not by string pointer reference (two parameters). The solution is to create a subroutine for sending a single character that is also used by the TX_STR subroutine. See the examples page for details.
--------------------------------------------------------------------------------
Related instructions: DATA/WDATA and LOOKUP
Below is an excerpt from the Parallax SX HELP page for READ and READINC (e.g. READ with increment):
READ | READINC Examples
READ | READINCBase {+ Offset}, Variable {, Variable, ...}
Function
Read one or more bytes from a table.
Base is the base address of data to be read which may be specified as a DATA or WDATA statement label, or as a string-pointer variable created by the compiler (see below).
Offset is an optional variable indicating the relative position (to Base) for the READ operation. This may be specified when Base is a label, or can be created by the compiler when strings are used (see below).
Variable is a byte or word variable.
Explanation
The DATA directive can be used to create [read-only] tables for SX/B programs. The READ instruction is used to move one or more table values into the specified byte variable(s)
If READINC is used, the Offset wil be automatically incremented to to point to the next DATA item. If Offset is not used the Base will be incremented.
Start:
OUTPUT RB
Main:
FOR idx = 0 TO 3
READ Pattern + idx, RB ' move pattern to LEDs
PAUSE 100
NEXT idx
FOR idx = 4 TO 1 STEP -1
READ Pattern + idx, RB
PAUSE 100
NEXT idx
GOTO Main ' do it again
' -------------------------------------------------------------------------
Pattern: ' LED patterns
DATA %00000000
DATA %00011000
DATA %00111100
DATA %01111110
DATA %11111111
As of version 1.4, SX/B can handle inline strings (of two or more characters) and z-strings (of any length) stored in DATA statements. Using READ, the following subroutine will send a string to a defined serial port:
' Use: TX_STR [ string | label ]
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
SUB TX_STR
tmpW1 = __WPARAM12 ' get offset/base
DO
READ tmpW1, tmpW3 ' read a character
IF tmpW3 = 0 THEN EXIT ' if 0, string complete
SEROUT SOut, Baud, tmpW3 ' send the byte
INC tmpW1 ' point to next character
LOOP
ENDSUB
This subroutine expects two parameters: the base address and the character offset of the string. The subroutine uses a word variable to accept the base+offset string pointer that is passed as a parameter. When a literal string or DATA label is specified as the TX_STR parameter, the compiler inserts the appropriate values that form a pointer to the string. Using the subroutine above strings can be transmitted like this:
TX_STR SUB 2 ' strings use two parameters
' -------------------------------------------------------------------------
Main:
TX_STR "Version " ' inline string (compiles to z-string)
TX_STR VerNum
END
' -------------------------------------------------------------------------
VerNum:
DATA "1.0", 0 ' defined z-string
Note that when using a label as a subroutine parameter it must be defined before use, and the SX/B compiler adds the terminating zero to inline strings when there are two are more characters. If the following syntax is used:
TX_STR "X" ' character passed by value
an error will be raised as single characters are passed by value (one parameter), not by string pointer reference (two parameters). The solution is to create a subroutine for sending a single character that is also used by the TX_STR subroutine. See the examples page for details.
--------------------------------------------------------------------------------
Related instructions: DATA/WDATA and LOOKUP
READ | READINC Examples
READ | READINCBase {+ Offset}, Variable {, Variable, ...}
Function
Read one or more bytes from a table.
Base is the base address of data to be read which may be specified as a DATA or WDATA statement label, or as a string-pointer variable created by the compiler (see below).
Offset is an optional variable indicating the relative position (to Base) for the READ operation. This may be specified when Base is a label, or can be created by the compiler when strings are used (see below).
Variable is a byte or word variable.
Explanation
The DATA directive can be used to create [read-only] tables for SX/B programs. The READ instruction is used to move one or more table values into the specified byte variable(s)
If READINC is used, the Offset wil be automatically incremented to to point to the next DATA item. If Offset is not used the Base will be incremented.
Start:
OUTPUT RB
Main:
FOR idx = 0 TO 3
READ Pattern + idx, RB ' move pattern to LEDs
PAUSE 100
NEXT idx
FOR idx = 4 TO 1 STEP -1
READ Pattern + idx, RB
PAUSE 100
NEXT idx
GOTO Main ' do it again
' -------------------------------------------------------------------------
Pattern: ' LED patterns
DATA %00000000
DATA %00011000
DATA %00111100
DATA %01111110
DATA %11111111
As of version 1.4, SX/B can handle inline strings (of two or more characters) and z-strings (of any length) stored in DATA statements. Using READ, the following subroutine will send a string to a defined serial port:
' Use: TX_STR [ string | label ]
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
SUB TX_STR
tmpW1 = __WPARAM12 ' get offset/base
DO
READ tmpW1, tmpW3 ' read a character
IF tmpW3 = 0 THEN EXIT ' if 0, string complete
SEROUT SOut, Baud, tmpW3 ' send the byte
INC tmpW1 ' point to next character
LOOP
ENDSUB
This subroutine expects two parameters: the base address and the character offset of the string. The subroutine uses a word variable to accept the base+offset string pointer that is passed as a parameter. When a literal string or DATA label is specified as the TX_STR parameter, the compiler inserts the appropriate values that form a pointer to the string. Using the subroutine above strings can be transmitted like this:
TX_STR SUB 2 ' strings use two parameters
' -------------------------------------------------------------------------
Main:
TX_STR "Version " ' inline string (compiles to z-string)
TX_STR VerNum
END
' -------------------------------------------------------------------------
VerNum:
DATA "1.0", 0 ' defined z-string
Note that when using a label as a subroutine parameter it must be defined before use, and the SX/B compiler adds the terminating zero to inline strings when there are two are more characters. If the following syntax is used:
TX_STR "X" ' character passed by value
an error will be raised as single characters are passed by value (one parameter), not by string pointer reference (two parameters). The solution is to create a subroutine for sending a single character that is also used by the TX_STR subroutine. See the examples page for details.
--------------------------------------------------------------------------------
Related instructions: DATA/WDATA and LOOKUP
Here is a link for the Parallax online reference set for SX/B:
http://forums.parallax.com/forums/attach.aspx?a=14085
On page 51, you will see DATA and WDATA commands listed which work hand in hand with READ / READINC commands.
http://forums.parallax.com/forums/attach.aspx?a=14085
On page 51, you will see DATA and WDATA commands listed which work hand in hand with READ / READINC commands.
-
- Posts: 158
- Joined: 24 May 2008 15:55
- Location: Germany
Thank you and I have found this out already. For example code written for the Parallax SX28 chip like this (blue) and into the MikroBasic Pro (red):
pos VAR Byte
data_bit VAR Byte
fig_R2A:
DATA %01000100, %10001000, %00110100, %10000001, %11000010, %00011000, %00100010, %00010001
for pos = 1 to 8
READ fig_R2A + pos, data_bit
next pos
dim pos, data_bit as byte
const fig_R2A as byte[8] = (%01000100, %10001000, %00110100, %10000001, %11000010, %00011000, %00100010, %00010001)
for pos = 1 to 8
data_bit = fig_R2A[pos]
next
pos VAR Byte
data_bit VAR Byte
fig_R2A:
DATA %01000100, %10001000, %00110100, %10000001, %11000010, %00011000, %00100010, %00010001
for pos = 1 to 8
READ fig_R2A + pos, data_bit
next pos
dim pos, data_bit as byte
const fig_R2A as byte[8] = (%01000100, %10001000, %00110100, %10000001, %11000010, %00011000, %00100010, %00010001)
for pos = 1 to 8
data_bit = fig_R2A[pos]
next
Using the previous post as a guide line, how would I convert the following SX/B code into MikroBasic Pro code:
hold_reg VAR Byte
alpha VAR Byte
message:
DATA "PJ ALLEN"
DATA "0134 @#$"
DATA "TGILMORE"
DATA "5678:.&Z"
for alpha = 0 to 7
READ message + alpha, hold_reg
next alpha
When I try to do something like this under MikroBasic Pro, it says it is not correct or invalid.
dim hold_reg, alpha as byte
const message as byte[32]=("PJ ALLEN01234@#$TGILMORE5678:.&Z")
for alpha = 0 to 31
hold_reg = message(alpha)
next alpha
How can I do something like this?
hold_reg VAR Byte
alpha VAR Byte
message:
DATA "PJ ALLEN"
DATA "0134 @#$"
DATA "TGILMORE"
DATA "5678:.&Z"
for alpha = 0 to 7
READ message + alpha, hold_reg
next alpha
When I try to do something like this under MikroBasic Pro, it says it is not correct or invalid.
dim hold_reg, alpha as byte
const message as byte[32]=("PJ ALLEN01234@#$TGILMORE5678:.&Z")
for alpha = 0 to 31
hold_reg = message(alpha)
next alpha
How can I do something like this?