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 |
|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 Access)|
|_WM||Words _WM(0) to _WM(31)||M Register (Word 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)|
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.
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.