Table of Contents

Advertisement

Quick Links

C-Control Pro
Mega Series
© 2008 Conrad Electronic

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the C-Control Pro Mega Series and is the answer not in the manual?

Questions and answers

Summary of Contents for Conrad C-Control Pro Mega Series

  • Page 1 C-Control Pro Mega Series © 2008 Conrad Electronic...
  • Page 2: Table Of Contents

    C-Control Pro Mega Series Table of Contents Part 1 Important Notes 1 Introduction ...................................................... Reading this operating manual 3 Handling ........................... 4 Intended use ...................................................... Warranty and Liability ........................... Service 7 Open Source ........................... 8 History ........................... Part 2 Installation ...........................
  • Page 3 1.2 Preprocessor ........................... 1.3 Pragma Instructions ...................................................... Map File 2 CompactC ...................................................... Program 2.2 Instructions ........................... 2.3 Data Types ...................................................... Variables 2.5 Operators ........................... 2.6 Control Structures ........................... 2.7 Functions ...................................................... Tabellen © 2008 Conrad Electronic...
  • Page 4 C-Control Pro Mega Series 3 BASIC ...................................................... Program 3.2 Instructions ........................... 3.3 Data Types ...................................................... Variables 3.5 Operators ........................... 3.6 Control Structures ........................... 3.7 Functions ........................... 3.8 Tables ...................................................... ASCII Table Part 6 Libraries 1 Internal Functions ...........................
  • Page 5 11.3 LCD_CursorOn ........................... 11.4 LCD_CursorPos ........................... 11.5 LCD_Init ........................... 11.6 LCD_Locate ........................... 11.7 LCD_SubInit ........................... 11.8 LCD_TestBusy ........................... 11.9 LCD_WriteChar ........................... 11.10 LCD_WriteCTRRegister ........................... 11.11 LCD_WriteDataRegister ........................... 11.12 LCD_WriteFloat ........................... 11.13 LCD_WriteRegister ........................... 11.14 LCD_WriteText ........................... © 2008 Conrad Electronic...
  • Page 6 C-Control Pro Mega Series 11.15 LCD_WriteWord ........................... 12 Math ........................... 12.1 acos ........................... 12.2 asin ........................... 12.3 atan ........................... 12.4 ceil ........................... 12.5 cos ........................... 12.6 exp ........................... 12.7 fabs ........................... 12.8 floor ........................... 12.9 ........................... ldexp 12.10 ln ...........................
  • Page 7 19.1 Event Counter ........................... 19.2 ........................... Frequency Generation 19.3 ........................... Frequency Measurement 19.4 ........................... Pulse Width Modulation 19.5 ........................... Pulse & Period Measurement 19.6 Timer Functions ........................... 19.7 ........................... Timer_Disable 19.8 Timer_T0CNT ........................... 19.9 Timer_T0FRQ ........................... © 2008 Conrad Electronic...
  • Page 8 C-Control Pro Mega Series 19.10 Timer_T0GetCNT ........................... 19.11 ........................... Timer_T0PW 19.12 ........................... Timer_T0PWM 19.13 Timer_T0Start ........................... 19.14 Timer_T0Stop ........................... 19.15 ........................... Timer_T0Time 19.16 Timer_T1CNT ........................... 19.17 Timer_T1CNT_Int ........................... 19.18 Timer_T1FRQ ........................... 19.19 Timer_T1FRQX ........................... 19.20 Timer_T1GetCNT ........................... 19.21 ........................... Timer_T1GetPM 19.22...
  • Page 9 Inhalt VIII © 2008 Conrad Electronic...
  • Page 10 Part...
  • Page 11: Part 1 Important Notes

    In case of damages to material or personnel caused by improper handling or non-compliance to this operating manual the warranty claim will expire! We will further not take liability for consequential damages. © 2008 Conrad Electronic...
  • Page 12: Handling

    Item Technical Data in the attachment. Warranty and Liability For the C-Control Pro Unit Conrad Electronic grants a warranty period of 24 months from the date of billing. Within this time period faulty units will be replaced free of charge if the fault provable originates in faulty production or loss on goods in transit.
  • Page 13: Service

    Service Conrad Electronic provides you with a team of experienced service technicians. If you have any question with regard to our C-Control Pro Unit you can reach our Technical Service by letter, telefax or e-mail.
  • Page 14 C-Control Pro Mega Series · Editor supports code folding · Simple serial Terminal · Pulldownmenu to start your own programs (Tool Quickstart) · Syntaxhighlighting of all standard library functions · Configuration of Syntaxhighlighting · Extension of Select .. Case in BASIC ·...
  • Page 15 · New Function Thread_MemFree() · Additional EEPROM Routines for Word and Floating Point access · Time Measurement with Timer_TickCount() · #pragma Commands to create Errors or Warnings · Pre-defined Symbol in Pre-Prozessor: __DATE__, __TIME__ __FILE__, __FUNCTION__, __LINE__ © 2008 Conrad Electronic...
  • Page 16 C-Control Pro Mega Series · Version Number in Splashscreen · Extended Documentation · Interactive Graphics at "Jumper Application Board" in Help File · New Demo Programs · Ctrl-F1 starts Context Help Error Corrections · An Error is created if the Return Command is missing at the end of a function ·...
  • Page 17 Part...
  • Page 18: Part 2 Installation

    C-Control Pro Mega Series Installation In this chapter the installation of hardware and software is described. Applicationboard Important Note on Inserting/ Retrieving a Mega Module For the connection between Module and Application Board high quality connectors have been used in order to ensure intimate contacts. Mounting and dismounting of a Module should only take place during power-down condition (switched off voltage) since otherwise damages may occur to Application Board and/ or Module resp.
  • Page 19 Operating System or use only the serial connection to the Application Board. If the Application Board is connected for the first time then there will be no driver for the FTDI chip. The following window will then be shown under Windows XP. © 2008 Conrad Electronic...
  • Page 20 C-Control Pro Mega Series From here select "Install software from a list or other source" and click "Next".. © 2008 Conrad Electronic...
  • Page 21 Installation Then type in the path to the driver’s directory. If the software has been installed to "C:\Programs" it will be path "C:\Programs\C-Control-Pro\FTDI USB Driver". © 2008 Conrad Electronic...
  • Page 22: Software

    C-Control Pro Mega Series The message "C-Control Pro USB Device has not passed the Windows Logo Test .." will normally appear. This does not mean that the driver has failed during the Windows Logo Test. It merely means that the driver has not taken part in the (quite costly) Redmond Test.
  • Page 23 Part...
  • Page 24: Part 3 Hardware

    C-Control Pro Mega Series Hardware This chapter gives a description of the hardware coming into operation with the C-Control Pro series. The Modules C-Control Pro Mega32 and C-Control Pro Mega128 will be described. Further chapters will comment on construction and function of the accompanying application boards and LCD modules as well as the keyboard.
  • Page 25 Bootloader mode then the Bytecode (if available) is started in the Interpreter. This means that in case that the module is inserted into a hardware application the mere connection of the operating voltage will suffice to automatically start the user program. © 2008 Conrad Electronic...
  • Page 26: Lcd Matrix

    C-Control Pro Mega Series LCD Matrix The complete datasheets are on the CD-ROM in the directory "Datasheets". CHARACTER MODULE FONT TABLE (Standard font) Character modules with built in controllers and Character Generator (CG) ROM & RAM will display 96 ASCII and spe- cial characters in a dot matrix format.
  • Page 27: Module

    GND level, i. e. 0V. The reference voltage for the upper limit can be selected by the user: · 5V Operating Voltage (VCC) · Internal Reference Voltage of 2.56V · External Reference Voltage e. g. 4,096V generated by a Reference Voltage IC. © 2008 Conrad Electronic...
  • Page 28 C-Control Pro Mega Series If x is a digital measuring value then the corresponding voltage value u is computed as follows: u = x * Reference Voltage / 1024 Clock Generation Clock generation takes place by a 14.7456MHz Quartz Oscillator. All time dependent actions within the controller are derived from this clock frequency.
  • Page 29 Range of admissable ambient temperature 0°C … 70°C Range of admissable ambient relative humidity 20% … 60% Power Supply Range of admissable supply voltage 4,5V … 5,5V Power reqirement of the module without external appr. 20mA loads © 2008 Conrad Electronic...
  • Page 30: Application Board

    C-Control Pro Mega Series Clock Clock Frequency (Quartz Oscillator) 14.7456MHz Mechanics Overall measurements less pins, appr. 53 mm x 21mm x 8 mm Weight appr. 90g Pin pitch 2.54mm Number of pins (two rows) Distance between rows 15.24mm Ports Max. adimissable current from digital ports ±...
  • Page 31 With activating the PL (parallel load - KEY-E) input of the 74HC165 all 12 keyboard wires are transferred in the 74HC165 shift register. After that all information bits are latched to Q7 with triggering of CP (clock input - EXT-SCK). There they can be read with the EXT-Data Port. Since one © 2008 Conrad Electronic...
  • Page 32 C-Control Pro Mega Series 74HC165 holds only 8 Bit information, Q7 of the 1st 74HC165 is connected with DS of the 2nd 74HC165. I2C Interface Through this interface serial data can be transmitted at high speed. To do this only two signal lines are necessary.
  • Page 33 Note: Detailed information's can be found in the IC manufacturer’s PDF files on the C-Control Pro Software CD-ROM. All voltage specifications are referring to direct current (DC). Mechanics Overall measurements, appr. 160 mm x 100 mm Pin pitch wiring field 2.54 mm © 2008 Conrad Electronic...
  • Page 34: Pin Assignment

    C-Control Pro Mega Series Environmental Conditions Range of admissible ambient temperature 0°C … 70°C Range of admissible relative ambient humidity 20% … 60% Power Supply 8V … 24V Range of admissibly operating voltage Power consumption without external loads appr. 125mA Max.
  • Page 35: Jumper Application Board

    JP1 and JP2 These jumpers are assigned to push buttons SW1 and SW2. There is the possibility to operate the push button against both GND or VCC. In the basic setting the push buttons are switching to GND. © 2008 Conrad Electronic...
  • Page 36 C-Control Pro Mega Series Jumperpositions at delivery JP4 serves to toggle the operating voltage (Mains Plug-In Power Supply or USB). The application board should be operated using Plug-In Power Supply and voltage control (Shipping Condition). The maximum current to be drawn from the USB interface is lower than from the Plug-In Power Supply.
  • Page 37: Connection Diagrams

    Hardware 3.3.5 Connection Diagrams Additionally the connection diagrams can be found as PDF files on the Installation CD-ROM. 3.3.5.1 Mega 32 Modul © 2008 Conrad Electronic...
  • Page 38 C-Control Pro Mega Series 3.3.5.2 Applicationboard © 2008 Conrad Electronic...
  • Page 39 Hardware © 2008 Conrad Electronic...
  • Page 40 C-Control Pro Mega Series © 2008 Conrad Electronic...
  • Page 41 Hardware 3.3.5.3 Component Parts Plan © 2008 Conrad Electronic...
  • Page 42: Mega128

    C-Control Pro Mega Series Mega128 The Micro Controller Atmega128 originates from the AVR family by ATMEL. It is a low-power Micro Controller with Advanced RISC Architecture. In the following see a short summary of its hardware resources: · 133 Powerful Instructions – Most Single Clock Cycle Execution ·...
  • Page 43: Module

    The C-Control Pro 128 Module provides 128kB FLASH, 4kB EEPROM and 4kB SRAM. A supplementary EEPROM with an 8kB memory depth and an SRAM with a 64kB memory depth is mounted on the application board. The EEPROM can be addressed by an I2C interface. © 2008 Conrad Electronic...
  • Page 44 C-Control Pro Mega Series Note: Detailed information can be found in the IC manufacturer’s PDF files on the C-Control Pro Software CD-ROM. ADC Reference Voltage Generation The Micro Controller is equipped with an analog-to-digital converter with a 10 Bit resolution. This means that measured voltages can be represented by integral numbers from 0 through 1023.
  • Page 45 Range of admissible ambient temperature 0°C … 70°C Range of admissible relative ambient humidity 20% … 60% Power Supply Range of admissible operating voltage 4.5V … 5.5V Power consumption of the module without appr. 20mA external loads © 2008 Conrad Electronic...
  • Page 46: Application Board

    C-Control Pro Mega Series Clock Clock Frequency (Quartz Oscillator) 14.7456MHz Mechanics Overall measurements less pins, appr. 40 mm x 40mm x 8 mm Weight appr. 90g Pin pitch 2.54mm Number of pins (two rows) Ports Max. admissible current from digital ports ±...
  • Page 47 CP (clock input - EXT-SCK). There they can be read with the EXT-Data Port. Since one 74HC165 holds only 8 Bit information, Q7 of the 1st 74HC165 is connected with DS of the 2nd © 2008 Conrad Electronic...
  • Page 48 C-Control Pro Mega Series 74HC165. SRAM The application board holds an SRAM chip (K6X1008C2D) made by Samsung. By using this the available SRAM memory is extended to 64kByte. Mentioned SRAM uses Ports A, C and partly G for triggering. If the SRAM is not used then it can be de-activated by JP7 and then these ports become available to the user.
  • Page 49 Mechanics Overall measurements, appr. 160 mm x 100 mm 2.54 mm Pin pitch wiring field Environmental Conditions Range of admissible ambient temperature 0°C … 70°C 20% … 60% Range of admissible relative ambient humidity Power Supply © 2008 Conrad Electronic...
  • Page 50: Pin Assignment

    C-Control Pro Mega Series Range of admissibly operating voltage 8V … 24V Power consumption without external loads appr. 125mA Max. admissibly permanent current from a 200mA stabilized 5V power supply 3.4.3 Pin Assignment PortA through PortG are for direct pin functions (e. g. Port_WriteBit) counted from 0 through 52, see "PortBit".
  • Page 51: Jumper Application Board

    Pins PortE.0 and PortE.1. If the serial interface is not being used then the corresponding jumpers can be removed and these pins will then be available for other functions. Besides the port jumpers there are additional jumpers which are described in the following. © 2008 Conrad Electronic...
  • Page 52 C-Control Pro Mega Series Jumperpositionen im Auslieferzustand Ports A through G The ports available with the Mega128 Module are inscribed in this graph. Here the yellow side is connected to the module while the light blue side connects to the components of the application board.
  • Page 53: Connection Diagrams

    This Module has not been built. Inside the C-Control Pro 128 Module is working a Mega 128 processor, and not a AT90CAN128 like shown in this diagram. Therefore there is also no ATA6660 CAN-Bus Transceiver inside the C-Control Module. © 2008 Conrad Electronic...
  • Page 54 C-Control Pro Mega Series XTAL2 AREF XTAL1 22pF AVCC b0805j RESET b0805_spule 22pF b0805j 100nF b0805j schäffel electronic gmbh CANH CANL Project: MEGA128V2 VREF ATA6660 b0805j PCB-Design: MEGA128 MODUL 2/3 10mm Sheet 1 of 1 © 2008 Conrad Electronic...
  • Page 55 SRG8 KEY6 KEY5 G1[SHIFT] KEY3 C2[LOAD] b0805j KEY12 b0805j KEY3 KEY3 schäffel electronic gmbh KEY6 b0805j KEY9 Project: MEGA128app_V2 KEY6 KEY2 b0805j KEY9 PCB-Design: MEGA Appl.-Board b0805j KEY2 $plname 10mm 74HC165 Sheet 2 of 4 b0805j © 2008 Conrad Electronic...
  • Page 56 C-Control Pro Mega Series RES_FT b0805j SIWU b0805j b0805j RESET- 33pF 100nF 100nF b0805j b0805j b0805j XTAL1 XTAL2 33pF AVCC b0805j b0805j RESET RESET- AREF 100nF VUSB PWREN b0805j b0805j 100nF AGND MOSI b0805j MISO RES_FT 3V3OUT b0805j 33nF b0805j...
  • Page 57 Hardware 3.4.5.3 Component Parts Plan © 2008 Conrad Electronic...
  • Page 58 Part...
  • Page 59: Part 4 Ide

    In order to edit files as many editor windows as necessary can be opened. Compiler Messages Here error messages and general compiler informations are displayed C-Control Outputs Distribution of the CompactC program’s debug messages Variables Window Here monitored variables are displayed © 2008 Conrad Electronic...
  • Page 60: Projects

    C-Control Pro Mega Series Projects Every program for the C-Control Pro Module is configured through a project. The project states which source files and libraries are being utilized. Also the settings of the Compiler are noted. A project consists of the project file with the extension ".cprj" and the appropriate source files.
  • Page 61: Project Management

    Open Dialog will appear. Here the files to be added to the project can be selected. Any number of files can be selected. Alternative by use of Drag&Drop files from the Windows Explorer can be transferred into the project management. © 2008 Conrad Electronic...
  • Page 62: Thread Options

    C-Control Pro Mega Series Project Files When files have been added to the project these can be opened by a double mouse click onto the file name. By use of a right click further options will appear: · – The project file will move up the list (also with Ctrl - Arrow up).
  • Page 63 Cycle time is the number of cycles (Bytecode Operations) which a Thread can process before a change to another Thread takes place. By use of the number of Threads up to the Thread change also the priority of Threads is controlled. See also Threads. © 2008 Conrad Electronic...
  • Page 64: Project Options

    C-Control Pro Mega Series 4.1.5 Project Options For each project the compiler settings can be changed separately. The items Author, Version, Commentary can be freely inscribed. They serve as memory support in order to better remember the project details at a later date.
  • Page 65: Library Management

    – The selected entry in the list is replaced by the path name. · · Delete – The selected list entry is deleted. · Update Library – Files present in the Compiler Presetting but not in this list will be added. © 2008 Conrad Electronic...
  • Page 66: Editor

    C-Control Pro Mega Series Editor Several windows can be opened in the C-Control Pro Interface. Each window can be altered in size and displayed text detail. A double mouse click on the title line will maximize the window. A mouse click in the area to the left of the text will there set a Breakpoint. Prior to this the source text must be compiled error free with "Debug Info"...
  • Page 67 A click on the minus sign in the small box folds the text, so that only the first line of the function can be seen. Another click on the small plus sign, and the code unfolds again. © 2008 Conrad Electronic...
  • Page 68: Editor Functions

    C-Control Pro Mega Series To fold or unfold all functions in an editor file, the options Full Collapse Full Expand selectable in the right click editor pull-up menu. Syntactical Input Help The editor now has a syntactical input help. When the beginning of a reserved word or a function name from the standard library is typed into the editor, the input help can be activated with Ctrl- Space.
  • Page 69: Print Preview

    Pull-Down Menu: Print: Prints the indicated pages Print Preview: Shows a print preview Printer Setup: Choose the printer, paper size and orientation Page Setup: Header and Footer lines, line numbers and other parameters can be selected © 2008 Conrad Electronic...
  • Page 70: Keyboard Shortcuts

    C-Control Pro Mega Series 4.2.3 Keyboard Shortcuts Taste Funktion Left Move cursor left one char Right Move cursor right one char Move cursor up one line Down Move cursor down one line Ctrl + Left Move cursor left one word...
  • Page 71 Ctrl + O + K Normal selection mode Ctrl + O + C Column selection mode Ctrl + K + B Marks the beginning of a block Ctrl + K + K Marks the end of a block © 2008 Conrad Electronic...
  • Page 72: Regular Expressions

    C-Control Pro Mega Series Reset selection Ctrl + digit (0-9) Go to Bookmark digit (0-9) Shift + Ctrl + (0-9) Set Bookmark digit (0-9) Ctrl + Space Auto completion popup 4.2.4 Regular Expressions The search function in the editor supports Regular Expressions. With this function character chains can highly flexible be searched for and replaced.
  • Page 73: Start Program

    According to the pin assignments of M128 INT_0 is connected to the same pin as switch SW1. When SW1 is pressed during power-up of the Module this will activate the Serial Bootloader Mode and the program will not automatically be started. © 2008 Conrad Electronic...
  • Page 74: Outputs

    C-Control Pro Mega Series 4.3.2 Outputs For display of Debug messages there is an "Outputs" window section. Here is shown when the Bytecode Interpreter has been started and terminated and for how long (in milliseconds) the Interpreter was in operation. The operation time however is not very useful if the Interpreter has been stopped during Debug Mode.
  • Page 75: Version Check

    4.3.4 Version Check Since the C-Control Pro Mega Series supports various hardware platforms it is important to closely monitor the current version numbers of Bootloader, Interpreter and Hardware. This is possible by use of item Hardware Version in the C-Control menu.
  • Page 76: Breakpoints

    C-Control Pro Mega Series If in Debug Mode, the next Breakpoint will be reached by use of Start (F10). If no Breakpoint is set then the programm will be executed in its normal way. There is the exception however that the...
  • Page 77: Array Window

    On the left side the Array indices are shown while the contents are displayed on the right side. It should be noted that with multi-dimensional arrays the indices on the right will gain at the faster pace. © 2008 Conrad Electronic...
  • Page 78: Variable Watch Window

    C-Control Pro Mega Series The contents of an array window may at every stop of the Debugger or at every single step no longer be actual. If with each single step in the Debugger several array windows are newly brought up-to- date then delays may occur since the data must always be loaded from the Module.
  • Page 79 The contents of these variables will then only be displayed after the command Actualize Variable is executed. This way the Debugger can quickly be operated in single steps and the contents are only actualized on demand. © 2008 Conrad Electronic...
  • Page 80: Tools

    C-Control Pro Mega Series Variables of the Character type are displayed as single ASCII characters. Tools Terminal Window In the Tools pulldown menu a simple terminal program can be started. Received characters are directly shown in the terminal window. Characters can be send in two different ways.
  • Page 81: Options

    - Undo operation will not be performed in small steps but in blocks. · Group redo - If it is set Redo will involve group of changes. Keep caret in text - Allows move caret only into text like in Memo. © 2008 Conrad Electronic...
  • Page 82: Syntax Highlighting

    C-Control Pro Mega Series Double click line - Highlights the line when you double-click any character in the line. If disabled, only the selected word is highlighted. Fixed line height - Prevents line height calculation. Line height will be calculated by means of Default Style.
  • Page 83 Identifier: all names that are not reserved words or part of the library Reserved Word: alle reserved words of the destination language Comment: comments Preprocessor: preprocessor statements Marked Block: marked editor blocks © 2008 Conrad Electronic...
  • Page 84: Compiler Presetting

    C-Control Pro Mega Series Library: function names of the standard library Default, Line separator Sub background are not used. 4.6.3 Compiler Presetting In the Compiler Presetting the standard values can be configured which will be stored during creation of a new project. Presetting can be reached under Compiler in the Options menu.
  • Page 85: Ide Settings

    – When the C-Control Pro interface is started several times it may create conflicts with regard to the USB interface. Also here the lists of the "last opened projects" as well as the "last opened files" can be deleted. © 2008 Conrad Electronic...
  • Page 86 C-Control Pro Mega Series 4.6.4.1 Interfaces Through a selection box the connection to the application board can be set. USB connections will start with the prefix "USB" and will then be successively numbered: USB0, USB1, ... Serial interfaces will be handled equally. They will start with the prefix "COM": COM0, COM1, ..., aso.
  • Page 87 4.6.4.2 Internet Update In order to check if any improvements or error corrections have been issued by Conrad Electronic the Internet Update can be activated. When the selection box "Update Check Every Days" is selected then an update will be searched for in the Internet at an interval of days at every start of the IDE.
  • Page 88 C-Control Pro Mega Series 4.6.4.3 Terminal Here you can set the serial parameter for the built in terminal program. For the Port entry an available serial COM Port can be chosen from. Further the standard baudrates, the number of Data...
  • Page 89: Windows

    Side By Side – Will arrange the windows next to each other from left to right. · · Minimize All – Will minimize all windows to symbol size. · Close – Will close all active windows. © 2008 Conrad Electronic...
  • Page 90: Help

    "Version Information" and will at the same time copy the contents onto the clipboard. These informations are important if a Support E-Mail needs to be sent to Conrad Electronic. Since these informations are automatically placed onto the clipboard when...
  • Page 91 © 2008 Conrad Electronic...
  • Page 92 Part...
  • Page 93: Part 5 Compiler

    If a project consists of several sources then #define is a constant for all source files existing following the file, in which the constant has been defined. It is thus possible to change the order of source files in a project. © 2008 Conrad Electronic...
  • Page 94 C-Control Pro Mega Series Conditional Compiling #ifdef symbol #else // optional #endif It is possible to monitor which parts of the source texts are really being compiled. After a #ifdef symbol instruction the following text is only compiled when symbol...
  • Page 95: Pragma Instructions

    #endif 5.1.4 Map File If during compilation a Map File has been generated then the memory size of the used variable can there be ascertained. Example The project CNT0.cprj generates the following Map File during compilation: © 2008 Conrad Electronic...
  • Page 96: Compactc

    C-Control Pro Mega Series Global Variable Length Position (RAM Start) --------------------------------------------------------------- Total Length: bytes Local Variable Length Position (Stack relative) ----------------------------------------------------------------- Function Pulse() count Total Length: bytes Function main() count Total Length: bytes From this list can be seen that no global variables are being used. There are further the two functions "Pulse()"...
  • Page 97: Instructions

    There are two types of commentaries, which are the single line and the multi line commentaries. The text within commentaries is ignored by the Compiler. · Single line commentaries start with "//" and end up at the line’s end. © 2008 Conrad Electronic...
  • Page 98 C-Control Pro Mega Series · Multi line commentaries start with "/*" and end up with "*/". /* a multi line commentary */ // a single line commentary Identifier Identifier are the names of Functions Variables · Valid characters are letters (A-Z,a-z), numbers (0-9) and the low dash ('_') ·...
  • Page 99: Data Types

    (a is of type integer variable). In this case a is first converted into the data type float and then 5.5 is added. The data type of the result is also float. For data type conversion there are the following rules: © 2008 Conrad Electronic...
  • Page 100: Variables

    C-Control Pro Mega Series · If in a linkage of 8 Bit or 16 Bit integer values one of the two data types is sign afflicted ("signed") then the result of the expression is also sign afflicted. I. e. the operation is executed "signed".
  • Page 101 Additionally some space is needed for a terminating character (decimal Zero) inorder to indicate the end of the character string. Example for a character string with a 20 character maximum: char str1[21]; © 2008 Conrad Electronic...
  • Page 102 C-Control Pro Mega Series As an exception char arrays may have character strings assigned to. Here the character string is placed between quotation marks. str1="hallo world!"; Strings cannot be assigned to multi dimensional Char arrays. There are however tricks for advanced users: char str_array[3][40];...
  • Page 103: Operators

    Integer data type assigned to it. If a figure of data type float should be explicitly created then a decimal point has to be added: Operator Description Example Result Addition 3.2 + 4 Subtraction 2 - 3 22 - 1.1e1 © 2008 Conrad Electronic...
  • Page 104 C-Control Pro Mega Series Multiplication 5 * 4 Division 7 / 2 7.0 / 2 Modulo 15 % 4 17 % 2 Negative Sign -(2+2) 5.2.5.2 Bit Operators Bit operators are only allowed for Integer data types Operator Description Example Result &...
  • Page 105 Logical operators are only allowed for Integer data types. Any value unequal null is meant to be a logical Only null is valid as logical 0. Operator Description Example Result && logical And 1 && 1 5 && 0 logical Or 0 || 0 1 || 0 logical Not © 2008 Conrad Electronic...
  • Page 106: Control Structures

    C-Control Pro Mega Series 5.2.6 Control Structures Control structures allow to change the program completion depending on expressions, variables or external influences. 5.2.6.1 Conditional Valuation With a conditional valuation expressions can be generated which will be conditionally calculated. The form is:...
  • Page 107 It must be observed that variable i will within the loop run through values 0 through 9 rather than 1 through 10! If a loop needs to be programmed with a different step width Instruction2 needs to be modified accordingly: for(i=0;i<100;i=i+3) // variable i does now increment in steps to 3 a=5*i; © 2008 Conrad Electronic...
  • Page 108 C-Control Pro Mega Series break Instruction A break instruction will leave the loop and the program execution starts with the next instruction after the for loop. continue Instruction continue will immediately initialize a new calculation of the Expression. Depending on the result Instruction2 will be executed at unequal and the loop will repeat itself.
  • Page 109 Expression ) case constant_1: Instruction_1; break; case constant_2: Instruction_2; break; case constant_n: Instruction_n; break; default: // default is optional Instruction_0; The value of the Expression is calculated. Then the program execution will jump to the constant © 2008 Conrad Electronic...
  • Page 110 C-Control Pro Mega Series corresponding to the value of the Expression and will continue the program from there. If no constant corresponds to the value of the expression the switch construct will be left. If a default is defined within a switch instruction then the instructions after default will be executed if no constant corresponding to the value of the instruction has been found.
  • Page 111: Functions

    A program does in any case contain the function "main", which is started in first place. After that other functions can be called up. A simple example: void func1(void) // instructions in function func1 © 2008 Conrad Electronic...
  • Page 112 C-Control Pro Mega Series void main(void) // function func1 will be called up twice func1(); func1(); Parameter Passing In order to enable functions to be flexibly used they can be set up parametric. To do this the parameters for the function are separated by commas and passed in parenthesis after the function name.
  • Page 113: Tabellen

    Through parameter str in StringLength the contents of text can be changed since str is only the reference (pointer) to the array variable text. Presently arrays can only be passed "by Reference"! 5.2.8 Tabellen 5.2.8.1 Operator Precedence Rang Operator ++ -- ! (negatives Vorzeichen) © 2008 Conrad Electronic...
  • Page 114 C-Control Pro Mega Series << >> < <= > >= & && 5.2.8.2 Operators Arithmetische Operatoren Addition Subtraktion Multiplikation Division Modulo negatives Vorzeichen Vergleichsoperatoren < kleiner > größer <= kleiner gleich >= größer gleich gleich ungleich Bitschiebeoperatoren << um ein Bit nach links schieben >>...
  • Page 115 Oder Bitinvertierung 5.2.8.3 Reserved Words The following words are reserved and cannot be used as identifier: break byte case char continue default else false float goto return signed static switch true unsigned void while word © 2008 Conrad Electronic...
  • Page 116: Basic

    C-Control Pro Mega Series BASIC The second programming language for the C-Control Pro Mega Module is BASIC. The Compiler translates the BASIC commands into a Bytecode which is then processed by the C-Control Pro Interpreter. The language volume of the BASIC dialect used here corresponds to a large extent to the industry standard of the large software suppliers.
  • Page 117: Instructions

    · Valid characters are letters (A-Z,a-z), numbers (0-9) and the low dash ('_') · An identifier always starts with a letter · Upper and lower case writings are differentiated · are not allowed as identifiers Reserved Words © 2008 Conrad Electronic...
  • Page 118 C-Control Pro Mega Series · The length of an identifier is unlimited Arithmetic Expressions An arithmetic expression is a quantity of values connected by Operators. In this case quantities can either be Figures, Variables Functions A simple example: Here the numerical values are connected by the Operator "+".
  • Page 119: Data Types

    A variable definition appears as follows: Dim Variable Name As Type When several variables of the same type need to be defined then these variables can be stated separated by commas: Dim Name1, Name2, Name3 As Integer © 2008 Conrad Electronic...
  • Page 120 C-Control Pro Mega Series As types are allowed: Char, Byte, Integer, Word, Single Examples: Dim a As Integer Dim i,j As Integer Dim xyz As Single Integer variables may have decimal figure values or Hex values assigned to. With Hex values the characters "&H"...
  • Page 121 Dim Single_str(40) As Char Single_str="A String" Str_StrCopy(str_array,Single_str,40) // will copy Single_str in the second string This will work because with a gap of 40 characters after the first string there will in str_array be room for the second string. © 2008 Conrad Electronic...
  • Page 122 C-Control Pro Mega Series Visibility of Variables When variables are declared outside of functions then they will have global visibility. I. e. they can be addressed from every function. Variable declarations within functions produce local variables. Local variables can only be reached within the function. An example:...
  • Page 123: Operators

    Multiplication 5 * 4 Division 7 / 2 7.0 / 2 Modulo 15 % 4 17 % 2 Negative Sign -(2+2) 5.3.5.2 Bitoperators Bit operators are only allowed for Integer data types Operator Description Example Result © 2008 Conrad Electronic...
  • Page 124 C-Control Pro Mega Series &H0f And 3 &Hf0 And &H0f 1 Or 3 &Hf0 Or &H0f &Hff exclusive Or &Hff Xor &H0f &Hf0 &Hf0 Xor &H0f &Hff Bit inversion Not &Hff Not &Hf0 &H0f 5.3.5.3 Bit-Shift Operators Bit-Shift operators are only allowed for Integer data types. With a Bit-Shift operation a will always be moved into one end.
  • Page 125: Control Structures

    An Exit instruction will leave the loop and the program execution starts with the next instruction after the Do Loop While loop. Example: a=a+1 a>10 Then Exit ' Will terminate loop End If Loop While ' Endless loop © 2008 Conrad Electronic...
  • Page 126 C-Control Pro Mega Series 5.3.6.2 Do While With a while instruction the instructions can depending on a condition be repeated in a loop: Do While Expression Instructions End While At first the Expression is evaluated. If the result is unequal then the expression is executed.
  • Page 127 In order to mark a label the command word Lab is set in front of the label name. ' For loop with goto will realize Sub main() Dim a As Integer Lab label1 © 2008 Conrad Electronic...
  • Page 128 C-Control Pro Mega Series a=a+1 a<10 Then Goto label1 End If End Sub 5.3.6.5 If .. Else An If instruction does have the following syntax: If Expression1 Then Instructions1 ElseIf Expression2 Then Instructions2 Else Instructions3 End If After the if instruction an Arithmetic Expression will follow.
  • Page 129 Select Case construct will be left. If an Else is defined within a Select Case instruction then the instructions after Else will be executed if no constant comparison could be fulfilled. Example: Select Case Case b=b*2 Case = b=b+2 © 2008 Conrad Electronic...
  • Page 130: Functions

    C-Control Pro Mega Series Case &Hf b=b/c Case < 10 b=10 Case <= 10 b=11 Case 20 To 30 b=12 Case > 100 b=13 Case >= 100 b=14 Case <> 25 b=15 Else b=b+2 End Case In CompactC the instructions will be continued after a Case instruction until a break comes up or the switch instruction is left.
  • Page 131 Since it is not possible to pass on arrays as parameters the access to parameters is possible through references. For this the attribute "ByRef" is written ahead of the parameter name in the parameter declaration of a function. Sub StringLength(ByRef str As Char) As Integer Dim i As Integer © 2008 Conrad Electronic...
  • Page 132: Tables

    C-Control Pro Mega Series Do While str(i) i=i+1 ' Repeat character as long as unequal zero End While Return i End Sub Sub main() Dim Len As Integer Dim Text(15) As Char Text="hello world" Len=StringLength(Text) End Sub In main the reference of text is presented as parameters to the function StringLength. If in a function a normal parameter is changed then the change is not visible outside this function.
  • Page 133: Ascii Table

    The following words are reserved and cannot be used as identifiers: ByRef Byte Case Char Else ElseIf Exit False Goto Integer Loop Next Return Select Single SizeOf Static Step Then True While Word ASCII Table Char Char Char Char © 2008 Conrad Electronic...
  • Page 134 C-Control Pro Mega Series " & < > © 2008 Conrad Electronic...
  • Page 135 Compiler © 2008 Conrad Electronic...
  • Page 136 Part...
  • Page 137: Part 6 Libraries

    5000 cycles (default value) to the next thread, the next thread will begin after after about 5000 * 1000ms. This happens because an AbsDelay() call will be treated like on cycle. Parameter wait duration in milliseconds © 2008 Conrad Electronic...
  • Page 138: Analog-Comparator

    C-Control Pro Mega Series Analog-Comparator The Analog Comparator allows to compare two analog signals. The result of this comparison is returned as either "0" or "1". 6.3.1 AComp AComp Functions Example Syntax void AComp(byte mode); Sub AComp(mode As Byte); Description The Analog Comparator allows to compare two analog signals.
  • Page 139: Analog-Digital-Converter

    If x is a digital measuring value then the corresponding voltage value u is calculated as follows: u = x * Reference Voltage / 1024 If the external reference voltage e. g. produced by a reference voltage IC is 4.096V, then the © 2008 Conrad Electronic...
  • Page 140: Adc_Disable

    C-Control Pro Mega Series difference of one bit of the digitized measuring value corresponds to a voltage difference of 4mV, or: u = x * 0,004V Differential Inputs ADC22x10 Differential Inputs ADC2, ADC2, Gain 10 ; Offset Measurement ADC23x10 Differential Inputs ADC2, ADC3, Gain 10...
  • Page 141: Adc_Readint

    ADC0 to ADC7 can be measured against ground, or differentiation measurement with gain factor of 1/10/100 can be made. Return Parameter measured value of ADC-Port 6.4.4 ADC_Set ADC Functions Syntax word ADC_Set(byte v_ref,byte channel); Sub ADC_Set(v_ref As Byte,channel As Byte) As Word © 2008 Conrad Electronic...
  • Page 142: Adc_Setint

    C-Control Pro Mega Series Description The function ADC_Set initializes the Analog-Digital converter. The reference voltage and the measurement channel number is selected and the A/D converter is prepared for usage. After the measurement the value is read with ADC_Read(). Parameter (Port A.0 to A.7 at Mega32, Port F.0 to F.7 at Mega128)
  • Page 143: Adc_Startint

    BCD numbers, whereby in any case the least significant bit will be the start bit. Bits Meaning Start bit (in any case "1") 21 - 27 Minute Parity Minute 29 - 34 Hour © 2008 Conrad Electronic...
  • Page 144 C-Control Pro Mega Series Parity Hour 36 - 41 Day of the Month 42 - 44 Weekday 45 - 49 Month 50 - 57 Year Parity Date This signifies that reception must be in progress for at least one full minute before time information can be provided.
  • Page 145: Dcf_Frame

    3 ("d Parameter None 6.5.2 DCF_INIT DCF Functions Syntax void DCF_INIT(void); Sub DCF_INIT() Description DCF_INIT initializes DCF usage. The input of the DCF signal is adjusted. DCF_Mode is set to 0. Parameter None 6.5.3 DCF_PULS DCF Functions © 2008 Conrad Electronic...
  • Page 146: Dcf_Start

    C-Control Pro Mega Series Syntax void DCF_PULS(void); Sub DCF_PULS() Description ") DCF_Mode to 1 ("look for pulse Parameter None 6.5.4 DCF_START DCF Functions Syntax void DCF_START(void); Sub DCF_START() Description DCF_Mode to 1. From now on DCF time recording is DCF_START initializes all variables and sets working automatically.
  • Page 147: Debug

    ) generates a jump to the next line (linefeed). Parameter c output character 6.6.2 Msg_WriteFloat Debug Message Functions Syntax void Msg_WriteFloat(float val); Sub Msg_WriteFloat(val As Single) Description The passed floating point number is displayed with a preceding decimal sign. © 2008 Conrad Electronic...
  • Page 148: Msg_Writehex

    C-Control Pro Mega Series Parameter val float value 6.6.3 Msg_WriteHex Debug Message Functions Syntax void Msg_WriteHex(word val); Sub Msg_WriteHex(val As Word) Description The 16bit value is displayed in the output window. The Output is formatted as a hexadecimal value with 4 digits.
  • Page 149: Msg_Writetext

    The C-Control Pro Modules integrate M32:1kB resp. M128:4kB EEPROM. These library functions allow access to the EEPROM of the Interpreter. 32 Bytes of the EEPROM area are used for internal tasks and are thus not accessible. 6.7.1 EEPROM_Read EEPROM Functions Syntax © 2008 Conrad Electronic...
  • Page 150: Eeprom_Readword

    C-Control Pro Mega Series byte EEPROM_Read(word pos); Sub EEPROM_Read(pos As Word) As Byte Description Reads one byte out of the EEPROM at position pos. The first 32 byte are reserved for the OS of C-Control Pro. Therefore a pos value of 0 and higher accesses the EEPROM memory at position 32 and upwards.
  • Page 151: Eeprom_Write

    Therefore a pos value of 0 and higher accesses the EEPROM memory at position 32 and upwards. Parameter pos byte position in EEPROM val new EEPROM value 6.7.5 EEPROM_WriteWord EEPROM Functions Syntax void EEPROM_WriteWord(word pos,word val); Sub EEPROM_WriteWord(pos As Word,val As Word) © 2008 Conrad Electronic...
  • Page 152: Eeprom_Writefloat

    C-Control Pro Mega Series Description Writes one word into the EEPROM at position pos. The first 32 byte are reserved for the OS of C-Control Pro. Therefore a pos value of 0 and higher accesses the EEPROM memory at position 32 and upwards.
  • Page 153: I2C_Read_Ack

    I2C bus 6.8.3 I2C_Read_NACK I2C Functions Example Syntax byte I2C_Read_NACK(void); Sub I2C_Read_NACK() As Byte Description This function receives a byte and acknowledges with NACK. Afterwards the status of the interface can be returned with I2C_Status(). © 2008 Conrad Electronic...
  • Page 154: I2C_Start

    C-Control Pro Mega Series Return Parameter value read from the I2C bus 6.8.4 I2C_Start I2C Functions Example Syntax void I2C_Start(void); Sub I2C_Start() Description This function introduces communication with a starting sequence. Afterwards the status of the interface can be returned with I2C_Status().
  • Page 155: I2C_Stop

    I2C_Write I2C Functions Example Syntax void I2C_Write(byte data); Sub I2C_Write(data As Byte) Description I2C_Write() sends a byte to the I2C bus. Afterwards the status of the interface can be returned with I2C_Status(). Parameter data data byte © 2008 Conrad Electronic...
  • Page 156: I2C Status Codes

    C-Control Pro Mega Series 6.8.8 I2C Status Codes Table: Status Codes Master Transmitter Mode Status Code Description 0x08 a START sequence has been sent 0x10 a "repeated" START sequence has been sent 0x18 SLA+W has been sent, ACK has been received...
  • Page 157: Interrupt

    Msg_WriteHex(EEPROM_data); Interrupt The Controller provides a multitude of interrupts. Some of them are used for system functions and are thus not available to the user. The following interrupts can be utilized by the user. Table: Interrupts © 2008 Conrad Electronic...
  • Page 158: Ext_Intenable

    C-Control Pro Mega Series Interrupt Name Description INT_0 external Interrupt0 INT_1 external Interrupt1 INT_2 external Interrupt2 INT_3 external Interrupt3 (only Mega128) INT_4 external Interrupt4 (only Mega128) INT_5 external Interrupt5 (only Mega128) INT_6 external Interrupt6 (only Mega128) INT_7 external Interrupt7 (only...
  • Page 159: Ext_Intdisable

    Syntax byte Irq_GetCount(byte irqnr); Sub Irq_GetCount(irqnr As Byte) As Byte Description Acknowledges the interrupt. If the function is not called at the end of a interrupt service routine, the interrupt service routine gets called continuously. Parameter © 2008 Conrad Electronic...
  • Page 160: Irq_Setvect

    C-Control Pro Mega Series specifies the interrupt type (see table) irqnr Return Parameter The return value expresses how often a interrupt got triggered until the function Irq_GetCount() has been called. A value greater 1 shows that the interrupts are triggered more rapidly than the interrupt service routine is processed.
  • Page 161: Keyboard

    The global keymap array gets initialized with the ASCII values of the keyboard. Parameter None 6.10.2 Key_Scan Keyboard Functions Syntax word Key_Scan(void); Sub Key_Scan() As Word Description Key_Scan scans sequentially the input pins of the connected keyboard and returns the result as a bit field © 2008 Conrad Electronic...
  • Page 162: Key_Translatekey

    C-Control Pro Mega Series with 16 bits. Bits that are set represent keys that have been pressed during the scan. Return Parameter 16 bits that represent the input lines of the keyboard 6.10.3 Key_TranslateKey Keyboard Functions (Library "Key_Lib.cc") Syntax char Key_TranslateKey(word keys);...
  • Page 163: Lcd_Cursoroff

    Syntax void LCD_CursorOff(void); Sub LCD_CursorOff() Description Turns the cursor off on the display. Parameter None 6.11.3 LCD_CursorOn LCD Functions (Library "LCD_Lib.cc") Syntax void LCD_CursorOn(void); Sub LCD_CursorOn() Description Turns the cursor in the display on. Parameter None © 2008 Conrad Electronic...
  • Page 164: Lcd_Cursorpos

    C-Control Pro Mega Series 6.11.4 LCD_CursorPos LCD Functions (Library "LCD_Lib.cc") Syntax void LCD_CursorPos(byte pos); Sub LCD_CursorPos(pos As Byte) Description Moves the cursor to position pos. Parameter cursorposition Value of pos Position on Display 0x00-0x07 0-7 in der 1. Zeile 0x40-0x47 0-7 in der 2.
  • Page 165: Lcd_Locate

    Sub LCD_SubInit() Description Initializes the display ports on assembler level. Must be called before all other LCD output functions. This function will be used as first command from LCD_Init(). Parameter None 6.11.8 LCD_TestBusy LCD Functions Syntax © 2008 Conrad Electronic...
  • Page 166: Lcd_Writechar

    C-Control Pro Mega Series void LCD_TestBusy(void); Sub LCD_TestBusy() Description This function waits for a non-busy of the display controller. If the controller is accessed in his busy period the output data will be corrupted. Parameter None 6.11.9 LCD_WriteChar LCD Functions (Library "LCD_Lib.cc")
  • Page 167: Lcd_Writedataregister

    Sub LCD_WriteFloat(value As Single, length As Byte) Description Writes a floating point value with given length to LCD display. Parameter value floating point value length output length 6.11.13 LCD_WriteRegister LCD Functions Syntax void LCD_WriteRegister(byte y,byte x); © 2008 Conrad Electronic...
  • Page 168: Lcd_Writetext

    C-Control Pro Mega Series Sub LCD_WriteRegister(y As Byte,x As Byte) Description LCD_WriteRegister divides the data byte y in 2 nibbles (4bit values) and sends the nibbles to the display controller. y data byte x command nibble 6.11.14 LCD_WriteText LCD Functions (Library "LCD_Lib.cc")
  • Page 169: Math

    [0..Pi], expressed in radians 6.12.2 asin Mathematical Functions Syntax float asin(float val); Sub asin(val As Single) As Single Description The mathematical arc sine (inverse sine) is calculated. Parameter val input value between -1 and 1 Return Parameter © 2008 Conrad Electronic...
  • Page 170: Atan

    C-Control Pro Mega Series arc sine of the input value in the range [-Pi/2..Pi/2], expressed in radians 6.12.3 atan Mathematical Functions Syntax float atan(float val); Sub atan(val As Single) As Single Description The mathematical arc tangent (inverse tangent) is calculated.
  • Page 171: Cos

    6.12.6 exp Mathematical Functions Syntax float exp(float val); Sub exp(val As Single) As Single Description The exponential function e ^ val is calculated. Parameter val exponent Return Parameter result 6.12.7 fabs Mathematical Functions Syntax float fabs(float val); © 2008 Conrad Electronic...
  • Page 172: Floor

    C-Control Pro Mega Series Sub fabs(val As Single) As Single Description The absolute value of the floating point number val is calculated. Parameter val input value Return Parameter result 6.12.8 floor Mathematical Functions Syntax float floor(float val); Sub floor(val As Single) As Single...
  • Page 173: Log

    The natural logarithm is calculated. Parameter val input value Return Parameter result 6.12.11 log Mathematical Functions Syntax float log(float val); Sub log(val As Single) As Single Description The logarithm base 10 is calculated. Parameter val input value © 2008 Conrad Electronic...
  • Page 174: Pow

    C-Control Pro Mega Series Return Parameter result 6.12.12 pow Mathematical Functions Syntax float pow(float x,float y); Sub pow(x As Single,y As Single) As Single Description The power function x ^ y is calculated. Parameter x base y exponent Return Parameter result 6.12.13 sin...
  • Page 175: Sqrt

    (without clock signal) in groups of 64 bit. Data can either be sent or received, but not at the same time (half-duplex). The special about 1-Wire devices is the parasitically power supply, that is made over the signal wire: © 2008 Conrad Electronic...
  • Page 176: Onewire_Read

    C-Control Pro Mega Series When there is no communication, the signal wire has a +5V level and charges a capacitor. During low-pulse communication the slave device is powered from his capacitor. Dependent on the charge of the capacitor, low-time gaps up to 960 µs can be bridged.
  • Page 177: Onewire Example

    A byte is written to the One-Wire Bus. Parameter data data byte 6.13.4 Onewire Example CompactC // Sample Code to read DS18S20 temperature sensor from Dallas Maxim void main(void) char text[40]; int ret, i; byte rom_code[8]; byte scratch_pad[9]; ret= OneWire_Reset(7); // PortA.7 © 2008 Conrad Electronic...
  • Page 178: Onewire_Reset

    C-Control Pro Mega Series if(ret == 0) text= "no device found"; Msg_WriteText(text); goto end; OneWire_Write(0xcc); // skip ROM cmd OneWire_Write(0x44); // start temperature measure cmd AbsDelay(3000); OneWire_Reset(7); // PortA.7 OneWire_Write(0xcc); // skip ROM cmd OneWire_Write(0xbe); // read scratch_pad cmd for(i=0;i<9;i++) // read whole scratchpad scratch_pad[i]= OneWire_Read();...
  • Page 179: Port

    Port_DataDirBit. If a pin is configured as input then this pin can either be operated high resistive ("floating") or with an internal pull-up resistor. If with Port_Write Port_WriteBit a "1" is written to an input then the pull-up resistor (Reference Level VCC) is activated and the input is defined. © 2008 Conrad Electronic...
  • Page 180: Port_Datadir

    C-Control Pro Mega Series 6.14.1 Port_DataDir Port Functions Example Syntax void Port_DataDir(byte port,byte val); Sub Port_DataDir(port As Byte,val As Byte) Description The function Port_DataDir configures the port for input or output direction. Is a bit set, then the Pin corresponding to the bit position is switched to output. Example: Is port = PortB and val = 0x02, then PortB.1 is configured for output, all other ports on PortB are set to input (...
  • Page 181: Port_Read

    Sub Port_Read(port As Byte) As Byte Description Reads a byte from the specified port. Only the Pins of port that are configured for input return a valid value and M128). on their bit position see Pin Assignment © 2008 Conrad Electronic...
  • Page 182: Port_Readbit

    C-Control Pro Mega Series Parameter port port number (see table) Return Parameter port byte value port number table Definition Value PortA PortB PortC PortD PortE (Mega128) PortF (Mega128) PortG (Mega128) 6.14.4 Port_ReadBit Port Functions Syntax byte Port_ReadBit(byte port); Sub Port_ReadBit(port As Byte) As Byte Description The function Port_ReadBit reads the value of a Pin that is configured for input.
  • Page 183: Port_Write

    (bit = 1) or off (bit = 0). and M128. See Pin Assignment Parameter port port number (see table) val output byte port number table Definition Value PortA PortB © 2008 Conrad Electronic...
  • Page 184: Port_Writebit

    C-Control Pro Mega Series PortC PortD PortE (Mega128) PortF (Mega128) PortG (Mega128) 6.14.6 Port_WriteBit Port Functions Syntax void Port_WriteBit(byte portbit,byte val); Sub Port_WriteBit(portbit As Byte,val As Byte) Description Is a Pin configured as The function Port_WriteBit sets the value of a Pin that is configured for output.
  • Page 185: Port Example

    The baudrate is derived from the processor clock (14,7456 MHz). According to the Atmel processor handbook the following formula is used to calculate the divider for a specified baudrate: © 2008 Conrad Electronic...
  • Page 186: Serial_Disable

    C-Control Pro Mega Series divider = (14745600 / baudrate / 16 ) -1 Example: 15 = (14745600 / 57600 / 16 ) -1 DoubleClock Mode If the High-Bit of the divider is set, the DoubleClock Mode is enabled. In this mode the divider value must be doubled.
  • Page 187: Serial_Init

    5 Bit char length SR_6BIT 6 Bit char length SR_7BIT 7 Bit char length SR_8BIT 8 Bit char length SR_1STOP 1 stop bit SR_2STOP 2 stop bit SR_NO_PAR no parity SR_EVEN_PAR even parity SR_ODD_PAR odd parity © 2008 Conrad Electronic...
  • Page 188: Serial_Init_Irq

    C-Control Pro Mega Series 6.15.4 Serial_Init_IRQ Serial Functions Example Syntax void Serial_Init_IRQ(byte serport,byte ramaddr[],byte recvlen,byte sendlen,byte par Sub Serial_Init_IRQ(serport As Byte,ByRef ramaddr As Byte,recvlen As Byte,sendlen A par As Byte,div As Byte) Description The serial interface gets initialized for usage in interrupt mode. The user has to provide a global variable as a serial buffer.
  • Page 189: Serial_Irq_Info

    6.15.6 Serial_Read Serial Functions Syntax byte Serial_Read(byte serport); Sub Serial_Read(serport As Byte) As Byte Description Reads one byte from the serial interface. If is there is no byte available in the serial interface, the function © 2008 Conrad Electronic...
  • Page 190: Serial_Readext

    C-Control Pro Mega Series waits until a byte has been received. Please use Serial_ReadExt() if you work in serial IRQ mode. Serial_Read() only supports polled mode. Parameter serport interface number (0 = 1st serial port, 1 = 2nd serial port )
  • Page 191: Serial_Writetext

    // output string to serial port 6.15.11 Serial Example (IRQ) // 35 byte send + receive buffer + 6 byte internal FIFO organization byte buffer[41]; // array declaration // string output to serial interface void main(void) © 2008 Conrad Electronic...
  • Page 192: Spi

    C-Control Pro Mega Series int i; char str[10]; str="test"; i=0; // initialize serial port with 19200baud, 8 bit, 1 stop bit, no parity // 20 byte receive buffer - 15 byte send buffer Serial_Init_IRQ(0,buffer,20,15,SR_8BIT|SR_1STOP|SR_NO_PAR,SR_BD19200); while(str[i]) Serial_Write(0,str[i++]); // display string 6.16 Presently the SPI interface is used on the Applicationboard to receive USB data from the Mega8 controller.
  • Page 193: Str_Comp

    Sub Str_Copy(ByRef destination As Char,ByRef source As Char,offset As Word) Description The source string (source) is copied to the destination string (destination). During copying also the string termination character of the source character string is copied. Parameter © 2008 Conrad Electronic...
  • Page 194: Str_Fill

    C-Control Pro Mega Series pointer to destination string destination source pointer to source string offset Number of characters by which the source string is offset when copied to the destination string.. If offset has the value STR_APPEND (0xffff) then the length of the destination string is assumed as offset.
  • Page 195: Str_Isalpha

    String Functions Syntax word Str_Len(char str[]); Sub Str_Len(ByRef str As Char) As Word Description The length of the string (character array) is returned. Parameter str pointer to string Return Parameter length of the string (without terminating zero) © 2008 Conrad Electronic...
  • Page 196: Str_Substr

    C-Control Pro Mega Series 6.17.7 Str_Substr String Functions (Library "String_Lib.cc") Syntax int Str_SubStr(char source[],char search[]); Sub Str_SubStr(ByRef source As Char,ByRef search As Char) As Integer Description A substring search is searched inside string source. If the substring is found, the position of the substring is returned.
  • Page 197: Str_Writeint

    A base of 8 produces an octal string, and a base of 16 a hexadecimal string. If the base is set to a number greater than 16, more characters of the alphabet are used. E.g. a base of 18 produces a string with the digits '0'-'9' and 'A'-'H'. Parameter © 2008 Conrad Electronic...
  • Page 198: Threads

    C-Control Pro Mega Series 16 bit word base base of the number system text pointer to destination string offset offset that is applied to the position where the string is copied minwidth minimal width of the string If offset has the value STR_APPEND (0xffff) then the length of the destination string is assumed as offset.
  • Page 199: Thread_Cycles

    If a thread is freshly started, it will get the cycle count that was defined in the project options. It only makes sense to call Thread_Cylces() after a thread has been started. Parameter thread (0-13) number of the thread cycles cycle count until thread change © 2008 Conrad Electronic...
  • Page 200: Thread_Delay

    C-Control Pro Mega Series 6.18.2 Thread_Delay Thread Functions Example Syntax void Thread_Delay(word delay); Sub Thread_Delay(delay As Word) Description With this function a thread will set to "sleep" for a specified time. After this time the thread is again ready for execution.
  • Page 201: Thread_Kill

    If you forget to remove the thread lock, the multithreading is not working. Parameter lock if set to 1 thread changes are inhibited, 0 means thread changes are allowed © 2008 Conrad Electronic...
  • Page 202: Thread_Memfree

    C-Control Pro Mega Series 6.18.6 Thread_MemFree Thread Functions Syntax word Thread_MemFree(void); Sub Thread_MemFree() As Word Description Returns the free memory that is available for the calling thread. Parameter None Return Parameter free memory in bytes 6.18.7 Thread_Resume Thread Functions Syntax void Thread_Resume(byte thread);...
  • Page 203: Thread_Start

    The floating point data type seems not suitable for an function vector, but a 4 byte data type is needed to specify a function in the Mega128 environment. 6.18.10 Thread_Wait Thread Functions Syntax void Thread_Wait(byte thread,byte signal); Sub Thread_Wait(thread As Byte,signal As Byte) © 2008 Conrad Electronic...
  • Page 204: Thread Example

    C-Control Pro Mega Series Description The thread gets the state "waiting". The state can be changed back to "inactive" with calls to Thread_Resume() or Thread_Signal(). Parameter thread (0-13) thread number signal signal value 6.18.11 Thread Example // demo program of multithreading...
  • Page 205: Timer

    Frequency Measurement · 6.19.1 Event Counter Here are two examples for how a Timer can be used for an Event Counter: Timer0 (8 Bit) // Example: Pulse Counting with CNT0 Timer_T0CNT(); pulse(n); // generate n Pulses count=Timer_T0GetCNT(); © 2008 Conrad Electronic...
  • Page 206: Frequency Generation

    C-Control Pro Mega Series With Mega128 for reasons of the hardware the use of Timer_0 as counter is not possible! Timer1 (16 Bit) // Example: Pulse Counting with CNT1 Timer_T1CNT(); pulse(n); // generate n Pulses count=Timer_T1GetCNT(); 6.19.2 Frequency Generation To generate frequencies Timer_0, Timer_1 and Timer_3 can be utilized as follows: Timer0 (8 Bit) 1.
  • Page 207: Frequency Measurement

    This function utilizes the Capture-Interrupt (INT_TIM1CAPT). A pulse is measured between a rising and the next falling signal edge. A period is measured between two rising signal edges. Because of the Input Capture Function program delay times will not as an inaccuracy © 2008 Conrad Electronic...
  • Page 208: Timer Functions

    C-Control Pro Mega Series be entered into the measuring result. With a programmable prescaler the resolution of Timer_1 can be set. Prescaler see Table Example: Activate Pulse Width Measurement (Project PMeasurement) 434 µs (100 x 4,34 µs, see Table word PM_Value;...
  • Page 209: Timer_Disable

    This function disables the specified timer. Timer functions occupy I/O ports. If a timer is not needed and the corresponding I/O ports are used otherwise, the timer must be disabled. Parameter 0 = Timer_0 1 = Timer_1 3 = Timer_3 (only Mega128) 6.19.8 Timer_T0CNT Timer Functions Syntax void Timer_T0CNT(void); Sub Timer_T0CNT() © 2008 Conrad Electronic...
  • Page 210: Timer_T0Frq

    C-Control Pro Mega Series Description These function initializes Counter0. Counter0 gets incremented at every positive signal edge at Input Mega32:T0 (PIN1). Due to hardware reasons it is not possible to use Timer_0 as a counter in the Mega128! Parameter None 6.19.9 Timer_T0FRQ...
  • Page 211: Timer_T0Getcnt

    Due to hardware reasons it is not possible to use Timer_0 as a counter in the Mega128! Return Parameter counter value 6.19.11 Timer_T0PW Timer Functions Syntax void Timer_T0PW(byte PW); Sub Timer_T0PW(PW As Byte) Description This function sets a new pulse width for Timer0 without changing the prescaler. Parameter PW pulse width © 2008 Conrad Electronic...
  • Page 212: Timer_T0Pwm

    C-Control Pro Mega Series 6.19.12 Timer_T0PWM Timer Functions Syntax void Timer_T0PWM(byte PW,byte PS); Sub Timer_T0PWM(PW As Byte,PS As Byte) Description This function initializes Timer0 with given prescaler and pulse width, see table. The output signal is generated at Mega32: PortB.3 (PIN4), Mega128: PortB.4 (X1_4). There is an extended prescaler definition for the Mega128, see table.
  • Page 213: Timer_T0Stop

    This function initializes Timer_0 with a prescaler and a timer interval value, see table. After the timing interval is expired The Timer_0 Interrupt (INT_TIM0COMP) is triggered. There is an extended prescaler definition for the Mega128, see table. Parameter © 2008 Conrad Electronic...
  • Page 214: Timer_T1Cnt

    C-Control Pro Mega Series Time time period after that the interrupt is triggered prescaler Table prescaler: Mega32 Prescaler Time Base (duration of a tick) PS0_1 (1) 67,8 ns PS0_8 (2) 542,5 ns PS0_64 (3) 4,34 µs PS0_256 (4) 17,36 µs PS0_1024 (5) 69,44 µs...
  • Page 215: Timer_T1Cnt_Int

    There is an extended prescaler definition for the Mega128, see table. Parameter period period duration PS prescaler Table prescaler: Mega32 Prescaler Time Base (duration of a tick) PS0_1 (1) 135,6 ns PS0_8 (2) 1,085 µs PS0_64 (3) 8,681 µs © 2008 Conrad Electronic...
  • Page 216: Timer_T1Frqx

    C-Control Pro Mega Series PS0_256 (4) 34,72 µs PS0_1024 (5) 138,9 µs Mega128 Prescaler Time Base (duration of a tick) PS0_1 (1) 135,6 ns PS0_8 (2) 1,085 µs PS0_32 (3) 4,340 µs PS0_64 (4) 8,681 µs PS0_128 (5) 17,36 µs PS0_256 (6) 34,72 µs...
  • Page 217: Timer_T1Getpm

    Timer_T1PM. 6.19.22 Timer_T1PWA Timer Functions Syntax void Timer_T1PWA(word PW0); Sub Timer_T1PWA(PW0 As Word) Description This function sets a new pulse width (Channel A) for Timer1 without changing the prescaler. Parameter PW0 pulse width © 2008 Conrad Electronic...
  • Page 218: Timer_T1Pm

    C-Control Pro Mega Series 6.19.23 Timer_T1PM Timer Functions Syntax void Timer_T1PM(byte Mode,byte PS); void Timer_T1PM(Mode As Byte,PS As Byte) Description pulse width measurement or period measurement should be done. This function defines if Then it initializes Timer_1 and sets the prescaler.
  • Page 219: Timer_T1Pwm

    Mega32 Prescaler Time Base (duration of a tick) PS0_1 (1) 67,8 ns PS0_8 (2) 542,5 ns PS0_64 (3) 4,34 µs PS0_256 (4) 17,36 µs PS0_1024 (5) 69,44 µs Mega128 Prescaler Time Base (duration of a tick) © 2008 Conrad Electronic...
  • Page 220: Timer_T1Pwmx

    C-Control Pro Mega Series PS0_1 (1) 67,8 ns PS0_8 (2) 542,5 ns PS0_32 (3) 2,17 µs PS0_64 (4) 4,34 µs PS0_128 (5) 8,68 µs PS0_256 (6) 17,36 µs PS0_1024 (7) 69,44 µs 6.19.26 Timer_T1PWMX Timer Functions Syntax void Timer_T1PWMX(word period,word PW0,word PW1,byte PS);...
  • Page 221: Timer_T1Start

    The frequency generation gets stopped. The output signal can be 0 or 1, dependent on the last state. Only the clock generation is stopped, all other settings stay the same. Parameter None 6.19.30 Timer_T1Time Timer Functions Syntax © 2008 Conrad Electronic...
  • Page 222: Timer_T3Cnt

    C-Control Pro Mega Series void Timer_T1Time(word Time,byte PS); Sub Timer_T1Time(Time As Word,PS As Byte) Description This function initializes Timer_1 with a prescaler and a timer interval value (16bit), see table. After the timing interval is expired Timer_1 Interrupt (INT_TIM1CMPA) is triggered. There is an extended prescaler definition for the Mega128, see table.
  • Page 223: Timer_T3Cnt_Int

    Description This function initializes Timer3 for frequency generation. Parameters are period duration and prescaler, see table. The output signal is generated at PortE.3 (X1_13). The frequency generation is started automatically.. Parameter period period duration PS prescaler © 2008 Conrad Electronic...
  • Page 224: Timer_T3Frqx

    C-Control Pro Mega Series Table prescaler: Prescaler Time Base (duration of a tick) PS0_1 (1) 135,6 ns PS0_8 (2) 1,085 µs PS0_32 (3) 4,340 µs PS0_64 (4) 8,681 µs PS0_128 (5) 17,36 µs PS0_256 (6) 34,72 µs PS0_1024 (7) 138,9 µs 6.19.34 Timer_T3FRQX...
  • Page 225: Timer_T3Getpm

    Timer_T3PM. 6.19.37 Timer_T3PWA Timer Functions Syntax void Timer_T3PWA(word PW0); Sub Timer_T3PWA(PW0 As Word) Description This function sets a new pulse width (Channel A) for Timer3 without changing the prescaler. Parameter PW0 pulse width © 2008 Conrad Electronic...
  • Page 226: Timer_T3Pm

    C-Control Pro Mega Series 6.19.38 Timer_T3PM Timer Functions Syntax void Timer_T3PM(byte Mode,byte PS); void Timer_T3PM(Mode As Byte,PS As Byte) Description pulse width measurement or period measurement should be done. This function defines if Then it initializes Timer_3 and sets the prescaler.
  • Page 227: Timer_T3Pwm

    Timer Functions Syntax void Timer_T3PWMX(word period,word PW0,word PW1,byte PS); Sub Timer_T3PWMX(period As Word,PW0 As Word,PW1 As Word,PS As Byte) Description This function initializes Timer_3 with given period duration, prescaler, pulse width for channel A and B. The © 2008 Conrad Electronic...
  • Page 228: Timer_T3Pwmy

    C-Control Pro Mega Series output signal is generated at PortE.3 (X1_13) and PortE.4 (X1_12). Parameter period period duration pulse width channel A pulse width channel B prescaler (see table prescaler) 6.19.42 Timer_T3PWMY Timer Functions Syntax void Timer_T3PWMY(word period,word PW0,word PW1,word PW2,byte PS);...
  • Page 229: Timer_T3Stop

    This function initializes Timer_3 with a prescaler and a timer interval value (16bit), see table. After the timing interval is expired Timer_3 Interrupt (INT_TIM3CMPA) is triggered. Parameter Time time period after that the interrupt is triggered prescaler Table prescaler: Prescaler Time Base (duration of a tick) PS0_1 (1) 67,8 ns © 2008 Conrad Electronic...
  • Page 230: Timer_Tickcount

    C-Control Pro Mega Series PS0_8 (2) 542,5 ns PS0_32 (3) 2,17 µs PS0_64 (4) 4,34 µs PS0_128 (5) 8,68 µs PS0_256 (6) 17,36 µs PS0_1024 (7) 69,44 µs 6.19.46 Timer_TickCount Timer Functions Syntax word Timer_TickCount(void); Sub Timer_TickCount() As Word Description Timer_TickCount().
  • Page 231 Part...
  • Page 232: Part 7 Faq

    C-Control Pro Mega Series Problems 1. No USB connection existing to the Application Board. · Has the FTDI USB driver been loaded onto the PC? Or does “Unknown Device” appear in the Hardware Manager, when the USB connector is plugged in? ·...
  • Page 233 GND and the rightmost column is VCC. You can see it clearly, when you take a look of the backside of the board. 13. I need more ports for my hardware application. Many ports are used by other functions. © 2008 Conrad Electronic...
  • Page 234 C-Control Pro Mega Series · Take a look at the Pin Assignment of and M128. You can use all ports that have no special functionality ( SPI, RS232, LCD, Keyboard etc.) that is needed for your application. Do not forget to remove the jumper that connects the port pins to the application board.
  • Page 235 21, 29, 37, 46 arc cosine Cosine arc sine CPU choosage arc tangent - D - Arithmetic Operators 94, 114 Array 91, 110 Array Window data bits ASCII Data Types 90, 110 asin DCF_FRAME atan DCF_INIT © 2008 Conrad Electronic...
  • Page 236 C-Control Pro Mega Series DCF_Lib.cc 98, 117 DCF_PULS Frequency Generation DCF_RTC.cc Frequency Measurement DCF_START Functions 102, 121 DCF_SYNC - G - DCF77 Debugger Goto 99, 118 default Divider greater 96, 115 Division 94, 114 greater or equal 96, 115 116, 117...
  • Page 237 94, 114 ldexp Options left shift 95, 115 95, 114 Liability Outputs Library Management - P - Pattern logical And Period Measurement logical Not logical Operators Pin Assignment 25, 41 logical Or Pointer 102, 121 Loop While © 2008 Conrad Electronic...
  • Page 238 C-Control Pro Mega Series Port_DataDir Serial_Read Port_DataDirBit Serial_ReadExt Port_Read Serial_Write Port_ReadBit Serial_WriteText Port_Write Service Port_WriteBit Sign 94, 114 Precedence sine Predefined Symbols Single Preprocessor SizeOf 91, 110 previous error smaller 96, 115 Print Preview smaller or equal 96, 115 Program...
  • Page 239 Visibility of Variables 91, 110 Timer_T1FRQ void Timer_T1FRQX Timer_T1GetCNT - W - Timer_T1GetPM Timer_T1PM Warranty Timer_T1PWA While 101, 117 Timer_T1PWB Window Timer_T1PWM Word 90, 110 Timer_T1PWMX Timer_T1PWMY Timer_T1Start Timer_T1Stop Timer_T1Time Timer_T3CNT Timer_T3CNT_Int Timer_T3FRQ Timer_T3FRQX Timer_T3GetCNT Timer_T3GetPM Timer_T3PM Timer_T3PWA © 2008 Conrad Electronic...

This manual is also suitable for:

C-control pro mega32C-control pro mega128

Table of Contents