User Manual Version 07/07 E BA001 ProgRef C-Control I Programmer´s Reference UNIT-M 2.0 UNIT-M Advanced Station 2.0 Station Advanced Best.- Nr.: 19 88 22 Best.- Nr.: 19 88 05 Best.-Nr..: 19 88 63 Best.-Nr.: 19 72 39 Please check at Hwww.c-control-support.
Content INTRODUCTION ................................................................................................................................................4 ABOUT C-CONTROL...............................................................................................................................4 ABOUT BASIC++ .....................................................................................................................................4 ABOUT THIS DOCUMENT ................................
FLOAT ....................................................................................................................................................32 INT..........................................................................................................................................................33 LOOPS WITH FLOAT VARIABLES .................................................................................................................35 FUNCTIONS WITH PARAMETERS...........................
INTRODUCTION ABOUT C-CONTROL Small microcontrollers can everywhere be found. They mostly are programmed in assembly language which requires a deep knowledge in this language and processor architectures. The manual for the controller counts most times some hundred pages and is hard to understand. To learn the assembly language you additionally have to study books about. BASIC++ is the language to program these microcontrollers without special knowledge.
Variable= (SQR(value*value)) MOD value2 This is legal when the result of the term matches the mentioned type Additional to the Syntax description an example is shown. Please note that the required definitions are not mentioned on samples trougout the document. Definiton: DEFINE MyWord as word DEFINE MyByte1 as byte DEFINE MyByte2 as byte Example: MyWord=MyByte1 MOD MyByte2 DECLARATIONS AND DEFINITIONS Variables and Port registers are memory locations in the controller.
will result in global variables. More can be found in the chapter „Functions“. Prior to use a variable has do be declared otherwise an error message will occur at compilation. BYTE Variables Byte (value 0 ... 255) is the smallest numeric data type, ocupies 1 Byte = 8 Bit define MyByte as byte WORD Variables Word (value -32768 ... 32767) this data type occupies 2 Byte = 16 Bit define MyWord as word FLOAT Variables While the C-Control M 2.
ON OFF boolean true (numerical 255 at byte values and -1 at word values) boolean false(numerical 0 for byte and word values) EXTERNAL FILES IMPORT The Import keyword causes the compiler to insert external files (Basic Code, Tables, ...) during compilation. This is great for complex programs and makes your source code better readable. Any File with any extension is insertet, but must of course be a BASIC Source code or table, readable by the compiler. Syntax: Import [Datei] IMPORT "\MYFILE.
RXD/TXD The serial interface (RXD=input TXD=output) is designed for 5V digital logic level, You never must connect a RS232 interface directly to this ports. This would immediately result in permanent damage to the C-Control Computer RXD and TXD are predefined. No user definition has to be done STANDARD DIGITAL I/O PORTS The C-Control Computer provides two standard byteports (16 bitports, P1 to P16). Each bitport can be used as input or output port.
Interface and the ports can not be used freely any more. RF INTERFACE (PORT 2 and 3) Any usage of the RF Functions (see chapter RF OBJECT) will occupy this ports to work as special coded RF Interface and the ports can not be used freely any more. EXTENDED PORTS The Extended Ports are not really property of the Unit M 2.0 but they are treated this way by the Operating System. Therefore a connected IIC-Bus PCF8574 Digital Ports circuit can be accessed in the same simple way as the standard ports.
ANALOGPORTS The C-Control Computer offers eight A/D ports and two D/A-ports (witch servo drive capabilities as alternate function). The maximum input conversion range of the A/D-converters is fixed by the applied reference voltage. The maximum output voltage of the D/A-converters is independent of the reference voltage and always as high (and accurate) as the operating voltage.
Syntax: Beep Tone, duration, BEEP 10,100,20 pause Tone The Tone audio frequency has to be defined. The value may be inthe range from 1 to app. 60. Values higher than 100 are possible but don't cause much difference in frequency. Duration Duration in 20ms steps duration in ms * 20 Pause Pause after the tone in 20ms steps RTC Real Time Clock (RTC) provides the user with the system time.
Example for request counter IF FREQ1 = 10000 THEN GOTO X MyWord=FREQ/100 EVENT COUNTING In mode event counting FREQ is a read/write value. For Instruction to switch the mode please see the chapter CONFIG REGISTER IF FREQ1 = 10000 THEN GOTO X Example for request FREQ1 MyWord=FREQ/100 FREQ1 = 0 Example for set FREQ1 INSTRUCTIONS AND KEYWORDS INPUT/OUTPUT Some of the available Input/output instructions can be redirected form the (default) serial interface to the Objects LCD,CONFIG,IIC,RF or IR.
arguments with a single"Print" instruction you may use the concatenation operator & The Print instruction is also applicable to the LCD Objekt and the IIC Object. See the Chapter OBJECTS for reference. Printing the character # is illegal because this character is internal used to precede a Control Sequence Syntax: Print Argument [ & Argument [ & ...
Example for request FILEFREE IF FILEFREE = 0 THEN GOTO X EOF EOF contains the boolean value if the last position of a previously created data file is reached when reading. EOF is true (-1) if end of file is reached or false (0) if not In principle it is a compare of the current datapointer and the the saved pointer (done with CLOSE#) Example for request EOF IF EOF THEN GOTO X EEPROM.WRITE EEPROM.APPEND EEPROM.
STANDARD DIGITAL PORTS After reset all ports are usually Inputs. please note that some options my change this (See Chapter CONFIG REGISTER).
EXTENDED PORTS Extended Ports are handled in the same manner as the standard digital ports, except the fact that PULSE and TOG are not applicable.
ABS The ABS function returns absolute value of a word or byte size value. It works for bytes but usually it makes no sense because byte values are unsigned MyWord=ABS(MyWord) Syntax: Variable = ABS(value1) Variable: Variable of Byte oder Word type value1: Variable, value oder constant of Byte oder Word type SGN The SGN function returns 1 if the value is >0 and -1 if the value is <0.
MATH AND BOOLEAN OPERATORS For Floatingpoint Operators (Unit ADVANCED only) see Chapter FOATING POINT MODULE When computing terms with operators and functions the rank in hierarchy is most important.
MyWord=MyByte1 MOD MyByte2 Syntax: Variable = value1 AND value2 Variable: Variable of Byte oder Word type value1 Variable, value oder constant of Byte oder Word type value2 Variable, value oder constant of Byte oder Word type Using ths operators with IF then, they behave like a function call that accepts two parametres and returns either True or False.
To create a simple program loop, you should use DO LOOP UNTIL. The loop is executed at least one time and may be quit early with Exit Do. The Until instruction at the end of the loop checks the expression to be True or False. True will cause to exit the loop. The Exit Do can only be used within a Do...Loop control structure to provide an alternate way to exit a Do...Loop. Any number of Exit Do statements may be placed anywhere in the Do...Loop.
SELECT CASE statements can be nested. Each nested SELECT CASE statement must have a matching END SELECT statement. SELECT CASE i CASE 1 Select Case matchexpression [Case expression] [instructions] [Case Else expression] [elseinstructions] End Select PRINT "1" CASE 2 PRINT "2" CASE ELSE PRINT "No Match" END SELECT WAIT The Wait instructionis used as level-sensitive control. The processor waits when the expressions is False. When the expression is True, the statement is executed.
Expression Optional. Term, variable, value or constant as return value OBJECTS The Config Object is introduced together with the newer generation of the C-Control computers and is part of the Extended Functions. For any access to Objects belonging to the Extended Functions it is required to activate the Object prior to any read/write action. Because only one Object may be active at the same time it is required to cose the object before activating another Object.
Syntax: OBJECT.instruction CONFIG.INIT The Example shows how to read/write a special bit to set up a configuration (here: PWM DACs to SERVO MODE) CONFIG.GET MyByte MyByte = MyByte OR 00000001b CONFIG.PUT MyByte CONFIG.OFF I²C-BUS OBJECT The IIC Object supports all basic functions to design I²C-Bus driver programs in an very easy manner. The I²C-Bus is connected to PORT 9 (SDA) und PORT 10 (SCL). An I²C-BUS error flag can be accessed at the CONFIG 1 register.
IR OBJECT The IR Object supports all basic functions for infrared communication (based on the RC5 format) in an very easy manner. The IR Receiver/Transmitter connected to PORT 2 (RX) und PORT 3 (TX). The RC5 data format consists of a device address and a data byte reveived from (or transmitted to) a IR remote device. Even Word sized values are accepted, IR.SEND/GET will transfer 6 bytes for command and 6 bytes for address and Toggle.
RF OBJECT The RF Object supports all basic functions for RF communication (based on the HT12 format) in an very easy manner. The RF Receiver/Transmitter connected to PORT 2 (RX) und PORT 3 (TX). The HT12 data format consists of a device address and a data byte reveived from (or transmitted to) a FT12 remote device. Even Word sized values are accepted, RF.SEND/GET will transfer 4 bytes for command and 8 bytes for address.
LCD OBJECT One of the mostly used features is the direct print to LCD function. The LCD must be initialised with LCD.INIT once prior tu use. As this is a true initialisation of the LCD onboard controller it takes app. 20ms. Once the LCD is ititialised, LCD INIT switchonly is recommended I Due to technical reasons you must not use the "#" Character when writing to the LCD. LCD.INIT The LCD must be initialised with LCD.INIT once prior tu use.
START OPTION REGISTER Both Units M 2.0 and ADVANCED feature a Start Option. Here a Hardware Option can be set at a non volatile register. This may not be confused with the CONFIG REGISTER what sets an option at runtime and keeps this options only until next reset. One the Start Option is activated it is maintained (even after reset) until the corresponding bit in the register has been cleared. The Start Option Register has following functions, switched to ON if the corresponding bit is set.
While downloading the program size and progress of written bytes is shown at the LCD. BAS: XXXX BYTES WRITING: XXX The download is finished when the corresponding message is shown at the LCD. The Chipcard is ready to be used as boot device. BAS: XXXX BYTES WRITING: XXX To aktive/deactivate the Boot Option run the programs run the dedicated programs, located in the folder START OPTION Please note that the Unit M 2.0 and M ADVANCED need different files to deactivate the boot option.
DETAILS OF THE DATA TYPE FLOAT Internal organisation While the C-Control usually has just BYTE and WORD Types, even for non professionals easy to handle, now there is the new Data Type Float. It consists on one byte exponent and 3 byte mantissa with sign. Therefore a floating point value occupies 4 bytes (32 bit). Value size The flaoting point Module is able to compute values in the range of +-1 × 10±38.
To avoid annoing wrong results or even crashes split your computation into small termes, what makes the code better readable too. Stack overflow will cause wrong results and even a crash or other unpredictable behaviour of the CControl FLOATING POINT INPUT/OUTPUT It is important to instruct the compiler that float values will have to be compiled. This is done with the compiler instruction "OPTION FLOAT" , located the beginning of your program file.
valid. All inputs may appear different when they will be shown on LCD or printed. This is caused by internal formatting, but of course does not change the value itself. OUTPUT Output ot terminal or LCD is controlled by the Object that is active. All examples for the Unit ADVANCED write to LCD Outputformat: Values larger than 1: For output in decimal there are 7 digits available which are distributed to be located before and after the decimal point.
LCD.PRINT MyVar & "VOLT" Note: It is not possible to print a term of float variables like PRINT (MyVar1*MyVar2). It alway has to be a float variable like this print example: PRINT(MyVar) Examples: option float define FV1 as float define FV2 as float LCD.INIT '--------------------------------------------------------------------------- ------------------------FV1=exp(1.23456789,4) '1.23456789E04 '---------------------------------------------------------------------------- -----------------------FV2=12345.
Mixed Data Types as below shown are not supported: MyFloat = MyFloat*FLOAT(MyWord)*MyWord Will lead to wrong results MyFloat = MyWord Will lead to stackerrrors and related trouble INT Conversion of a FlOAT varaiable to INTEGER/BYTE Type Here it is not possible to convert a Term. There always only a variable can be converted.
option float define LIGHT as port[16] define WV1 as word define WV2 as word define FV1 as float define FRESULT as float define IRESULT as word LIGHT=off LCD.INIT FV1=exp(1.23456789,4) '1.
Review the sample program 2_FP_CONVERSION LOOPS WITH FLOAT VARIABLES FOR TO NEXT loops will not work together with FP variables. This does not matter because it is possible to use DO LOOP UNTIL and here it is possible to create loops working with all valid floating point values. DO ..... .....
FUNCTIONS WITH PARAMETER RETURN A function also can return a float value if the return value is assigned to a help variable (in this example MyFunction) that is named equal to the function itself (here MyFunction) The help variable must dot be declared seperately. FUNCTION MyFunction(FVAL1 as FLOAT,FVAL2 as FLOAT) ....... MyFunction=FVAL1*FVAL2 ....... END FUNCTION '------------ FUNCTION AUFRUF MIT RÜCKGABE -----------------------FLOATVAR=MyFunction(10.9, 33.
DO VOLTS=FLOAT(ADC8)*0.0196 LCD.POS 1,1 LCD.PRINT VOLTS & "V " LOOP DO MILLIVOLT=98*ADC8/5 VOLT=MILLIVOLT/1000 NACHKOMMA=MILLIVOLT MOD 1000 LCD.POS 1,1 LCD.PRINT "ADC8: "& VOLT & "." if NACHKOMMA<100 then LCD.PRINT "0" LCD.PRINT NACHKOMMA & " V " LOOP Samples of some complexTerms MyFloat=MyFloat/FLOAT(ADC8*MyByte)*0.
ABS ABS calculates the absolute value of a terms or a variable MyFloat=ABS(FLOAT(ADC8*MyByte)*0.0196+MyFloat*MyFloat) MyFloat= ABS(FLOAT(MyWord-MyByte*MyWord))/ABS(MyFloat+MyFloat/5) COMPARES A compare is always related to two variables. Compares of constants or terms are not allowed. Valid compare operators are: <, >, =, <=, >= IF MyFloat1>MyFloat2 THEN..... IF FLOAT(MyWord) > MyFloat1 THEN...... LOOP UNTIL MyFloat1>MyFloat2 LOOP UNTIL FLOAT(MyWord) > MyFloat1 IF NOT(MyFloat1=MyFloat2) THEN.....
The FLOATING POINT MATH BASIC++ LIBRARY Not all floating point operations are done on operating system level. Some special operations are available as extension, and are executed as BASIC Code. The functions are provided at the FLOTMATH.BLIB and described here. The FLOATMATH.
EXP(MyFloatX,MyByteY) Calculates x power y based on continued multiplication and is full 32 bit accurate. EXP(MyFloat, Mybyte) EXP(12.345,3) EXP(MyFloat,3) The variable RESULT contains calculation result ----------------------------------------------------------------------------------------------TAN(x) (x=degrees) TAN is calculated with a SIN function and has an absolute error of 0.5 at 89°. At lower angles the accuracy increases rapidly. At 80° the calculation is accurate up to 3 digits.
2) The exponent must have two digits: 0.234E03 (not: E3) 3) After the decimal point one digit has to follow as a minimum 1234.0 (not:1234.) 4)The total entered number of characters (inclusive E , minus and decimal point) must be 15 characters maximum. Examples of valid inputs 0.0000000000001 1.1234567891234 123456789123456 123.12345678912 3456.7891234E09 -12345678.1E-12 12.3E12 -1234.56789E-01 The input is terminated when pressing the Button "E" (do not confuse with pressind F1 for character E ).
C-Control I in Internet http://www.c-control-support.net Impressum Diese Bedienungsanleitung wurde erstellt für Conrad Electronic SE, Klaus- Conrad- Straße 1, 92240 Hirschau/ Germany. Alle Rechte einschließlich Übersetzung vorbehalten. Reproduktionen jeder Art, z. B. Fotokopie, Mikroverfilmung, oder die Erfassung in elektronischen Datenverarbeitungsanlagen, bedürfen der schriftlichen Genehmigung der Autoren. Nachdruck, auch auszugsweise, verboten.