The device being used must be declared before using BASIC or Ladder Logic. Below is an example of declaring the CUBLOC CB220 module.
Const Device = CB220 ' Use CB220.
This should be the first line of a program. When this command is not used, the CB220 model will be assumed.
Const Device = CB400 ' Use CB400. Const Device = CB280 ' Use CB280.
CUBLOC BASIC supports functions and subroutines.
The user is able to create subroutines and functions to organize their programs. Using subroutines and functions allows the user to reuse code, and organize programs for better readability.
Function SUM( A As Integer, B As Integer) As Integer Dim RES As Integer RES = A + B SUM = RES End Function
Calculations can be done within conditional statements such as If, While, etc…
A graphic LCD library is provided.
CUBLOC provides a complete graphic LCD library for the Comfile GHLCD, CUTOUCH product. Boxes, lines, circles, and other graphics commands are easily implemented in a few lines of code.
Various Communication Protocols are supported.
CUNET(I2C) : Display peripherals such as character LCDs RS232C : up to 4 channels MODBUS : built-in slave functions I2C : I2C commands supported (I2CRead I2CWrite) SPI : SPI commands supported (ShiftIn, ShiftOut) PAD: Keypad, touchpad supported.
Below is an example of a simple BASIC program with a Do…Loop statement.
Dim A As Byte Do ByteOut 0, A A=A+1 Loop
This program outputs the increasing binary value of A to Ports P0-P7. The next program uses a function to accomplish the same task:
Dim A As Byte Do ByteOut 0, A A=ADD_VALUE(A) Loop End Function ADD_VALUE(B As Byte) As Byte ADD_VALUE = B + 1 End Function
By placing A=A+1 in a function, the user will be able to separate one big program into small manageable pieces. As you can see here, the main program ends at the End command, and functions are added afterwards.