Cubloc executes BASIC first. To enable Ladder Logic, use the command Set Ladder On.
Set Ladder On ' If using only BASIC, don't use this statement
If you do not need to use BASIC, you can program in Ladder Logic alone. But you will need a few lines of BASIC to get started, as shown below:
Const Device = CB280 ' Select device UsePin 0,In,START ' Declare pins to use UsePin 1,Out,RELAY Alias M0 = MOTORSTATE ' Set Aliases Alias M1 = RELAY1STATE Set Ladder On ' Start Ladder.
Device model, aliases, and pin I/O mode must be set in BASIC. Ladder
Logic must be started in BASIC with the Set Ladder On
statement.
The Cubloc has separate BASIC and Ladder Logic data memory areas.
Ladder Logic data memory can be accessed from BASIC easily by using system variables. Using these system variables, data can be easily read from or written to Ladder Logic data memory.
System Variable (Array) | Access Units | Ladder Logic Register |
---|---|---|
_P | Bits _P(0) to _P(127) | P Register |
_M | Bits _M(0) to _M(511) | M Register |
_WP | Words _WP(0) to _WP(7) | P Register (Word, Integer Access) |
_WM | Words _WM(0) to _WM(31) | M Register (Word, Integer Access) |
_T | Words _T(0) to _T(99) | T Register (Timer) |
_C | Words _C(0) to _C(49) | C Register (Counter) |
_D | Words _D(0) to _D(99) | D Register (Data) |
_A | Double-Words _A(0) to _A(49) | D Register (Floating Point, Single Access) |
_B | Double-Words _B(0) to _B(49) | D Register (Double-Word, Long Access) |
Registers P and M can be accessed in units of bits, and registers C, T, and D
can be accessed in units of words.
To access P and M registers in units of
words, use _WP
and _WD
. For example, _WP(0)
represents P0 through P15.
To access the D region in units of 32-bit floating point (i.e. Single
) use _A
. For example _A(0)
represents D0 through D1.
To access the D region in units of 32-bit integers (i.e. Long
) use _B
. For example _B(0)
represents D0 through D1.
The following is an example program :
_D(0) = 1234 _D(1) = 3456 _D(2) = 100 For I = 0 TO 99 _M(I) = 0 Next IF _P(3) = 1 Then _M(127) = 1
Accessing BASIC variables from Ladder Logic is not possible, but you can use Ladder interrupts to request a BASIC routine to change a Ladder Logic variable.
If the data stored in the D area is of floating point type (i.e. Single
), use _A
instead of _D
.
Do Delay 1000 Debug Float _A(1),Cr Loop
The Single
type is 32 bits, so it requires two D registers.
_A(0)
is D0 and D1.
_A(1)
is D2 and D3.