MikroElektronika mikroC PRO for dsPIC User guide

mikroC PRO for dsPIC
mikroC PRO for dsPIC30/33 and PIC24 is a full-featured C compiler for dsPIC30, dsPIC33 and PIC24 MCUs from Microchip. It is designed for developing, building and debugging dsPIC30/33 and PIC24­based embedded applications. This development environment has a wide range of features such as: easy-to-use IDE, very compact and
efcient code, many hardware and software libraries, comprehensive documentation, software simulator, COFF le generation, SSA
optimization (up to 30% code reduction) and many more. Numerous ready-to-use and well-explained examples will give a good start for your embedded project.
Manual
Compiler
MikroElektronika
mikoC PRO for dsPIC
Table of Contents
CHAPTER 1 32 INTRODUCTION 32
Introduction to mikroC PRO for dsPIC30/33 and PIC24 33
Features 33 Where to Start 33
What’s new in mikroC PRO for dsPIC30/33 and PIC24 34
Compiler Changes 34 IDE Changes 34
Software License Agreement 35
mikroElektronika Associates License Statement and Limited Warranty 35 IMPORTANT - READ CAREFULLY 35 LIMITED WARRANTY 35 HIGH RISK ACTIVITIES 36 GENERAL PROVISIONS 36
Technical Support 37 How to Register 37
Who Gets the License Key 37 How to Get License Key 37 After Receving the License Key 39
CHAPTER 2 41 mikroC PRO for dsPIC30/33 and PIC24 Environment 41
Main Menu Options 42 File 43
File Menu Options 43
Edit 44
Edit Menu Options 44 Find Text 45 Replace Text 45 Find In Files 46 Go To Line 46 Regular expressions option 46
View 47
View Menu Options 47
Project 49
Project Menu Options 49
Build 50
Build Menu Options 50
Run 51
Run Menu Options 51
Tools 52
Tools Menu Options 52
MikroElektronika
2
mikroC PRO for dsPIC
Help 53
Help Menu Options 53
mikroC PRO for dsPIC30/33 and PIC24 IDE 54
IDE Overview 54
Code Editor 55
Editor Settings 55 Auto Save 56 Highlighter 56 Spelling 56 Comment Style 56 Code Folding 56 Code Assistant 57 Parameter Assistant 57 Bookmarks 57 Go to Line 57 Column Select Mode 58 Editor Colors 58 Auto Correct 59 Auto Complete (Code Templates) 60
Code Explorer 62
Routine List 63
Project Manager 63 Project Settings 65 Library Manager 66
Managing libraries using Package Manager 67
Statistics 68
Memory Usage Windows 68 RAM Memory Usage 69 Used RAM Locations 69 SFR Locations 70 ROM Memory Usage 70 ROM Memory Constants 71 Functions 71 Functions Sorted By Name Chart 72 Functions Sorted By Size Chart 72 Functions Sorted By Addresses 73 Function Tree 73 Memory Summary 74
Messages Window 75 Quick Converter 76 Macro Editor 76 Image Preview 77 Toolbars 79
File Toolbar 80 Edit Toolbar 80
3
MikroElektronika
mikoC PRO for dsPIC
Advanced Edit Toolbar 81 Find/Replace Toolbar 81 Project Toolbar 82 Build Toolbar 82 Debug Toolbar 83 Styles Toolbar 83 Tools Toolbar 84 View Toolbar 84 Layout Toolbar 85 Help Toolbar 85
Customizing IDE Layout 86
Docking Windows 86 Saving Layout 87 Auto Hide 87
Options 88
Code editor 88 Tools 88 Output settings 89
Integrated Tools 91
Active Comments Editor 91 ASCII Chart 92 EEPROM Editor 93 Filter Designer 93 Graphic Lcd Bitmap Editor 94 HID Terminal 95 Lcd Custom Character 96 Seven Segment Editor 97 UDP Terminal 97 USART Terminal 98
Active Comments 99
New Active Comment 99 Renaming Active Comment 106 Deleting Active Comment 107
Export Project 108 Jump To Interrupt 109 Regular Expressions 110
Introduction 110 Simple matches 110 Escape sequences 110 Character classes 110 Metacharacters 111 Metacharacters - Line separators 111 Metacharacters - Predened classes 112 Metacharacters - Word boundaries 112 Metacharacters - Iterators 112 Metacharacters - Alternatives 113
MikroElektronika
4
mikroC PRO for dsPIC
Metacharacters - Subexpressions 113 Metacharacters - Backreferences 113
Keyboard Shortcuts 114
CHAPTER 3 116 mikroC PRO for dsPIC30/33 and PIC24 Command Line Options 116 CHAPTER 4 118 mikroICD (In-Circuit Debugger) 118
Introduction 118 mikroICD Debugger Options 120
Debugger Options 120
mikroICD Debugger Example 121 mikroICD Debugger Windows 125
Debug Windows 125 Breakpoints Window 125 Watch Values Window 125 RAM Window 127 Stopwatch Window 127 EEPROM Watch Window 128 Code Watch Window 129
CHAPTER 5 130 Software Simulator Overview 130
Software Simulator 131 Software Simulator Debug Windows 132
Debug Windows 132 Breakpoints Window 132 Watch Values Window 132 RAM Window 134 Stopwatch Window 134 EEPROM Watch Window 135 Code Watch Window 136
Software Simulator Debugger Options 137
Debugger Options 137
CHAPTER 6 138 mikroC PRO for dsPIC30/33 and PIC24 Specics 138
GOTO Table 139
ANSI Standard Issues 140
Divergence from the ANSI C Standard 140 C Language Extensions 140
Implementation-dened Behavior 140
Predened Globals and Constants 141
Predened project level denes 141
Accessing Individual Bits 142
sbit type 143
5
MikroElektronika
mikoC PRO for dsPIC
at keyword 144 bit type 144
Interrupts 145
Function Calls from Interrupt 145 Disable Context Saving 145 Interrupt Handling 145 Interrupt Example 146
Linker Directives 147
Directive absolute 147 Directive orgall 147 Directive funcorg 148
Indirect Function Calls 148 Built-in Routines 149
Lo 150 Hi 150 Higher 151 Highest 151 LoWord 152 HiWord 152 Delay_us 153 Delay_ms 153 Vdelay_ms 153 VDelay_Advanced_ms 154 Delay_Cyc 154 Delay_Cyc_Long 154 Clock_kHz 155 Clock_Mhz 155 Get_Fosc_kHz 155 Get_Fosc_Per_Cyc 156
Code Optimization 157
Constant folding 157 Constant propagation 157 Copy propagation 157 Value numbering 157 "Dead code" ellimination 157 Stack allocation 157 Local vars optimization 157 Better code generation and local optimization 157
Single Static Assignment Optimization 158
Introduction 158 Proper Coding Recommendations 159 Asm code and SSA optimization 160 Debugging Notes 160 Warning Messages Enhancement 160
Common Object File Format (COFF) 161
COFF File Format 161
MikroElektronika
6
mikroC PRO for dsPIC
COFF File Generation 161
CHAPTER 7 163 dsPIC30/33 and PIC24 Specics 163
Types Efciency 164 Nested Calls Limitations 164 Limits of Indirect Approach Through PSV 164 Limits of Pointer to Function 164 Variable, constant and routine alignment 164
dsPIC Memory Organization 165
Program Memory (ROM) 165 Data Memory (RAM) 166 SFR Memory Space 166 X and Y Data RAM 166 DMA RAM 167 Unimplemented Memory Space 167
Memory Type Speciers 168
code 168 data 168 rx 168 sfr 168 xdata 169 ydata 169 dma 169
Memory Type Qualiers 170
Near Memory Qualier 170 Far Memory Qualier 170
Read Modify Write Problem 171
CHAPTER 8 175 mikroC PRO for dsPIC30/33 and PIC24 Language Reference 175
Lexical Elements Overview 178 Whitespace 179
Whitespace in Strings 179 Line Splicing with Backslash (\) 179
Comments 180
C comments 180 C++ comments 180 Nested comments 180
Tokens 181
Token Extraction Example 181
Constants 182 Integer Constants 182
Long and Unsigned Sufxes 182 Decimal 182 Hexadecimal 183
7
MikroElektronika
mikoC PRO for dsPIC
Binary 183 Octal 183
Floating Point Constants 184 Character Constants 184
Escape Sequences 184 Disambiguation 185
String Constants 186
Line Continuation with Backslash 186
Enumeration Constants 187 Pointer Constants 187 Constant Expressions 188 Keywords 189 Identiers 190
Case Sensitivity 190 Uniqueness and Scope 191 Identier Examples 191
Punctuators 191
Brackets 191 Parentheses 192 Braces 192 Comma 192 Semicolon 193 Colon 193 Asterisk (Pointer Declaration) 193 Equal Sign 194 Pound Sign (Preprocessor Directive) 194
Concepts 195 Objects 195
Objects and Declarations 195 Lvalues 196 Rvalues 196
Scope and Visibility 196
Scope 196 Visibility 196
Name Spaces 197 Duration 198
Static Duration 198 Local Duration 198
Types 199
Type Categories 199
Fundamental Types 200 Arithmetic Types 200
Integral Types 200 Floating-point Types 201
MikroElektronika
8
mikroC PRO for dsPIC
Enumerations 201
Enumeration Declaration 201 Anonymous Enum Type 202 Enumeration Scope 202
Void Type 203
Void Functions 203 Generic Pointers 203
Derived Types 203 Arrays 204
Array Declaration 204 Array Initialization 204 Arrays in Expressions 205 Multi-dimensional Arrays 205
Pointers 206
Pointer Declarations 206 Null Pointers 207 Assign an address to a Function Pointer 207 Function Pointers 209 Assign an address to a Function Pointer 209
Pointer Arithmetic 210
Arrays and Pointers 210 Assignment and Comparison 211 Pointer Addition 212 Pointer Subtraction 213
Structures 213
Structure Declaration and Initialization 213 Incomplete Declarations 214 Untagged Structures and Typedefs 215 Anonymous Structures 215
Working with Structures 216
Assignment 216 Size of Structure 216 Structures and Functions 216
Structure Member Access 217
Accessing Nested Structures 218 Structure Uniqueness 218
Unions 219
Union Declaration 219 Size of Union 219 Union Member Access 219 Anonymous Unions 220 Anonymous Union Member Access 220
Bit Fields 221
Bit Fields Declaration 221 Bit Fields Access 222
9
MikroElektronika
mikoC PRO for dsPIC
Types Conversions 222 Standard Conversions 223
Arithmetic Conversions 223 Pointer Conversions 224
Explicit Types Conversions (Typecasting) 224 Declarations 225
Declarations and Denitions 225 Declarations and Declarators 226
Linkage 226
Linkage Rules 227 Internal Linkage Rules 227
Storage Classes 227
Auto 228 Register 228 Static 228 Extern 228
Type Qualiers 229
Qualier const 229 Qualier volatile 229
Typedef Specier 229
asm Declaration 230
Accessing variables 230 Asm code and SSA optimization 231
Initialization 232
Automatic Initialization 232
Functions 233
Function Declaration 233 Function Prototypes 234 Function Denition 234 Functions reentrancy 235
Function Calls and Argument Conversions 235
Function Calls 235 Argument Conversions 236
Ellipsis (‘...’) Operator 237 Operators 238
Operators Precedence and Associativity 239 Binary Arithmetic Operators 240 Unary Arithmetic Operators 240
Relational Operators 241
Relational Operators Overview 241 Relational Operators in Expressions 241
Bitwise Operators 242
Bitwise Operators Overview 242 Logical Operations on Bit Level 242
MikroElektronika
10
mikroC PRO for dsPIC
Bitwise Shift Operators 243 Bitwise vs. Logical 243
Logical Operators 244
Logical Operators Overview 244 Logical Operations 244 Logical Expressions and Side Effects 244 Logical vs. Bitwise 245
Conditional Operator ? : 245
Conditional Operator Rules 245
Assignment Operators 246
Simple Assignment Operator 246 Compound Assignment Operators 246 Assignment Rules 246
Unary Operators 247
Unary Arithmetic Operators 247 Unary Logical Operator 248 Unary Bitwise Operator 248 Address and Indirection Operator 248
Sizeof Operator 249
Sizeof Applied to Expression 249 Sizeof Applied to Type 249
Expressions 250 Comma Expressions 250 Statements 251 Labeled Statements 251 Expression Statements 252 Selection Statements 252 If Statement 252
Nested If statements 252
Switch Statement 253
Nested switch 254
Iteration Statements (Loops) 254
While Statement 254
Do Statement 254 For Statement 255 Jump Statements 256 Break and Continue Statements 256
Break Statement 256 Continue Statement 256
Goto Statement 257 Return Statement 257 Compound Statements (Blocks) 258 Preprocessor 258
11
MikroElektronika
mikoC PRO for dsPIC
Preprocessor Directives 258
Line Continuation with Backslash (\) 259
Macros 259
Dening Macros and Macro Expansions 259 Macros with Parameters 260 Undening Macros 261
File Inclusion 261
Explicit Path 262
Preprocessor Operators 263
Operator # 263 Operator ## 263
Conditional Compilation 264
Directives #if, #elif, #else, and #endif 264 Directives #ifdef and #ifndef 265
CHAPTER 9 266 mikroC PRO for dsPIC30/33 and PIC24 Libraries 266
Hardware Libraries 267 Digital Signal Processing Libraries 267 Standard ANSI C Libraries 268 Miscellaneous Libraries 268 Hardware Libraries 269 ADC Library 269
Library Routines 270 ADCx_Init 270 ADCx_Init_Advanced 271 ADCx_Get_Sample 272 ADCx_Read 272 ADC_Set_Active 273 Library Example 273
CAN Library 275
Library Routines 275 CANxSetOperationMode 276 CANxGetOperationMode 276 CANxInitialize 277 CANxSetBaudRate 278 CANxSetMask 279 CANxSetFilter 280 CANxRead 281 CANxWrite 282 CAN Constants 283 CAN_OP_MODE Constants 283 CAN_CONFIG_FLAGS Constants 283 CAN_TX_MSG_FLAGS Constants 284 CAN_RX_MSG_FLAGS Constants 285
MikroElektronika
12
mikroC PRO for dsPIC
CAN_MASK Constants 285 CAN_FILTER Constants 286 Library Example 286 HW Connection 289
CANSPI Library 290
Library Dependency Tree 290 External dependencies of CANSPI Library 290 Library Routines 291 CANSPISetOperationMode 291 CANSPIGetOperationMode 292 CANSPIInitialize 292 CANSPISetBaudRate 294 CANSPISetMask 295 CANSPISetFilter 296 CANSPIRead 297 CANSPIWrite 298 CANSPI Constants 298 CANSPI_OP_MODE Constants 298 CANSPI_TX_MSG_FLAGS Constants 300 CANSPI_RX_MSG_FLAGS Constants 300 CANSPI_MASK Constants 301 CANSPI_FILTER Constants 301 Library Example 302 HW Connection 305
Compact Flash Library 306
Library Dependency Tree 306 External dependencies of Compact Flash Library 307 Library Routines 308 Cf_Init 309 Cf_Detect 310 Cf_Enable 310 Cf_Disable 310 Cf_Read_Init 311 Cf_Read_Byte 311 Cf_Write_Init 311 Cf_Write_Byte 312 Cf_Read_Sector 312 Cf_Write_Sector 312 Cf_Fat_Init 313 Cf_Fat_QuickFormat 313 Cf_Fat_Assign 314 Cf_Fat_Reset 315 Cf_Fat_Read 315 Cf_Fat_Rewrite 316 Cf_Fat_Append 316 Cf_Fat_Delete 316 Cf_Fat_Write 317
13
MikroElektronika
mikoC PRO for dsPIC
Cf_Fat_Set_File_Date 317 Cf_Fat_Get_File_Date 318 Cf_Fat_Get_File_Date_Modied 318 Cf_Fat_Get_File_Size 319 Cf_Fat_Get_Swap_File 319 Library Example 321 HW Connection 323
ECAN Library 324
Library Routines 324 ECANxDmaChannelInit 325 ECANxSetOperationMode 325 ECANxGetOperationMode 326 ECANxInitialize 327 ECANxSelectTxBuffers 328 ECANxFilterDisable 328 ECANxFilterEnable 329 ECANxSetBufferSize 329 ECANxSetBaudRate 330 ECANxSetMask 331 ECANxSetFilter 332 ECANxRead 333 ECANxWrite 334 ECAN Constants 335 ECAN_OP_MODE Constants 335 ECAN_CONFIG_FLAGS Constants 335 ECAN_TX_MSG_FLAGS Constants 336 ECAN_RX_MSG_FLAGS Constants 336 ECAN_MASK Constants 337 ECAN_FILTER Constants 337 ECAN_RX_BUFFER Constants 338 Library Example 339 HW Connection 343
EEPROM Library 343
Library Routines 343 EEPROM_Erase 344 EEPROM_Erase_Block 344 EEPROM_Read 344 EEPROM_Write 345 EEPROM_Write_Block 345 Library Example 345
Epson S1D13700 Graphic Lcd Library 347
External dependencies of the Epson S1D13700 Graphic Lcd Library 347 Library Routines 348 S1D13700_Init 349 S1D13700_Write_Command 350 S1D13700_Write_Parameter 351 S1D13700_Read_Parameter 351
MikroElektronika
14
mikroC PRO for dsPIC
S1D13700_Fill 351 S1D13700_GrFill 352 S1D13700_TxtFill 352 S1D13700_Display_GrLayer 352 S1D13700_Display_TxtLayer 353 S1D13700_Set_Cursor 353 S1D13700_Display_Cursor 354 S1D13700_Write_Char 354 S1D13700_Write_Text 355 S1D13700_Dot 355 S1D13700_Line 356 S1D13700_H_Line 356 S1D13700_V_Line 357 S1D13700_Rectangle 357 S1D13700_Box 358 S1D13700_Rectangle_Round_Edges 358 S1D13700_Rectangle_Round_Edges_Fill 359 S1D13700_Circle 359 S1D13700_Circle_Fill 360 S1D13700_Image 360 S1D13700_PartialImage 361
Flash Memory Library 362
dsPIC30: 362 PIC24 and dsPIC33: 362 24F04KA201 and 24F16KA102 Family Specics : 363 Library Routines 363 dsPIC30 Functions 363 PIC24 and dsPIC33 Functions 363 dsPIC30 Functions 363 FLASH_Erase32 364 FLASH_Write_Block 364 FLASH_Write_Compact 365 FLASH_Write_Init 365 FLASH_Write_Loadlatch4 366 FLASH_Write_Loadlatch4_Compact 367 FLASH_Write_DoWrite 368 FLASH_Read4 368 FLASH_Read4_Compact 369 PIC24 and dsPIC33 Functions 369 FLASH_Erase 369 FLASH_Write 370 FLASH_Write_Compact 370 FLASH_Read 371 FLASH_Read_Compact 371 Library Example 372
Graphic Lcd Library 373
Library Dependency Tree 373
15
MikroElektronika
mikoC PRO for dsPIC
External dependencies of Graphic Lcd Library 374 Glcd_Init 375 Glcd_Set_Side 377 Glcd_Set_X 377 Glcd_Set_Page 377 Glcd_Read_Data 378 Glcd_Write_Data 378 Glcd_Fill 379 Glcd_Dot 379 Glcd_Line 379 Glcd_V_Line 380 Glcd_H_Line 380 Glcd_Rectangle 381 Glcd_Rectangle_Round_Edges 381 Glcd_Rectangle_Round_Edges_Fill 382 Glcd_Box 382 Glcd_Circle 383 Glcd_Circle_Fill 383 Glcd_Set_Font 384 Glcd_Write_Char 385 Glcd_Write_Text 385 Glcd_Image 386 Glcd_PartialImage 386 Library Example 387 HW Connection 389
I²C Library 390
Library Routines 390 I2Cx_Init 390 I2Cx_Start 391 I2Cx_Restart 391 I2Cx_Is_Idle 392 I2Cx_Read 392 I2Cx_Write 393 I2Cx_Stop 393 Library Example 394 HW Connection 394
Keypad Library 395
External dependencies of Keypad Library 395 Library Routines 395 Keypad_Init 395 Keypad_Key_Press 396 Keypad_Key_Click 396 Library Example 397 HW Connection 398
Lcd Library 399
Library Dependency Tree 399 Keypad_Key_Click 399
MikroElektronika
16
mikroC PRO for dsPIC
Library Routines 399 Lcd_Init 400 Lcd_Out 401 Lcd_Out_Cp 401 Lcd_Chr 401 Lcd_Chr_Cp 402 Lcd_Cmd 402 Available Lcd Commands 402 Library Example 403
Manchester Code Library 405
Keypad_Key_Click 405 Library Routines 406 Man_Receive_Init 406 Man_Receive 407 Man_Send_Init 407 Man_Send 408 Man_Synchro 408 Man_Break 409 Library Example 410 Connection Example 412
Multi Media Card Library 413
Secure Digital Card 413 Secure Digital High Capacity Card 413 Library Dependency Tree 414 External dependencies of MMC Library 414 Library Routines 414 Mmc_Init 415 Mmc_Read_Sector 416 Mmc_Write_Sector 416 Mmc_Read_Cid 417 Mmc_Read_Csd 417 Mmc_Fat_Init 418 Mmc_Fat_QuickFormat 419 Mmc_Fat_Assign 420 Mmc_Fat_Reset 421 Mmc_Fat_Read 421 Mmc_Fat_Rewrite 422 Mmc_Fat_Append 422 Mmc_Fat_Delete 422 Mmc_Fat_Write 423 Mmc_Fat_Set_File_Date 423 Mmc_Fat_Get_File_Date 424 Mmc_Fat_Get_File_Date_Modied 425 Mmc_Fat_Get_File_Size 425 Mmc_Fat_Get_Swap_File 426 Library Example 427 HW Connection 431
17
MikroElektronika
mikoC PRO for dsPIC
OneWire Library 432
Library Routines 432 Ow_Reset 432 Ow_Read 433 Ow_Write 433 Library Example 434 HW Connection 436
Peripheral Pin Select Library 437
Library Routines 437 Unlock_IOLOCK 437 Lock_IOLOCK 437 PPS_Mapping 438 Direction Parameters 438 Input Functions 438 Output Functions 439
Port Expander Library 441
Library Dependency Tree 441 External dependencies of Port Expander Library 441 Library Routines 441 Expander_Init 442 Expander_Init_Advanced 443 Expander_Read_Byte 444 Expander_Write_Byte 444 Expander_Read_PortA 444 Expander_Read_PortB 445 Expander_Read_PortAB 445 Expander_Write_PortA 446 Expander_Write_PortB 446 Expander_Write_PortAB 447 Expander_Set_DirectionPortA 447 Expander_Set_DirectionPortB 448 Expander_Set_DirectionPortAB 448 Expander_Set_PullUpsPortA 448 Expander_Set_PullUpsPortB 449 Expander_Set_PullUpsPortAB 449 HW Connection 451
PS/2 Library 452
External dependencies of PS/2 Library 452 Library Routines 452 Ps2_Cong 453 Ps2_Key_Read 453 Special Function Keys 454 Library Example 455 HW Connection 456
PWM Library 456
Library Routines 456
MikroElektronika
18
mikroC PRO for dsPIC
PWM_Init 457 PWM_Set_Duty 457 PWM_Start 458 PWM_Stop 458 Library Example 458 HW Connection 460
PWM Motor Control Library 460
Library Routines 460 PWMx_Mc_Init 461 PWMx_Mc_Set_Duty 462 PWMx_Mc_Start 462 PWMx_Mc_Stop 463 HW Connection 464
RS-485 Library 464
Library Dependency Tree 465 External dependencies of RS-485 Library 465 Library Routines 465 RS485Master_Init 465 RS485Master_Receive 466 RS485Master_Send 466 RS485Slave_Init 467 RS485Slave_Receive 468 RS485Slave_Send 468 Library Example 469 HW Connection 472 Message format and CRC calculations 473
Software I²C Library 474
External dependencies of Software I²C Library 474 Library Routines 474 Soft_I2C_Init 475 Soft_I2C_Start 475 Soft_I2C_Read 476 Soft_I2C_Write 476 Soft_I2C_Stop 477 Soft_I2C_Break 478 Library Example 479
Software SPI Library 481
External dependencies of Software SPI Library 481 Library Routines 481 Soft_SPI_Init 482 Soft_SPI_Read 483 Soft_SPI_Write 483 Library Example 483
Software UART Library 485
Library Routines 485 Soft_UART_Init 485
19
MikroElektronika
mikoC PRO for dsPIC
Soft_UART_Read 486 Soft_UART_Write 486 Soft_UART_Break 487 Library Example 488
Sound Library 489
Library Routines 489 Sound_Init 489 Sound_Play 489 HW Connection 491
SPI Library 492
Library Routines 492 SPIx_Init 493 SPIx_Init_Advanced 494 SPIx_Read 496 SPIx_Write 496 SPI_Set_Active 497 Library Example 497 HW Connection 498
SPI Ethernet Library 499
Library Dependency Tree 499 External dependencies of SPI Ethernet Library 500 Library Routines 501 SPIx_Write 501 SPIx_Write 502 SPI_Ethernet_Enable 503 SPI_Ethernet_Disable 504 SPI_Ethernet_doPacket 505 SPI_Ethernet_putByte 505 SPI_Ethernet_putBytes 506 SPI_Ethernet_putConstBytes 506 SPI_Ethernet_putString 506 SPI_Ethernet_putConstString 507 SPI_Ethernet_getByte 507 SPI_Ethernet_getBytes 507 SPI_Ethernet_UserTCP 508 SPI_Ethernet_UserUDP 509 SPI_Ethernet_getIpAddress 510 SPI_Ethernet_getDnsIpAddress 510 SPI_Ethernet_getIpMask 510 SPI_Ethernet_confNetwork 511 SPI_Ethernet_arpResolve 511 SPI_Ethernet_sendUDP 512 SPI_Ethernet_dnsResolve 512 SPI_Ethernet_initDHCP 513 SPI_Ethernet_doDHCPLeaseTime 514 SPI_Ethernet_renewDHCP 514 Library Example 515
MikroElektronika
20
mikroC PRO for dsPIC
HW Connection 522
SPI Ethernet ENC24J600 Library 523
Library Dependency Tree 523 External dependencies of SPI Ethernet ENC24J600 Library 524 Library Routines 525 SPI_Ethernet_24j600_Init 526 SPI_Ethernet_24j600_Enable 528 SPI_Ethernet_24j600_Disable 529 SPI_Ethernet_24j600_doPacket 530 SPI_Ethernet_24j600_putByte 530 SPI_Ethernet_24j600_putBytes 531 SPI_Ethernet_24j600_putConstBytes 531 SPI_Ethernet_24j600_putString 532 SPI_Ethernet_24j600_putConstString 532 SPI_Ethernet_24j600_getByte 532 SPI_Ethernet_24j600_getBytes 533 SPI_Ethernet_24j600_UserTCP 533 SPI_Ethernet_24j600_UserUDP 534 SPI_Ethernet_24j600_getIpAddress 534 SPI_Ethernet_24j600_getGwIpAddress 535 SPI_Ethernet_24j600_getDnsIpAddress 535 SPI_Ethernet_24j600_getIpMask 536 SPI_Ethernet_24j600_confNetwork 536 SPI_Ethernet_24j600_arpResolve 537 SPI_Ethernet_24j600_sendUDP 537 SPI_Ethernet_24j600_dnsResolve 538 SPI_Ethernet_24j600_initDHCP 539 SPI_Ethernet_24j600_doDHCPLeaseTime 540 SPI_Ethernet_24j600_renewDHCP 540 Library Example 540
SPI Graphic Lcd Library 541
Library Dependency Tree 541 External dependencies of SPI Lcd Library 541 Library Routines 541 SPI_Glcd_Init 542 SPI_Glcd_Set_Side 543 SPI_Glcd_Set_Page 543 SPI_Glcd_Set_X 543 SPI_Glcd_Read_Data 544 SPI_Glcd_Write_Data 544 SPI_Glcd_Fill 545 SPI_Glcd_Dot 545 SPI_Glcd_Line 546 SPI_Glcd_V_Line 546 SPI_Glcd_H_Line 547 SPI_Glcd_Rectangle 547 SPI_Glcd_Rectangle_Round_Edges 548
21
MikroElektronika
mikoC PRO for dsPIC
SPI_Glcd_Rectangle_Round_Edges_Fill 548 SPI_Glcd_Box 549 SPI_Glcd_Circle 549 SPI_Glcd_Circle_FIll 550 SPI_Glcd_Set_Font 551 SPI_Glcd_Write_Char 552 SPI_Glcd_Write_Text 552 SPI_Glcd_Image 553 SPI_Glcd_PartialImage 553 Library Example 554 HW Connection 556
SPI Lcd Library 557
Library Dependency Tree 557 External dependencies of SPI Lcd Library 557 Library Routines 557 SPI_Lcd_Cong 558 SPI_Lcd_Out 558 SPI_Lcd_Out_Cp 559 SPI_Lcd_Chr 559 SPI_Lcd_Chr_Cp 559 SPI_Lcd_Cmd 560 SPI_Lcd_Cmd 560 Library Example 561 Default Pin Conguration 561
SPI Lcd8 (8-bit interface) Library 563
Library Dependency Tree 563 External dependencies of SPI Lcd Library 563 Library Routines 563 SPI_Lcd8_Cong 564 SPI_Lcd8_Out 565 SPI_Lcd8_Out_Cp 565 SPI_Lcd8_Chr 565 SPI_Lcd8_Chr_Cp 566 SPI_Lcd8_Cmd 566 Available SPI Lcd8 Commands 567 Library Example 567
SPI T6963C Graphic Lcd Library 570
Library Dependency Tree 570 External dependencies of SPI T6963C Graphic Lcd Library 570 Library Routines 571 SPI_Lcd8_Cmd 572 SPI_T6963C_writeData 573 SPI_T6963C_writeCommand 573 SPI_T6963C_setPtr 574 SPI_T6963C_waitReady 574 SPI_T6963C_ll 574 SPI_T6963C_dot 575
MikroElektronika
22
mikroC PRO for dsPIC
SPI_T6963C_write_char 575 SPI_T6963C_write_text 576 SPI_T6963C_line 577 SPI_T6963C_rectangle 577 SPI_T6963C_rectangle_round_edges 578 SPI_T6963C_rectangle_round_edges_ll 578 SPI_T6963C_box 579 SPI_T6963C_circle 579 SPI_T6963C_circle_ll 579 SPI_T6963C_image 580 SPI_T6963C_PartialImage 580 SPI_T6963C_sprite 581 SPI_T6963C_set_cursor 581 SPI_T6963C_clearBit 581 SPI_T6963C_setBit 582 SPI_T6963C_negBit 582 SPI_T6963C_displayGrPanel 582 SPI_T6963C_displayTxtPanel 583 SPI_T6963C_setGrPanel 583 SPI_T6963C_setTxtPanel 583 SPI_T6963C_panelFill 584 SPI_T6963C_grFill 584 SPI_T6963C_txtFill 584 SPI_T6963C_cursor_height 585 SPI_T6963C_graphics 585 SPI_T6963C_text 585 SPI_T6963C_cursor 586 SPI_T6963C_cursor_blink 586 Library Example 586 HW Connection 591
T6963C Graphic Lcd Library 592
Library Dependency Tree 592 Library Dependency Tree 593 Library Routines 594 SPI_T6963C_cursor 595 T6963C_writeData 596 T6963C_writeCommand 597 T6963C_setPtr 597 T6963C_waitReady 597 T6963C_ll 598 T6963C_dot 598 T6963C_write_char 599 T6963C_write_text 600 T6963C_line 600 T6963C_rectangle 601 T6963C_rectangle_round_edges 601 T6963C_rectangle_round_edges_ll 602
23
MikroElektronika
mikoC PRO for dsPIC
T6963C_box 602 T6963C_circle 602 T6963C_circle_ll 603 T6963C_image 603 T6963C_PartialImage 604 T6963C_sprite 604 T6963C_set_cursor 605 T6963C_clearBit 605 T6963C_setBit 605 T6963C_negBit 606 T6963C_displayGrPanel 606 T6963C_displayTxtPanel 606 T6963C_setGrPanel 607 T6963C_setTxtPanel 607 T6963C_panelFill 607 T6963C_grFill 608 T6963C_txtFill 608 T6963C_cursor_height 608 T6963C_graphics 609 T6963C_text 609 T6963C_cursor 609 T6963C_cursor_blink 610 Library Example 610 HW Connection 614
TFT Library 615
External dependencies of TFT Library 615 Library Routines 616 TFT_Init 617 TFT_Set_Index 618 TFT_Write_Command 618 TFT_Write_Data 618 TFT_Set_Active 619 TFT_Set_Font 620 TFT_Write_Char 621 TFT_Write_Text 621 TFT_Fill_Screen 622 TFT_Dot 623 TFT_Set_Pen 624 TFT_Set_Brush 625 TFT_Line 627 TFT_H_Line 628 TFT_V_Line 628 TFT_Rectangle_Round_Edges 629 TFT_Circle 629 TFT_Image 629 TFT_Partial_Image 630 TFT_Image_Jpeg 630
MikroElektronika
24
mikroC PRO for dsPIC
TFT_RGBToColor16bit 631 TFT_Color16bitToRGB 631 HW Connection 632
Touch Panel Library 633
Library Dependency Tree 633 External dependencies of Touch Panel Library 633 Library Routines 633 TP_Init 634 TP_Set_ADC_Threshold 634 TP_Press_Detect 635 TP_Get_Coordinates 636 TP_Calibrate_Bottom_Left 636 TP_Calibrate_Upper_Right 637 TP_Get_Calibration_Consts 637 TP_Set_Calibration_Consts 638 Library Example 638
Touch Panel TFT Library 643
Library Dependency Tree 643 External dependencies of Touch Panel TFT Library 643 Library Routines 643 TP_TFT_Init 644 TP_TFT_Set_ADC_Threshold 644 TP_TFT_Press_Detect 645 TP_TFT_Get_Coordinates 646 TP_TFT_Calibrate_Min 646 TP_TFT_Calibrate_Max 647 TP_TFT_Get_Calibration_Consts 647 TP_TFT_Set_Calibration_Consts 648 HW Connection 648
UART Library 649
Library Routines 649 UARTx_Init 650 UARTx_Init_Advanced 651 UARTx_Data_Ready 653 UARTx_Tx_Idle 654 UARTx_Read 655 UARTx_Read_Text 656 UARTx_Write 657 UARTx_Write_Text 658 UART_Set_Active 659 Library Example 660 HW Connection 661
USB Library 662
USB HID Class 662 Library Routines 662 HID_Enable 663
25
MikroElektronika
mikoC PRO for dsPIC
HID_Read 663 HID_Write 664 HID_Disable 664 USB_Interrupt_Proc 665 USB_Polling_Proc 665 Gen_Enable 666 Gen_Read 666 Gen_Write 667 Library Example 668 HW Connection 668
DSP Libraries 669
Digital Signal Processing Libraries 669
FIR Filter Library 670
Library Routines 670 FIR_Radix 670
IIR Filter Library 671
Library Routines 671 IIR_Radix 671
FFT Library 672
Library Dependency Tree 672 FFT 672 Twiddle Factors: 673 TwiddleCoeff_64 673 TwiddleCoeff_128 673 TwiddleCoeff_256 674 TwiddleCoeff_512 674
Bit Reverse Complex Library 676
Library Routines 676 BitReverseComplex 676
Vectors Library 677
Library Routines 677 Vector_Set 677 Vector_Power 678 Vector_Subtract 678 Vector_Scale 679 Vector_Negate 679 Vector_Multiply 680 Vector_Min 680 Vector_Max 681 Vector_Dot 681 Vector_Correlate 682 Vector_Convolve 683 Vector_Add 684
Matrices Library 685
Library Routines 685 Matrix_Transpose 685
MikroElektronika
26
mikroC PRO for dsPIC
Matrix_Subtract 686 Matrix_Scale 686 Matrix_Multiply 687 Matrix_Add 688
Standard ANSI C Libraries 689 ANSI C Ctype Library 689
Library Functions 689 isalnum 690 isalpha 690 iscntrl 690 isdigit 690 isgraph 691 islower 691 ispunct 691 isspace 691 isupper 692 isxdigit 692 toupper 692 tolower 692
ANSI C Math Library 693
Library Functions 693 acos 693 asin 694 atan 694 atan2 694 ceil 694 cos 695 cosh 695 exp 695 fabs 695 oor 695 frexp 696 ldexp 696 log 696 log10 696 modf 697 pow 697 sin 697 sinh 697 sqrt 698 tan 698 tanh 698
ANSI C Stdlib Library 699
Library Dependency Tree 699 Library Functions 699 abs 699
27
MikroElektronika
mikoC PRO for dsPIC
atof 700 atoi 700 atol 700 div 700 ldiv 701 uldiv 701 labs 701 max 701 min 702 rand 702 srand 702 xtoi 702 Div Structures 703
ANSI C String Library 704
Library Functions 704 memchr 704 memcmp 705 memcpy 705 memmove 705 memset 706 strcat 706 strchr 706 strcmp 707 strcpy 707 strlen 707 strncat 708 strncpy 708 strspn 708 strncmp 709 strstr 709 strcspn 710 strpbrk 710 strrchr 710 strtok 711
Miscellaneous Libraries 712 Button Library 712
Library Routines 712 strrchr 712
Conversions Library 714
Library Dependency Tree 714 Library Routines 714 ByteToStr 715 ShortToStr 715 WordToStr 716 IntToStr 716 LongToStr 717
MikroElektronika
28
mikroC PRO for dsPIC
LongWordToStr 717 FloatToStr 718 WordToStrWithZeros 719 IntToStrWithZeros 719 LongWordToStrWithZeros 720 LongIntToStrWithZeros 720 ByteToHex 721 ShortToHex 721 WordToHex 722 IntToHex 722 LongWordToHex 723 LongIntToHex 723 Dec2Bcd 724 Bcd2Dec 724 Dec2Bcd16 725 Bcd2Dec16 725 Rtrim 726 Ltrim 726
PrintOut Library 727
Library Dependency Tree 727 Library Routines 727 PrintOut 727
Setjmp Library 731
Library Routines 731 Setjmp 731 Longjmp 732 Library Example 732
Sprint Library 734
Library Dependency Tree 734 Functions 734 sprintf 734 sprintl 736 sprinti 736 Library Example 737
Time Library 738
Library Routines 738 Time_dateToEpoch 738 Time_epochToDate 739 Time_dateDiff 740 Library Example 741
Trigonometry Library 742
Library Routines 742 sinE3 742 cosE3 743
CHAPTER 10 744 Tutorials 744
29
MikroElektronika
mikoC PRO for dsPIC
Managing Project 744
Projects 744
New Project 745
New Project Wizard Steps 745
New Project 748
New Project Wizard Steps 748
Customizing Projects 752
Managing Project Group 752 Add/Remove Files from Project 752 Project Level Denes: 753
Add/Remove Files from Project 754
Project Level Denes: 755
Source Files 756
Managing Source Files 756
Creating new source le 756 Opening an existing le 756 Printing an open le 756 Saving le 756 Saving le under a different name 757 Closing le 757
Search Paths 757 Paths for Source Files (.c) 758 Paths for Header Files (.h) 758
Edit Project 759 Source Files 760
Managing Source Files 760
Creating new source le 760 Opening an existing le 760 Printing an open le 760 Saving le 760 Saving le under a different name 761 Closing le 761
Search Paths 761 Paths for Source Files (.c) 762 Paths for Header Files (.h) 762
Clean Project Folder 763 Compilation 764
Output Files 764 Assembly View 764 Multiple Library Versions 765
Using Microchip MPLAB® IDE with mikroElektronika compilers 766
Debugging Your Code 766
Using MPLAB® ICD 2 Debugger 766 Using MPLAB® Simulator 773
MikroElektronika
30
mikroC PRO for dsPIC
Frequently Asked Questions 778
Can I use your compilers and programmer on Windows Vista (Windows 7) ? 778 I am getting “Access is denied” error in Vista, how to solve this problem ? 778 What are differences between mikroC PRO, mikroPascal PRO and mikroBasic PRO compilers ? Why do they have different prices ? 778 Why do your PIC compilers don’t support 12F508 and some similar chips ? 778 What are limitations of demo versions of mikroElektronika’s compilers ? 778 Why do I still get demo limit error when I purchased and installed license key ? 778 I have bought license for the older version, do I have to pay license for the new version of the com­piler ? 779 Do your compilers work on Windows Vista (Windows 7) ? 779 What does this function/procedure/routine do ? 779 I try to compile one of the provided examples and nothing happens, what is the problem? 779 Can I get your library sources ? I need to provide all sources with my project. 779 Can I use code I developed in your compilers in commercial purposes ? Are there some limitations ? 779 Why does an example provided with your compilers doesn’t work ? 779 Your example works if I use the same MCU you did, but how to make it work for another MCU ? 779 I need this project nished, can you help me ? 780 Do you have some discount on your compilers/development systems for students/professors ? 780 I have a question about your compilers which is not listed here. Where can I nd an answer ? 780
31
MikroElektronika
mikoC PRO for dsPIC
CHAPTER 1
INTRODUCTION
The mikroC PRO for dsPIC30/33 and PIC24 is a powerful, feature-rich development tool for dsPIC30/33 and PIC24 microcontrollers. It is designed to provide the programmer with the easiest possible solution to developing applications for embedded systems, without compromising performance or control.
mikroC PRO for dsPIC30/33 and PIC24 IDE
MikroElektronika
32
mikroC PRO for dsPIC
Introduction to mikroC PRO for dsPIC30/33 and PIC24
dsPIC30/33 and PIC24 and C t together well: dsPIC is designed as PIC with digital signal processing capabilities. These are Microchip’s rst inherent 16-bit (data) microcontrollers. They build on the PIC’s existing strength offering
hardware MAC (multiply-accumulate), barrel shifting, bit reversal, (16x16)-bit multiplication and other digital signal
processing operations. Having a wide range of application, being prized for its efciency, dsPIC30/33 and PIC24 MCUs
are a natural choice for developing embedded systems. mikroC PRO for dsPIC30/33 and PIC24 provides a successful match featuring highly advanced IDE, ANSI compliant compiler, broad set of hardware libraries, comprehensive documentation, and plenty of ready-to-run examples.
Features
mikroC PRO for dsPIC30/33 and PIC24 allows you to quickly develop and deploy complex applications:
- Write your source code using the built-in Code Editor (Code and Parameter Assistants, Code Folding, Syntax Highlighting, Auto Correct, Code Templates, and more.)
- Use included mikroC PRO for dsPIC30/33 and PIC24 libraries to dramatically speed up the development: data acquisition, memory, displays, conversions, communication etc.
- Monitor your program structure, variables, and functions in the Code Explorer.
- Generate commented, human-readable assembly, and standard HEX compatible with all programmers.
- Use the integrated mikroICD (In-Circuit Debugger) Real-Time debugging tool to monitor program execution on the hardware level.
- Inspect program ow and debug executable logic with the integrated Software Simulator.
- Generate COFF(Common Object File Format) le for software and hardware debugging under Microchip’s
MPLAB software.
- Use Single Static Assignment optimization to shrink your code to even smaller size.
- Get detailed reports and graphs: RAM and ROM map, code statistics, assembly listing, calling tree, and more.
- Active Comments enable you to make your comments alive and interactive.
- mikroC PRO for dsPIC30/33 and PIC24 provides plenty of examples to expand, develop, and use as
building bricks in your projects. Copy them entirely if you deem t – that’s why we included them
with the compiler.
Where to Start
- In case that you’re a beginner in programming dsPIC30/33 and PIC24 microcontrollers, read carefully the
dsPIC Specics chapter. It might give you some useful pointers on dsPIC30/33 and PIC24 constraints,
code portability, and good programming practices.
- If you are experienced in C programming, you will probably want to consult mikroC PRO for dsPIC30/33
and PIC24 Specics rst. For language issues, you can always refer to the comprehensive Language
Reference. A complete list of included libraries is available at mikroC PRO for dsPIC30/33 and PIC24 Libraries.
- If you are not very experienced in C programming, don’t panic! mikroC PRO for dsPIC30/33 and PIC24
provides plenty of examples making it easy for you to go quickly. We suggest that you rst consult Projects
and Source Files, and then start browsing the examples that you’re the most interested in.
Copyright (c) 2002-2010 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
33
MikroElektronika
mikoC PRO for dsPIC
What’s new in mikroC PRO for dsPIC30/33 and PIC24
IDE build 4.60 Command line build 4.60
New features and enhancements in the following areas will boost your productivity by helping you complete many tasks more easily and in less time.
For a complete version history of mikroC PRO for dsPIC30/33 and PIC24, visit the following link : http://www.mikroe. com/download/eng/documents/compilers/mikroc/pro/dspic/version_history.txt
- Compiler Changes
- IDE Changes
Compiler Changes
Fixed :
- Optimization issues in specic cases when destination variable is in Rx space.
- Alignment not set for the rst variable which is the rst in block of initializers.
IDE Changes
Fixed :
- Error in Code Explorer in case void interrup is dened (without brackets).
- Compiler version is not visible in caption if no projects are open.
- Parameter assistant ignores commas when switching to another parameter.
- Occasional lost of conguration ags when swithing between projets.
- Improper display of RAM memory usage in statistics.
Improved :
- Communication to programmer concerning supported chips.
- License Key Request form.
MikroElektronika
34
mikroC PRO for dsPIC
Software License Agreement
mikroElektronika Associates License Statement and Limited Warranty
IMPORTANT - READ CAREFULLY
This license statement and limited warranty constitute a legal agreement (“License Agreement”) between you (either as an individual or a single entity) and mikroElektronika (“mikroElektronika Associates”) for software product (“Software”)
identied above, including any software, media, and accompanying on-line or printed documentation.
BY INSTALLING, COPYING, OR OTHERWISE USING SOFTWARE, YOU AGREE TO BE BOUND BY ALL TERMS AND CONDITIONS OF THE LICENSE AGREEMENT.
Upon your acceptance of the terms and conditions of the License Agreement, mikroElektronika Associates grants you the right to use Software in a way provided below.
This Software is owned by mikroElektronika Associates and is protected by copyright law and international copyright treaty. Therefore, you must treat this Software like any other copyright material (e.g., a book).
You may transfer Software and documentation on a permanent basis provided. You retain no copies and the recipient agrees to the terms of the License Agreement. Except as provided in the License Agreement, you may not transfer, rent, lease, lend, copy, modify, translate, sublicense, time-share or electronically transmit or receive Software, media
or documentation. You acknowledge that Software in the source code form remains a condential trade secret of
mikroElektronika Associates and therefore you agree not to modify Software or attempt to reverse engineer, decompile, or disassemble it, except and only to the extent that such activity is expressly permitted by applicable law notwithstanding this limitation.
If you have purchased an upgrade version of Software, it constitutes a single product with the mikroElektronika Associates software that you upgraded. You may use the upgrade version of Software only in accordance with the License Agreement.
LIMITED WARRANTY
Respectfully excepting the Redistributables, which are provided “as is”, without warranty of any kind, mikroElektronika Associates warrants that Software, once updated and properly used, will perform substantially in accordance with the accompanying documentation, and Software media will be free from defects in materials and workmanship, for a period of ninety (90) days from the date of receipt. Any implied warranties on Software are limited to ninety (90) days.
mikroElektronika Associates’ and its suppliers’ entire liability and your exclusive remedy shall be, at mikroElektronika Associates’ option, either (a) return of the price paid, or (b) repair or replacement of Software that does not meet mikroElektronika Associates’ Limited Warranty and which is returned to mikroElektronika Associates with a copy of your receipt. DO NOT RETURN ANY PRODUCT UNTIL YOU HAVE CALLED MIKROELEKTRONIKA ASSOCIATES FIRST AND OBTAINED A RETURN AUTHORIZATION NUMBER. This Limited Warranty is void if failure of Software has resulted from an accident, abuse, or misapplication. Any replacement of Software will be warranted for the rest of the original warranty period or thirty (30) days, whichever is longer.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MIKROELEKTRONIKA ASSOCIATES AND ITS SUPPLIERS DISCLAIM ALL OTHER WARRANTIES AND CONDITIONS, EITHER EXPRESSED OR IMPLIED, INCLUDED, BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO SOFTWARE, AND THE PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES.
35
MikroElektronika
mikoC PRO for dsPIC
IN NO EVENT SHALL MIKROELEKTRONIKA ASSOCIATES OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS AND BUSINESS INFORMATION, BUSINESS INTERRUPTION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE PRODUCT OR THE PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF MIKROELEKTRONIKA ASSOCIATES HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY CASE, MIKROELEKTRONIKA ASSOCIATES’ ENTIRE LIABILITY UNDER ANY PROVISION OF THIS LICENSE AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR SOFTWARE PRODUCT PROVIDED, HOWEVER, IF YOU HAVE ENTERED INTO A MIKROELEKTRONIKA ASSOCIATES SUPPORT SERVICES AGREEMENT, MIKROELEKTRONIKA ASSOCIATES’ ENTIRE LIABILITY REGARDING SUPPORT SERVICES SHALL BE GOVERNED BY THE TERMS OF THAT AGREEMENT.
HIGH RISK ACTIVITIES
Software is not fault-tolerant and is not designed, manufactured or intended for use or resale as on-line control equipment in hazardous environments requiring fail-safe performance, such as in the operation of nuclear facilities,
aircraft navigation or communication systems, air trafc control, direct life support machines, or weapons systems, in
which the failure of Software could lead directly to death, personal injury, or severe physical or environmental damage
(“High Risk Activities”). mikroElektronika Associates and its suppliers specically disclaim any expressed or implied warranty of tness for High Risk Activities.
GENERAL PROVISIONS
This statement may only be modied in writing signed by you and an authorised ofcer of mikroElektronika Associates.
If any provision of this statement is found void or unenforceable, the remainder will remain valid and enforceable according to its terms. If any remedy provided is determined to have failed for its essential purpose, all limitations of liability and exclusions of damages set forth in the Limited Warranty shall remain in effect.
This statement gives you specic legal rights; you may have others, which vary, from country to country. mikroElektronika Associates reserves all rights not specically granted in this statement.
mikroElektronika
Visegradska 1A, 11000 Belgrade, Europe.
Phone: + 381 11 36 28 830 Fax: +381 11 36 28 831 Web: www.mikroe.com E-mail: ofce@mikroe.com
MikroElektronika
36
mikroC PRO for dsPIC
Technical Support
The latest software can be downloaded free of charge via Internet (you might want to bookmark the page so you could check news, patches, and upgrades later on): www.mikroe.com/en/compilers/mikroC PRO/dspic/download.htm .
In case you encounter any problem, you are welcome to our support forums at www.mikroe.com/forum/. Here, you may
also nd helpful information, hardware tips, and practical code snippets. Your comments and suggestions on future
development of the mikroC PRO for dsPIC30/33 and PIC24 are always appreciated — feel free to drop a note or two on our Wishlist.
In our Knowledge Base www.mikroe.com/en/kb/ you can nd the answers to Frequently Asked Questions and solutions to known problems. If you can not nd the solution to your problem in Knowledge Base then report it to Support Desk www.mikroe.com/en/support/. In this way, we can record and track down bugs more efciently, which is in our mutual
interest. We respond to every bug report and question in a suitable manner, ever improving our technical support.
How to Register
The latest version of the mikroC PRO for dsPIC30/33 and PIC24 is always available for downloading from our website. It is a fully functional software with the mikroICD(in-circuit Debugger), all the libraries, examples, and comprehensive help included.
The only limitation of the free version is that it cannot generate hex output over 2K of program words. Although it might sound restrictive, this margin allows you to develop practical, working applications with no thinking of demo limit. If you intend to develop really complex projects in the mikroC PRO for dsPIC30/33 and PIC24, then you should consider the possibility of purchasing the license key.
Who Gets the License Key
Buyers of the mikroC PRO for dsPIC30/33 and PIC24 are entitled to the license key. After you have completed the payment procedure, you have an option of registering your mikroC PRO for dsPIC30/33 and PIC24. In this way you can generate hex output without any limitations.
How to Get License Key
After you have completed the payment procedure, start the program. Select Help › How to Register from the drop-
down menu or click the How To Register Icon .
You can choose between two registering methods, I work online or I work ofine, based on your current internet connection and click Request license key now button :
37
MikroElektronika
mikoC PRO for dsPIC
If you choose I work online registering method, following page will be opened in your default browser :
MikroElektronika
38
mikroC PRO for dsPIC
Fill out the registration form, select your distributor, and click the Submit button.
If you choose I work ofine registering method, following window will be opened :
Fill out the registration form, select your distributor, and click the Submit button.
This will start your e-mail client with message ready for sending. Review the information you have entered, and add the comment if you deem it necessary. Please, do not modify the subject line.
Upon receiving and verifying your request, we will send the license key to the e-mail address you specied in the
form.
After Receving the License Key
The license key comes as a small autoextracting le – just start it anywhere on your computer in order to activate
your copy of compiler and remove the demo limit. You do not need to restart your computer or install any additional components. Also, there is no need to run the mikroC PRO for dsPIC30/33 and PIC24 at the time of activation.
39
MikroElektronika
mikoC PRO for dsPIC
Important :
- The license key is valid until you format your hard disk. In case you need to format the hard disk, you should request a new activation key.
- Please keep the activation program in a safe place. Every time you upgrade the compiler you should start this program again in order to reactivate the license.
MikroElektronika
40
mikroC PRO for dsPIC
CHAPTER 2
mikroC PRO for dsPIC30/33 and PIC24 Environment
41
MikroElektronika
Main Menu Options
Available Main Menu options are:
mikoC PRO for dsPIC
Related topics: Keyboard shortcuts, Toolbars
MikroElektronika
42
mikroC PRO for dsPIC
File
File Menu Options
The File menu is the main entry point for manipulation with the source les.
File Description
Open a new editor window.
Open source le for editing or image le for viewing.
Reopen recently used le.
Save changes for active editor.
Save the active source le with the different name or change the le type.
Close active source le.
Close all opened les.
Print Preview.
Print.
Exit IDE.
Related topics: Keyboard shortcuts, File Toolbar, Managing Source Files
43
MikroElektronika
Edit
Edit Menu Options
The Edit Menu contains commands for editing the contents of the current document.
mikoC PRO for dsPIC
Edit Description
Undo last change.
Redo last change.
Cut selected text to clipboard.
Copy selected text to clipboard.
Paste text from clipboard.
Delete selected text.
Select all text in active editor.
Find text in active editor.
Find next occurence of text in active editor.
Find previous occurence of text in active editor.
Replace text in active editor.
Find text in current le, in all opened les, or in les from desired folder.
Go to line to the desired line in active editor.
Advanced Code Editor options
MikroElektronika
44
mikroC PRO for dsPIC
Advanced » Description
Comment selected code or put single line comment if there is no selection.
Uncomment selected code or remove single line comment if there is no selection.
Indent selected code.
Outdent selected code.
Changes selected text case to lowercase.
Changes selected text case to uppercase.
Changes selected text case to titlercase.
Find Text
Dialog box for searching the document for the specied text. The search is performed in the direction specied. If the
string is not found a message is displayed.
Replace Text
Dialog box for searching for a text string in le and replacing it with another text string.
45
MikroElektronika
mikoC PRO for dsPIC
Find In Files
Dialog box for searching for a text string in current le, all opened les, or in les on a disk.
The string to search for is specied in the Text to nd eld. If Search in directories option is selected, The les to search are specied in the Files mask and Path elds.
Go To Line
Dialog box that allows the user to specify the line number at which the cursor should be positioned.
Regular expressions option
By checking this box, you will be able to advance your search, through Regular expressions.
Related topics: Keyboard shortcuts, Edit Toolbar, Advanced Edit Toolbar
MikroElektronika
46
mikroC PRO for dsPIC
View
View Menu Options
View Menu contains commands for controlling the on-screen display of the current project.
47
MikroElektronika
View Description
Show/Hide Software Simulator / mikroICD (In-Circuit Debugger) Debug Windows.
Show/Hide Toolbars.
Show/Hide Bookmarks window.
Show/Hide Code Explorer window.
Show/Hide Library Manager window.
Show/Hide Macro Editor window.
Show/Hide Messages window.
Show/Hide Project Manager window.
Show/Hide Project Settings window.
Show/Hide Routine List in active editor.
Show/Hide Quick Converter window.
Show/Hide View Image Preview window.
mikoC PRO for dsPIC
View Assembly.
View Listing.
View Statistics.
Show Window List window.
The Tools toolbar can easily be customized by adding new tools in Options(F12) window.
Related topics: Keyboard shortcuts, Integrated Tools
MikroElektronika
48
mikroC PRO for dsPIC
Project
Project Menu Options
Project Menu allows user to easily manipulate current project.
Project Description
Open New Project Wizard
Open existing project.
Open project group.
Open recently used project or project group.
Save current project.
Save active project le with the different name.
Close active project.
Close project group.
Add le to project.
Remove le from project.
Edit search paths.
Edit project settings
Clean Project Folder
Export Project.
Related topics: Keyboard shortcuts, Project Toolbar, Creating New Project, Project Manager, Project Settings
49
MikroElektronika
Build
Build Menu Options
Build Menu allows user to easily manage building and compiling process.
Build Description
Build active project.
Rebuild all sources in acrive project.
Build all projects.
Stop building of all projects.
mikoC PRO for dsPIC
Build and program active project.
Related topics: Keyboard shortcuts, Project Toolbar, Creating New Project, Project Manager, Project Settings
MikroElektronika
50
mikroC PRO for dsPIC
Run
Run Menu Options
Run Menu is used to debug and test compiled code on a software or harware level.
Run Description
Start Software Simulator or mikroICD (In-Circuit Debugger).
Stop debugger.
Run/Pause Debugger.
Step Into.
Step Over.
Step Out.
Run To Cursor.
Jump to interrupt in current project.
Toggle Breakpoint.
Clear Breakpoints.
Toggle between source and disassembly.
Related topics: Keyboard shortcuts, Debug Toolbar
51
MikroElektronika
mikoC PRO for dsPIC
Tools
Tools Menu Options
Tools Menu contain a number of applications designed to ease the use of compiler and included library routines.
Tools Description
Run mikroElektronika Programmer.
Run Package Manager.
Show/Hide Active Comment Editor window.
Run ASCII Chart
Run EEPROM Editor
Generate HTML code suitable for publishing source code on the web.
Run Filter Designer Tool.
Run Glcd bitmap editor
Run HID Terminal
Run Lcd custom character
Run Seven Segment Editor
Run UDP communication terminal
Run USART Terminal
Open Options window
Related topics: Keyboard shortcuts, Tools Toolbar
MikroElektronika
52
mikroC PRO for dsPIC
Help
Help Menu Options
Help Description
Оpen Help File.
Оpen Code Migration Document.
Check if new compiler version is available.
Open mikroElektronika Support Forums in a default browser.
Open mikroElektronika Web Page in a default browser.
Information on how to register
Open About window.
Related topics: Keyboard shortcuts, Help Toolbar
53
MikroElektronika
mikoC PRO for dsPIC
mikroC PRO for dsPIC30/33 and PIC24 IDE
IDE Overview
The mikroC PRO for dsPIC30/33 and PIC24 is an user-friendly and intuitive environment.
For a detailed information on a certain part of IDE, simply click on it (hovering a mouse cursor above a desired IDE part will pop-up its name) :
- The Code Editor features adjustable Syntax Highlighting, Code Folding, Code Assistant, Parameters Assistant, Spell Checker, Auto Correct for common typos and Code Templates (Auto Complete).
- The Code Explorer is at your disposal for easier project management.
- The Project Manager alows multiple project management
- General project settings can be made in the Project Settings window
- Library manager enables simple handling libraries being used in a project
- The Messages Window displays all messages during compiling and linking.
- The source-level Software Simulator lets you debug executable logic step-by-step by watching the program ow.
- The New Project Wizard is a fast, reliable, and easy way to create a project.
- Help les are syntax and context sensitive.
- Like in any modern Windows application, you may customize the layout of mikroC PRO for dsPIC30/33 and PIC24 to suit your needs best.
- Spell checker underlines identiers which are unknown to the project. In this way it helps the programmer to spot
potential problems early, much before the project is compiled. Spell checker can be disabled by choosing the option in the Preferences dialog (F12).
MikroElektronika
54
mikroC PRO for dsPIC
Code Editor
The Code Editor is advanced text editor fashioned to satisfy needs of professionals. General code editing is the same as working with any standard text-editor, including familiar Copy, Paste and Undo actions, common for Windows environment.
Available Code Editor options are: Editor Settings, Editor Colors, Auto Correct, Auto Complete and Style.
Editor Settings
Main Editor Settings Features are :
- Auto Save
- Highlighter
- Spelling
- Comment Style
- Code Folding
- Code Assistant
- Parameter Assistant
- Bookmarks and Go to Line
55
MikroElektronika
mikoC PRO for dsPIC
Auto Save
Auto Save is a function which saves an opened project automatically, helping to reduce the risk of data loss in case of
a crash or freeze. Autosaving is done in time intervals dened by the user.
Highlighter
Highlighting is a convenient feature for spotting brackets which notate begin or end of a routine, by making them visually distinct.
Spelling
The Spell Checker underlines unknown objects in the code, so they can be easily noticed and corrected before compiling your project.
Select Tools › Options from the drop-down menu, or click the Show Options Icon and then select the Spell Checker Tab.
Comment Style
Code Editor has a feature to change the comment style to either single-line or multi-line. Commenting or uncommenting
the selected code is done by a simple click of a mouse, using the Comment Icon and Uncomment Icon from
the Advanced Edit Toolbar.
Code Folding
Code folding is IDE feature which allows users to selectively hide and display sections of a source le. In this way it is
easier to manage large regions of code within one window, while still viewing only those subsections of the code that are relevant during a particular editing session.
While typing, the code folding symbols ( and ) appear automatically. Use the folding symbols to hide/unhide the code subsections.
MikroElektronika
56
mikroC PRO for dsPIC
Another way of folding/unfolding code subsections is by using Alt+← and Alt+→.
If you place a mouse cursor over the tooltip box, the collapsed text will be shown in a tooltip style box.
Code Assistant
If you type the rst few letters of a word and then press Ctrl+Space, all valid identiers matching the letters you have typed will be prompted in a oating panel (see the image below). Now you can keep typing to narrow the choice, or you
can select one from the list using the keyboard arrows and Enter.
Parameter Assistant
The Parameter Assistant will be automatically invoked when you open parenthesis “(” or press Shift+Ctrl+Space. If the
name of a valid function precedes the parenthesis, then the expected parameters will be displayed in a oating panel.
As you type the actual parameter, the next expected parameter will become bold.
Bookmarks
Bookmarks make navigation through a large code easier. To set a bookmark, use Ctrl+Shift+number. The same princliple applies to the removal of the bookmarks. To jump to a bookmark, use Ctrl+number.
Go to Line
The Go to Line option makes navigation through a large code easier. Use the shortcut Ctrl+G to activate this option.
57
MikroElektronika
mikoC PRO for dsPIC
Column Select Mode
This mode changes the operation of the editor for selecting text. When column select mode is used, highlighted text
is based on the character column position of the rst character selected to the column of the last character of text
selected. Text selected in this mode does not automatically include all text between the start and end position, but includes all
text in the columns between the rst and last character selected.
Column mode editing is sometimes referred to as block mode editing as the act of selecting text forms a rectangle.
To enter this mode, press Alt + Left mouse button, drag the mouse towards the desired direction thus selecting the text.
Editor Colors
MikroElektronika
58
mikroC PRO for dsPIC
Editor Colors option allows user to set, change and save text and color settings organized in schemes. Schemes represent custom graphical appearance that can be applied to GUI(Graphical User Interface) to satifsy tastes of different users.
Auto Correct
Auto Correct option facilitate user in such a fashion that it automatically corrects common typing or spelling errors as it types.
This option is already set up to automatically correct some words. For example, if you type whiel, it will be corrected to while when you press the spacebar :
59
MikroElektronika
mikoC PRO for dsPIC
User can easily add its common typos by entering original typo, for example btye, to the Original box, and replacement, byte, to the Replacement box, and just click "Add" button. Next time when the typo occurs, it will be automatically corrected.
Auto Complete (Code Templates)
Auto Complete option saves lots of keystrokes for commonly used phrases by automatically completing user's typing.
MikroElektronika
60
mikroC PRO for dsPIC
User can insert the Code Template by typing the name of the template (for instance, dow), then press Ctrl+J and the Code Editor will automatically generate a code :
You can add your own templates to the list by entering the desired keyword, description and code of your template in appropriate boxes. Autocomplete macros can retreive system and project information :
- %DATE% - current system date
- %TIME% - current system time
- %DEVICE% - device(MCU) name as specied in project settings
- %DEVICE_CLOCK% - clock as specied in project settings
- %COMPILER% - current compiler version
These macros can be used in template code, see template ptemplate provided with mikroC PRO for dsPIC30/33 and PIC24 installation.
61
MikroElektronika
mikoC PRO for dsPIC
Code Explorer
The Code Explorer gives clear view of each item declared inside the source code. You can jump to a declaration of
any item by double clicking it, or pressing the Enter button. Also, besides the list of dened and declared objects, code explorer displays message about rst error and it's location in code.
Following options are available in the Code Explorer:
Icon Description
Expand/Collapse all nodes in tree.
Locate declaration in code.
MikroElektronika
62
mikroC PRO for dsPIC
Routine List
Routine list diplays list of routines, and enables ltering routines by name. Routine list window can be accessed by
pressing Ctrl+L.
You can jump to a desired routine by double clicking on it, or pressing the Enter button. Also, you can sort routines by size or by address.
Project Manager
Project Manager is IDE feature which allows users to manage multiple projects. Several projects which together make project group may be open at the same time. Only one of them may be active at the moment. Setting project in active mode is performed by double clicking the desired project in the Project Manager, which will result in bolding the project's name. Also, the name of the currently active project will be diplayed in the Program Manager window title, alongside with the number of projects in project group.
63
MikroElektronika
Following options are available in the Project Manager:
Icon Description
mikoC PRO for dsPIC
For details about adding and removing les from project see Add/Remove Files from Project.
Save project Group.
Open project group.
Close the active project.
Close project group.
Add project to the project group.
Remove project from the project group.
Add le to the active project.
Remove selected le from the project.
Build the active project.
Run mikroElektronika’s Flash programmer.
Related topics: Project Settings, Project Menu Options, File Menu Options, Project Toolbar, Build Toolbar, Add/Remove Files from Project
MikroElektronika
64
mikroC PRO for dsPIC
Project Settings
Following options are available in the Project Settings :
- Device - select the appropriate device from the device drop-down list.
- MCU Clock - enter the clock frequency value.
- Build/Debugger Type - choose debugger type.
Related topics: Edit Project, Customizing Projects, Project Manager
65
MikroElektronika
mikoC PRO for dsPIC
Library Manager
Library Manager enables simple handling libraries being used in a project. Library Manager window lists all libraries (extension .mcl) which are instantly stored in the compiler Uses folder. The desirable library is added to the project by selecting check box next to the library name.
In order to have all library functions accessible, simply press the button Check All and all libraries will be selected.
In case none library is needed in a project, press the button Clear All and all libraries will be cleared from the
project.
Only the selected libraries will be linked.
Icon Description
Refresh Library by scanning les in “Uses” folder.Useful when new libraries are added by copying les to
“Uses” folder.
Rebuild all available libraries. Useful when library sources are available and need refreshing.
Include all available libraries in current project.
No libraries from the list will be included in current project.
Restore library to the state just before last project saving.
MikroElektronika
66
mikroC PRO for dsPIC
Managing libraries using Package Manager
The Package Manager is a tool which enables users to easily install their own libraries in the mikroIDE. Libraries are
distributed in the form of a package, which is an archive composed of one or more les, containing libraries. For more
information on Package Manager, visit our website.
Upon package installation, a new node with the package name will be created in the Library Manager. For example :
From the Library Manager, user can also uninstall the desired package by right clicking the the appropriate node, and from the drop-down menu choose Uninstall package :
67
MikroElektronika
Related topics: mikroC PRO for PIC Libraries, Creating New Library
mikoC PRO for dsPIC
Statistics
After successful compilation, you can review statistics of your code. Click the Statistics Icon .
Memory Usage Windows
Provides overview of RAM and ROM usage in the various forms.
MikroElektronika
68
mikroC PRO for dsPIC
RAM Memory Usage
Displays RAM memory usage in a pie-like form.
Used RAM Locations
Displays used RAM memory locations and their names.
69
MikroElektronika
SFR Locations
Displays list of used SFR locations.
mikoC PRO for dsPIC
ROM Memory Usage
Displays ROM memory space usage in a pie-like form.
MikroElektronika
70
mikroC PRO for dsPIC
ROM Memory Constants
Displays ROM memory constants and their addresses.
Functions
Sorts and displays functions in various ways.
71
MikroElektronika
Functions Sorted By Name Chart
Sorts and displays functions by their name, in the ascending order.
mikoC PRO for dsPIC
Functions Sorted By Size Chart
Sorts and displays functions by their sizes in a chart-like form.
MikroElektronika
72
mikroC PRO for dsPIC
Functions Sorted By Addresses
Sorts and displays functions by their addresses, in the ascending order.
Function Tree
Displays Function Tree with the relevant data for each function.
73
MikroElektronika
Memory Summary
Displays summary of RAM and ROM memory in a pie-like form.
mikoC PRO for dsPIC
MikroElektronika
74
mikroC PRO for dsPIC
Messages Window
Messages Window displays various informations and notications about the compilation process.
It reports for example, time needed for preprocessing, compilation and linking; used RAM and ROM space, generated
baud rate with error percentage, etc.
User can lter which notications will Messages Window display by checking Errors, Warning and Hints box.
In case that errors were encountered during compiling, the compiler will report them and won’t generate a hex le. The
Messages Window will display errros at the bottom of the window by default.
The compiler also reports warnings, but these do not affect the output; only errors can interefere with the generation
of hex.
Double click the message line in the Message Window to highlight the line where the error was encountered.
75
MikroElektronika
mikoC PRO for dsPIC
Quick Converter
Quick Converter enables user to easily transform numbers from one base to another.
User can convert integers of various sizes (8, 16 or 32 bits), signed and unsigned, using different representation (decimal, hexadecimal, binary and character).
Also, Quick Converter features oat point numbers conversion from/to Float Decimal, Float 32bit (IEEE), Float 32bit
(Microchip) and Radix 1.15 for dsPIC family of MCUs.
Macro Editor
A macro is a series of keystrokes that have been 'recorded' in the order performed. A macro allows you to 'record' a series of keystrokes and then 'playback', or repeat, the recorded keystrokes.
MikroElektronika
76
mikroC PRO for dsPIC
The Macro offers the following commands:
Icon Description
Related topics: Code Editor, Code Templates
Starts ‘recording’ keystrokes for later playback.
Stops capturing keystrokes that was started when the Start Recording command was selected.
Allows a macro that has been recorded to be replayed.
New macro.
Delete macro.
Image Preview
There are a lot of occassions in which the user besides the code, must look at the appropriate schematics in order to succesfully write the desired program. The mikroC PRO for dsPIC30/33 and PIC24 provides this possibility through a Image Preview Window.
To add a image to the Image Preview Window, right click the Image Files node in the Project Manager :
77
MikroElektronika
Now, navigate to the desired image le, and simply add it :
Next, right click the added le, and choose Set As Preview Image :
mikoC PRO for dsPIC
MikroElektronika
78
mikroC PRO for dsPIC
Once you have added the image, it will appear in the Image Preview Window :
Also, you can add multiple images to the Image Files node, but only the one that is set will be automatically displayed in the Image Preview Window upon opening the project.
By changing the Image Preview Window size, displayed image will be t by its height in such a way that its proportions will remain intact.
Toolbars
This section provides an overview of the toolbars available in mikroC PRO for dsPIC30/33 and PIC24 Help :
- File Toolbar
- Edit Toolbar
- Advanced Edit Toolbar
- Find Toolbar
- Project Toolbar
- Build Toolbar
- Debug Toolbar
- Styles Toolbar
- Tools Toolbar
- View Toolbar
- Layout Toolbar
- Help Toolbar
79
MikroElektronika
File Toolbar
File Toolbar is a standard toolbar with following options:
Icon Description
mikoC PRO for dsPIC
Opens a new editor window.
Open source le for editing or image le for viewing.
Save changes for active window.
Save changes in all opened windows.
Print Preview.
Print.
Edit Toolbar
Edit Toolbar is a standard toolbar with following options:
Icon Description
Undo last change.
Redo last change.
Cut selected text to clipboard.
Copy selected text to clipboard.
Paste text from clipboard.
MikroElektronika
80
mikroC PRO for dsPIC
Advanced Edit Toolbar
Advanced Edit Toolbar comes with following options:
Icon Description
Comment selected code or put single line comment if there is no selection
Uncomment selected code or remove single line comment if there is no selection.
Select text from starting delimiter to ending delimiter.
Go to ending delimiter.
Go to line.
Indent selected code lines.
Outdent selected code lines.
Generate HTML code suitable for publishing current source code on the web.
Find/Replace Toolbar
Find/Replace Toolbar is a standard toolbar with following options:
Icon Description
Find text in current editor.
Find next occurence.
Find previous occurence.
Replace text.
Find text in les.
81
MikroElektronika
Project Toolbar
Project Toolbar comes with following options:
Icon Description
mikoC PRO for dsPIC
New project.
Open Project
Save Project
Edit project settings.
Close current project.
Clean project folder.
Add File To Project
Remove File From Project
Build Toolbar
Build Toolbar comes with following options:
Icon Description
Build current project.
Build all opened projects.
Build and program active project.
Start programmer and load current HEX le.
MikroElektronika
82
mikroC PRO for dsPIC
Debug Toolbar
Debug Toolbar comes with following options:
Icon Description
Start Software Simulator or mikroICD (In-Circuit Debugger).
Run/Pause Debugger.
Stop Debugger.
Step Into.
Step Over.
Step Out.
Run To Cursor.
Toggle Breakpoint.
View Breakpoints Window
Clear Breakpoints.
View Watch Window
View Stopwatch Window
Styles Toolbar
Styles toolbar allows you to easily change colors of your workspace.
83
MikroElektronika
Tools Toolbar
Tools Toolbar comes with following default options:
Icon Description
mikoC PRO for dsPIC
Tip : The Tools toolbar can easily be customized by adding new tools in Options menu window.
Run USART Terminal
EEPROM
ASCII Chart
Seven Segment Editor.
Open Active Comment editor.
Options menu
View Toolbar
View Toolbar provides access to assembly code, listing le and statistics windows.
Icon Description
Open assembly code in editor.
Open listing le in editor.
View statistics for current project.
MikroElektronika
84
mikroC PRO for dsPIC
Layout Toolbar
Styles toolbar allows you to easily customize workspace through a number of different IDE layouts.
Help Toolbar
Help Toolbar provides access to information on using and registering compilers :
Icon Description
Related topics: Keyboard shortcuts, Integrated Tools
Open Help le.
How To Register.
85
MikroElektronika
mikoC PRO for dsPIC
Customizing IDE Layout
Docking Windows
You can increase the viewing and editing space for code, depending on how you arrange the windows in the IDE.
Step 1: Click the window you want to dock, to give it focus.
Step 2: Drag the tool window from its current location. A guide diamond appears. The four arrows of the diamond point
towards the four edges of the IDE.
MikroElektronika
86
mikroC PRO for dsPIC
Step 3: Move the pointer over the corresponding portion of the guide diamond. An outline of the window appears in the designated area.
Step 4: To dock the window in the position indicated, release the mouse button.
Tip : To move a dockable window without snapping it into place, press CTRL while dragging it.
Saving Layout
Once you have a window layout that you like, you can save the layout by typing the name for the layout and pressing
the Save Layout Icon .
To set the layout select the desired layout from the layout drop-down list and click the Set Layout Icon .
To remove the layout from the drop-down list, select the desired layout from the list and click the Delete Layout
Icon .
Auto Hide
Auto Hide enables you to see more of your code at one time by minimizing tool windows along the edges of the IDE when not in use.
- Click the window you want to keep visible to give it focus.
- Click the Pushpin Icon on the title bar of the window.
87
MikroElektronika
mikoC PRO for dsPIC
When an auto-hidden window loses focus, it automatically slides back to its tab on the edge of the IDE. While a window is auto-hidden, its name and icon are visible on a tab at the edge of the IDE. To display an auto-hidden window, move your pointer over the tab. The window slides back into view and is ready for use.
Options
Options menu consists of three tabs: Code Editor, Tools and Output settings
Code editor
The Code Editor is advanced text editor fashioned to satisfy needs of professionals.
Tools
The mikroC PRO for dsPIC30/33 and PIC24 includes the Tools tab, which enables the use of shortcuts to external programs, like Calculator or Notepad. You can set up to 10 different shortcuts, by editing Tool0 - Tool9.
MikroElektronika
88
mikroC PRO for dsPIC
Output settings
By modifying Output Settings, user can congure the content of the output les. You can enable or disable, for example, generation of ASM and List le.
Also, user can choose optimization level, and compiler specic settings, which include case sensitivity, dynamic link for string literals setting (described in mikroC PRO for dsPIC30/33 and PIC24 specics).
Build all les as library enables user to use compiled library (*.mcl) on any MCU (when this box is checked), or for a
selected MCU (when this box is left unchecked).
For more information on creating new libraries, see Creating New Library.
89
MikroElektronika
mikoC PRO for dsPIC
MikroElektronika
90
mikroC PRO for dsPIC
Integrated Tools
Active Comments Editor
Active Comments Editor is a tool, particularly useful when working with Lcd display. You can launch it from the drop-
down menu Tools › Active Comments Editor or by clicking the Active Comment Editor Icon from Tools toolbar.
91
MikroElektronika
mikoC PRO for dsPIC
ASCII Chart
The ASCII Chart is a handy tool, particularly useful when working with Lcd display. You can launch it from the drop-
down menu Tools › ASCII chart or by clicking the View ASCII Chart Icon from Tools toolbar.
MikroElektronika
92
mikroC PRO for dsPIC
EEPROM Editor
The EEPROM Editor is used for manipulating MCU's EEPROM memory. You can launch it from the drop-down menu Tools › EEPROM Editor.
When you run mikroElektronika programmer software from mikroC PRO for dsPIC30/33 and PIC24 IDE - project_
name.hex le will be loaded automatically while ihex le must be loaded manually.
Filter Designer
The Filter designer is a tool for designing FIR and IIR lters. It has an user-friendly visual interface for setting the lter
parameters. Filter designer output is the mikroC PRO for dsPIC30/33 and PIC24 compatible code. You can launch it from the drop-down menu Tools › Filter Designer.
93
MikroElektronika
mikoC PRO for dsPIC
Graphic Lcd Bitmap Editor
The mikroC PRO for dsPIC30/33 and PIC24 includes the Graphic Lcd Bitmap Editor. Output is the mikroC PRO for dsPIC30/33 and PIC24 compatible code. You can launch it from the drop-down menu Tools › Glcd Bitmap Editor.
MikroElektronika
94
mikroC PRO for dsPIC
HID Terminal
The mikroC PRO for dsPIC30/33 and PIC24 includes the HID communication terminal for USB communication. You can launch it from the drop-down menu Tools › HID Terminal.
95
MikroElektronika
mikoC PRO for dsPIC
Lcd Custom Character
mikroC PRO for dsPIC30/33 and PIC24 includes the Lcd Custom Character. Output is mikroC PRO for dsPIC30/33 and PIC24 compatible code. You can launch it from the drop-down menu Tools › Lcd Custom Character.
MikroElektronika
96
mikroC PRO for dsPIC
Seven Segment Editor
The Seven Segment Editor is a convenient visual panel which returns decimal/hex value for any viable combination you would like to display on seven segment display. Click on the parts of seven segment image to get the requested value
in the edit boxes. You can launch it from the drop-down menu Tools › Seven Segment Editor or by clicking the Seven
Segment Editor Icon from Tools toolbar.
UDP Terminal
The mikroC PRO for dsPIC30/33 and PIC24 includes the UDP Terminal. You can launch it from the drop-down menu Tools › UDP Terminal.
97
MikroElektronika
mikoC PRO for dsPIC
USART Terminal
The mikroC PRO for dsPIC30/33 and PIC24 includes the USART communication terminal for RS232 communication.
You can launch it from the drop-down menu Tools › USART Terminal or by clicking the USART Terminal Icon from
Tools toolbar.
MikroElektronika
98
mikroC PRO for dsPIC
Active Comments
The idea of Active Comments is to make comments alive and give old fashioned comments new meaning and look. From now on, you can assign mouse event on your comments and 'tell' your comments what to do on each one. For example, on left mouse click, open some web address in your browser, on mouse over show some picture and on
mouse double click open some le.
Let suppose we are writing a example for a GSM/GPSR module which is connected to EasyPIC6 and we would like to provide a photo of our hardware (jumpers, cables, etc.). within the example. Also, it would be also nice to put some documentation about chip we are using and a GSM module extra board. Now we can have all those things dened in one single comment using Active Comment Editor.
New Active Comment
When you start Active Comment Editor for the rst time (from the View menu, from editor's pop-up menu, or by pressing
Ctrl + Alt + P) you will get an empty editor :
By clicking the button you are prompted to enter a name for the comment :
99
MikroElektronika
mikoC PRO for dsPIC
You can notice that when you start typing a name, properties pane is automatically displayed so you can edit properties
if you wish. A Comment will be is created when you click button.
Properties are consisted of two major categories - Attributes and Events.
Attributes can be :
- URL - Valid web address.
- Image - Image has to be previously added to Project (Project Manager > Images).
- File - File has to be previously added to Project (Project Manager > Other Files).
There are four predened event types you can apply to an Active Comment :
1. OnLeftClick + Alt
2. OnRightClick
3. OnDoubleClick
4. OnMouseOver
MikroElektronika
100
Loading...