MikroElektronika mikroBasic PRO for PIC32 User guide

mikroBasic PRO for PIC32
mikroBasic PRO for PIC32 is a full-featured compiler for PIC32 MCUs from Microchip. It is designed for developing, building and debugging PIC32-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 PIC32
Table of Contents
CHAPTER 1 30 INTRODUCTION 30
Introduction to mikroBasic PRO for PIC32 31
Features 31 Where to Start 31
Software License Agreement 32
mikroElektronika Associates License Statement and Limited Warranty 32 IMPORTANT - READ CAREFULLY 32 LIMITED WARRANTY 32 HIGH RISK ACTIVITIES 33 GENERAL PROVISIONS 33
Technical Support 34 How to Register 34
Who Gets the License Key 34 How to Get License Key 34 After Receving the License Key 36
CHAPTER 2 38 mikroBasic PRO for PIC32 38 Environment 38
Main Menu Options 39 File 40
File Menu Options 40
Edit 41
Edit Menu Options 41 Find Text 42 Replace Text 42 Find In Files 43 Go To Line 43 Regular expressions option 43
View 44
View Menu Options 44
Project 46
Project Menu Options 46
Build 47
Build Menu Options 47
Run 48
Run Menu Options 48
Tools 49
Tools Menu Options 49
Help 50
Help Menu Options 50
MikroElektronika
2
mikroBasic PRO for PIC32
mikroBasic PRO for PIC32 IDE 51
IDE Overview 51
Code Editor 52
Editor Settings 52 Auto Save 53 Highlighter 53 Spelling 53 Comment Style 53 Code Folding 53 Code Assistant 54 Parameter Assistant 54 Bookmarks 54 Go to Line 54 Column Select Mode 55 Editor Colors 55 Auto Correct 56 Auto Complete (Code Templates) 57
Code Explorer 59
Routine List 60
Project Manager 60 Project Settings 62 Library Manager 63
Managing libraries using Package Manager 64
Routine List 65 Statistics 65
Memory Usage Windows 65 Variables 66 Used RAM Locations 66 SFR Locations 67 ROM Memory Usage 67 ROM Memory Constants 68 Functions 68 Functions Sorted By Name Chart 69 Functions Sorted By Size Chart 69 Functions Sorted By Addresses 70 Function Tree 70 Memory Summary 71
Messages Window 72 Quick Converter 73 Macro Editor 73 Image Preview 74 Toolbars 76
File Toolbar 77 Edit Toolbar 77
3
MikroElektronika
mikoBasic PRO for PIC32
Advanced Edit Toolbar 78 Find/Replace Toolbar 78 Project Toolbar 79 Build Toolbar 79 Debug Toolbar 80 Styles Toolbar 80 Tools Toolbar 81 View Toolbar 81 Layout Toolbar 82 Help Toolbar 82
Customizing IDE Layout 83
Docking Windows 83 Saving Layout 84 Auto Hide 84
Options 85
Code editor 85 Tools 85 Output settings 86
Integrated Tools 88
Active Comments Editor 88 ASCII Chart 89 EEPROM Editor 90 Graphic Lcd Bitmap Editor 91 HID Terminal 92 Interrupt Assistant 92 Lcd Custom Character 93 Seven Segment Editor 94 UDP Terminal 94 USART Terminal 95
Active Comments 96
New Active Comment 96 Renaming Active Comment 103 Deleting Active Comment 104
Export Project 105 Jump To Interrupt 106 Regular Expressions 107
Introduction 107 Simple matches 107 Escape sequences 107 Character classes 107 Metacharacters 108 Metacharacters - Line separators 108 Metacharacters - Predened classes 109 Metacharacters - Word boundaries 109 Metacharacters - Iterators 109 Metacharacters - Alternatives 110
MikroElektronika
4
mikroBasic PRO for PIC32
Metacharacters - Subexpressions 110 Metacharacters - Backreferences 110
Keyboard Shortcuts 111
CHAPTER 3 113 mikroBasic PRO for PIC32 Command Line Options 113 CHAPTER 4 115 mikroICD (In-Circuit Debugger) 115
Introduction 115 mikroICD Debugger Options 117
Debugger Options 117
mikroICD Debugger Example 118 mikroICD Debugger Windows 122
Debug Windows 122 Breakpoints Window 122 Watch Values Window 122 RAM Window 124 Stopwatch Window 124 EEPROM Watch Window 125 Code Watch Window 126
CHAPTER 5 127 Software Simulator Overview 127
Software Simulator 128 Software Simulator Debug Windows 129
Debug Windows 129 Breakpoints Window 129 Watch Values Window 129 RAM Window 131 Stopwatch Window 131 EEPROM Watch Window 132 Code Watch Window 133
Software Simulator Debugger Options 134
Debugger Options 134
CHAPTER 6 135 mikroBasic PRO for PIC32 Specics 135
GOTO Table 136 Basic Standard Issues 136
Divergence from the Basic Standard 136 Basic Language Extensions 136
Predened Globals and Constants 137
Predened project level denes 137
Accessing Individual Bits 138
sbit type 139 at keyword 140
5
MikroElektronika
mikoBasic PRO for PIC32
bit type 140
Interrupts 141
Conguring Interrupts 141 Single Vector Mode 141 Multi Vector Mode 141 Interrupt Priorities 142 Interrupts and Register Sets 142 Register Set Selection in Single Vector Mode 142 Interrupts and Register Sets 142 Interrupt Coding Requirements 142 Interrupt Service Routine 142 Function Calls from Interrupt 143 Interrupt Example 144
Linker Directives 145
Directive absolute 145 Directive org 145 Directive orgall 146
Built-in Routines 146
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 154 Vdelay_ms 154 VDelay_Advanced_ms 155 Delay_Cyc 155 Delay_Cyc_Long 155 Clock_kHz 156 Clock_Mhz 156 Get_Fosc_kHz 156 Get_Fosc_Per_Cyc 157 Reset 157 ClrWdt 157 DisableContextSaving 158 SetFuncCall 158 SetOrg 159
MikroElektronika
6
mikroBasic PRO for PIC32
DoGetDateTime 159 DoGetVersion 159 KVA0_TO_KVA1 160 KVA1_TO_KVA0 160 KVA_TO_PA 160 PA_TO_KVA0 161 PA_TO_KVA1 161 CP0_GET 161 CP0_SET 162 EnableInterrupts 162 DisableInterrupts 162
Code Optimization 164
Constant folding 164 Constant propagation 164 Copy propagation 164 Value numbering 164 "Dead code" ellimination 164 Stack allocation 164 Local vars optimization 164 Better code generation and local optimization 164
Single Static Assignment Optimization 165
Introduction 165 Proper Coding Recommendations 166 Asm code and SSA optimization 167 Debugging Notes 167 Warning Messages Enhancement 167
CHAPTER 7 168 PIC32 Specics 168
Types Efciency 169 Nested Calls Limitations 169 Variable, constant and routine alignment 169 Boot Start-up Initialization 169
PIC32 Memory Organization 170
PIC32MX Memory Layout 171 Virtual vs Physical Addresses 172
Memory Type Speciers 173
code 173 data 173 rx 173 sfr 173
Read Modify Write Problem 174
CHAPTER 8 178 mikroBasic PRO for PIC32 Language Reference 178
Lexical Elements Overview 180 Whitespace 181
7
MikroElektronika
mikoBasic PRO for PIC32
Newline Character 181 Whitespace in Strings 181
Comments 182 Tokens 182
Token Extraction Example 182
Literals 183
Long and Unsigned Sufxes 183 Floating Point Literals 183 Character Literals 184 String Literals 184
Keywords 185 Identiers 187
Case Sensitivity 187 Uniqueness and Scope 188 Identier Examples 188
Punctuators 188
Brackets 188 Parentheses 189 Comma 189 Colon 189 Dot 189
Program Organization 190
Organization of Main Module 190 Organization of Other Modules 191 192 Note: Sub functions and sub procedures must have the same declarations in the interface and implementation section. Otherwise, compiler will report an error. 192
Scope and Visibility 192
Scope 192 Visibility 192
Name Spaces 193 Modules 193
Include Clause 193 Main Module 194 Other Modules 194 Interface Section 195 Implementation Section 195
Variables 195
External Modier 195 Variables and PIC32 197
Constants 197 Labels 198 Symbols 198 Functions and Procedures 199
MikroElektronika
8
mikroBasic PRO for PIC32
Functions 199 Calling a function 199 Procedures 200 Forward declaration 201 Functions reentrancy 202
Types 203
Type Categories 203
Simple Types 203 Derived Types 204 Arrays 204
Array Declaration 204 Constant Arrays 204 Multi-dimensional Arrays 205
Strings 205
String Concatenating 206
Pointers 207
Pointers and memory spaces 207 Function Pointers 208
@ Operator 209 Pointer Arithmetic 210
Assignment and Comparison 210 Pointer Addition 211 Pointer Subtraction 211
Structures 212
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 218
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 220
Bitwise Operators Overview 220
9
MikroElektronika
mikoBasic PRO for PIC32
Logical Operations on Bit Level 220 Unsigned and Conversions 221 Signed and Conversions 221 Bitwise Shift Operators 221
Boolean Operators 222 Unary Operators 222
Unary Arithmetic Operators 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 225 Conditional Statements 226 If Statement 226
Nested If statements 226
Select Case Statement 227
Nested switch 228
Iteration Statements (Loops) 228 For Statement 228
Endless Loop 229
While Statement 229 Do Statement 230 Jump Statements 230 Break and Continue Statements 230
Break Statement 230 Continue Statement 231 Exit Statement 231
Return Statement 231 Goto Statement 232 Gosub Statement 233 asm Statement 233
Accessing variables 233 Asm code and SSA optimization 234
Directives 235 Compiler Directives 235
Directives #DEFINE and #UNDEFINE 235 Directives #IFDEF, #IFNDEF, #ELSE and #ENDIF 235 Include Directive #I 236
MikroElektronika
10
mikroBasic PRO for PIC32
Explicit Path 237
Directive absolute 237 Directive org 237 Directive orgall 238
CHAPTER 9 239 mikroBasic PRO for PIC32 Libraries 239
Hardware Libraries 240 Miscellaneous Libraries 240 Hardware Libraries 241 ADC Library 241
Library Routines 242 ADCx_Init 242 ADCx_Init_Advanced 242 ADCx_Get_Sample 243 ADCx_Read 243 Library Example 244
CANSPI Library 245
Library Dependency Tree 245 External dependencies of CANSPI Library 245 Library Routines 246 CANSPISetOperationMode 246 CANSPIGetOperationMode 247 CANSPIInit 247 CANSPISetBaudRate 249 CANSPISetMask 250 CANSPISetFilter 251 CANSPIRead 252 CANSPIWrite 253 CANSPI Constants 253 CANSPI_OP_MODE Constants 253 CANSPI_CONFIG_FLAGS Constants 254 CANSPI_TX_MSG_FLAGS Constants 255 CANSPI_RX_MSG_FLAGS Constants 255 CANSPI_MASK Constants 256 CANSPI_FILTER Constants 256 Library Example 257 HW Connection 260
Compact Flash Library 261
Library Dependency Tree 261 External dependencies of Compact Flash Library 262 Library Routines 263 Cf_Init 264 Cf_Detect 265 Cf_Enable 265 Cf_Disable 265
11
MikroElektronika
mikoBasic PRO for PIC32
Cf_Read_Init 266 Cf_Read_Byte 266 Cf_Write_Init 266 Cf_Write_Byte 267 Cf_Read_Sector 267 Cf_Write_Sector 267 Cf_Fat_Init 268 Cf_Fat_QuickFormat 268 Cf_Fat_Assign 269 Cf_Fat_Reset 270 Cf_Fat_Read 270 Cf_Fat_Rewrite 271 Cf_Fat_Append 271 Cf_Fat_Delete 271 Cf_Fat_Write 272 Cf_Fat_Set_File_Date 272 Cf_Fat_Get_File_Date 273 Cf_Fat_Get_File_Date_Modied 273 Cf_Fat_Get_File_Size 274 Cf_Fat_Get_Swap_File 274 Library Example 275 HW Connection 280
Epson S1D13700 Graphic Lcd Library 281
External dependencies of the Epson S1D13700 Graphic Lcd Library 281 Library Routines 282 S1D13700_Init 283 S1D13700_Write_Command 284 S1D13700_Write_Parameter 285 S1D13700_Read_Parameter 285 S1D13700_Fill 285 S1D13700_GrFill 286 S1D13700_TxtFill 286 S1D13700_Display_GrLayer 286 S1D13700_Display_TxtLayer 287 S1D13700_Set_Cursor 287 S1D13700_Display_Cursor 288 S1D13700_Write_Char 288 S1D13700_Write_Text 289 S1D13700_Dot 289 S1D13700_Line 290 S1D13700_H_Line 290 S1D13700_V_Line 291 S1D13700_Rectangle 291 S1D13700_Box 292 S1D13700_Rectangle_Round_Edges 292 S1D13700_Rectangle_Round_Edges_Fill 293 S1D13700_Circle 293
MikroElektronika
12
mikroBasic PRO for PIC32
S1D13700_Circle_Fill 294 S1D13700_Image 294 S1D13700_PartialImage 295
Flash Memory Library 296
Library Routines 296 Flash_Write_Word 297 Flash_Write_Row 297 Flash_Erase_Page 297
Graphic Lcd Library 298
Library Dependency Tree 298 External dependencies of Graphic Lcd Library 299 Glcd_Init 300 Glcd_Set_Side 302 Glcd_Set_X 302 Glcd_Set_Page 302 Glcd_Read_Data 303 Glcd_Write_Data 303 Glcd_Fill 304 Glcd_Dot 304 Glcd_Line 304 Glcd_V_Line 305 Glcd_H_Line 305 Glcd_Rectangle 306 Glcd_Rectangle_Round_Edges 306 Glcd_Rectangle_Round_Edges_Fill 307 Glcd_Box 307 Glcd_Circle 308 Glcd_Circle_Fill 308 Glcd_Set_Font 309 Glcd_Write_Char 310 Glcd_Write_Text 310 Glcd_Image 311 Glcd_PartialImage 311
I²C Library 312
Library Routines 312 I2Cx_Init 312 I2Cx_Init_Advanced 313 I2Cx_Start 313 I2Cx_Restart 314 I2Cx_Is_Idle 314 I2Cx_Read 315 I2Cx_Write 315 I2Cx_Stop 316 Library Example 316
Keypad Library 318
External dependencies of Keypad Library 318
13
MikroElektronika
mikoBasic PRO for PIC32
Library Routines 318 Keypad_Init 318 Keypad_Key_Press 319 Keypad_Key_Click 319 Library Example 320 HW Connection 321
Lcd Library 322
Library Dependency Tree 322 External dependencies of Lcd Library 322 Library Routines 322 Lcd_Init 323 Lcd_Out 324 Lcd_Out_Cp 324 Lcd_Chr 324 Lcd_Chr_Cp 325 Lcd_Cmd 325 Available Lcd Commands 325 Library Example 326
Manchester Code Library 328
External dependencies of Manchester Code Library 328 Library Routines 329 Man_Receive_Init 329 Man_Receive 330 Man_Send_Init 330 Man_Send 331 Man_Synchro 331 Man_Break 332 Library Example 333 Connection Example 335
Memory Manager Library 336
Library Routines 336 Heap_Init 336 GetMem 336 FreeMem 337 MM_LargestFreeMemBlock 337 MM_TotalFreeMemSize 337
Multi Media Card Library 338
Secure Digital Card 338 Secure Digital High Capacity Card 338 Library Dependency Tree 339 External dependencies of MMC Library 339 Library Routines 339 Mmc_Init 340 Mmc_Read_Sector 341 Mmc_Write_Sector 341 Mmc_Read_Cid 342
MikroElektronika
14
mikroBasic PRO for PIC32
Mmc_Read_Csd 342 Mmc_Fat_Init 343 Mmc_Fat_QuickFormat 344 Mmc_Fat_Assign 345 Mmc_Fat_Reset 346 Mmc_Fat_Read 346 Mmc_Fat_Rewrite 347 Mmc_Fat_Append 347 Mmc_Fat_Delete 347 Mmc_Fat_Write 348 Mmc_Fat_Set_File_Date 348 Mmc_Fat_Get_File_Date 349 Mmc_Fat_Get_File_Date_Modied 350 Mmc_Fat_Get_File_Size 350 Mmc_Fat_Get_Swap_File 351 Library Example 352 HW Connection 356
OneWire Library 357
Library Routines 357 Ow_Reset 357 Ow_Read 358 Ow_Write 358
Port Expander Library 359
Library Dependency Tree 359 External dependencies of Port Expander Library 359 Library Routines 359 Expander_Init 360 Expander_Init_Advanced 361 Expander_Read_Byte 362 Expander_Write_Byte 362 Expander_Read_PortA 362 Expander_Read_PortB 363 Expander_Read_PortAB 363 Expander_Write_PortA 364 Expander_Write_PortB 364 Expander_Write_PortAB 365 Expander_Set_DirectionPortA 365 Expander_Set_DirectionPortB 366 Expander_Set_DirectionPortAB 366 Expander_Set_PullUpsPortA 366 Expander_Set_PullUpsPortB 367 Expander_Set_PullUpsPortAB 367 Library Example 368 HW Connection 369
PS/2 Library 370
External dependencies of PS/2 Library 370
15
MikroElektronika
mikoBasic PRO for PIC32
Library Routines 370 Ps2_Cong 371 Ps2_Key_Read 371 Special Function Keys 372 Library Example 373 HW Connection 374
PWM Library 374
Library Routines 374 PWM_Init 375 PWM_Init_Advanced 375 PWM_Set_Duty 376 PWM_Start 376 PWM_Stop 376 Library Example 377 HW Connection 378
RS-485 Library 379
Library Dependency Tree 379 External dependencies of RS-485 Library 379 Library Routines 380 RS485Master_Init 380 RS485Master_Receive 381 RS485Master_Send 381 RS485Slave_Init 382 RS485Slave_Receive 383 RS485Slave_Send 383 Library Example 384 HW Connection 387 Message format and CRC calculations 388
Software I²C Library 389
External dependencies of Software I²C Library 389 Library Routines 389 Soft_I2C_Init 390 Soft_I2C_Start 390 Soft_I2C_Read 391 Soft_I2C_Write 391 Soft_I2C_Stop 391 Soft_I2C_Break 392 Library Example 393
Software SPI Library 395
External dependencies of Software SPI Library 395 Library Routines 395 Soft_SPI_Init 396 Soft_SPI_Read 397 Soft_SPI_Write 397 Library Example 397
Software UART Library 399
MikroElektronika
16
mikroBasic PRO for PIC32
Library Routines 399 Soft_UART_Init 399 Soft_UART_Read 400 Soft_UART_Write 400 Soft_UART_Break 401 Library Example 402
Sound Library 403
Library Routines 403 Sound_Init 403 Sound_Play 403 HW Connection 406
SPI Library 407
Library Routines 407 SPIx_Init 408 SPIx_Init_Advanced 409 SPIx_Read 411 SPIx_Write 411 SPI_Set_Active 412 Library Example 412 HW Connection 414
SPI Ethernet Library 415
Library Dependency Tree 415 External dependencies of SPI Ethernet Library 416 Library Routines 417 SPI_Ethernet_Init 417 SPI_Ethernet_Enable 419 SPI_Ethernet_Disable 420 SPI_Ethernet_doPacket 421 SPI_Ethernet_putByte 421 SPI_Ethernet_putBytes 422 SPI_Ethernet_putConstBytes 422 SPI_Ethernet_putString 422 SPI_Ethernet_putConstString 423 SPI_Ethernet_getByte 423 SPI_Ethernet_getBytes 423 SPI_Ethernet_UserTCP 424 SPI_Ethernet_UserUDP 425 SPI_Ethernet_setUserHandlers 426 SPI_Ethernet_getIpAddress 426 Ethernet_getGwIpAddress 426 SPI_Ethernet_getDnsIpAddress 427 SPI_Ethernet_getIpMask 427 SPI_Ethernet_confNetwork 428 SPI_Ethernet_arpResolve 429 SPI_Ethernet_sendUDP 429 SPI_Ethernet_dnsResolve 430
17
MikroElektronika
mikoBasic PRO for PIC32
SPI_Ethernet_initDHCP 431 SPI_Ethernet_doDHCPLeaseTime 431 SPI_Ethernet_renewDHCP 432 Library Example 432 HW Connection 439
SPI Ethernet ENC24J600 Library 440
Library Dependency Tree 440 External dependencies of SPI Ethernet ENC24J600 Library 441 Library Routines 442 SPI_Ethernet_24j600_Init 443 SPI_Ethernet_24j600_Enable 445 SPI_Ethernet_24j600_Disable 446 SPI_Ethernet_24j600_doPacket 447 SPI_Ethernet_24j600_putByte 447 SPI_Ethernet_24j600_putBytes 448 SPI_Ethernet_24j600_putConstBytes 448 SPI_Ethernet_24j600_putString 449 SPI_Ethernet_24j600_putConstString 449 SPI_Ethernet_24j600_getByte 449 SPI_Ethernet_24j600_getBytes 450 SPI_Ethernet_24j600_UserTCP 450 SPI_Ethernet_24j600_UserUDP 451 SPI_Ethernet_24j600_setUserHandlers 452 SPI_Ethernet_24j600_getIpAddress 452 SPI_Ethernet_24j600_getGwIpAddress 453 SPI_Ethernet_24j600_getDnsIpAddress 453 SPI_Ethernet_24j600_getIpMask 454 SPI_Ethernet_24j600_confNetwork 454 SPI_Ethernet_24j600_arpResolve 455 SPI_Ethernet_24j600_sendUDP 455 SPI_Ethernet_24j600_dnsResolve 456 SPI_Ethernet_24j600_initDHCP 457 SPI_Ethernet_24j600_doDHCPLeaseTime 458 SPI_Ethernet_24j600_renewDHCP 458
SPI Graphic Lcd Library 459
Library Dependency Tree 459 External dependencies of SPI Lcd Library 459 Library Routines 459 SPI_Glcd_Init 460 SPI_Glcd_Set_Side 461 SPI_Glcd_Set_Page 461 SPI_Glcd_Set_X 461 SPI_Glcd_Read_Data 462 SPI_Glcd_Write_Data 462 SPI_Glcd_Fill 463 SPI_Glcd_Dot 463
MikroElektronika
18
mikroBasic PRO for PIC32
SPI_Glcd_Line 464 SPI_Glcd_V_Line 464 SPI_Glcd_H_Line 465 SPI_Glcd_Rectangle 465 SPI_Glcd_Rectangle_Round_Edges 466 SPI_Glcd_Rectangle_Round_Edges_Fill 466 SPI_Glcd_Box 467 SPI_Glcd_Circle 467 SPI_Glcd_Circle_FIll 468 SPI_Glcd_Set_Font 469 SPI_Glcd_Write_Char 470 SPI_Glcd_Write_Text 470 SPI_Glcd_Image 471 SPI_Glcd_PartialImage 471 Library Example 472 HW Connection 474
SPI Lcd Library 475
Library Dependency Tree 475 External dependencies of SPI Lcd Library 475 Library Routines 475 SPI_Lcd_Cong 476 SPI_Lcd_Out 476 SPI_Lcd_Out_Cp 477 SPI_Lcd_Chr 477 SPI_Lcd_Chr_Cp 477 SPI_Lcd_Cmd 478 Available SPI Lcd Commands 478 Library Example 479 Default Pin Conguration 479
SPI Lcd8 (8-bit interface) Library 481
Library Dependency Tree 481 External dependencies of SPI Lcd Library 481 Library Routines 481 SPI_Lcd8_Cong 482 SPI_Lcd8_Out 482 SPI_Lcd8_Out_Cp 483 SPI_Lcd8_Chr 483 SPI_Lcd8_Chr_Cp 483 SPI_Lcd8_Cmd 484 Available SPI Lcd8 Commands 484 Library Example 485
SPI T6963C Graphic Lcd Library 487
Library Dependency Tree 487 External dependencies of SPI T6963C Graphic Lcd Library 487 Library Routines 488 SPI_T6963C_cong 489
19
MikroElektronika
mikoBasic PRO for PIC32
SPI_T6963C_writeData 490 SPI_T6963C_writeCommand 490 SPI_T6963C_setPtr 491 SPI_T6963C_waitReady 491 SPI_T6963C_ll 491 SPI_T6963C_dot 492 SPI_T6963C_write_char 492 SPI_T6963C_write_text 493 SPI_T6963C_line 494 SPI_T6963C_rectangle 494 SPI_T6963C_rectangle_round_edges 495 SPI_T6963C_rectangle_round_edges_ll 495 SPI_T6963C_box 496 SPI_T6963C_circle 496 SPI_T6963C_circle_ll 496 SPI_T6963C_image 497 SPI_T6963C_PartialImage 497 SPI_T6963C_sprite 498 SPI_T6963C_set_cursor 498 SPI_T6963C_clearBit 498 SPI_T6963C_setBit 499 SPI_T6963C_negBit 499 SPI_T6963C_displayGrPanel 499 SPI_T6963C_displayTxtPanel 500 SPI_T6963C_setGrPanel 500 SPI_T6963C_setTxtPanel 500 SPI_T6963C_panelFill 501 SPI_T6963C_grFill 501 SPI_T6963C_txtFill 501 SPI_T6963C_cursor_height 502 SPI_T6963C_graphics 502 SPI_T6963C_text 502 SPI_T6963C_cursor 503 SPI_T6963C_cursor_blink 503 Library Example 503 HW Connection 509
T6963C Graphic Lcd Library 510
Library Dependency Tree 510 External dependencies of T6963C Graphic Lcd Library 511 Library Routines 512 T6963C_init 513 T6963C_writeData 514 T6963C_writeCommand 515 T6963C_setPtr 515 T6963C_waitReady 515 T6963C_ll 516 T6963C_dot 516
MikroElektronika
20
mikroBasic PRO for PIC32
T6963C_write_char 517 T6963C_write_text 518 T6963C_line 518 T6963C_rectangle 519 T6963C_rectangle_round_edges 519 T6963C_rectangle_round_edges_ll 520 T6963C_box 520 T6963C_circle 520 T6963C_circle_ll 521 T6963C_image 521 T6963C_PartialImage 522 T6963C_sprite 522 T6963C_set_cursor 523 T6963C_displayGrPanel 523 T6963C_displayTxtPanel 523 T6963C_setGrPanel 524 T6963C_setTxtPanel 524 T6963C_panelFill 524 T6963C_grFill 525 T6963C_txtFill 525 T6963C_cursor_height 525 T6963C_graphics 526 T6963C_text 526 T6963C_cursor 526 T6963C_cursor_blink 527 Library Example 527 HW Connection 533
TFT Library 534
External dependencies of TFT Library 534 Library Routines 535 TFT_Init 536 TFT_Set_Index 537 TFT_Write_Command 537 TFT_Write_Data 537 TFT_Set_Active 538 TFT_Set_Font 539 TFT_Write_Char 540 TFT_Write_Text 540 TFT_Fill_Screen 541 TFT_Dot 542 TFT_Set_Pen 543 TFT_Set_Brush 544 TFT_Line 546 TFT_H_Line 547 TFT_V_Line 547 TFT_Rectangle 547 TFT_Rectangle_Round_Edges 548
21
MikroElektronika
mikoBasic PRO for PIC32
TFT_Circle 548 TFT_Image 548 TFT_Partial_Image 549 TFT_Image_Jpeg 549 TFT_RGBToColor16bit 550 TFT_Color16bitToRGB 550 HW Connection 551
Touch Panel Library 552
Library Dependency Tree 552 External dependencies of Touch Panel Library 552 Library Routines 552 TP_Init 553 TP_Set_ADC_Threshold 553 TP_Press_Detect 554 TP_Get_Coordinates 555 TP_Calibrate_Bottom_Left 555 TP_Calibrate_Upper_Right 555 TP_Get_Calibration_Consts 556 TP_Set_Calibration_Consts 556
Touch Panel TFT Library 557
Library Dependency Tree 557 External dependencies of Touch Panel TFT Library 557 Library Routines 557 TP_TFT_Init 558 TP_TFT_Set_ADC_Threshold 558 TP_TFT_Press_Detect 559 TP_TFT_Get_Coordinates 560 TP_TFT_Calibrate_Min 560 TP_TFT_Calibrate_Max 560 TP_TFT_Get_Calibration_Consts 561 TP_TFT_Set_Calibration_Consts 561 HW Connection 562
UART Library 563
Library Routines 563 UARTx_Init 564 UARTx_Init_Advanced 565 UARTx_Data_Ready 566 UARTx_Tx_Idle 566 UARTx_Read 567 UARTx_Read_Text 568 UARTx_Write 569 UARTx_Write_Text 569 UART_Set_Active 570 Library Example 571 HW Connection 572
USB Library 573
MikroElektronika
22
mikroBasic PRO for PIC32
USB HID Class 573 Descriptor File 573 Library Routines 573 HID_Enable 574 HID_Read 574 HID_Write 574 HID_Disable 575 USB_Interrupt_Proc 575 USB_Polling_Proc 576 Gen_Enable 576 Gen_Read 577 Gen_Write 577 Library Example 578 HW Connection 578
Miscellaneous Libraries 579 Button Library 579
Library Routines 579 Button 580
C Type Library 581
Library Functions 581 isalnum 581 isalpha 581 iscntrl 581 isdigit 581 isgraph 582 islower 582 ispunct 582 isspace 582 isupper 582 isxdigit 583 toupper 583 tolower 583
Conversions Library 584
Library Dependency Tree 584 Library Routines 584 ByteToStr 585 ShortToStr 585 WordToStr 585 WordToStrWithZeros 586 IntToStr 586 LongintToStr 587 LongWordToStr 587 FloatToStr 588 WordToStrWithZeros 588 IntToStrWithZeros 589 LongWordToStrWithZeros 589
23
MikroElektronika
mikoBasic PRO for PIC32
LongIntToStrWithZeros 590 ByteToHex 590 ShortToHex 591 WordToHex 591 IntToHex 592 LongWordToHex 592 LongIntToHex 593 StrToInt 593 StrToWord 594 Bcd2Dec 594 Dec2Bcd 595 Bcd2Dec16 595 Dec2Bcd16 595
Setjmp Library 596
Library Routines 596 Setjmp 596 Longjmp 596 Library Example 597
String Library 598
Library Functions 598 memchr 598 memcmp 599 memcpy 599 memmove 600 memset 600 strcat 600 strcat2 601 strchr 601 strcmp 601 strcpy 602 strlen 602 strncat 602 strncpy 602 strspn 603 strncmp 603 strstr 603 strcspn 604 strpbrk 604 strrchr 604 ltrim 604 rtrim 605 strappendpre 605 strappendsuf 605 length 605
Time Library 606
Library Routines 606
MikroElektronika
24
mikroBasic PRO for PIC32
Time_dateToEpoch 606 Time_epochToDate 607 Time_dateDiff 607 Library Example 608
Trigon Library 609
Library Functions 609 acos 610 asin 610 atan 610 atan2 610 ceil 610 cos 610 cosh 611 eval_poly 611 exp 611 fabs 611 oor 611 frexp 611 ldexp 612 log 612 log10 612 modf 612 pow 612 sin 612 sinh 613 sqrt 613 tan 613 tanh 613
Trigonometry Library 614
Library Routines 614 sinE3 614 cosE3 614
CHAPTER 10 615 Tutorials 615
Managing Project 615
Projects 615
New Project 616
New Project Wizard Steps 616
Customizing Projects 620
Managing Project Group 620 Add/Remove Files from Project 620 Project Level Denes: 621
Source Files 622
Managing Source Files 622 Creating new source le 622
25
MikroElektronika
mikoBasic PRO for PIC32
Opening an existing le 622 Printing an open le 622 Saving le 622 Saving le under a different name 623 Closing le 623
Search Paths 623 Paths for Source Files (.mbas) 624
Edit Project 625 Clean Project Folder 626 Compilation 627
Output Files 627 Assembly View 627
Creating New Library 628
Multiple Library Versions 628
Frequently Asked Questions 629
Can I use your compilers and programmer on Windows Vista (Windows 7) ? 629 I am getting “Access is denied” error in Vista, how to solve this problem ? 629 What are differences between mikrobasic PRO, mikroPascal PRO and mikroC PRO compilers ? Why do they have different prices ? 629 Why do your PIC compilers don’t support 12F508 and some similar chips ? 629 What are limitations of demo versions of mikroElektronika’s compilers ? 629 Why do I still get demo limit error when I purchased and installed license key ? 629 I have bought license for the older version, do I have to pay license for the new version of the com­piler ? 630 Do your compilers work on Windows Vista (Windows 7) ? 630 What does this function/procedure/routine do ? 630 I try to compile one of the provided examples and nothing happens, what is the problem? 630 Can I get your library sources ? I need to provide all sources with my project. 630 Can I use code I developed in your compilers in commercial purposes ? Are there some limitations ? 630 Why does an example provided with your compilers doesn’t work ? 630 Your example works if I use the same MCU you did, but how to make it work for another MCU ? 630 I need this project nished, can you help me ? 631 Do you have some discount on your compilers/development systems for students/professors ? 631 I have a question about your compilers which is not listed here. Where can I nd an answer ? 631
MikroElektronika
26
mikroBasic PRO for PIC32
27
MikroElektronika
mikoBasic PRO for PIC32
CHAPTER 1
INTRODUCTION
mikroBasic PRO for PIC32 is a powerful, feature-rich development tool for PIC32 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 PIC32 IDE
MikroElektronika
28
mikroBasic PRO for PIC32
Introduction to mikroBasic PRO for PIC32
The PIC32 is a 32-bit family of general purpose microcontrollers. This is the Microchip’s rst inherent 32-bit (data)
microcontroller family. It builds upon the MIPS M4K 32-bit core, offering high-performance hardware multiply/divide
unit, programmable user and kernel memory partition through an unied 4GB virtual memory space, with powerful
peripherals to address a wide range of applications.
Having a wide range of application, being prized for its efciency, PIC32 MCUs are a natural choice for developing
embedded systems. mikroBasic PRO for PIC32 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
mikroBasic PRO for PIC32 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 mikroBasic PRO for PIC32 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.
- 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.
- mikroBasic PRO for PIC32 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 the PIC32 microcontrollers, read carefully the PIC32
Specics chapter. It might give you some useful information on the PIC32 constraints, code portability, and
good programming practices.
- If you are experienced in Basic programming, you will probably want to consult the mikroBasic PRO
for PIC32 Specics rst. For language issues, you can always refer to the comprehensive Language
Reference. A complete list of included libraries is available in the mikroBasic PRO for PIC32 Libraries.
- If you are not very experienced in Basic programming, don’t panic! mikroBasic PRO for PIC32 provides plenty of examples making it easy for you to go quickly through it . We suggest you to consult Projects and
Source Files rst, 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!
29
MikroElektronika
mikoBasic PRO for PIC32
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.
MikroElektronika
30
Loading...
+ 600 hidden pages