background image

85

C-Control Pro Mega Series

© 2008 Conrad Electronic

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

 has also been defined by 

#define

symbol

.  

If there is an optional 

#else

 instruction then the source text will be processed after 

#else

 if the

symbol

 has not been defined.  

Insertion of Text

#include path\file name

By this instruction a text file can be inserted into the source code.  

 Because of some restrictions in the Preprocessor a path within a 

#include

 instruction must not

contain any blank characters!

5.1.2.1

Predefined Symbols

In order to ease the work with different versions of the C-Control Pro series there are a number of
definitions which are set depending on target system and Compiler project options. These constants
can be called up by 

#ifdef,

 

#ifndef

 or 

#if

.  

Symbol

Meaning

  MEGA32

  Configuration for Mega 32

  MEGA128

  Configuration for Mega 128

  MEGA128CAN

  Configuration for Mega 128 CAN Bus

  __DEBUG__

  Debug Data will be created

  __MAPFILE__

  A Memory Layout will be computed

The following constants contain a string. It is sensible to use them in conjunction with text outputs.  

Symbol

Meaning

  __DATE__

  Current Date

  __TIME__

  Time of Compiling

  __LINE__

  Current Line in Sourcecode

  __FILE__

  Name of Current Source File

  __FUNCTION__

  Current Function Name

Summary of Contents for C-Control Pro Mega Series

Page 1: ... 2008 Conrad Electronic C Control Pro Mega Series ...

Page 2: ... Applicationboard 13 2 Software Part 3 Hardware 15 15 1 Firmware 17 2 LCD Matrix 17 3 Mega32 18 3 1 Module 21 3 2 Application Board 25 3 3 Pin Assignment 26 3 4 Jumper Application Board 28 3 5 Connection Diagrams 33 4 Mega128 34 4 1 Module 37 4 2 Application Board 41 4 3 Pin Assignment 42 4 4 Jumper Application Board 44 4 5 Connection Diagrams Part 4 IDE 50 51 1 Projects 51 1 1 Create Projects 51 ...

Page 3: ...ugger 67 4 1 Breakpoints 68 4 2 Array Window 69 4 3 Variable Watch Window 71 5 Tools 72 6 Options 72 6 1 Editor Settings 73 6 2 Syntax Highlighting 75 6 3 Compiler Presetting 76 6 4 IDE Settings 80 7 Windows 81 8 Help Part 5 Compiler 84 84 1 General Features 84 1 1 External RAM 84 1 2 Preprocessor 86 1 3 Pragma Instructions 86 1 4 Map File 87 2 CompactC 87 2 1 Program 88 2 2 Instructions 90 2 3 Da...

Page 4: ... 3 Analog Comparator 129 3 1 AComp 129 3 2 AComp Example 130 4 Analog Digital Converter 131 4 1 ADC_Disable 131 4 2 ADC_Read 132 4 3 ADC_ReadInt 132 4 4 ADC_Set 133 4 5 ADC_SetInt 134 4 6 ADC_StartInt 134 5 DCF 77 136 5 1 DCF_FRAME 136 5 2 DCF_INIT 136 5 3 DCF_PULS 137 5 4 DCF_START 137 5 5 DCF_SYNC 138 6 Debug 138 6 1 Msg_WriteChar 138 6 2 Msg_WriteFloat 139 6 3 Msg_WriteHex 139 6 4 Msg_WriteInt ...

Page 5: ...pt 149 9 1 Ext_IntEnable 150 9 2 Ext_IntDisable 150 9 3 Irq_GetCount 151 9 4 Irq_SetVect 151 9 5 IRQ Example 152 10 Keyboard 152 10 1 Key_Init 152 10 2 Key_Scan 153 10 3 Key_TranslateKey 153 11 LCD 153 11 1 LCD_ClearLCD 154 11 2 LCD_CursorOff 154 11 3 LCD_CursorOn 155 11 4 LCD_CursorPos 155 11 5 LCD_Init 156 11 6 LCD_Locate 156 11 7 LCD_SubInit 156 11 8 LCD_TestBusy 157 11 9 LCD_WriteChar 157 11 1...

Page 6: ...rt 166 12 15 tan 166 13 OneWire 167 13 1 Onewire_Read 167 13 2 Onewire_Reset 168 13 3 Onewire_Write 168 13 4 Onewire Example 170 14 Port 171 14 1 Port_DataDir 171 14 2 Port_DataDirBit 172 14 3 Port_Read 173 14 4 Port_ReadBit 174 14 5 Port_Write 175 14 6 Port_WriteBit 176 14 7 Port Example 176 15 RS232 176 15 1 Divider 177 15 2 Serial_Disable 178 15 3 Serial_Init 179 15 4 Serial_Init_IRQ 180 15 5 S...

Page 7: ...r_WriteWord 189 18 Threads 190 18 1 Thread_Cycles 191 18 2 Thread_Delay 191 18 3 Thread_Info 192 18 4 Thread_Kill 192 18 5 Thread_Lock 193 18 6 Thread_MemFree 193 18 7 Thread_Resume 193 18 8 Thread_Signal 194 18 9 Thread_Start 194 18 10 Thread_Wait 195 18 11 Thread Example 195 18 12 Thread Example 2 196 19 Timer 196 19 1 Event Counter 197 19 2 Frequency Generation 198 19 3 Frequency Measurement 19...

Page 8: ...9 23 Timer_T1PM 209 19 24 Timer_T1PWB 210 19 25 Timer_T1PWM 211 19 26 Timer_T1PWMX 211 19 27 Timer_T1PWMY 212 19 28 Timer_T1Start 212 19 29 Timer_T1Stop 212 19 30 Timer_T1Time 213 19 31 Timer_T3CNT 214 19 32 Timer_T3CNT_Int 214 19 33 Timer_T3FRQ 215 19 34 Timer_T3FRQX 215 19 35 Timer_T3GetCNT 216 19 36 Timer_T3GetPM 216 19 37 Timer_T3PWA 217 19 38 Timer_T3PM 217 19 39 Timer_T3PWB 218 19 40 Timer_T...

Page 9: ...VIII Inhalt 2008 Conrad Electronic ...

Page 10: ...Part 1 ...

Page 11: ...elong to this user group please allow us to give you the following advice C Control Pro is only of limited use for the entry into programming of micro computers and electronic circuit technique We presuppose that you have at least a basic knowledge in a higher programming language such as BASIC PASCAL C C or Java Furthermore we presume that you are used to operating a PC under one of the Microsoft...

Page 12: ...nd shielding s to ensure the observance of legally directed maximum values lies in the responsibility of the user The maximum allowable length of connected wire lines is without additional precautions appr 0 25 Meters Exception Serial Interface Under influence of strong electro magnetic alternating fields or interference pulses the function of the C Control Pro Unit can be detracted If need be a r...

Page 13: ...master c control de Please preferably use e mail communication If there is a problem possibly provide us with a sketch of your connection diagram in form of an attached picture file jpg format as well as the program source code reduced to the part referring to your problem max 20 lines Further information s and current software for download please find on the C Control homepage under www c control...

Page 14: ...called functions with pointers Corrected error message at assignment when function had no return parameter Nested switch Select statements are working now Very long switch Select statements are functioning properly now Better Error recovery when selected COM Port already in use No longer a crash if very huge amounts of faulty data where transferred over USB or COM Port Exit in BASIC For Loops is w...

Page 15: ...pts 3 7 Mega128 Routines for the 2 Serial Interface Mega128 Mathematical Functions Mega128 Display of Memory Volume when Interpreter is started Internal RAM check for recognition when Global Variables too large for Main Memory Interner RAM check for recognition when Thread Configuration too large for Main Memory Transit Time Check if Stack Limits have been violated Source Files can be moved up and...

Page 16: ...imits at EEPROM Access can now be checked closer internal overflow seized In the Debugger a single step can no longer depose the next command too early Version 1 39 from 06 09 2005 New Features BASIC Support CompactC and BASIC can be mixed in a project Extended Documentation Loop Optimizing for For Next in BASIC ThreadInfoFunction New Demo Programs Error Corrections Compiler does no longer break d...

Page 17: ...Part 2 ...

Page 18: ...ly take place during power down condition switched off voltage since otherwise damages may occur to Application Board and or Module resp Because of the high number of contacts 40 64 Pins considerable force may be necessary to insert retrieve the Module When inserting it must be ensured that the Module is pressed into the socket evenly i e not out of line To do this the Module should be placed onto...

Page 19: ...lly corrected by means of diodes Depending on additionally used components it may later become necessary to use a power supply with higher output Establish a connection between the Application Board and your PC by use of a USB cable Switch on the Application Board A Windows Operating System prior to Win98 SE Second Edition will supposedly not allow a reliable USB connection between PC and Applicat...

Page 20: ...11 C Control Pro Mega Series 2008 Conrad Electronic From here select Install software from a list or other source and click Next ...

Page 21: ...12 Installation 2008 Conrad Electronic 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 ...

Page 22: ...its to the PC interface connected to the Application Board 2 2 Software When the attached CD ROM is inserted into the computer the Installer should be automatically started in order to install the C Control Pro software If this is not the case because e g the Autostart Function in Windows is not activated then please manually start the Installer C ControlSetup exe in the main directory of your CD ...

Page 23: ...Part 3 ...

Page 24: ...the push button SW1 Port M32 D 2 and M128 E 4 resp at low level must be held pressed during power up of the module In this mode any communication will be directed through the serial interface This is useful when the module has already been incorporated into the hardware application and the application board is thus not available The serial communication however is considerably slower than the USB ...

Page 25: ...OM Interfaces are used by the IDE s Debugger to get access to the variables when the Debugger is stopped at any Breakpoint Autostart If no USB interface is connected and if SW1 has not been pressed during power up in order to reach the serial 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 ...

Page 26: ...racter generator RAM These locations can be loaded with the user designed symbols and then displayed along with the characters stored in the CG ROM CHARACTER FONT TABLE LOWER 4 BITS 0000 0010 0011 0100 0101 0110 0111 1010 1011 1100 1101 1110 1111 0000 CG RAM 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 1 1001 2 1010 3 1011 4 1100 5 1101 6 1110 7 1111 8 UPPER 4 BITS CHARACTER MODULE FONT...

Page 27: ... Serial Interface I2C Programmable Serial USART On chipAnalogComparator External and Internal Interrupt Sources 32 Programmable I O Lines 40 pinDIP Operating Voltages 4 5 5 5V 3 3 1 Module Module Memory The C Control Pro Module provides 32kB FLASH 1kB EEPROM and 2kB SRAM A supplementary EEPROM with an 8kB memory depth is mounted on the application board The latter can be addressed by an I2C interf...

Page 28: ... work as outputs Digital input pins are high impedance or wired to internal pull up resistors and transform an applied voltage signal into a logical value For this it is required that the voltage signal is within the limits defined for TTL and CMOS IC s high or low levels During further processing in the program the logical values on the respective input ports are represented as 0 low or 1 high Pi...

Page 29: ... and Timer_1 have independent time base and period length In applications for pulse width modulated digital to analog conversion the time base and period length are set once and then only the output value is varied According to their electrical properties the PLM ports are digital ports Please observe the technical boundary conditions for digital ports max current Technical Data Module Note Detail...

Page 30: ...to the serial interface Communication takes place through a USB Controller by FTDI and an AVR Mega8 Controller The Mega8 provides its own Reset push button SW5 During USB operation the status of the interface is indicated by two light emitting diodes LD4 red LD5 green When only the green LED lights up the USB interface is ready for operation During data transmission both LED s will light up This a...

Page 31: ...ized displays can be operated through this interface Each character consists of a monochrome matrix of 5x7 pixels A flashing cursor below any one of the characters will indicate the current output position The operating system provides a simple software interface for output on the display This display is connected to connector X14 16 poles double row By means of a mechanical protection a faulty co...

Page 32: ...ttery operated Please see the note on short time breakdowns of the power supply see Reset Characteristics If you turn the application board to a position where the interface connectors USB and serial show to the upper side the leftmost column on the breadboard is GND and the rightmost column is VCC Serial Interfaces The Micro Controller Atmega32 contains in its hardware an asynchronous serial inte...

Page 33: ...esting Interfaces The 4 pole pin strip X16 is to be used for testing purposes only and will not necessarily be armed with components of any kind on every application board For the user this pin strip is of no importance One further testing interface is the 6 pole pin strip two rows at 3 pins each at JP4 This pin strip too is only meant for internal use and may likely no longer be fitted with compo...

Page 34: ...er Counter1 3 PB2 PortB 2 10 INT2 AIN0 Analog Comparator external Interrupt2 4 PB3 PortB 3 11 OT0 AIN1 Analog Comparator Output Timer0 5 PB4 PortB 4 12 SS USB Communication 6 PB5 PortB 5 13 MOSI USB Communication 7 PB6 PortB 6 14 MISO USB Communication 8 PB7 PortB 7 15 SCK USB Communication 9 RESET 10 VCC 11 GND 12 XTAL2 Oscillator 14 7456MHz 13 XTAL1 Oscillator 14 7456MHz 14 PD0 PortD 0 24 RXD EX...

Page 35: ... to several ports which are provided with special functions see Pin Assignment Table for M32 E g the serial interface is relized through Pins PortD 0 and PortD 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 P...

Page 36: ...and voltage control Shipping Condition The maximum current to be drawn from the USB interface is lower than from the Plug In Power Supply Exceeding this current can lead to damage on the USB interface of the computer JP6 When using the displays the LED back lighting can be switched off by use of JP6 PAD3 PAD3 to the right of the module below the blue inscription is required as ADC_VREF_EXT for fun...

Page 37: ...GND 6 PB0 XCK T0 40 PD4 OC1B 13 PD5 OC1A 14 GND 18 PD7 OC2 16 VCC 5 AGND 28 AREF 29 VCC 38 GND 39 IC1 IC S ATMEGA32 16AI 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 S1 SOCKEL DIL40 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 PC0 PC1 P...

Page 38: ...10 R2OUT 9 R2IN 8 T2OUT 7 R1IN 13 T1OUT 14 C2 4 VCC 16 GND 15 IC1 MAX202 VCC C9 100NF 50V GND VCC C6 100NF 50V GND VCC GND AREF 1 4 2 3 SW1 SW D B 6810 GND 1 3 2 JP1 JUMPER 3 VCC EXT DATA EXT SCK LCD E KEY E U_DispKey DispKey sch VCC 8 GND 4 SCL 6 SDA 5 A0 1 A1 2 A2 3 WP 7 IC2 AT24C64AN VCC GND EXT SCL EXT SDA GND EXT TXD EXT RXD R4 10K R5 10K C10 10NF 50V C11 10NF 50V ANA1 ANA2 GND GND EXT A1 EXT...

Page 39: ... D7 6 CP 2 CE 15 PL 1 Q7 9 Q7 7 VCC 16 GND 8 IC9 74HC165 R20 1K R21 1K R22 1K LCD D4 LCD D5 LCD D6 LCD RW LCD RS LCD D7 VCC VCC VCC VCC GND GND GND 2 1 3 4 5 6 7 8 9 10 11 12 13 X15 13X1 GND KEY01 KEY02 KEY03 KEY04 KEY05 KEY06 KEY07 KEY08 KEY09 KEY10 KEY11 KEY12 VCC KEY01 KEY02 KEY03 KEY04 KEY05 KEY06 KEY07 KEY08 KEY09 KEY10 KEY11 KEY12 R23 1K EXT SCK EXT DATA LCD E KEY E GND GND C29 100NF 50V VCC...

Page 40: ...DATA GND GND GND GND Q2 6 0MHZ Q1 11 0592M HZ C26 33PF 16V C27 33PF 16V GND GND XF1 XF2 GND C23 33NF 16V GND GND GND GND GND VCC VCC D0 D1 D2 D3 D4 D5 D6 D7 RD WR VCC VCC VCC C24 33PF 16V C25 33PF 16V GND GND XA1 XA2 MISO MOSI SCK TX REQ SS RX BUSY GND VCC MOSI RESET RESET SCK MISO RXE RXE TXE TXE D0 D1 D2 D3 D4 D5 D6 D7 GND GNDGND GND GND VCC VCC C22 100NF 16V D5 LL4148 VCC VCC GND GND RESET VCC ...

Page 41: ...32 Hardware 2008 Conrad Electronic 3 3 5 3 Component Parts Plan ...

Page 42: ...or Software Security SPI Interface for In System Programming JTAG IEEE std 1149 1 Compliant Interface Boundary scan Capabilities According to the JTAG Standard Extensive On chip Debug Support Programming of Flash EEPROM Fuses and Lock Bits through the JTAG Interface Peripheral Features Two 8 bit Timer Counters with Separate Prescalers and Compare Modes Two Expanded 16 bit Timer Counters with Separ...

Page 43: ...he Module The Mega128 Module is shipped on 4 dual row 2x8 square pins For hardware application the corresponding socket strips must be organized in the following pitch format In the graph the socket strip X1 X4 and then the first two pins of the socket strip can be seen Pin 1 of strip X1 corresponds to terminal X1_1 see Mega128Pinzuordnung Module Memory The C Control Pro 128 Module provides 128kB ...

Page 44: ...ecuted after the operating voltage is switched on Hardware Reset is executed when the Module s RESET X2_3 is pulled to low and released again by e g shortly pressing the connected Reset push button RESET1 SW3 A Brown Out Detection avoids that the Controller can enter undefined conditions in case of dropping operating voltages Digital Ports PortA PortB PortC PortD PortE PortF PortG The C Control Pr...

Page 45: ...as Timer_3 with 16 bits each They can be used for D A conversion to control servo motors in pattern making and to output audio frequencies A pulse length modulated signal has a period of N so called Ticks The duration of one tick is the time base If the output value of a PLM port is set to X then the port will hold high level for X ticks of one period and will then for the balance of the period dr...

Page 46: ...Communication takes place through a USB Controller by FTDI and an AVR Mega8 Controller The Mega8 provides its own Reset push button SW5 During USB operation the status of the interface is indicated by two light emitting diodes LD4 red LD5 green When only the green LED lights up the USB interface is ready for operation During data transmission both LEDs will light up This also applies to the Debug ...

Page 47: ...character consists of a monochrome matrix of 5x7 pixels A flashing cursor below any one of the characters will indicate the current output position The operating system provides a simple software interface for output on the display This display is connected to connector X14 16 poles double row By means of a mechanical protection a faulty connection and thus the confusing of poles is avoided The LC...

Page 48: ...ing A fixed voltage control generates an internally stabilized 5V supply voltage This voltage is provided to all circuit components on the application board Due to the power reserve of the Plug In Power Supply this voltage can also be used to power external ICs Please observe the Maximum Drawable Current Exceeding this current may lead to immediate destruction Because of the relativelly high curre...

Page 49: ... cables interferences may detract correct data transmission Only use cables of which the pin assignments are known Never connect the serial transmission outputs of two devices directly together Transmission outputs can usually be identified by their negative output voltage in quiescent condition Testing Interfaces The 4 pole pin strip X16 is to be used for testing purposes only and will not necess...

Page 50: ... SPI_TX_REQ X1_10 8 PE6 4 38 INT6 T3 EXT T2 Switch 2 Input Timer 3 X1_9 9 PE7 4 39 INT7 IC3 EXT DATA LCD_Interface X1_8 10 PB0 1 8 SS SPI X1_7 11 PB1 1 9 SCK SPI X1_6 12 PB2 1 10 MOSI SPI X1_5 13 PB3 1 11 MISO SPI X1_4 14 PB4 1 12 OC0 RX BUSY SPI_RX_BUSY X1_3 15 PB5 1 13 OC1A EXT A1 DAC1 X1_2 16 PB6 1 14 OC1B EXT A2 DAC2 X1_1 17 PB7 1 15 OC1C OC2 EXT SCK LCD_Interface X2_5 18 PG3 6 51 TOSC2 LED1 L...

Page 51: ...53 GND X3_8 54 PF7 5 47 ADC7 TDI JTAG X3_7 55 PF6 5 46 ADC6 TDO JTAG X3_6 56 PF5 5 45 ADC5 TMS JTAG X3_5 57 PF4 5 44 ADC4 TCK JTAG X3_4 58 PF3 5 43 ADC3 X3_3 59 PF2 5 42 ADC2 X3_2 60 PF1 5 41 ADC1 X3_1 61 PF0 5 40 ADC0 X4_11 62 AREF X4_12 63 GND X4_9 64 AVCC 3 4 4 Jumper Application Board Jumper By use of jumpers certain options can be selected This applies to several ports which are provided with...

Page 52: ... the board The gray marking indicates the first Pin Pin 0 of the Port 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 JP4 JP4 serves to toggle the operating voltage Mains Plug In Power Supply or USB The application board should be operated using ...

Page 53: ...the Mega128 is connected through a level converter Pin 1 left gray TxD Pin 2 center RxD Pin 3 right GND PAD3 PAD3 to the right of the module is required as ADC_VREF_EXT for functions ADC_Set and ADC_SetInt 3 4 5 Connection Diagrams Additionally the connection diagrams can be found as PDF files on the Installation CD ROM 3 4 5 1 Mega 128 Module The shown connection diagram shows the planned C Contr...

Page 54: ...G2 PG3 PG4 RESET AREF AVCC GND Vcc GND GND RXD TXD VREF IC2 ATA6660 CANH CANL L1 Q1 16MHz R1 20k R2 62R R3 62R R4 0R X1 X2 X3 X4 AREF AREF AVCC AVCC GND GND GND GND GND GND GND GND Vdd Vdd Vdd Vdd 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30 31 32 33 34 35 36 37 38 39 4 40 41 42 43 44 45 46 47 48 49 5 50 51 52 53 54 55 56 57 58 59 6 60 61 62 63 64 7 8 9 1 2 3 4 5 6 7 8 2 1 1 ...

Page 55: ...2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 1 2 1 2 3 4 5 6 b0805j b0805j e03c165 e01d5x11s b0805j b0805j b0805j b0805j b0805j b0805j plname plname plname plname plname b0805_spule splname splname splname b0805j b0805j b0805j b0805j b0805j plname taster1 C28 100nF C29 100nF C30 100nF C31 100nF 10mm Project MEGA128app_V2 Sheet 2 of 4 PCB Design MEGA Appl Board schäffel electronic gmbh V...

Page 56: ... 9 1 10 11 12 13 14 15 16 17 18 2 20 21 23 24 25 26 27 28 29 3 30 31 32 4 5 6 7 8 9 1 2 3 4 5 6 8 1 2 1 2 1 2 1 2 3 4 5 1 2 3 4 b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j sod80 splname splname splname plname plname b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j b0805j plname C1 100nF C2...

Page 57: ...48 Hardware 2008 Conrad Electronic 3 4 5 3 Component Parts Plan ...

Page 58: ...Part 4 ...

Page 59: ...several files can be filed to form a project Editor Window 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 ...

Page 60: ...ct the dialog box Create Project can be opened by use of item New Here a project name is issued for the project Then the project is created in the sidebar It is not necessary to decide in advance whether a CompactC or a BASIC project will be created In a project CompactC or BASIC files can be arranged combined as project files in order to create a program The source text files in a project will de...

Page 61: ...e area of the compiler messages the following actions can be initiated delete will delete the list of compiler messages copy to clipboard will copy all text messages onto the clipboard 4 1 3 Project Management A right mouse click on the newly created project in the sidebar will open a pop up menu with the following options Newly Add A new file will be set up and simultaneously an editor window wil...

Page 62: ...he project file will move up the list also with Ctrl Arrow up Down The project file will move down also with Ctrl Arrow down Rename The name of the project file will be changed Delete The file will be deleted from the project Options The project options can be changed 4 1 4 Thread Options In order to activate a Thread to runtime it must be activated in the selection box and the parameters Stack Si...

Page 63: ...s more space than assigned to then the memory space of the other Threads is affected and a program breakdown may occur 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 ...

Page 64: ...se click on ScanHardware will scan the connected C Control Pro Module and select the correct CPU In Options Multi Threading is configured and it is further determined if a Debug Code should be generated If a Debug Code is compiled the Byte Code becomes insignificantly longer For each line in the source text which contains executable commands the Byte Code will be one Byte longer In case Multi Thre...

Page 65: ...roject files Only those files will be used for compilation whose CheckBox has been selected The list can be altered by use of the path text input field Library Name and the buttons in the dialog Add The path will be added to the list Replace 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 ...

Page 66: ... to this the source text must be compiled error free with Debug Info and in the corresponding line really executable program text must be placed i e no commentary line o e Functions Overview On the left side is an overview of all syntactically correct defined functions The function names with parameters are expressed in this view The function where the cursor in this moment resides is drawn with a...

Page 67: ...e syntactical analyzer that is built into the editor recognizes a defined function beams are drawn on the left side along the range of the function 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 ...

Page 68: ...tions the syntactic analysis can repeated if the command Refresh is selected from the Edit pull down menu 4 2 1 Editor Functions Under menu item Edit the most important editor functions can be found Undo Ctrl Z will execute an Undo operation The possible number of Undo steps depends on the settings in Undo Groups Restore Ctrl Y will restore the editor condition that has been changed by previous us...

Page 69: ...ng the user will be asked for approval Furthermore it can be pre determined whether the entire text or a selected text area only should be scoured and what search direction should be used 4 2 2 Print Preview To deliver the source code as Hard Copy or for archiving purposes the C Control Pro IDE has built in printer functions The following options can be selected from the File Pull Down Menu Print ...

Page 70: ...Move cursor right one word PgUp Move cursor up one page PgDn Move cursor down one page Ctrl PgUp Move cursor to top of page Ctrl PgDn Move cursor to bottom of page Ctrl Home Move cursor to absolute beginning Ctrl End Move cursor to absolute end Home Move cursor to first char of line End Move cursor to last char of line Shift Left Move cursor and select left one char Shift Right Move cursor and sel...

Page 71: ...ottom of page Alt Shift Ctrl Home Move cursor and column select to absolute beginning Alt Shift Ctrl End Move cursor and column select to absolute end Alt Shift Home Move cursor and column select to first char of line Alt Shift End Move cursor and column select to last char of line Ctrl C Ctrl Ins Copy selection to clipboard Ctrl X Cut selection to clipboard Ctrl V Shift Ins Paste clipboard to cur...

Page 72: ...attern Characters in square brackets represent the appearance of one of the characters A Circumflex in square brackets negates the selection A Minus in square brackets symbolizes a character range Tailed braces will group separate expressions Up to ten levels may be nested A Back Slash will take the special meaning from the following character Examples Example will find void the word void only at ...

Page 73: ...he program runs in Debug Mode In rare cases the system can get jammed during USB operation when the RESET1 button is pressed To overcome this please also press RESET2 in order to issue a Reset pulse to the Mega8 too The Mega8 is on the Application Board responsible for the USB interface AutoStart If no USB interface is connected and SW1 has not been pressed during power up in order to reach the Se...

Page 74: ...normal operations are prohibited By means of a new transfer the Interpreter can be overwritten the PIN will however stay preserved Also a normal start other than the Autostart behaviour is no longer allowed Furthermore the scans of hardware and firmware version numbers are locked If access to a forbidden function is tried a dialod with the following text will be displayed C Control is Password pro...

Page 75: ...eVersion in the C Control menu 4 4 Debugger In order to activate the Debugger the project must first be compiled in Debug Code free of errors and then transferred to the Module The file holding the Debug Code dbg must be present in the project list In the Debugger menu all Debugger commands can be found The Debugger ist started with Debug Mode Shift F10 If at this point of time no Breakpoint is se...

Page 76: ...posing to Single Step the function Procedure Step will not jump into the function calls but will overpass them If a loop contains only one code line then one single step will execute the entire loop since only after this branching out to a new code line will take place With the instruction Leave Debug Mode the Debug Mode will be terminated During active Debug Mode the program text can not be alter...

Page 77: ...r 10 000 writing accesses 4 4 2 Array Window In order to monitor the contents of Array Variables it is possible to call up a window with the array contents To do this the pointer is placed over the the variable and Show Array is selected by a right mouse click 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 dimensio...

Page 78: ...ing switch Actualize 4 4 3 Variable Watch Window The contents of variables can be displayed within the Debugger To do this the mouse pointer is placed over the variable Within approximately 2 seconds the content of the variable is displayed in form of a Tooltip The variable is first displayed in accordance to its data type and then separated by a comma as Hex number with a preceeding 0x If several...

Page 79: ...value in the list no Debug Code No Debug Code has been generated wrong Syntax During text entry invalid characters have been entered for a variable Function unknown The Function Name is not known Variable unknown The Variable Name is not known not in Debug Mode The Debug Mode has not been activated no Context Local variables can only be displayed while within this function not actual The content o...

Page 80: ... hand the user can click into the terminal window and directly type the characters from the keyboard on the other hand the text can be entered in to the ASCII input line and send with the Send button Instead of ASCII the characters can be defined as integer values in the Integer input line Is send C R selected a Carriage Return 13 is sent at the end of the line Enable PreserveInput to prevent that...

Page 81: ...rst non blank character of the preceding non blank line when you press Enter Backspace unindents Aligns the insertion point to the previous indentation level outdents it when you press Backspace if the cursor is on the first non blank character of a line Group undo Undo operation will not be performed in small steps but in blocks Groupredo If it is set Redo will involve group of changes Keep caret...

Page 82: ...se cursor when user type text and mouse cursor within client area Scroll to last line When it is true you may scroll to last line of text otherwise you can scroll to last page When this option is off and total text height less then client height vertical scroll bar will be hidden Greedy selection If this option is set selection will contain extra column line during column line selection modes Keep...

Page 83: ... the option Capitalization Effect The selectable Elements have the following meaning Symbol all non alpha numeric characters Number all numeric characters String all characters that are recognized as strings 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 Mark...

Page 84: ...r 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 A description of the options can be found under Project Options The selection boxes Configure Threads and ConfigureLibrary are identical to the descriptions in chapter Projects ...

Page 85: ...ct will be re opened when the C Control Pro IDE is started Open Maximized Editor Window When a file is opened the editor window will automatically be switched to maximum size Splashscreen Short Display The Splashscreen is only displayed until the main window is opened Allow Multiple Instances Of C Control Pro When the C Control Pro interface is started several times it may create conflicts with re...

Page 86: ...refix COM COM0 COM1 aso By use of the button Search Interface all interfaces will be evaluated until the command line interface of C Control Pro will react In order to recognize an application board power must be supplied and the firmware must not have stalled It is recommended to switch the power off and on again prior to the searching action The buttons C Control Test and Hardware Version allow ...

Page 87: ...IDE Theparameter n can be set in the input field on the right The button Update Check Now will immediately activate an update search In order to have the Internet update function correctly the MS Internet Explorer must not be in Offline Mode If e g the Internet access is restricted by a Proxy due to a firewall then the Proxy settings such as address user name and password can be entered in this di...

Page 88: ...t can be chosen from Further the standard baudrates the number of Data Bits and Stop Bits and the Flow Control is selectable 4 6 4 4 Tools In the Tool settings the user can insert delete and edit entries that defines external programs that can be executed fast and simple from the IDE The names of the programs can be found in the Tools pulldown menu and can be started with a single click ...

Page 89: ...ically be arranged by use of commands in the Window Menu Overlap The windows will be arranged on top of each other with each successive window placed fractionally lower and more to the right than the preceeding one Beneath The windows are placed vertically beneath each other Side By Side Will arrange the windows next to each other from left to right Minimize All Will minimize all windows to symbol...

Page 90: ...atically placed onto the clipboard when Program Version is called up the data can easily be added to the end of an E Mail If the user needs to find a certain search term in the Help file the Context Help may be of advantage If e g in the Editor the cursor stands over the word AbsDelay and the correct parameters are searched for then Context Help should be selected This function will automatically ...

Page 91: ...82 IDE 2008 Conrad Electronic ...

Page 92: ...Part 5 ...

Page 93: ...2 Preprocessor The Gnu Generic Preprocessor used here provides some additional functions which are documented under http nothingisreal com gpp gpp html Only the functions described here however have also together with the C Control Pro Compiler been thoroughly tested Using the here undocumented functions will thus be at your own risk The C Control development system contains a complete C Preprozes...

Page 94: ...n a include instruction must not contain any blank characters 5 1 2 1 Predefined Symbols In order to ease the work with different versions of the C Control Pro series there are a number of definitions which are set depending on target system and Compiler project options These constants can be called up by ifdef ifndef or if Symbol Meaning MEGA32 Configuration for Mega 32 MEGA128 Configuration for ...

Page 95: ...ed The following commands are authorized pragma Error xyz An error is created and text xyz is issued pragma Warning xyz A warning is created and text xyz is issued pragma Message xyz The text xyz is issued by the Compiler Example These pragma instructions are often used in conjunction with Preprocessor commands and Predefined Constants A classical example is the creation of an error message in cas...

Page 96: ...the C Control Pro The language volume of CompactC does essentially correspond with ANSI C It is however reduced to some extent since the firmware had to be implemented in a resource saving way The following language constructs are missing structs unions typedef enum constants const instruction pointer Arithmetic Detailed program examples can be found in directory Demo Programs which was installed ...

Page 97: ... by one or several Whitespaces Simple Instruction a 5 An instruction does not necessarily have to completely stand in one line Since line feeds do also belong to the space category it is legitimate to separate an instruction across several lines if a 5 instruction across 2 lines a a 10 InstructionBlock Several instructions can be grouped into a block Here the block is opened by a left tailed brack...

Page 98: ...e quantities can either be Figures Variables and Functions A simple example 2 3 Here the numerical values 2 and 3 are connected by the Operator An arithmetic value again represents a value In this case the value is 5 Further examples a 3 b f 5 2 3 6 Following the rule Dot before Line here 3 times 6 is calculated first and then 2 is added This priority is in case of operators called precedence A li...

Page 99: ... 38 to 3 402e38 32 As one can see the data types unsigned char and byte as well as unsigned int and word are identical Strings There is no explicit String data type A string is based on a character array The size of the array must be chosen in such a way that all characters of the string fit into the character array Additionally some space is needed for a terminating character decimal Zero in orde...

Page 100: ...ch they have been defined A variable definition appears as follows Type Variable Name When several variables of the same type need to be defined then these variables can be stated separated by commas Typ Name1 Name2 Name3 As types are allowed char unsigned char byte int unsigned int word float Examples int a int i j float xyz Integer variables may have decimal figure values or Hex values assigned ...

Page 101: ...ce of C Control Pro is the only limit Multi dimensional arrays can also be declared by attaching further brackets during variable definition int x 3 4 array with 3 4 entries int y 2 2 2 array with 2 2 2 entries Arrays may in CompactC have up to 16 indices dimensions The maximum value for an index is 65535 The indices of arrays are in any case zero based i e each index will start with a 0 During pr...

Page 102: ... from every function Variable declarations within functions produce local variables Local variables can only be reached within the function An example int a b void func1 void int a x y global b is accessable global a is not accessable since concealed by local a local x y are accessable u is not accessable since local to function main void main void int u globale a b are accessable local u is acces...

Page 103: ... partial expressions The operators are then evaluated in the succession of their priorities precedence Expressions with operators of identical precedence will be calculated from left to right Example i 2 3 4 5 result 9 first 3 4 then 2 finally 5 The succession of the execution can be influenced by setting of parenthesis Parenthesis have the highest priority If the last example should strictly be c...

Page 104: ... 3 0 Or 1 3 0xf0 0x0f 3 0xff exclusive Or 0xff 0x0f 0xf0 0x0f 0xf0 0xff Bit inversion 0xff 0xf0 0 0x0f 5 2 5 3 Bit Shift Operators Bit Shift operators are only allowed for Integer data types With a Bit Shift operation a 0 will always be moved into one end Operator Description Example Result shift to left 1 2 3 3 4 24 shift to right 0xff 6 16 2 3 4 5 2 5 4 In Decrement Operators Incremental and dec...

Page 105: ...mented by one before access predecrement a a 1 5 2 5 5 Comparison Operators Comparison operators are allowed for float and Integer data types Operator Description Example Result smaller 1 2 2 1 2 2 1 0 0 greater 3 2 3 2 0 1 smaller or equal 2 2 3 2 1 0 greater or equal 2 3 3 2 0 1 equal 5 5 1 2 1 0 not equal 2 2 2 5 0 1 5 2 5 6 Logical Operators Logical operators are only allowed for Integer data ...

Page 106: ...s expression 3 Examples a i 5 i 0 a i b 2 i 5 b 1 while i x y x y i 5 2 6 2 do while With a do while construct the instructions can depending on a condition be repeated in a loop do Instruction while Expression The instruction or the Instruction Block is being executed At the end the Expression is evaluated If the result is unequal 0 then the execution of the expression will be repeated The entire...

Page 107: ...n1 Expression Instruction2 Instruction3 At first Instruction1 will be executed which normally contains an initialization Following the evaluation of the Expression takes place If the Expression is unequal 0 Instruction2 and Instruction3 will be executed and the loop will repeat itself When Expression reaches the value 0 the loop will be terminated As with other loop types at Instruction3 an Instru...

Page 108: ...d be avoided within structured programming languages it is possible with goto to jump to a label within a procedure for loop with realized with goto void main void int a a 0 label0 a if a 10 goto label0 5 2 6 5 if else An if instruction does have the following syntax if Expression Instruction1 else Instruction2 After the if instruction an Arithmetic Expression will follow in parenthesis If this Ex...

Page 109: ...y 5 2 6 6 switch If depending on the value of an expression various commands should be executed a switch instruction is an elegant solution switch 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 consta...

Page 110: ...5 b b 2 break case 100 0xf b b c break default b b 2 breakInstruction A break will leave the switch instruction If break is left out ahead of case then the instruction will be executed even when a jump to the preceeding case does take place switch a case 1 a case 2 a is also executed at a value of a 1 case 3 a is also executed at a value of a 1 or a 2 In this example all three a instructions are e...

Page 111: ...tion of continue within a loop will immediately initialize a new calculation of the Expression Depending on the result the loop will be repeated at unequal 0 A result of 0 will terminate the loop Example while 1 endless loop a if a 10 break will terminate the loop 5 2 7 Functions In order to structure a larger program it is separated into several sub functions This not only improves the readabilit...

Page 112: ...s are only visible within the function itself In order to call up function func1 by use of the parameters the parameters for call up should be written in the same succession as they have been defined in func1 If the function does not get parameters the parenthesis will stay empty void main void word a float f func1 128 12 0 you can passs numerical constants a 100 f 12 0 func1 a 28 f or yet variabl...

Page 113: ...function int StringLength char str int i i 0 while str i i repeat character as long as unequal zero return i void main void int len char text 15 text hello world len StringLength text 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 With references this is differ...

Page 114: ...ikation Division Modulo negatives Vorzeichen Vergleichsoperatoren kleiner größer kleiner gleich größer gleich gleich ungleich Bitschiebeoperatoren um ein Bit nach links schieben um ein Bit nach rechts schieben Inkrement Dekrement Operatoren Post Pre Inkrement Post Pre Dekrement Logische Operatoren logisches Und logisches Oder logisches Nicht ...

Page 115: ...der exclusives 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 do else false float for goto if int return signed static switch true unsigned void while word ...

Page 116: ... interface There example solutions can be found for almost every field of purpose of the C Control Pro Module The following chapters offer a systematical introduction to syntax and semantics of C Control Pro BASIC 5 3 1 Program A program consists of a number of instructions such as e g a 5 which are distributed among various Functions The starting function which must be present in every program is...

Page 117: ...instruction across two lines a a 10 It is also possible to place more than one instruction into the same line The character colon will then separate the individual instructions For reason of better readability however this option should rather seldom be used a 1 b 2 c 3 Comments Comments There are two types of commentaries which are the single line and the multi line commentaries The text within c...

Page 118: ... 3 times 6 is calculated first and then 2 is added This priority is in case of operators called precedence A list of priorities can be found in the Precedence Table Comparisons too are arithmetic expressions The comparison operators return a truth value of 1 or 0 depending on whether the comparison was true or not The expression 3 5 yields the value 1 true ConstantExpressions An expression or port...

Page 119: ... the case that individual values are not of the same type So the data types a 5 5 In this case a is first converted into the Single data type and then 5 5 is added The data type of the result is also Single For data type conversion there are the following rules If in a linkage of 8 Bit or 16 Bit integer values one of the two data types is sign afflicted then the result of the expression is also si...

Page 120: ...rd Dim i j As Integer a H3ff i 15 j 22 a 0x3ff Floating Point Figures data type Single may contain a decimal point and an exponent Dim x y As Single x 5 70 y 2 3e 2 x 5 33e 1 SizeOf Operator By the operator SizeOf the number of Bytes a variable takes up in memory can be determined Examples Dim s As Integer Dim f As Single s SizeOf f the value of s is 4 With arrays only the Byte length of the basic...

Page 121: ...If an index becomes too large during program execution the access to alien variables will be tried which in turn may create a good chance for a program breakdown Strings There is no explicit String data type A string is based on an array of data type Char The size of the array must be chosen in such a way that all characters of the string fit into the character array Additionally some space is nee...

Page 122: ...ables will be initialized by zero Local variables will during calculation of a function be arranged on the stack I e local variables exist in memory only during the time period in which the function is executed If with local variables the same name is selected as with a global variable then the local variable will conceal the global variable While the program is working in the function where the i...

Page 123: ... result 15 first 2 3 then 4 finally 5 A list of priorities can be found in Precedence Table 5 3 5 1 ArithmeticOperators All arithmetic operators with the exception of Modulo are defined for Integer and Floating Point data types Modulo is restricted to data type Integer only It must be observed that in an expression the figure 7 will have an Integer data type assigned to it If a figure of data type...

Page 124: ...allowed for Integer data types With a Bit Shift operation a 0 will always be moved into one end Operator Description Example Result shift to left 1 2 3 3 4 24 shift to right Hff 6 16 2 3 4 5 3 5 4 Comparison Operators Comparison operators are allowed for Single and Integer data types Operator Description Example Result smaller 1 2 2 1 2 2 1 0 0 greater 3 2 3 2 0 1 smaller or equal 2 2 3 2 1 0 grea...

Page 125: ...sult is unequal 0 then the execution of the expression will be repeated The entire procedure will constantly be repeated until the Expression takes on the value 0 Examples Do a a 2 Loop While a 10 Do a a 2 x a Loop While a The essential difference between the Do Loop While loop and the normal Do While loop is the fact that in a Do Loop While loop the instruction is executed at least once ExitInstr...

Page 126: ...it instruction is executed within a loop than the loop will be left and the program execution starts with the next instruction after the While loop Example Do While 1 Endless loop a a 1 If a 10 Then Exit Will terminate loop End If End While 5 3 6 3 For Next A For Next loop is normally used to program a definite number of loop runs For Counter Variable Startvalue To Endvalue Step Stepwidth Instruct...

Page 127: ...ased A For Next loop should thus rather run from 0 through 9 ExitInstruction An Exit instruction will leave the loop and the program execution starts with the next instruction after the For loop Example For i 1 To 10 If i 6 Then Exit End If Next 5 3 6 4 Goto Even though it should be avoided within structured programming languages it is still possible with goto to jump to a label within a procedure...

Page 128: ...ed By use of the command word else an alternative Instruction2 can be defined which will be executed when the Expression has been calculated as 0 The addition of an else instruction is optional and not really necessary If directly in an Else branch an If instruction needs again to be placed then it is possible to initialize an If again direcly by use of an ElseIf Thus the new If does not need to b...

Page 129: ... smaller equal Constant Constant Expression greater Constant Constant Expression greater equal Constant Constant Expression unequal Constant Constant1 To Constant2 Constant1 Expression Constant2 The new features to use comparisons are introduced for Select Case statements with version 1 71 This extension is not available for CompactC switch statements The value of the Expression is calculated Then...

Page 130: ...proves the readability but allows to combine all program instructions repeatedly appearing in 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 from main A simple example Sub func1 Instructions in function func1 End Sub Sub main Function func1 will be called up twice func1 func1 End Sub ParameterPassing In ord...

Page 131: ...meters must always be stated The following call up is inadmissible func1 func1 gets 2 parameters func1 128 func1 gets 2 parameters Return Parameters It is not only possible to pass parameters A function can also offer a return value The data type of this value is during function definition entered after the parameter list of the function Sub func1 a As Integer As Integer Return a 10 End Sub The re...

Page 132: ...h If in a function a normal parameter is changed then the change is not visible outside this function With references this is different Through parameter str can in StringLength the contents of text be changed since str is only the reference pointer to the array variable text Presently arrays can only be presented by Reference 5 3 8 Tables 5 3 8 1 Operator Precedence Rang Operator 10 9 negatives V...

Page 133: ... rechts schieben Bitoperatoren And Und Or Oder Xor exclusives Oder Not Bitinvertierung 5 3 8 3 Reserved Words The following words are reserved and cannot be used as identifiers And As ByRef Byte Case Char Dim Do Else ElseIf End Exit False For Goto If Integer Lab Loop Mod Next Not Opc Or Return Select Single SizeOf Static Step Sub Then To True While Word Xor 5 4 ASCII Table Dec Hex Char Dec Hex Cha...

Page 134: ... 12 C FF 44 2C 76 4C L 108 6C l 13 D CR 45 2D 77 4D M 109 6D m 14 E SO 46 2E 78 4E N 110 6E n 15 F SI 47 2F 79 4F O 111 6F o 16 10 DLE 48 30 0 80 50 P 112 70 p 17 11 DC1 49 31 1 81 51 Q 113 71 q 18 12 DC2 50 32 2 82 52 R 114 72 r 19 13 DC3 51 33 3 83 53 S 115 73 s 20 14 DC4 52 34 4 84 54 T 116 74 t 21 15 NAK 53 35 5 85 55 U 117 75 u 22 16 SYN 54 36 6 86 56 V 118 76 v 23 17 ETB 55 37 7 87 57 W 119 ...

Page 135: ...126 Compiler 2008 Conrad Electronic 31 1F US 63 3F 95 5F _ 127 7F DEL ...

Page 136: ...Part 6 ...

Page 137: ...x23 and a word has to be transferred to the stack as a parameter Changes in the library IntFunc_Lib cc may cause that the functions declared there can no longer be executed correctly 6 2 AbsDelay GeneralFunctions Syntax void AbsDelay word ms Sub AbsDelay ms As Word Description The function Absdelay waits for a specified number of milliseconds This function works in a very accurate manner but suspe...

Page 138: ...ga32 AIN0 PortB 2 Mega128 AIN0 PortE 2 or an internal reference voltage of 1 22V Parameter mode working mode Mode Values 0x00 external inputs AIN0 and AIN1 are used 0x40 external Input AIN1and internal reference voltage are used 0x80 Analog Comparator gets disabled 6 3 2 AComp Example Example Usage of Analog Comparators AComp Analog Comparator Mega32 Input PB2 PortB 2 bzw band gap reference 1 22V ...

Page 139: ...olution of 10 Bit I e measured voltages can be displayed as integral numbers from 0 through 1023 Reference voltage for the lower limit is GND level 0V The reference voltage for the upper limit can be selected at will External Reference Voltage AVCC with capacitor on AREF Internal Reference Voltage 2 56V with capacitor on AREF Analog Inputs ADC0 ADC7 ADC_BG ADC_GND For the ADC the Inputs ADC0 ADC7 ...

Page 140: ...x1 Differential Inputs ADC2 ADC3 Gain 1 ADC24x1 Differential Inputs ADC2 ADC4 Gain 1 ADC25x1 Differential Inputs ADC2 ADC5 Gain 1 ADC2 is the negative input The ADC can also perform differential measurements The result can either be positive or negative The resolution during differential operation amounts to 9 bit and is displayed in Two s Complement format For differential operation an amplifier ...

Page 141: ... As Word Description This function is used to read the measurement value after a successful ADC Interrupt The ADC Interrupt gets triggered after the AD conversion is completed and a new measurement value is available See ADC_SetInt and ADC_StartInt The function ADC_Read delivers the digitized measured value from one of the 8 ADC ports The port number 0 7 has been given as a parameter in the call o...

Page 142: ...Board M32 or M128 6 4 5 ADC_SetInt ADCFunctions Syntax word ADC_SetInt byte v_ref byte channel Sub ADC_SetInt v_ref As Byte channel As Byte As Word Description The function ADC_SetInt initializes the Analog Digital converter for interrupt usage The reference voltage and the measurement channel number is selected and the A D converter is prepared for the measurement An interrupt service routine mus...

Page 143: ... of carrier amplitude to 25 The start of the decrease lies at the respective beginning of the seconds 0 58 within a minute In second 59 there is no decrease so the following second mark can indicate the beginning of a minute and the receiver can be synchronized The sign duration yields the logical value of the signs 100 ms are 0 200 ms are 1 Because of this there are 59 bits for informations avail...

Page 144: ...te_Minute There are two libraries used DCF_Lib cc and LCD_Lib cc For the radio reception of the time signal a DCF 77 receiver is necessary The output of the DCF receiver is connected to the input port Mega32 PortD 7 M128 PortF 0 At first the beginning of a time information has to be found It will be synchronized onto the pulse gap bit 59 Following the bit will be received in seconds time There wil...

Page 145: ...he RTC is not backed up by a battery i e the clock time will not be updated if there is no power applied to the Controller 6 5 1 DCF_FRAME DCFFunctions Syntax void DCF_FRAME void Sub DCF_FRAME Description Set DCF_Mode to 3 data decode and save parity check Parameter None 6 5 2 DCF_INIT DCFFunctions Syntax void DCF_INIT void Sub DCF_INIT Description DCF_INIT initializes DCF usage The input of the D...

Page 146: ...1 look for pulse Parameter None 6 5 4 DCF_START DCFFunctions Syntax void DCF_START void Sub DCF_START Description DCF_START initializes all variables and sets DCF_Mode to 1 From now on DCF time recording is working automatically Parameter None 6 5 5 DCF_SYNC DCFFunctions Syntax void DCF_SYNC void Sub DCF_SYNC Description ...

Page 147: ...takes place in the background If it is tried to send more than 128 Byte then the Mega RISC CPU will have to wait until all characters not fitting into the buffer anymore have been transferred 6 6 1 Msg_WriteChar Debug Message Functions Syntax void Msg_WriteChar char c Sub Msg_WriteChar c As Char Description One character is written to the output window A C R Carriage Return Value 13 generates a ju...

Page 148: ...isplayed in the output window The Output is formatted as a hexadecimal value with 4 digits Leading zeros are displayed Parameter val 16bit integer value 6 6 4 Msg_WriteInt Debug Message Functions Syntax void Msg_WriteInt int val Sub Msg_WriteInt val As Integer Description The passed 16bit value is display in the output window Negative values are displayed with a preceding minus sign Parameter val ...

Page 149: ..._WriteWord Debug Message Functions Syntax void Msg_WriteWord word val Sub Msg_WriteWord val As Word Description The parameter val is written to the output windows as an unsigned decimal number Parameter val 16bit unsigned integer value 6 7 EEPROM 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 EE...

Page 150: ... EEPROM value 6 7 2 EEPROM_ReadWord EEPROMFunctions Syntax word EEPROM_ReadWord word pos Sub EEPROM_ReadWord pos As Word As Word Description Reads one word 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 The value of pos describes a byte position in the EEPROM Th...

Page 151: ...en using word or floating point accesses Parameter pos byte position in EEPROM Return Parameter EEPROM value 6 7 4 EEPROM_Write EEPROMFunctions Syntax void EEPROM_Write word pos byte val Sub EEPROM_Write pos As Word val As Byte Description Writes one byte 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 EE...

Page 152: ...at val Sub EEPROM_WriteFloat pos As Word val As Single Description Writes a floating point value 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 The value of pos describes a byte position in the EEPROM This should be taken care of when using word or floating point ...

Page 153: ...s Syntax byte I2C_Read_ACK void Sub I2C_Read_ACK As Byte Description This function receives a byte and acknowledges with ACK Afterwards the status of the interface can be returned with I2C_Status Return Parameter value read from the I2C bus 6 8 3 I2C_Read_NACK I2CFunctions Example Syntax byte I2C_Read_NACK void Sub I2C_Read_NACK As Byte Description This function receives a byte and acknowledges wi...

Page 154: ... introduces communication with a starting sequence Afterwards the status of the interface can be returned with I2C_Status Parameter None 6 8 5 I2C_Status I2CFunctions Syntax byte I2C_Status void Sub I2C_Status Description With I2C_Status the status of the I2C interface can be accessed For the meaning of the return value please look inside the I2C status code table Return Parameter current I2C Stat...

Page 155: ...unication with a stop sequence Afterwards the status of the interface can be returned with I2C_Status Parameter None 6 8 7 I2C_Write I2CFunctions 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 ...

Page 156: ...Mode Status Code Description 0x08 a START sequence has been sent 0x10 a repeated START sequence has been sent 0x38 conflict with SLA R or data bytes 0x40 SLA R has been sent ACK has been received 0x48 SLA R has been sent NACK has been received 0x50 Data byte has been sent ACK has been received 0x58 Data byte has been sent NACK has been received 6 8 9 I2C Example Example read EEPROM 24C64 and write...

Page 157: ...Write address 8 HIGH WORD ADDRESS I2C_Write address LOW WORD ADDRESS I2C_Start RESTART I2C_Write 0xA1 DEVICE ADDRESS A1 EEPROM_data I2C_Read_NACK I2C_Stop Msg_WriteHex EEPROM_data 6 9 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 ...

Page 158: ...M3CMPA Timer3 CompareA only Mega128 INT_TIM3CMPB Timer3 CompareB only Mega128 INT_TIM3CMPC Timer3 CompareC only Mega128 INT_TIM3OVF Timer3 Overflow only Mega128 The corresponding interrupt has to receive the corresponding instructions in an Interrupt Service Routine ISR and also the interrupt has to be enabled See Example During execution of the interrupt routine the Multi Threading is suspended A...

Page 159: ...ng edge triggers the interrupt 3 a rising edge triggers the interrupt 6 9 2 Ext_IntDisable InterruptFunctions Syntax void Ext_IntDisable byte IRQ Sub Ext_IntDisable IRQ As Byte Description The external Interrupt IRQ gets disabled Parameter IRQ number of the interrupt to disable 6 9 3 Irq_GetCount Interrupt Functions Example Syntax byte Irq_GetCount byte irqnr Sub Irq_GetCount irqnr As Byte As Byte...

Page 160: ...nterrupt service routine for a specified interrupt At the end of the interrupt service routine the function Irq_GetCount has to be called otherwise the interrupt service routine gets called continuously Parameter irqnr specifies the interrupt type see table vect is the name of the interrupt function to be called Remark The floating point data type seems not suitable for an interrupt vector but a 4...

Page 161: ...e advantage that they can be taken from the project by omitting the library in case they are not needed Direct Interpreter functions are always present will however take up flash memory 6 10 1 Key_Init KeyboardFunctions Library Key_Lib cc Syntax void Key_Init void Sub Key_Init Description The global keymap array gets initialized with the ASCII values of the keyboard Parameter None 6 10 2 Key_Scan ...

Page 162: ...er keys bit field value that has been retuned from Key_Scan Return Parameter ASCII value of recognized keys 1 if no key is pressed 6 11 LCD A part of these routines is implemented in the Interpreter another part can be called up by appending library LCD_Lib cc Since the functions in LCD_Lib cc are realized through Bytecode they are slower when executed Library functions however have the advantage ...

Page 163: ...orOff LCDFunctions Library LCD_Lib cc Syntax void LCD_CursorOff void Sub LCD_CursorOff Description Turns the cursor off on the display Parameter None 6 11 3 LCD_CursorOn LCDFunctions Library LCD_Lib cc Syntax void LCD_CursorOn void Sub LCD_CursorOn Description Turns the cursor in the display on Parameter None ...

Page 164: ...00 0x07 0 7 in der 1 Zeile 0x40 0x47 0 7 in der 2 Zeile The following table is valid for displays with more than 2 lines and up to 32 chars per line Value of pos PositiononDisplay 0x00 0x1f 0 31in der 1 Zeile 0x40 0x5f 0 31in der 2 Zeile 0x20 0x3f 0 31in der 3 Zeile 0x60 0x6f 0 31in der 4 Zeile 6 11 5 LCD_Init LCDFunctions Library LCD_Lib cc Syntax void LCD_Init void Sub LCD_Init Description High ...

Page 165: ...s the cursor of the LCD display to given row and column Parameter row column 6 11 7 LCD_SubInit LCDFunctions Syntax void LCD_SubInit void 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 LCDFunctions Syntax ...

Page 166: ...None 6 11 9 LCD_WriteChar LCDFunctions Library LCD_Lib cc Syntax void LCD_WriteChar char c Sub LCD_WriteChar c As Char Description Displays one character at the cursor position on the LCD display Parameter c ASCII value of output character 6 11 10 LCD_WriteCTRRegister LCDFunctions Library LCD_Lib cc Syntax void LCD_WriteCTRRegister byte cmd Sub LCD_WriteCTRRegister cmd As Byte Description Sends a ...

Page 167: ...yte to the display controller Parameter x data byte 6 11 12 LCD_WriteFloat LCDFunctions Syntax void LCD_WriteFloat float value byte length 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 LCDFunctions Syntax void LCD_WriteRegister byte y by...

Page 168: ...xt char text Sub LCD_WriteText ByRef Text As Char Description All characters of the char array up to the terminating zero are displayed Parameter text char array 6 11 15 LCD_WriteWord LCDFunctions Syntax void LCD_WriteWord word value byte length Sub LCD_WriteWord value As Word length As Byte Description Writes an unsigned integer word with given length to the LCD display If the resulting LCD outpu...

Page 169: ... 6 12 1 acos MathematicalFunctions Syntax float acos float val Sub acos val As Single As Single Description The mathematical arc cosine inverse cosine is calculated Parameter val input value between 1 and 1 Return Parameter arc cosine of the input value in the range 0 Pi expressed in radians 6 12 2 asin MathematicalFunctions Syntax float asin float val Sub asin val As Single As Single Description ...

Page 170: ...le Description The mathematical arc tangent inverse tangent is calculated Parameter val input value Return Parameter arc tangent of the input value in the range Pi 2 Pi 2 expressed in radians 6 12 4 ceil MathematicalFunctions Syntax float ceil float val Sub ceil val As Single As Single Description The largest integer value of the floating point number x is calculated Parameter val input value Retu...

Page 171: ...lculated Parameter val input angle expressed in radians Return Parameter cosine of the input value between 1 and 1 6 12 6 exp MathematicalFunctions 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 MathematicalFunctions Syntax float fabs float val ...

Page 172: ...lFunctions Syntax float floor float val Sub floor val As Single As Single Description The smallest integer value of the floating point number x is calculated Parameter val input value Return Parameter result 6 12 9 ldexp MathematicalFunctions Syntax float ldexp float val int expn Sub ldexp val As Single expn As Integer As Single Description The function val 2 expn is calculated also used as intern...

Page 173: ...alFunctions Syntax float ln float val Sub ln val As Single As Single Description The natural logarithm is calculated Parameter val input value Return Parameter result 6 12 11 log MathematicalFunctions Syntax float log float val Sub log val As Single As Single Description The logarithm base 10 is calculated Parameter val input value ...

Page 174: ... As Single As Single Description The power function x y is calculated Parameter x base y exponent Return Parameter result 6 12 13 sin MathematicalFunctions Syntax float sin float val Sub sin val As Single As Single Description The mathematical sine is calculated Parameter val input angle expressed in radians Return Parameter sine of the input value between 1 and 1 ...

Page 175: ... tan val As Single As Single Description The mathematical tangent is calculated Parameter val input angle expressed in radians Return Parameter tangent of the input value 6 13 OneWire 1 Wire or One Wire is a serial interface that needs only one wire for signaling and power The data is transferred asynchronously without clock signal in groups of 64 bit Data can either be sent or received but not at...

Page 176: ...1 Onewire_Read 1 Wire Functions Syntax byte Onewire_Read void Sub Onewire_Read As Byte Description A Byte is read from the One Wire Bus Return Parameter value read from One Wire Bus 6 13 2 Onewire_Reset 1 Wire Functions Syntax void Onewire_Reset byte portbit Sub Onewire_Reset portbit As Byte Description A reset is made on the One Wire Bus The port bit number for the One Wire Bus communication is s...

Page 177: ...tG 4 52 6 13 3 Onewire_Write 1 Wire Functions Syntax void Onewire_Write byte data Sub Onewire_Write data As Byte Description 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 ...

Page 178: ...i read whole scratchpad scratch_pad i OneWire_Read Msg_WriteHex scratch_pad i Msg_WriteChar r text Temperature Msg_WriteText text temp scratch_pad 1 256 scratch_pad 0 Msg_WriteFloat temp 0 5 Msg_WriteChar C Msg_WriteChar r end BASIC Sample Code to read DS18S20 temperature sensor from Dallas Maxim Dim Text 40 As Char Dim ret i As Integer Dim temp As Integer Dim rom_code 8 As Byte Dim scratch_pad 9 ...

Page 179: ...of pins in the Mega 32 Risc CPU is limited additional functions are assigned to individual ports A pin assignment table for M32 and M128 can be found in the documentation It is important to study the pin assignment prior to programming since important functions of the program design e g the USB Interface of the Application Board are assigned to specific ports If these ports are programmed differen...

Page 180: ...nput see Pin Assignment of M32 and M128 Parameter port port number see table val output byte port number table Definition Value PortA 0 PortB 1 PortC 2 PortD 3 PortE Mega128 4 PortF Mega128 5 PortG Mega128 6 6 14 2 Port_DataDirBit PortFunctions Syntax void Port_DataDirBit byte portbit byte val Sub Port_DataDirBit portbit As Byte val As Byte Description The function Port_DataDirBit configures one b...

Page 181: ...PortC 7 23 PortD 0 24 PortD 7 31 from here only Mega128 PortE 0 32 PortE 7 39 PortF 0 40 PortF 7 47 PortG 0 48 PortG 4 52 6 14 3 Port_Read PortFunctions Syntax byte Port_Read byte port 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 on their bit position see Pin Assignment of M32 and M128 ...

Page 182: ...rtE Mega128 4 PortF Mega128 5 PortG Mega128 6 6 14 4 Port_ReadBit PortFunctions 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 See Pin Assignment of M32 and M128 Parameter portbit bit number of port see table Return Parameter bit value 0 or 1 Portbits Table Definition Portbit ...

Page 183: ...yte port byte val Sub Port_Write port As Byte val As Byte Description Writes a byte to the specified port Only the Pins of port that are configured for output return a valid value on their bit position see Pin Assignment of M32 and M128 Is a Pin configured as input a Port_Write will set an internal pull up resistor on bit 1 or off bit 0 See Pin Assignment of M32 and M128 Parameter port port number...

Page 184: ...e function Port_WriteBit sets the value of a Pin that is configured for output Is a Pin configured as input a Port_WriteBit will set an internal pull up resistor on bit 1 or off bit 0 See Pin Assignment of M32 and M128 Parameter portbit bit number of port see table val bit value 0 or 1 Portbits Table Definition Portbit PortA 0 0 PortA 7 7 PortB 0 8 PortB 7 15 PortC 0 16 PortC 7 23 PortD 0 24 PortD...

Page 185: ...WriteBit PORT_LED2 PORT_ON AbsDelay 1000 6 15 RS232 The serial interface can be operated at speeds of up to 230 4 kilo baud With the functions for the serial interface the first parameter will indicate the port number 0 or 1 Mega32 does only provide one serial interface 0 while Mega128 does provide two 0 1 6 15 1 Divider The functions Serial_Init and Serial_Init_IRQ get a divider value as baudrate...

Page 186: ...ecified more accurate 0x8039 Table divider definition divider definition baudrate 767 SR_BD1200 1200bps 383 SR_BD2400 2400bps 191 SR_BD4800 4800bps 95 SR_BD9600 9600bps 63 SR_BD14400 14400bps 47 SR_BD19200 19200bps 31 SR_BD28800 28800bps 0x8039 SR_BDMIDI 31250bps 23 SR_BD38400 38400bps 15 SR_BD57600 57600bps 11 SR_BD76800 76800bps 7 SR_BD115200 115200bps 3 SR_BD230400 230400bps 6 15 2 Serial_Disab...

Page 187: ... the divider is set In DoubleClock mode the normal value from the divider table must be doubled to get the same baudrate This has the advantage that baudrates that have no exact divider value can be represented E g MIDI The new value SB_MIDI 0x803a lies much nearer at the correct value of 31250baud An example for 19200 baud The normal divider value for 19200 baud is 0x002f If DoubleClock Mode is u...

Page 188: ...mple An example in BASIC Syntax SR_7BIT Or SR_2STOP Or SR_EVEN_PAR The baud rate is defined as a divider value see divider table It is possible to activate the DoubleClock Mode of the Atmel AVR This happens if the Hi bit of the divider is set In DoubleClock mode the normal value from the divider table must be doubled to get the same baudrate This has the advantage that baudrates that have no exact...

Page 189: ...o parameter the function returns how many bytes have been received or a written to the send buffer Parameter serport interface number 0 1st serial port 1 2nd serial port info values RS232_FIFO_RECV 0 number of bytes received RS232_FIFO_Send 1 number of bytes written to he send buffer Return Parameter result in bytes 6 15 6 Serial_Read SerialFunctions Syntax byte Serial_Read byte serport Sub Serial...

Page 190: ...e As Word Description Reads one byte from the serial interface In opposite to Serial_Read Serial_ReadExt returns immediately even if there is no byte available in the serial port In this case 256 0x100 is returned 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 Return Parameter rec...

Page 191: ...ng zero are send to the serial interface Parameter serport interface number 0 1st serial port 1 2nd serial port text char array 6 15 10 Serial Example string output on the serial interface void main void int i char str 10 str test i 0 initialize serial port with 19200baud 8 bit 1 stop bit no parity Serial_Init 0 SR_8BIT SR_1STOP SR_NO_PAR SR_BD19200 while str i Serial_Write 0 str i output string t...

Page 192: ...led and the corresponding ports can be used otherwise Disabling the SPI interface will prevent usage of the USB interface on the application board On the other hand if you don t use the USB interface SPI_Disable will allow to use these ports for other purposes Parameter None 6 17 Strings One part of these string routines is implemented in the Interpreter another can be called up after appending li...

Page 193: ...1 str2 pointer to char array 2 Return Parameter 0 both strings are equal 0 if the first string is smaller than the second 0 if the first string is greater than the second Remark The attribute smaller or greater is specified for the character difference at the first point of difference between both strings 6 17 2 Str_Copy StringFunctions Syntax void Str_Copy char destination char source word offset...

Page 194: ...ctions Library String_Lib cc Syntax void Str_Fill char dest char c word len Sub Str_Fill ByRef dest As Char c As Char len As Word Description The string dest is filled with character c Parameter dest pointer to destination string c character that is written into the string len count how often c is written into the string 6 17 4 Str_Isalnum StringFunctions Library String_Lib cc Syntax byte Str_Isal...

Page 195: ...d if it is alphabetically Parameter c tested character Return Parameter 1 if the character is alphabetically upper or lowercase 0 else 6 17 6 Str_Len StringFunctions 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 ...

Page 196: ...t word offset Sub Str_WriteFloat n As Single decimal As Byte ByRef text As Char offset As Word Description The floating point number n is converted to an ASCII string with decimal number of decimal digits after the period The result is stored in the string text with an offset of offset The offset parameter is used to change a string after a specified number offset of characters and leave the begin...

Page 197: ...e destination string 6 17 10 Str_WriteWord StringFunctions Syntax void Str_WriteWord word n byte base char text word offset byte minwidth Sub Str_WriteWord n As Word base As Byte ByRef text As Char offset As Word minwidth As Byte Description The word n is converted to an ASCII string The result is stored in the string text with an offset of offset The offset parameter is used to change a string af...

Page 198: ...Bytecodes which one thread is allowed to execute until the next thread change takes place see ThreadOptions The smaller the number of cycles until the change takes place the lower the priority of the thread The execution time of one Bytecode is appr 7 9 microseconds With certain Bytecode instructions however this will take longer e g Floating Point Operations Also internal Interpreter functions co...

Page 199: ...dlocks When all active threads set out for a waiting condition with Thread_Wait then there will be no more threads which can release the other threads from their waiting conditon Therefore these constellations should be avoided when programming Table Thread Conditions Condition Meaning active The thread is presently executed inactive Can be activated again after a thread change sleeping Will after...

Page 200: ...hread_Delay looks like any other wait function you have to keep in mind that the thread is not automatically executed after the waiting period The thread is then ready for execution but it will not started until the next thread change Parameter delay number of 10ms ticks that should be waited 6 18 3 Thread_Info ThreadFunctions Syntax word Thread_Info byte info Sub Thread_Info info As Byte As Word ...

Page 201: ...d 0 13 thread number 6 18 5 Thread_Lock ThreadFunctions Syntax void Thread_Lock byte lock Sub Thread_Lock lock As Byte Description With this function you can inhibit thread changes This is reasonable if you have a series of port operations or other hardware actions that should not timely be separated in a thread change If you forget to remove the thread lock the multithreading is not working Param...

Page 202: ...Parameter free memory in bytes 6 18 7 Thread_Resume ThreadFunctions Syntax void Thread_Resume byte thread Sub Thread_Resume thread As Byte Description If a thread has the state waiting it can be set to inactive with this function call Inactive means that a thread is ready for activation at a thread change Parameter thread 0 13 thread number 6 18 8 Thread_Signal ThreadFunctions Syntax void Thread_S...

Page 203: ...e Description A new thread gets started Every function in the program can be used as starting function for the thread If the thread is started inside a function that has parameters defined in the function header the value of these parameters is undefined Parameter thread 0 13 thread number func function name of the function where the thread will be started Remark The floating point data type seems...

Page 204: ... outputs void thread1 void while true endless loop if Port_ReadBit PORT_SW2 Msg_WriteText str2 SW2 is pressed char str1 12 str2 12 void main void str1 Switch 1 str2 Switch 2 Port_DataDirBit PORT_SW1 PORT_IN set Pin to input Port_DataDirBit PORT_SW2 PORT_IN set Pin to input Port_WriteBit PORT_SW1 1 set pull up Port_WriteBit PORT_SW1 1 set pull up Thread_Start 1 thread1 start new Thread while true e...

Page 205: ...In C Control Pro Mega 32 there are two in Mega128 are three independent timers available These are Timer_0 with 8 bit and Timer_1 with 16 bit Timer_3 with 16 bit for Mega128 only Timer_2 is used by the firmware as an internal time base and is set firm to a 10ms interrupt These internal timers can be utilized for a multitude of tasks EventCounter Frequency Generation Pulse Width Modulation Timer Fu...

Page 206: ...e Pulsed Frequency Blocks Project FRQ0 void main void int delval Variable for the On Off Time delval 200 Value Assignment for Variable delval Frequency Period 138 9 µs 100 13 9 ms Frequency 72Hz Timer_T0FRQ 100 PS0_1024 Timer is set to Frequency while 1 AbsDelay delval Time Delay by 200ms Timer_T0Stop Timer is stopped AbsDelay delval Time Delay by 200ms Timer_T0Start PS0_1024 Timer will be switche...

Page 207: ...og Converters can be realized very easily On the Mega128 Timer_3 can be used additionally Timer0 8 Bit Example Pulse Width Modulation with 138 9 µs Period and 5 42 µs Pulse Width changed to 10 84 µs Pulse Width Pulse 10 542 5 ns 5 42 µs Period 256 542 5 ns 138 9 µs Timer_T0PWM 10 PS0_8 Timer_T0PW 20 Pulse 20 542 5 ns 10 84 µs Timer1 16 Bit Example Pulse Width Modulation with 6 4 ms Period and 1 28...

Page 208: ...Width Measurement and determine prescaler Timer_T1PM 0 PS_64 while PM_Value 0 Measure Pulse Width or Period Msg_WriteHex PM_Value Output Measuring Value For reason of better survey only a simplified version is shown here Because of a collision on Pin B 4 Timer_0 is used for pulse generation with Mega128 The entire program can be found in directory PW_Measurement 6 19 6 Timer Functions In C Control...

Page 209: ... Timer_T0Time 100 PS0_1024 set time and start Timer0 other program code 6 19 7 Timer_Disable TimerFunctions Syntax void Timer_Disable byte timer Sub Timer_Disable timer As Byte Description 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 ...

Page 210: ...d As Byte PS As Byte Description This function initializes Timer0 for frequency generation Parameters are period duration and prescaler see table The output signal is generated at Mega32 PortB 3 PIN4 Mega128 PortB 4 X1_4 The frequency generation is started automatically There is a extended prescaler definition for the Mega128 see table Parameter period period duration PS prescaler Table prescaler ...

Page 211: ...Timer_T0GetCNT As Byte Description The value of Counter0 is read If there was an overflow a value of 0xff is returned 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 TimerFunctions Syntax void Timer_T0PW byte PW Sub Timer_T0PW PW As Byte Description This function sets a new pulse width for Timer0 without changi...

Page 212: ...rtB 3 PIN4 Mega128 PortB 4 X1_4 There is an extended prescaler definition for the Mega128 see table Parameter PW pulse width PS 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 Mega128 Prescaler Time Base duration of a tick PS0_1 1 67 8 ns PS0_8 2 542 5 ns PS0_32 3 2 17 µs PS0_64 4 4 34 ...

Page 213: ...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 15 Timer_T0Time TimerFunctions Syntax void Timer_T0Time byte Time byte PS Sub Timer_T0Time Time As Byte PS As Byte Description This function initializes Timer_0 with a prescaler and a timer interval value see table A...

Page 214: ... 36 µs PS0_1024 5 69 44 µs Mega128 Prescaler Time Base duration of a tick 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 16 Timer_T1CNT TimerFunctions Syntax void Timer_T1CNT void Sub Timer_T1CNT Description These function initializes Counter1 Counter1 gets incremented at every positive signal edge at Input Mega32 Po...

Page 215: ... must be specified Parameter limit 6 19 18 Timer_T1FRQ TimerFunctions Syntax void Timer_T1FRQ word period byte PS Sub Timer_T1FRQ period As Word PS As Byte Description This function initializes Timer1 for frequency generation Parameters are period duration and prescaler see table The output signal is generated at Mega32 PortD 5 PIN19 Mega128 PortB 5 X1_3 The frequency generation is started automat...

Page 216: ...ew As Word PS As Byte Description This function initializes Timer1 for frequency generation Parameters are period duration prescaler and phase shift see table The output signal is generated at Mega32 PortD 5 PIN19 Mega128 PortB 5 X1_3 The frequency generation is started automatically There is an extended prescaler definition for the Mega128 see table The phase shift must be smaller than half the p...

Page 217: ...on Returns the result of the measurement Parameter None Return Parameter result of measurement To calculate the correct value the 16bit result is multiplied with the entry of the prescalerTable that was passed in the call to Timer_T1PM 6 19 22 Timer_T1PWA TimerFunctions Syntax void Timer_T1PWA word PW0 Sub Timer_T1PWA PW0 As Word Description This function sets a new pulse width Channel A for Timer...

Page 218: ...r_1 and sets the prescaler Parameter Mode 0 pulse width measurement 1 period measurement PS 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 Mega128 Prescaler Time Base duration of a tick 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...

Page 219: ... PS As Byte Description This function initializes Timer_1 with given period duration pulse width and prescaler see table The output signal is generated at Mega32 PortD 5 PIN19 Mega128 PortB 5 X1_3 There is an extended prescaler definition for the Mega128 see table Parameter period period duration PW0 pulse width PS prescaler Table prescaler Mega32 Prescaler Time Base duration of a tick PS0_1 1 67 ...

Page 220: ...for channel A and B The output signal is generated at Mega32 PortD 4 PIN18 and PortD 5 PIN19 Mega128 PortB 5 X1_3 and PortB 6 X1_2 Parameter period period duration PW0 pulse width channel A PW1 pulse width channel B PS prescaler see table prescaler 6 19 27 Timer_T1PWMY TimerFunctions Syntax void Timer_T1PWMY word period word PW0 word PW1 word PW2 byte PS Sub Timer_T1PWMY period As Word PW0 As Word...

Page 221: ... Byte Description The frequency generation is started with the already set parameters The prescaler must be given again Parameter prescaler prescaler see table 6 19 29 Timer_T1Stop TimerFunctions Syntax void Timer_T1Stop void Sub Timer_T1Stop Description 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 ...

Page 222: ...tended prescaler definition for the Mega128 see table Parameter Time time period after that the interrupt is triggered PS 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 Mega128 Prescaler Time Base duration of a tick 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...

Page 223: ...ignal edge at Input PortE 6 X1_10 After the limit is reached an interrupt Timer3 CompareA define INT_TIM3CMPA is triggered An appropriate Interrupt Service Routine must be specified Parameter limit 6 19 33 Timer_T3FRQ TimerFunctions Syntax void Timer_T3FRQ word period byte PS Sub Timer_T3FRQ period As Word PS As Byte Description This function initializes Timer3 for frequency generation Parameters ...

Page 224: ... PS As Byte Description This function initializes Timer3 for frequency generation Parameters are period duration prescaler and phase shift see table The output signal is generated at PortE 3 X1_13 und PortE 4 X1_12 The frequency generation is started automatically There is an extended prescaler definition for the Mega128 see table The phase shift must be smaller than half the period Parameter peri...

Page 225: ...on Returns the result of the measurement Parameter None Return Parameter result of measurement To calculate the correct value the 16bit result is multiplied with the entry of the prescalerTable that was passed in the call to Timer_T3PM 6 19 37 Timer_T3PWA TimerFunctions Syntax void Timer_T3PWA word PW0 Sub Timer_T3PWA PW0 As Word Description This function sets a new pulse width Channel A for Timer...

Page 226: ...mer_3 and sets the prescaler Parameter Mode 0 pulse width measurement 1 period measurement PS prescaler Table prescaler Prescaler Time Base duration of a tick 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 39 Timer_T3PWB TimerFunctions Syntax void Timer_T3PWB word PW1 Sub Timer_T3PWB PW1 As Word Description This func...

Page 227: ...PortE 3 X1_13 Parameter period period duration PW0 pulse width PS prescaler Table prescaler Prescaler Time Base duration of a tick 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 41 Timer_T3PWMX TimerFunctions Syntax void Timer_T3PWMX word period word PW0 word PW1 byte PS Sub Timer_T3PWMX period As Word PW0 As Word PW...

Page 228: ...W2 As Word PS As Byte Description This function initializes Timer_3 with given period duration prescaler pulse width for channel A B and C The output signal is generated at PortE 3 X1_13 PortE 4 X1_12 and PortE 5 X1_11 Parameter period period duration PW0 pulse width channel A PW1 pulse width channel B PW2 pulse width channel C PS prescaler see table prescaler 6 19 43 Timer_T3Start TimerFunctions ...

Page 229: ...l other settings stay the same Parameter None 6 19 45 Timer_T3Time TimerFunctions Syntax void Timer_T3Time word Time byte PS Sub Timer_T3Time Time As Word PS As Byte Description 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 inter...

Page 230: ...er_TickCount As Word Description Measures the number of 10ms ticks between two calls of Timer_TickCount Ignore the return value of the first call to Timer_TickCount If the delay between the two calls is greater than 655 36 seconds the result is undefined Parameter None Return Parameter time interval expressed in 10ms ticks Example void main void word time Timer_TickCount AbsDelay 500 wait 500 ms t...

Page 231: ...Part 7 ...

Page 232: ...n assignment of M32 and M128 Are the jumpers on the Application Board set to these ports 3 The Application Board does not react to any commands when serially connected In order to get the Bootloader into the serial mode the button SW1 must be pressed during startup of the Application Board observe jumper for SW1 For the serial mode M32 PortD 2 resp M128 PortE 4 SW1 can also be fixed to GND level 4...

Page 233: ...Options Compiler Configure Library but it is not being used by my current project This setting does only change the pre settings for new projects Projects already existing must be changed through Project Options Configure Library 10 Where is the second serial interface on the Mega128 Application Board See J4 chapter Jumper Application Board M128 11 I need no USB connection to the application board...

Page 234: ...nts XP and earlier or to Users Public Public Documents Vista directory When replacing an old installation the old Demos directory is deleted Therefore please create own programs outside of the C Control Pro Demos directory 16 Can I program the C Control Pro Module in Linux There is no native IDE for Linux but customer had sucessfully started the IDE under Wine und programmed the module in serial m...

Page 235: ...4 asin 160 atan 161 Auto Actualize 69 Autostart 15 64 B baud rate 79 Bit inversion 95 114 Bit Operators 95 114 Bitshift Operators 95 115 Bootloader 15 break 97 98 100 101 Breakpoints 67 Byte 90 110 C Cascade 80 Case 100 120 ceil 161 Change Variable 69 Char 90 110 COM Port 79 Comments 88 108 Communication 77 CompactC 87 Comparison Operators 96 115 compile 51 compile projects 51 Compiler Presetting ...

Page 236: ...able 150 Ext_IntEnable 149 external RAM 39 84 F fabs 162 FAQ 223 Fax 4 Firewall 78 Firmware 15 float 90 floor 163 For 98 117 Frequency Generation 197 Frequency Measurement 198 Functions 102 121 G Goto 99 118 GPP 4 greater 96 115 greater or equal 96 115 H Handling 3 Hardware 15 63 Hardware Version 66 Help 81 History 4 I I2C Status Codes 147 I2C_Init 143 I2C_Read_ACK 144 I2C_Read_NACK 144 I2C_Start ...

Page 237: ...xp 163 left shift 95 115 Liability 3 Library Management 56 ln 164 log 164 logical And 96 logical Not 96 logical Operators 96 logical Or 96 Loop While 116 M Map File 86 Mega32 17 messages 51 Module 28 44 Module Mega128 34 Module Mega32 18 Modulo 94 114 Msg_WriteChar 138 Msg_WriteFloat 138 Msg_WriteHex 139 Msg_WriteInt 139 Msg_WriteText 140 Msg_WriteWord 140 Multiplication 94 114 N new features 4 Ne...

Page 238: ...59 Select 120 serial Bootloader 15 Serial Example 182 Serial Example IRQ 182 Serial_Disable 177 Serial_Init 178 Serial_Init_IRQ 179 Serial_IRQ_Info 180 Serial_Read 180 Serial_ReadExt 181 Serial_Write 181 Serial_WriteText 182 Service 4 Sign 94 114 sin 165 sine 165 Single 110 SizeOf 91 110 smaller 96 115 smaller or equal 96 115 Smart Tabulator 72 Spellchecking 76 SPI switch off 15 SPI_Disable 183 Sp...

Page 239: ... 207 Timer_T1GetPM 208 Timer_T1PM 209 Timer_T1PWA 208 Timer_T1PWB 209 Timer_T1PWM 210 Timer_T1PWMX 211 Timer_T1PWMY 211 Timer_T1Start 212 Timer_T1Stop 212 Timer_T1Time 212 Timer_T3CNT 213 Timer_T3CNT_Int 214 Timer_T3FRQ 214 Timer_T3FRQX 215 Timer_T3GetCNT 215 Timer_T3GetPM 216 Timer_T3PM 217 Timer_T3PWA 216 Timer_T3PWB 217 Timer_T3PWM 218 Timer_T3PWMX 218 Timer_T3PWMY 219 Timer_T3Start 219 Timer_T...

Page 240: ......

Reviews: