MikroElektronika mikroBasic PRO for dsPIC User guide

mikroBasic PRO for dsPIC
mikroBasic PRO for dsPIC30/33 and PIC24 is a full-featured Basic 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
mikoBasic PRO for dsPIC30/33 and PIC24
Table of Contents
CHAPTER 1 30 INTRODUCTION 30
Introduction to mikroBasic PRO for dsPIC30/33 and PIC24 31
Features 31 Where to Start 31
What’s new in mikroBasic PRO for dsPIC30/33 and PIC24 32
Compiler Changes 32 IDE Changes 32
Software License Agreement 33
mikroElektronika Associates License Statement and Limited Warranty 33 IMPORTANT - READ CAREFULLY 33 LIMITED WARRANTY 33 HIGH RISK ACTIVITIES 34 GENERAL PROVISIONS 34
Technical Support 35 How to Register 35
Who Gets the License Key 35 How to Get License Key 35 After Receving the License Key 37
CHAPTER 2 39 mikroBasic PRO for dsPIC30/33 and PIC24 Environment 39
Main Menu Options 40 File 41
File Menu Options 41
Edit 42
Edit Menu Options 42 Find Text 43 Replace Text 43 Find In Files 44 Go To Line 44 Regular expressions option 44
View 45
View Menu Options 45
Project 47
Project Menu Options 47
Build 48
Build Menu Options 48
Run 49
Run Menu Options 49
Tools 50
Tools Menu Options 50
MikroElektronika
2
mikroBasic PRO for dsPIC30/33 and PIC24
Help 51
Help Menu Options 51
mikroBasic PRO for dsPIC30/33 and PIC24 IDE 52
IDE Overview 52
Code Editor 53
Editor Settings 53 Auto Save 54 Highlighter 54 Spelling 54 Comment Style 54 Code Folding 54 Code Assistant 55 Parameter Assistant 55 Bookmarks 55 Go to Line 55 Column Select Mode 56 Editor Colors 56 Auto Correct 57 Auto Complete (Code Templates) 58
Code Explorer 60
Routine List 61
Project Manager 61 Project Settings 63 Library Manager 64
Managing libraries using Package Manager 65
Routine List 66 Statistics 66
Memory Usage Windows 66 RAM Memory Usage 67 Used RAM Locations 67 SFR Locations 68 ROM Memory Usage 68 ROM Memory Constants 69 Functions 69 Functions Sorted By Name Chart 70 Functions Sorted By Size Chart 70 Functions Sorted By Addresses 71 Function Tree 71 Memory Summary 72
Messages Window 73 Quick Converter 74 Macro Editor 74 Image Preview 75 Toolbars 77
3
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
File Toolbar 78 Edit Toolbar 78 Advanced Edit Toolbar 79 Find/Replace Toolbar 79 Project Toolbar 80 Build Toolbar 80 Debug Toolbar 81 Styles Toolbar 81 Tools Toolbar 82 View Toolbar 82 Layout Toolbar 83 Help Toolbar 83
Customizing IDE Layout 84
Docking Windows 84 Saving Layout 85 Auto Hide 85
Options 86
Code editor 86 Tools 86 Output settings 87
Integrated Tools 89
Active Comments Editor 89 ASCII Chart 90 EEPROM Editor 91 Filter Designer 91 Graphic Lcd Bitmap Editor 92 HID Terminal 93 Lcd Custom Character 94 Seven Segment Editor 95 UDP Terminal 95 USART Terminal 96
Active Comments 97
New Active Comment 97 Renaming Active Comment 104 Deleting Active Comment 105
Export Project 106 Jump To Interrupt 107 Regular Expressions 108
Introduction 108 Simple matches 108 Escape sequences 108 Character classes 108 Metacharacters 109
Metacharacters - Line separators 109
Metacharacters - Predened classes 110
MikroElektronika
4
mikroBasic PRO for dsPIC30/33 and PIC24
Metacharacters - Word boundaries 110 Metacharacters - Iterators 110 Metacharacters - Alternatives 111 Metacharacters - Subexpressions 111 Metacharacters - Backreferences 111
Keyboard Shortcuts 112
CHAPTER 3 114 mikroBasic PRO for dsPIC30/33 and PIC24 Command Line Options 114 CHAPTER 4 116 mikroICD (In-Circuit Debugger) 116
Introduction 116 mikroICD Debugger Options 118
Debugger Options 118
mikroICD Debugger Example 119 mikroICD Debugger Windows 123
Debug Windows 123 Breakpoints Window 123 Watch Values Window 123 RAM Window 125 Stopwatch Window 125 EEPROM Watch Window 126 Code Watch Window 127
CHAPTER 5 128 Software Simulator Overview 128
Software Simulator 129 Software Simulator Debug Windows 130
Debug Windows 130 Breakpoints Window 130 Watch Values Window 130 RAM Window 132 Stopwatch Window 132 EEPROM Watch Window 133 Code Watch Window 134
Software Simulator Debugger Options 135
Debugger Options 135
CHAPTER 6 136 mikroBasic PRO for dsPIC30/33 and PIC24 Specics 136
GOTO Table 137
Basic Standard Issues 138
Divergence from the Basic Standard 138 C Language Extensions 138
Predened Globals and Constants 139
Predened project level denes 139
5
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
Accessing Individual Bits 140
sbit type 141 at keyword 142 bit type 142
Interrupts 143
Function Calls from Interrupt 143 Interrupt Handling 143 Interrupt Example 144
Linker Directives 145
Directive absolute 145 Directive orgall 145 Directive orgall 146
Built-in Routines 147
Lo 148 Hi 148 Higher 149 Highest 149 LoWord 150 HiWord 150 Inc 151 Dec 151 Chr 151 Ord 152 SetBit 152 ClearBit 152 TestBit 153 Delay_us 153 Delay_ms 153 Vdelay_ms 154 VDelay_advanced_ms 154 Delay_Cyc 155 Delay_Cyc_Long 155 Clock_kHz 155 Clock_MHz 156 Get_Fosc_kHz 156 Get_Fosc_Per_Cyc 156 Reset 157 ClrWdt 157 DisableContextSaving() 157 SetFuncCall 158 SetOrg 158 DoGetDateTime 159 DoGetVersion 159
Code Optimization 160
Constant folding 160 Constant propagation 160
MikroElektronika
6
mikroBasic PRO for dsPIC30/33 and PIC24
Copy propagation 160 Value numbering 160 "Dead code" ellimination 160 Stack allocation 160 Local vars optimization 160 Better code generation and local optimization 160
Single Static Assignment Optimization 161
Introduction 161 Proper Coding Recommendations 162 Asm code and SSA optimization 163 Debugging Notes 163 Warning Messages Enhancement 163
Common Object File Format (COFF) 164
COFF File Format 164 COFF File Generation 164
CHAPTER 7 166 dsPIC30/33 and PIC24 Specics 166
Types Efciency 167 Nested Calls Limitations 167 Limits of Indirect Approach Through PSV 167 Limits of Pointer to Function 167 Variable, constant and routine alignment 167
dsPIC Memory Organization 168
Program Memory (ROM) 168 Data Memory (RAM) 169 SFR Memory Space 169 X and Y Data RAM 169 DMA RAM 170 Unimplemented Memory Space 170
Memory Type Speciers 171
code 171 data 171 rx 171 sfr 171 xdata 172 ydata 172 dma 172
Memory Type Qualiers 173
Near Memory Qualier 173 Far Memory Qualier 173
Read Modify Write Problem 174
CHAPTER 8 178 mikroBasic PRO for dsPIC30/33 and PIC24 Language Reference 178
Lexical Elements Overview 180
7
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
Whitespace 181
Newline Character 181 Whitespace in Strings 181
Comments 182 Tokens 182
Token Extraction Example 182
Literals 183
Integer Literals 183 Floating Point Literals 183 Character Literals 184 String Literals 184
Keywords 185 Identiers 188
Case Sensitivity 188 Uniqueness and Scope 188 Identier Examples 188
Punctuators 189
Brackets 189 Parentheses 189 Comma 189 Colon 190 Dot 190
Program Organization 190
Organization of Main Module 190 Organization of Other Modules 191
Scope and Visibility 192
Scope 192 Visibility 193
Name Spaces 193 Modules 194
Include Clause 194 Main Module 194 Other Modules 195
Variables 196
External Modier 196 Variables and dsPIC30/33 and PIC24 197
Constants 198 Labels 198 Symbols 199 Functions and Procedures 200
Functions 200 Procedures 201 Forward declaration 202 Functions reentrancy 203
MikroElektronika
8
mikroBasic PRO for dsPIC30/33 and PIC24
Types 203
Type Categories 203
Simple Types 204 Derived Types 204 Arrays 204
Array Declaration 204 Constant Arrays 205 Multi-dimensional Arrays 205
Strings 206
String Concatenating 206
Pointers 207
Pointers and memory spaces 208 Function Pointers 208 @ Operator 209
Pointer Arithmetic 210
Assignment and Comparison 210 Pointer Addition 211 Pointer Subtraction 211
Structures 213
Structure Member Access 213
Types Conversions 214
Implicit Conversion 214 Explicit Conversion 215 Conversions Examples 215
Typedef Specier 216 Type Qualiers 216
Qualier const 216
Qualier volatile 217
Operators 217
Operators Precedence and Associativity 217
Arithmetic Operators 217
Arithmetic Operators Overview 218 Division by Zero 218 Unary Arithmetic Operators 218
Relational Operators 219
Relational Operators Overview 219 Relational Operators in Expressions 219
Bitwise Operators 219
Bitwise Operators Overview 219 Logical Operations on Bit Level 220 Unsigned and Conversions 220 Signed and Conversions 221 Bitwise Shift Operators 221
Boolean Operators 221
9
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
Unary Operators 222
Unary Arithmetic Operator 222 Unary Bitwise Operator 222 Address and Indirection Operator 222
Sizeof Operator 223
Sizeof Applied to Expression 223 Sizeof Applied to Type 223
Expressions 224
Expression Evaluation 224
Statements 225 Assignment Statements 226 Conditional Statements 226 If Statement 226
Nested if statements 226
Select Case Statement 227
Nested Case Statements 228
Iteration Statements 228 For Statement 229
Endless Loop 229
While Statement 229 Do Statement 230 Jump Statements 231 Break and Continue Statements 231
Break Statement 231 Continue Statement 231
Exit Statement 232 Return Statement 232 Goto Statement 232 Gosub Statement 233 asm Statement 234
Accessing variables 234 Asm code and SSA optimization 235
Directives 235 Compiler Directives 235
Directives #DEFINE and #UNDEFINE 236 Directives #IFDEF, #IFNDEF, #ELSE and #ENDIF 236 Include Directive #I 237
Linker Directives 237
Directive absolute 237 Directive org 238
CHAPTER 9 239 mikroBasic PRO for dsPIC30/33 and PIC24 Libraries 239
MikroElektronika
10
mikroBasic PRO for dsPIC30/33 and PIC24
Hardware Libraries 240 Digital Signal Processing Libraries 240 Miscellaneous Libraries 241 Hardware Libraries 242 ADC Library 242
Library Routines 243 ADCx_Init 243 ADCx_Init_Advanced 244 ADCx_Get_Sample 245 ADCx_Read 245 ADC_Set_Active 246 Library Example 246
CAN Library 248
Library Routines 248 CANxSetOperationMode 249 CANxGetOperationMode 249 CANxInitialize 250 CANxSetBaudRate 251 CANxSetMask 252 CANxSetFilter 253 CANxRead 254 CANxWrite 255 CAN Constants 256 CAN_OP_MODE Constants 256 CAN_CONFIG_FLAGS Constants 256 CAN_TX_MSG_FLAGS Constants 257 CAN_RX_MSG_FLAGS Constants 258 CAN_MASK Constants 258 CAN_FILTER Constants 259 Library Example 259 HW Connection 262
CANSPI Library 263
Library Dependency Tree 263 External dependencies of CANSPI Library 263 Library Routines 264 CANSPISetOperationMode 264 CANSPIGetOperationMode 265 CANSPIInit 265 CANSPISetBaudRate 267 CANSPISetMask 268 CANSPISetFilter 269 CANSPIRead 270 CANSPIWrite 271 CANSPI Constants 271 CANSPI_OP_MODE Constants 271
11
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
CANSPI_TX_MSG_FLAGS Constants 273 CANSPI_RX_MSG_FLAGS Constants 273 CANSPI_MASK Constants 274 CANSPI_FILTER Constants 274 Library Example 275 HW Connection 278
Compact Flash Library 279
Library Dependency Tree 279 External dependencies of Compact Flash Library 280 Library Routines 281 Cf_Init 282 Cf_Detect 283 Cf_Enable 283 Cf_Disable 283 Cf_Read_Init 284 Cf_Read_Byte 284 Cf_Write_Init 284 Cf_Write_Byte 285 Cf_Read_Sector 285 Cf_Write_Sector 285 Cf_Fat_Init 286 Cf_Fat_QuickFormat 286 Cf_Fat_Assign 287 Cf_Fat_Reset 288 Cf_Fat_Read 288 Cf_Fat_Rewrite 289 Cf_Fat_Append 289 Cf_Fat_Delete 289 Cf_Fat_Write 290 Cf_Fat_Set_File_Date 290 Cf_Fat_Get_File_Date 291 Cf_Fat_Get_File_Date_Modied 291 Cf_Fat_Get_File_Size 292 Cf_Fat_Get_Swap_File 292 Library Example 294 HW Connection 299
ECAN Library 300
Library Routines 300 ECANxDmaChannelInit 301 ECANxSetOperationMode 301 ECANxGetOperationMode 302 ECANxInitialize 303 ECANxSelectTxBuffers 304 ECANxFilterDisable 304 ECANxFilterEnable 305 ECANxSetBufferSize 305
MikroElektronika
12
mikroBasic PRO for dsPIC30/33 and PIC24
ECANxSetBaudRate 306 ECANxSetMask 307 ECANxSetFilter 308 ECANxRead 309 ECANxWrite 310 ECAN Constants 311 ECAN_OP_MODE Constants 311 ECAN_CONFIG_FLAGS Constants 311 ECAN_TX_MSG_FLAGS Constants 312 ECAN_RX_MSG_FLAGS Constants 312 ECAN_MASK Constants 313 ECAN_FILTER Constants 313 ECAN_RX_BUFFER Constants 314 Library Example 315 HW Connection 319
EEPROM Library 319
Library Routines 319 EEPROM_Erase 320 EEPROM_Erase_Block 320 EEPROM_Read 320 EEPROM_Write 321 EEPROM_Write_Block 321 Library Example 321
Epson S1D13700 Graphic Lcd Library 323
External dependencies of the Epson S1D13700 Graphic Lcd Library 323 Library Routines 324 S1D13700_Init 325 S1D13700_Write_Command 326 S1D13700_Write_Parameter 327 S1D13700_Read_Parameter 327 S1D13700_Fill 327 S1D13700_GrFill 328 S1D13700_TxtFill 328 S1D13700_Display_GrLayer 328 S1D13700_Display_TxtLayer 329 S1D13700_Set_Cursor 329 S1D13700_Display_Cursor 330 S1D13700_Write_Char 330 S1D13700_Write_Text 331 S1D13700_Dot 331 S1D13700_Line 332 S1D13700_H_Line 332 S1D13700_V_Line 333 S1D13700_Rectangle 333 S1D13700_Box 334 S1D13700_Rectangle_Round_Edges 334
13
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
S1D13700_Rectangle_Round_Edges_Fill 335 S1D13700_Circle 335 S1D13700_Circle_Fill 336 S1D13700_Image 336 S1D13700_PartialImage 337
Flash Memory Library 338
dsPIC30: 338 PIC24 and dsPIC33: 338 24F04KA201 and 24F16KA102 Family Specics: 339 Library Routines 339 dsPIC30 Functions 339 PIC24 and dsPIC33 Functions 339 dsPIC30 Functions 340 FLASH_Erase32 340 FLASH_Write_Block 340 FLASH_Write_Compact 341 FLASH_Write_Init 341 FLASH_Write_Loadlatch4 342 FLASH_Write_Loadlatch4_Compact 343 FLASH_Write_DoWrite 344 FLASH_Read4 344 FLASH_Read4_Compact 345 PIC24 and dsPIC33 Functions 345 FLASH_Erase 345 FLASH_Write 346 FLASH_Write_Compact 346 FLASH_Read 347 FLASH_Read_Compact 347 Library Example 347
Graphic Lcd Library 349
Library Dependency Tree 349 External dependencies of Graphic Lcd Library 350 Library Routines 351 Glcd_Init 351 Glcd_Set_Side 353 Glcd_Set_X 353 Glcd_Set_Page 353 Glcd_Read_Data 354 Glcd_Write_Data 354 Glcd_Fill 355 Glcd_Dot 355 Glcd_Line 355 Glcd_V_Line 356 Glcd_H_Line 356 Glcd_Rectangle 357 Glcd_Rectangle_Round_Edges 357
MikroElektronika
14
mikroBasic PRO for dsPIC30/33 and PIC24
Glcd_Rectangle_Round_Edges_Fill 358 Glcd_Box 358 Glcd_Circle 359 Glcd_Circle_Fill 359 Glcd_Set_Font 360 Glcd_Write_Char 361 Glcd_Write_Text 361 Glcd_Image 362 Glcd_PartialImage 362 Library Example 363 HW Connection 365
I²C Library 366
Library Routines 366 I2Cx_Init 366 I2Cx_Start 367 I2Cx_Restart 367 I2Cx_Is_Idle 368 I2Cx_Read 368 I2Cx_Write 369 I2Cx_Stop 369 Library Example 370 HW Connection 370
Keypad Library 371
External dependencies of Keypad Library 371 Library Routines 371 Keypad_Init 371 Keypad_Key_Press 372 Keypad_Key_Click 372 Library Example 373 HW Connection 374
Lcd Library 375
Library Dependency Tree 375 External dependencies of Lcd Library 375 Library Routines 375 Lcd_Init 376 Lcd_Out 377 Lcd_Out_Cp 377 Lcd_Chr 377 Lcd_Chr_Cp 378 Lcd_Cmd 378 Available Lcd Commands 378 Library Example 379
Manchester Code Library 381
External dependencies of Manchester Code Library 381 Library Routines 382 Man_Receive_Init 382
15
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
Man_Receive 383 Man_Send_Init 383 Man_Send 384 Man_Synchro 384 Man_Break 385 Library Example 386 Connection Example 388
Multi Media Card Library 389
Secure Digital Card 389 Secure Digital High Capacity Card 389 Library Dependency Tree 390 External dependencies of MMC Library 390 Library Routines 390 Mmc_Init 391 Mmc_Read_Sector 392 Mmc_Write_Sector 392 Mmc_Read_Cid 393 Mmc_Read_Csd 393 Mmc_Fat_Init 394 Mmc_Fat_QuickFormat 395 Mmc_Fat_Assign 396 Mmc_Fat_Reset 397 Mmc_Fat_Read 397 Mmc_Fat_Rewrite 398 Mmc_Fat_Append 398 Mmc_Fat_Delete 398 Mmc_Fat_Write 399 Mmc_Fat_Set_File_Date 399 Mmc_Fat_Get_File_Date 400 Mmc_Fat_Get_File_Date_Modied 401 Mmc_Fat_Get_File_Size 401 Mmc_Fat_Get_Swap_File 402 Library Example 403 HW Connection 407
OneWire Library 408
Library Routines 408 Ow_Reset 408 Ow_Read 409 Ow_Write 409 Library Example 410 HW Connection 412
Peripheral Pin Select Library 413
Library Routines 413 Unlock_IOLOCK 413 Lock_IOLOCK 413 PPS_Mapping 414
MikroElektronika
16
mikroBasic PRO for dsPIC30/33 and PIC24
Direction Parameters 414 Input Functions 414 Output Functions 415
Port Expander Library 417
Library Dependency Tree 417 External dependencies of Port Expander Library 417 Library Routines 417 Expander_Init 418 Expander_Init_Advanced 419 Expander_Read_Byte 419 Expander_Write_Byte 420 Expander_Read_PortA 420 Expander_Read_PortB 421 Expander_Read_PortAB 421 Expander_Write_PortA 422 Expander_Write_PortB 422 Expander_Write_PortAB 423 Expander_Set_DirectionPortA 423 Expander_Set_DirectionPortB 424 Expander_Set_DirectionPortAB 424 Expander_Set_PullUpsPortA 424 Expander_Set_PullUpsPortB 425 Expander_Set_PullUpsPortAB 425 HW Connection 427
PS/2 Library 428
External dependencies of PS/2 Library 428 Library Routines 428 Ps2_Cong 429 Ps2_Key_Read 429 Special Function Keys 430 Library Example 431 HW Connection 432
PWM Library 432
Library Routines 432 PWM_Init 433 PWM_Set_Duty 433 PWM_Start 434 PWM_Stop 434 Library Example 434 HW Connection 436
PWM Motor Control Library 436
Library Routines 436 PWMx_Mc_Init 437 PWMx_Mc_Set_Duty 438 PWMx_Mc_Start 438 PWMx_Mc_Stop 439
17
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
HW Connection 440
RS-485 Library 440
Library Dependency Tree 441 External dependencies of RS-485 Library 441 Library Routines 441 RS485Master_Init 441 RS485Master_Receive 442 RS485Master_Send 442 RS485Slave_Init 443 RS485Slave_Receive 444 RS485Slave_Send 444 Library Example 445 HW Connection 448 Message format and CRC calculations 449
Software I²C Library 450
External dependencies of Software I²C Library 450 Library Routines 450 Soft_I2C_Init 451 Soft_I2C_Start 451 Soft_I2C_Read 452 Soft_I2C_Write 452 Soft_I2C_Stop 452 Soft_I2C_Break 453 Library Example 454
Software SPI Library 456
External dependencies of Software SPI Library 456 Library Routines 456 Soft_SPI_Init 457 Soft_SPI_Read 457 Soft_SPI_Write 458 Library Example 458
Software UART Library 460
Library Routines 460 Soft_UART_Init 460 Soft_UART_Read 461 Soft_UART_Write 461 Soft_UART_Break 462 Library Example 463
Sound Library 464
Library Routines 464 Sound_Init 464 Sound_Play 464 HW Connection 467
SPI Library 468
Library Routines 468 SPIx_Init 469
MikroElektronika
18
mikroBasic PRO for dsPIC30/33 and PIC24
SPIx_Init_Advanced 470 SPIx_Read 472 SPIx_Write 472 SPI_Set_Active 473 Library Example 473 HW Connection 474
SPI Ethernet Library 475
Library Dependency Tree 475 External dependencies of SPI Ethernet Library 476 Library Routines 476 SPI_Ethernet_Init 477 SPI_Ethernet_Enable 479 SPI_Ethernet_Disable 480 SPI_Ethernet_doPacket 481 SPI_Ethernet_putByte 481 SPI_Ethernet_putBytes 482 SPI_Ethernet_putConstBytes 482 SPI_Ethernet_putString 483 SPI_Ethernet_putConstString 483 SPI_Ethernet_getByte 483 SPI_Ethernet_getBytes 484 SPI_Ethernet_UserTCP 484 SPI_Ethernet_UserUDP 485 SPI_Ethernet_setUserHandlers 485 SPI_Ethernet_getIpAddress 486 SPI_Ethernet_getGwIpAddress 486 SPI_Ethernet_getDnsIpAddress 487 SPI_Ethernet_getIpMask 487 SPI_Ethernet_confNetwork 488 SPI_Ethernet_arpResolve 489 SPI_Ethernet_sendUDP 489 SPI_Ethernet_dnsResolve 490 SPI_Ethernet_initDHCP 491 SPI_Ethernet_doDHCPLeaseTime 491 SPI_Ethernet_renewDHCP 492 Library Example 492 HW Connection 499
SPI Ethernet ENC24J600 Library 500
Library Dependency Tree 500 External dependencies of SPI Ethernet ENC24J600 Library 501 Library Routines 502 SPI_Ethernet_24j600_Init 503 SPI_Ethernet_24j600_Enable 505 SPI_Ethernet_24j600_Disable 506 SPI_Ethernet_24j600_doPacket 507 SPI_Ethernet_24j600_putByte 507
19
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
SPI_Ethernet_24j600_putBytes 508 SPI_Ethernet_24j600_putConstBytes 508 SPI_Ethernet_24j600_putString 509 SPI_Ethernet_24j600_putConstString 509 SPI_Ethernet_24j600_getByte 509 SPI_Ethernet_24j600_getBytes 510 SPI_Ethernet_24j600_UserTCP 510 SPI_Ethernet_24j600_UserUDP 511 SPI_Ethernet_24j600_setUserHandlers 511 SPI_Ethernet_24j600_getIpAddress 512 SPI_Ethernet_24j600_getGwIpAddress 512 SPI_Ethernet_24j600_getDnsIpAddress 512 SPI_Ethernet_24j600_getIpMask 513 SPI_Ethernet_24j600_confNetwork 513 SPI_Ethernet_24j600_arpResolve 514 SPI_Ethernet_24j600_sendUDP 514 SPI_Ethernet_24j600_dnsResolve 515 SPI_Ethernet_24j600_initDHCP 516 SPI_Ethernet_24j600_doDHCPLeaseTime 516 SPI_Ethernet_24j600_renewDHCP 517 Library Example 518
SPI Graphic Lcd Library 519
Library Dependency Tree 519 External dependencies of SPI Lcd Library 519 Library Routines 519 SPI_Glcd_Init 520 SPI_Glcd_Set_Side 521 SPI_Glcd_Set_Page 521 SPI_Glcd_Set_X 521 SPI_Glcd_Read_Data 522 SPI_Glcd_Write_Data 522 SPI_Glcd_Fill 522 SPI_Glcd_Dot 523 SPI_Glcd_Line 523 SPI_Glcd_V_Line 524 SPI_Glcd_H_Line 524 SPI_Glcd_Rectangle 525 SPI_Glcd_Rectangle_Round_Edges 525 SPI_Glcd_Rectangle_Round_Edges_Fill 526 SPI_Glcd_Box 526 SPI_Glcd_Circle 527 SPI_Glcd_Circle_FIll 527 SPI_Glcd_Set_Font 528 SPI_Glcd_Write_Char 529 SPI_Glcd_Write_Text 529 SPI_Glcd_Image 530
MikroElektronika
20
mikroBasic PRO for dsPIC30/33 and PIC24
SPI_Glcd_PartialImage 530 Library Example 531 HW Connection 533
SPI Lcd Library 534
Library Dependency Tree 534 External dependencies of SPI Lcd Library 534 Library Routines 534 SPI_Lcd_Cong 535 SPI_Lcd_Out 535 SPI_Lcd_Out_Cp 536 SPI_Lcd_Chr 536 SPI_Lcd_Chr_Cp 536 SPI_Lcd_Cmd 537 Available SPI Lcd Commands 537 Library Example 538 Default Pin Conguration 538
SPI Lcd8 (8-bit interface) Library 540
Library Dependency Tree 540 External dependencies of SPI Lcd Library 540 Library Routines 540 SPI_Lcd8_Cong 541 SPI_Lcd8_Out 541 SPI_Lcd8_Out_Cp 542 SPI_Lcd8_Chr 542 SPI_Lcd8_Chr_Cp 542 SPI_Lcd8_Cmd 543 Available SPI Lcd8 Commands 543 Library Example 544
SPI T6963C Graphic Lcd Library 546
Library Dependency Tree 546 External dependencies of SPI T6963C Graphic Lcd Library 546 Library Routines 547 SPI_T6963C_cong 548 SPI_T6963C_writeData 549 SPI_T6963C_writeCommand 549 SPI_T6963C_setPtr 550 SPI_T6963C_waitReady 550 SPI_T6963C_ll 550 SPI_T6963C_dot 551 SPI_T6963C_write_char 551 SPI_T6963C_write_text 552 SPI_T6963C_line 552 SPI_T6963C_rectangle 553 SPI_T6963C_rectangle_round_edges 553 SPI_T6963C_rectangle_round_edges_ll 554 SPI_T6963C_box 554
21
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
SPI_T6963C_circle 555 SPI_T6963C_circle_ll 555 SPI_T6963C_image 555 SPI_T6963C_PartialImage 556 SPI_T6963C_sprite 556 SPI_T6963C_set_cursor 557 SPI_T6963C_clearBit 557 SPI_T6963C_setBit 557 SPI_T6963C_negBit 558 SPI_T6963C_displayGrPanel 558 SPI_T6963C_displayTxtPanel 558 SPI_T6963C_setGrPanel 559 SPI_T6963C_setTxtPanel 559 SPI_T6963C_panelFill 559 SPI_T6963C_grFill 560 SPI_T6963C_txtFill 560 SPI_T6963C_cursor_height 560 SPI_T6963C_graphics 561 SPI_T6963C_text 561 SPI_T6963C_cursor 561 SPI_T6963C_cursor_blink 562 Library Example 562 HW Connection 566
T6963C Graphic Lcd Library 567
Library Dependency Tree 567 External dependencies of T6963C Graphic Lcd Library 568 Library Routines 569 T6963C_init 570 T6963C_writeData 571 T6963C_writeCommand 572 T6963C_setPtr 572 T6963C_waitReady 572 T6963C_ll 573 T6963C_dot 573 T6963C_write_char 574 T6963C_write_text 575 T6963C_line 575 T6963C_rectangle 576 T6963C_rectangle_round_edges 576 T6963C_rectangle_round_edges_ll 577 T6963C_box 577 T6963C_circle 577 T6963C_circle_ll 578 T6963C_image 578 T6963C_PartialImage 579 T6963C_sprite 579 T6963C_set_cursor 580
MikroElektronika
22
mikroBasic PRO for dsPIC30/33 and PIC24
T6963C_displayGrPanel 580 T6963C_displayTxtPanel 580 T6963C_setGrPanel 581 T6963C_setTxtPanel 581 T6963C_panelFill 581 T6963C_grFill 582 T6963C_txtFill 582 T6963C_cursor_height 582 T6963C_graphics 583 T6963C_text 583 T6963C_cursor 583 T6963C_cursor_blink 584 Library Example 584 HW Connection 588
TFT Library 589
External dependencies of TFT Library 589 Library Routines 590 TFT_Init 591 TFT_Set_Index 592 TFT_Write_Command 592 TFT_Write_Data 592 TFT_Set_Active 593 TFT_Set_Font 594 TFT_Write_Char 595 TFT_Write_Text 595 TFT_Fill_Screen 596 TFT_Dot 597 TFT_Set_Pen 598 TFT_Set_Brush 599 TFT_Line 601 TFT_H_Line 602 TFT_V_Line 602 TFT_Rectangle 602 TFT_Rectangle_Round_Edges 603 TFT_Circle 603 TFT_Image 603 TFT_Partial_Image 604 TFT_Image_Jpeg 604 TFT_RGBToColor16bit 605 TFT_Color16bitToRGB 605 HW Connection 606
Touch Panel Library 607
Library Dependency Tree 607 External dependencies of Touch Panel Library 607 Library Routines 607 TP_Init 608
23
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
TP_Set_ADC_Threshold 608 TP_Press_Detect 609 TP_Get_Coordinates 609 TP_Calibrate_Bottom_Left 610 TP_Calibrate_Upper_Right 610 TP_Get_Calibration_Consts 610 TP_Set_Calibration_Consts 611 Library Example 611
Touch Panel TFT Library 615
Library Dependency Tree 615 External dependencies of Touch Panel TFT Library 615 Library Routines 615 TP_TFT_Init 616 TP_TFT_Set_ADC_Threshold 616 TP_TFT_Press_Detect 617 TP_TFT_Get_Coordinates 618 TP_TFT_Calibrate_Min 618 TP_TFT_Calibrate_Max 618 TP_TFT_Get_Calibration_Consts 619 TP_TFT_Set_Calibration_Consts 619 HW Connection 620
UART Library 621
Library Routines 621 UARTx_Init 622 UARTx_Init_Advanced 623 UARTx_Data_Ready 624 UARTx_Tx_Idle 625 UARTx_Read 625 UARTx_Read_Text 626 UARTx_Write 627 UARTx_Write_Text 627 UART_Set_Active 628 Library Example 629 HW Connection 630
USB Library 631
USB HID Class 631 Library Routines 631 HID_Enable 632 HID_Read 632 HID_Write 632 HID_Disable 633 USB_Interrupt_Proc 633 USB_Polling_Proc 633 Gen_Enable 634 Gen_Read 634 Gen_Write 634
MikroElektronika
24
mikroBasic PRO for dsPIC30/33 and PIC24
Library Example 635 HW Connection 635
Digital Signal Processing Libraries 636
Digital Signal Processing Libraries 636
FIR Filter Library 637
Library Routines 637 FIR_Radix 637
IIR Filter Library 638
Library Routines 638 IIR_Radix 638
FFT Library 639
Library Dependency Tree 639 FFT 639 Twiddle Factors: 640 TwiddleCoeff_64 640 TwiddleCoeff_128 640 TwiddleCoeff_256 640 TwiddleCoeff_512 641
Bit Reverse Complex Library 643
Library Routines 643 BitReverseComplex 643
Vectors Library 644
Library Routines 644 Vector_Set 644 Vector_Power 645 Vector_Subtract 645 Vector_Scale 646 Vector_Negate 646 Vector_Multiply 647 Vector_Min 647 Vector_Max 648 Vector_Dot 648 Vector_Correlate 649 Vector_Convolve 650 Vector_Add 650
Matrices Library 651
Library Routines 651 Matrix_Transpose 651 Matrix_Subtract 652 Matrix_Scale 652 Matrix_Multiply 653 Matrix_Add 654
Miscellaneous Libraries 655 Button Library 655
Library Routines 655
25
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
Button 656
C Type Library 657
Library Functions 657 isalnum 657 isalpha 657 iscntrl 657 isdigit 658 isgraph 658 islower 658 ispunct 658 isspace 658 isupper 659 isxdigit 659 toupper 659 tolower 659
Conversions Library 660
Library Dependency Tree 660 Library Routines 660 ByteToStr 661 ShortToStr 661 WordToStr 662 WordToStrWithZeros 662 IntToStr 663 LongintToStr 663 LongWordToStr 664 FloatToStr 664 WordToStrWithZeros 665 IntToStrWithZeros 665 LongWordToStrWithZeros 666 LongIntToStrWithZeros 666 ByteToHex 667 ShortToHex 667 WordToHex 668 IntToHex 668 LongWordToHex 669 LongIntToHex 669 StrToInt 670 StrToWord 670 Bcd2Dec 670 Dec2Bcd 671 Bcd2Dec16 671 Dec2Bcd16 671
Setjmp Library 672
Library Routines 672 Setjmp 672 Longjmp 672
MikroElektronika
26
mikroBasic PRO for dsPIC30/33 and PIC24
Library Example 673
String Library 674
Library Functions 674 memchr 674 memcmp 675 memcmp 675 memcpy 675 memmove 676 memset 676 strcat 676 strcat2 677 strchr 677 strcmp 677 strcpy 678 strlen 678 strncat 678 strncpy 678 strspn 679 strncmp 679 strstr 679 strcspn 680 strpbrk 680 strrchr 680 ltrim 680 rtrim 681 strappendpre 681 strappendsuf 681 length 681
Time Library 682
Library Routines 682 Time_dateToEpoch 682 Time_epochToDate 683 Time_dateDiff 683 Library Example 684 TimeStruct type denition 685
Trigon Library 686
Library Routines 686 acos 686 asin 686 atan 687 atan2 687 ceil 687 cos 687 cosh 687 eval_poly 687 exp 688
27
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24
fabs 688 oor 688 frexp 688 log 688 ldexp 688 log10 689 modf 689 pow 689 sin 689 sinh 689 sqrt 689 tan 690 tanh 690
Trigonometry Library 691
Library Routines 691 sinE3 691 cosE3 691
CHAPTER 10 692 Tutorials 692
Managing Project 692
Projects 692
New Project 693
New Project Wizard Steps 693
New Project 696
New Project Wizard Steps 696
Customizing Projects 700
Managing Project Group 700 Add/Remove Files from Project 700 Project Level Denes: 701
Add/Remove Files from Project 702
Project Level Denes: 703
Source Files 704
Managing Source Files 704
Creating new source le 704 Opening an existing le 704 Printing an open le 704 Saving le 704 Saving le under a different name 704 Closing le 705
Search Paths 705
Paths for Source Files (.mbas) 706
Edit Project 706
Search Paths 707
Paths for Source Files (.mbas) 707
Clean Project Folder 708
MikroElektronika
28
mikroBasic PRO for dsPIC30/33 and PIC24
Compilation 709
Output Files 709 Assembly View 709
Creating New Library 710
Multiple Library Versions 710
Using Microchip MPLAB® IDE with mikroElektronika compilers 711
Debugging Your Code 711
Using MPLAB® ICD 2 Debugger 711 Using MPLAB® Simulator 718 Frequently Asked Questions 723
Can I use your compilers and programmer on Windows Vista (Windows 7) ? 723 I am getting “Access is denied” error in Vista, how to solve this problem ? 723 What are differences between mikroC PRO, mikroPascal PRO and mikroBasic PRO compilers ? Why do they have different prices ? 723 Why do your PIC compilers don’t support 12F508 and some similar chips ? 723 What are limitations of demo versions of mikroElektronika’s compilers ? 723 Why do I still get demo limit error when I purchased and installed license key ? 723 I have bought license for the older version, do I have to pay license for the new version of the com­piler ? 724 Do your compilers work on Windows Vista (Windows 7) ? 724 What does this function/procedure/routine do ? 724 I try to compile one of the provided examples and nothing happens, what is the problem? 724 Can I get your library sources ? I need to provide all sources with my project. 724 Can I use code I developed in your compilers in commercial purposes ? Are there some limitations ? 724 Why does an example provided with your compilers doesn’t work ? 724 Your example works if I use the same MCU you did, but how to make it work for another MCU ? 724 I need this project nished, can you help me ? 725 Do you have some discount on your compilers/development systems for students/professors ? 725 I have a question about your compilers which is not listed here. Where can I nd an answer ? 725
29
MikroElektronika
mikoBasic PRO for dsPIC30/33 and PIC24

CHAPTER 1

INTRODUCTION

mikroBasic 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.
mikroBasic PRO for dsPIC30/33 and PIC24 IDE
MikroElektronika
30
Loading...
+ 696 hidden pages