-
mikroPascal PRO for PIC32™ Manual Compiler mikroPascal PRO for PIC32 is a full-featured C 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 efficient code, many hardware and software libraries, comprehensive documentation, software simulator, COFF file generation, SSA optimization (up to 30% code reduction) and many more.
-
mikoPascal PRO for PIC32 Table of Contents CHAPTER 1 INTRODUCTION Introduction to mikroPascal PRO for PIC32 30 30 31 Software License Agreement 32 Technical Support How to Register 34 34 CHAPTER 2 mikroPascal PRO for PIC32 Environment Main Menu Options File 38 38 38 39 40 Edit 41 Features Where to Start mikroElektronika Associates License Statement and Limited Warranty IMPORTANT - READ CAREFULLY LIMITED WARRANTY HIGH RISK ACTIVITIES GENERAL PROVISIONS Who Gets the License Ke
-
mikroPascal PRO for PIC32 Help Menu Options 50 mikroPascal PRO for PIC32 IDE 51 Code Editor 52 Code Explorer 59 Project Manager Project Settings Library Manager 60 62 63 Routine List Statistics 65 65 Messages Window Quick Converter Macro Editor Image Preview Toolbars 72 73 73 74 76 IDE Overview Editor Settings Auto Save Highlighter Spelling Comment Style Code Folding Code Assistant Parameter Assistant Bookmarks Go to Line Column Select Mode Editor Colors Auto Correc
-
mikoPascal PRO for PIC32 Edit Toolbar Advanced Edit Toolbar Find/Replace Toolbar Project Toolbar Build Toolbar Debug Toolbar Styles Toolbar Tools Toolbar View Toolbar Layout Toolbar Help Toolbar 77 78 78 79 79 80 80 81 81 82 82 Customizing IDE Layout 83 Options 85 Integrated Tools 88 Active Comments 96 Docking Windows Saving Layout Auto Hide Code editor Tools Output settings Active Comments Editor ASCII Chart EEPROM Editor Graphic Lcd Bitmap Editor HID Terminal Interrupt
-
mikroPascal PRO for PIC32 Metacharacters - Iterators Metacharacters - Alternatives Metacharacters - Subexpressions Metacharacters - Backreferences 109 110 110 110 Keyboard Shortcuts CHAPTER 3 mikroPascal PRO for PIC32 Command Line Options CHAPTER 4 mikroICD (In-Circuit Debugger) Introduction mikroICD Debugger Options 111 113 113 115 115 115 117 mikroICD Debugger Example mikroICD Debugger Windows 118 122 CHAPTER 5 Software Simulator Overview Software Simulator Software Simulator Debug W
-
mikoPascal PRO for PIC32 Configuring Interrupts 140 Interrupt Priorities Interrupts and Register Sets 141 141 Interrupt Coding Requirements Interrupt Service Routine Function Calls from Interrupt Interrupt Example 141 141 142 143 Single Vector Mode Multi Vector Mode Register Set Selection in Single Vector Mode Interrupts and Register Sets 140 140 141 141 Linker Directives 144 Built-in Routines 146 Directive absolute Directive org Directive orgall Lo Hi Higher Highest LoWord
-
mikroPascal PRO for PIC32 KVA0_TO_KVA1 KVA1_TO_KVA0 KVA_TO_PA PA_TO_KVA0 PA_TO_KVA1 CP0_GET CP0_SET EnableInterrupts DisableInterrupts 158 159 159 159 159 160 160 160 161 Code Optimization 163 Single Static Assignment Optimization 164 CHAPTER 7 PIC32 Specifics 168 168 PIC32 Memory Organization 170 Memory Type Specifiers 173 Read Modify Write Problem CHAPTER 8 mikroPascal PRO for PIC32 Language Reference Lexical Elements Overview Whitespace 174 178 178 180 180 Constant foldi
-
mikoPascal PRO for PIC32 Whitespace in Strings 180 Comments 181 Tokens 182 Literals 183 Keywords Identifiers 185 186 Punctuators 187 Program Organization 189 Scope and Visibility 191 Name Spaces Units 192 193 Variables 195 Constants Labels Functions and Procedures 197 198 199 Nested comments Token Extraction Example Integer Literals Floating Point Literals Character Literals String Literals Case Sensitivity Uniqueness and Scope Identifier Examples Brackets Par
-
mikroPascal PRO for PIC32 Procedures 200 Types 202 Simple Types Derived Types Arrays 203 203 204 Strings 205 Pointers 206 @ Operator Pointer Arithmetic 209 209 Records 212 Types Conversions 213 Explicit Conversion 214 Type Specifier Type Qualifiers 215 216 Operators Operators Precedence and Associativity Arithmetic Operators 216 217 217 Relational Operators 218 Calling a procedure Example Example: Forward declaration Functions reentrancy Type Categories Arra
-
mikoPascal PRO for PIC32 Relational Operators in Expressions 218 Bitwise Operators 219 Boolean Operators Unary Operators 221 221 Sizeof Operator 222 Expressions 223 Statements Assignment Statements Compound Statements (Blocks) Conditional Statements If Statement 224 225 225 225 226 Case Statement 227 Iteration Statements For Statement 228 228 While Statement Repeat Statement Jump Statements asm Statement 229 229 230 230 With Statement Directives Compiler Directives 23
-
mikroPascal PRO for PIC32 Include Directive $I 234 Linker Directives 234 CHAPTER 9 mikroPascal PRO for PIC32 Libraries Hardware Libraries Miscellaneous Libraries Hardware Libraries ADC Library 236 236 237 237 238 239 CANSPI Library 243 Compact Flash Library 259 Directive absolute Directive org Directive orgall Library Routines ADC1_Init ADC1_Init_Advanced ADC1_Get_Sample ADC1_Read Library Example Library Dependency Tree External dependencies of CANSPI Library Library Routine
-
mikoPascal PRO for PIC32 Cf_Disable Cf_Read_Init Cf_Read_Byte Cf_Write_Init Cf_Write_Byte Cf_Read_Sector Cf_Write_Sector Cf_Fat_Init Cf_Fat_QuickFormat Cf_Fat_Assign Cf_Fat_Reset Cf_Fat_Read Cf_Fat_Rewrite Cf_Fat_Append Cf_Fat_Delete Cf_Fat_Write Cf_Fat_Set_File_Date Cf_Fat_Get_File_Date Cf_Fat_Get_File_Date_Modified Cf_Fat_Get_File_Size Cf_Fat_Get_Swap_File Library Example HW Connection Epson S1D13700 Graphic Lcd Library External dependencies of the Epson S1D13700 Graphic Lcd Libr
-
mikroPascal PRO for PIC32 S1D13700_Circle S1D13700_Circle_Fill S1D13700_Image S1D13700_PartialImage 292 293 293 294 Flash Memory Library 294 Graphic Lcd Library 296 I²C Library 310 Library Routines Flash_Write_Word Flash_Write_Row Flash_Erase_Page Library Dependency Tree External dependencies of Graphic Lcd Library Library Routines Glcd_Init Glcd_Set_Side Glcd_Set_X Glcd_Set_Page Glcd_Read_Data Glcd_Write_Data Glcd_Fill Glcd_Dot Glcd_Line Glcd_V_Line Glcd_H_Line Glcd_Rectan
-
mikoPascal PRO for PIC32 Keypad Library 316 Lcd Library 320 Memory Manager Library 326 Multi Media Card Library 328 External dependencies of Keypad Library Library Routines Keypad_Init Keypad_Key_Press Keypad_Key_Click Library Example HW Connection Library Dependency Tree Keypad_Key_Click Library Routines Lcd_Init Lcd_Out Lcd_Out_Cp Lcd_Chr Lcd_Chr_Cp Lcd_Cmd Available Lcd Commands Library Example Library Routines Heap_Init GetMem FreeMem MM_LargestFreeMemBlock MM_TotalFre
-
mikroPascal PRO for PIC32 Mmc_Fat_Write Mmc_Fat_Set_File_Date Mmc_Fat_Get_File_Date Mmc_Fat_Get_File_Date_Modified Mmc_Fat_Get_File_Size Mmc_Fat_Get_Swap_File Library Example HW Connection 338 338 339 340 340 341 342 347 OneWire Library 347 Port Expander Library 349 PS/2 Library 360 PWM Library 364 Library Routines Ow_Reset Ow_Read Ow_Write Library Dependency Tree External dependencies of Port Expander Library Library Routines Expander_Init Expander_Init_Advanced Expander_Rea
-
mikoPascal PRO for PIC32 PWM_Init_Advanced PWM_Set_Duty PWM_Start PWM_Stop Library Example HW Connection 365 366 366 366 367 368 RS-485 Library 369 Software I²C Library 379 Software SPI Library 385 Software UART Library 389 Sound Library 393 Library Dependency Tree External dependencies of RS-485 Library Library Routines RS485Master_Init RS485Master_Receive RS485Master_Send RS485Slave_Init RS485Slave_Receive RS485Slave_Send Library Example HW Connection Message format and C
-
mikroPascal PRO for PIC32 Sound_Play Library Example HW Connection 393 394 396 SPI Library 397 SPI Ethernet Library 405 SPI Ethernet ENC24J600 Library 430 Library Routines SPIx_Init SPIx_Init_Advanced SPIx_Read SPIx_Write SPI_Set_Active Library Example HW Connection Library Dependency Tree External dependencies of SPI Ethernet Library Library Routines SPI_Ethernet_Init SPI_Ethernet_Enable SPI_Ethernet_Disable SPI_Ethernet_doPacket SPI_Ethernet_putByte SPI_Ethernet_putBytes SP
-
mikoPascal PRO for PIC32 Library Routines SPI_Ethernet_24j600_Init SPI_Ethernet_24j600_Enable SPI_Ethernet_24j600_Disable SPI_Ethernet_24j600_doPacket SPI_Ethernet_24j600_putByte SPI_Ethernet_24j600_putBytes SPI_Ethernet_24j600_putConstBytes SPI_Ethernet_24j600_putString SPI_Ethernet_24j600_putConstString SPI_Ethernet_24j600_getByte SPI_Ethernet_24j600_getBytes SPI_Ethernet_24j600_UserTCP SPI_Ethernet_24j600_UserUDP SPI_Ethernet_24j600_getIpAddress SPI_Ethernet_24j600_getGwIpAddress SPI_Ethe
-
mikroPascal PRO for PIC32 SPI_Glcd_Write_Char SPI_Glcd_Write_Text SPI_Glcd_Image SPI_Glcd_PartialImage Library Example HW Connection 459 459 460 460 461 463 SPI Lcd Library 464 SPI Lcd8 (8-bit interface) Library 470 SPI T6963C Graphic Lcd Library 477 Library Dependency Tree External dependencies of SPI Lcd Library Library Routines SPI_Lcd_Config SPI_Lcd_Out SPI_Lcd_Out_Cp SPI_Lcd_Chr SPI_Lcd_Chr_Cp SPI_Lcd_Cmd Available SPI Lcd Commands Library Example Default Pin Configuration
-
mikoPascal PRO for PIC32 SPI_T6963C_rectangle_round_edges SPI_T6963C_rectangle_round_edges_fill SPI_T6963C_box SPI_T6963C_circle SPI_T6963C_circle_fill SPI_T6963C_image SPI_T6963C_PartialImage SPI_T6963C_sprite SPI_T6963C_set_cursor SPI_T6963C_clearBit SPI_T6963C_setBit SPI_T6963C_negBit SPI_T6963C_displayGrPanel SPI_T6963C_displayTxtPanel SPI_T6963C_setGrPanel SPI_T6963C_setTxtPanel SPI_T6963C_panelFill SPI_T6963C_grFill SPI_T6963C_txtFill SPI_T6963C_cursor_height SPI_T6963C_graphics S
-
mikroPascal PRO for PIC32 T6963C_PartialImage T6963C_sprite T6963C_set_cursor T6963C_displayGrPanel T6963C_displayTxtPanel T6963C_setGrPanel T6963C_setTxtPanel T6963C_panelFill T6963C_grFill T6963C_txtFill T6963C_cursor_height T6963C_graphics T6963C_text T6963C_cursor T6963C_cursor_blink Library Example HW Connection 512 512 513 513 513 514 514 514 515 515 515 516 516 516 517 517 524 TFT Library 525 Touch Panel Library 543 External dependencies of TFT Library Library Routines TFT_
-
mikoPascal PRO for PIC32 External dependencies of Touch Panel Library Library Routines TP_Init TP_Set_ADC_Threshold TP_Press_Detect TP_Get_Coordinates TP_Calibrate_Bottom_Left TP_Calibrate_Upper_Right TP_Get_Calibration_Consts TP_Set_Calibration_Consts 543 543 544 544 545 546 546 546 547 547 Touch Panel TFT Library 548 UART Library 554 USB Library 564 MikroElektronika 22 Library Dependency Tree External dependencies of Touch Panel TFT Library Library Routines TP_TFT_Init TP_TFT_Se
-
mikroPascal PRO for PIC32 Gen_Enable Gen_Read Gen_Write Library Example HW Connection 567 568 568 569 569 Miscellaneous Libraries Button Library 570 570 C Type Library 571 Conversions Library 574 Library Routines Button Button Library Functions isalnum isalpha iscntrl isdigit isgraph islower ispunct isspace isupper isxdigit toupper tolower Library Dependency Tree Library Routines ByteToStr ShortToStr WordToStr IntToStr LongToStr LongWordToStr FloatToStr WordToStrW
-
mikoPascal PRO for PIC32 Bcd2Dec Dec2Bcd Bcd2Dec16 Dec2Bcd16 583 584 584 584 Setjmp Library 585 Sprint Library 587 Time Library 595 Trigon Library 598 Library Routines Setjmp Longjmp Library Example Library Dependency Tree Functions memchr memcmp memcpy memmove memset strcat strcat2 strchr strcmp strcpy strlen strncat strncpy strspn strncmp strstr strcspn strpbrk strrchr ltrim rtrim strappendpre strappendsuf length Library Routines Time_dateToEpoch Time_epoc
-
mikroPascal PRO for PIC32 asin atan atan2 ceil cos cosh eval_poly exp fabs floor frexp ldexp log log10 modf pow sin sinh sqrt tan tanh 598 599 599 599 599 599 599 600 600 600 600 600 600 600 601 601 601 601 601 601 601 Trigonometry Library 602 CHAPTER 10 Tutorials Managing Project 603 603 603 New Project 604 Customizing Projects 608 Add/Remove Files from Project 608 Source Files Managing Source Files 610 610 Library Routines sinE3 cosE3 Projects New Project
-
mikoPascal PRO for PIC32 Edit Project Clean Project Folder Compilation 613 614 615 Assembly View Creating New Library 615 616 Frequently Asked Questions 617 Output Files Multiple Library Versions 615 616 Can I use your compilers and programmer on Windows Vista (Windows 7) ? 617 I am getting “Access is denied” error in Vista, how to solve this problem ? 617 What are differences between mikroC PRO, mikroPascal PRO and mikroBasic PRO compilers ? Why do they have different prices ? 617 Why
-
mikroPascal PRO for PIC32 27 MikroElektronika
-
CHAPTER 1 mikoPascal PRO for PIC32 INTRODUCTION The mikroPascal 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.
-
mikroPascal PRO for PIC32 Introduction to mikroPascal PRO for PIC32 The PIC32 is a 32-bit family of general purpose microcontrollers. This is the Microchip’s first 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 unified 4GB virtual memory space, with powerful peripherals to address a wide range of applications.
-
mikoPascal 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”) identified above, including any software, media, and accompanying on-line or printed documentation.
-
mikroPascal PRO for PIC32 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 POSSIBIL
-
mikoPascal PRO for PIC32 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): http://www.pic32compilers.com/ . In case you encounter any problem, you are welcome to our support forums at www.mikroe.com/forum/. Here, you may also find helpful information, hardware tips, and practical code snippets.
-
mikroPascal PRO for PIC32 If you choose I work online registering method, following page will be opened in your default browser: 33 MikroElektronika
-
mikoPascal PRO for PIC32 Fill out the registration form, select your distributor, and click the Submit button. If you choose I work offline 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.
-
mikroPascal PRO for PIC32 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.
-
CHAPTER 2 mikoPascal PRO for PIC32 mikroPascal PRO for PIC32 Environment MikroElektronika 36
-
mikroPascal PRO for PIC32 Main Menu Options Available Main Menu options are: Related topics: Keyboard shortcuts, Toolbars 37 MikroElektronika
-
mikoPascal PRO for PIC32 File File Menu Options The File menu is the main entry point for manipulation with the source files. File Description Open a new editor window. Open source file for editing or image file for viewing. Reopen recently used file. Save changes for active editor. Save the active source file with the different name or change the file type. Close active source file. Close all opened files. Print Preview. Print. Exit IDE.
-
mikroPascal PRO for PIC32 Edit Edit Menu Options The Edit Menu contains commands for editing the contents of the current document. 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.
-
mikoPascal PRO for PIC32 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 specified text. The search is performed in the direction specified.
-
mikroPascal PRO for PIC32 Find In Files Dialog box for searching for a text string in current file, all opened files, or in files on a disk. The string to search for is specified in the Text to find field. If Search in directories option is selected, The files to search are specified in the Files mask and Path fields. Go To Line Dialog box that allows the user to specify the line number at which the cursor should be positioned.
-
mikoPascal PRO for PIC32 View View Menu Options View Menu contains commands for controlling the on-screen display of the current project.
-
mikroPascal PRO for PIC32 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. View Assembly. View Listing.
-
mikoPascal PRO for PIC32 Project Project Menu Options Project Menu allows the 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 file with the different name. Close active project. Close project group. Add file to project. Remove file from project. Edit search paths.
-
mikroPascal PRO for PIC32 Build Build Menu Options Build Menu allows the user to easily manage building and compiling process. Build Description Build active project. Rebuild all sources in active project. Build all projects. Stop building all projects. Build and program active project.
-
mikoPascal PRO for PIC32 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.
-
mikroPascal PRO for PIC32 Tools Tools Menu Options Tools Menu contains 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.
-
mikoPascal PRO for PIC32 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.
-
mikroPascal PRO for PIC32 mikroPascal PRO for PIC32 IDE IDE Overview The mikroPascal PRO for PIC32 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).
-
mikoPascal PRO for PIC32 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.
-
mikroPascal PRO for PIC32 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 defined 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.
-
mikoPascal PRO for PIC32 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 first few letters of a word and then press Ctrl+Space, all valid identifiers matching the letters you have typed will be prompted in a floating panel (see the image below).
-
mikroPascal PRO for PIC32 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 first 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 first and last character selected.
-
mikoPascal PRO for PIC32 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 satisfy tastes of different users. Auto Correct Auto Correct option facilitates the 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.
-
mikroPascal PRO for PIC32 The 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.
-
mikoPascal PRO for PIC32 The 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.
-
mikroPascal PRO for PIC32 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 defined and declared objects, code explorer displays message about the first error and it's location in code. The following options are available in the Code Explorer: Icon Description Expand/Collapse all nodes in tree. Locate declaration in code.
-
mikoPascal PRO for PIC32 Routine List Routine list diplays list of routines, and enables filtering 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 the users to manage multiple projects. Several projects which together make project group may be open at the same time.
-
mikroPascal PRO for PIC32 Following options are available in the Project Manager: Icon Description 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 file to the active project. Remove selected file from the project. Build the active project. Run mikroElektronika’s Flash programmer. For details about adding and removing files from project see Add/Remove Files from Project.
-
mikoPascal PRO for PIC32 Project Settings The following options are available in the Project Settings window: - Device - select the appropriate device from the device drop-down list. - MCU Clock - enter the clock frequency value. - Build/Debugger Type - choose debugger type.
-
mikroPascal PRO for PIC32 Library Manager Library Manager enables simple handling libraries being used in a project. Library Manager window lists all libraries (extension .emcl) 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.
-
mikoPascal PRO for PIC32 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 files, 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.
-
mikroPascal PRO for PIC32 Routine List Routine list diplays list of routines, and enables filtering 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. 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.
-
mikoPascal PRO for PIC32 Variables Displays variables sorted by addresses. Used RAM Locations Displays used RAM memory locations and their names.
-
mikroPascal PRO for PIC32 SFR Locations Displays list of used SFR locations. ROM Memory Usage Displays ROM memory space usage in a pie-like form.
-
mikoPascal PRO for PIC32 ROM Memory Constants Displays ROM memory constants and their addresses. Functions Sorts and displays functions in various ways.
-
mikroPascal PRO for PIC32 Functions Sorted By Name Chart Sorts and displays functions by their name, in the ascending order. Functions Sorted By Size Chart Sorts and displays functions by their sizes in a chart-like form.
-
mikoPascal PRO for PIC32 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.
-
mikroPascal PRO for PIC32 Memory Summary Displays summary of RAM and ROM memory in a pie-like form.
-
mikoPascal PRO for PIC32 Messages Window Messages Window displays various informations and notifications 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. The user can filter which notifications will Messages Window display by checking Errors, Warning and Hints box.
-
mikroPascal PRO for PIC32 Quick Converter Quick Converter enables the user to easily transform numbers from one base to another. The 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 float point numbers conversion from/to Float Decimal, Float 32bit (IEEE), Float 32bit (Microchip) and Radix 1.15 for PIC32 family of MCUs.
-
mikoPascal PRO for PIC32 The Macro offers the following commands: Icon Description 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.
-
mikroPascal PRO for PIC32 Now, navigate to the desired image file, and simply add it: Next, right click the added file, and choose Set As Preview Image: 73 MikroElektronika
-
mikoPascal PRO for PIC32 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 fit by its height in such a way that its proportions will remain intact.
-
mikroPascal PRO for PIC32 File Toolbar File Toolbar is a standard toolbar with the following options: Icon Description Opens a new editor window. Open source file for editing or image file 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 the following options: Icon Description Undo last change. Redo last change. Cut selected text to clipboard. Copy selected text to clipboard.
-
mikoPascal PRO for PIC32 Advanced Edit Toolbar Advanced Edit Toolbar comes with the following options: Icon Description Comment selected code or put a 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.
-
mikroPascal PRO for PIC32 Project Toolbar Project Toolbar comes with the following options: Icon Description 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 the following options: Icon Description Build current project. Build all opened projects. Build and program active project. Start programmer and load current HEX file.
-
mikoPascal PRO for PIC32 Debug Toolbar Debug Toolbar comes with the 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.
-
mikroPascal PRO for PIC32 Tools Toolbar Tools Toolbar comes with the following default options: Icon Description Run USART Terminal EEPROM ASCII Chart Seven Segment Editor. Open Active Comment editor. Options menu Tip : The Tools toolbar can easily be customized by adding new tools in Options menu window. View Toolbar View Toolbar provides access to assembly code, listing file and statistics windows. Icon Description Open assembly code in editor. Open listing file in editor.
-
mikoPascal PRO for PIC32 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 Open Help file. How To Register.
-
mikroPascal PRO for PIC32 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.
-
mikoPascal PRO for PIC32 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 .
-
mikroPascal PRO for PIC32 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.
-
mikoPascal PRO for PIC32 Output settings By modifying Output Settings, user can configure the content of the output files. You can enable or disable, for example, generation of ASM and List file. Also, user can choose optimization level, and compiler specific settings, which include case sensitivity, dynamic link for string literals setting (described in mikroPascal PRO for PIC32 specifics). Build all files as library enables user to use compiled library (*.
-
mikroPascal PRO for PIC32 85 MikroElektronika
-
mikoPascal PRO for PIC32 Integrated Tools Active Comments Editor Active Comments Editor is a tool, particularly useful when working with Lcd display. You can launch it from the dropdown menu Tools › Active Comments Editor or by clicking the Active Comment Editor Icon MikroElektronika from Tools toolbar.
-
mikroPascal PRO for PIC32 ASCII Chart The ASCII Chart is a handy tool, particularly useful when working with Lcd display. You can launch it from the dropdown menu Tools › ASCII chart or by clicking the View ASCII Chart Icon 87 from Tools toolbar.
-
mikoPascal PRO for PIC32 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 mikroPascal PRO for PIC32 IDE - project_name.hex file will be loaded automatically while ihex file must be loaded manually.
-
mikroPascal PRO for PIC32 Graphic Lcd Bitmap Editor The mikroPascal PRO for PIC32 includes the Graphic Lcd Bitmap Editor. Output is the mikroPascal PRO for PIC32 compatible code. You can launch it from the drop-down menu Tools › Glcd Bitmap Editor.
-
mikoPascal PRO for PIC32 HID Terminal The mikroPascal PRO for PIC32 includes the HID communication terminal for USB communication. You can launch it from the drop-down menu Tools › HID Terminal. Interrupt Assistant mikroPascal PRO for PIC32 includes the Interrupt Assistant that assist user in configuring interrupts. Output is the code for the configured interrupt routine. You can launch it from the drop-down menu Tools › Interrupt Assistant.
-
mikroPascal PRO for PIC32 Lcd Custom Character mikroPascal PRO for PIC32 includes the Lcd Custom Character. Output is mikroPascal PRO for PIC32 compatible code. You can launch it from the drop-down menu Tools › Lcd Custom Character.
-
mikoPascal PRO for PIC32 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 mikroPascal PRO for PIC32 includes the UDP Terminal.
-
mikroPascal PRO for PIC32 USART Terminal The mikroPascal PRO for PIC32 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.
-
mikoPascal PRO for PIC32 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 file.
-
mikroPascal PRO for PIC32 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).
-
mikoPascal PRO for PIC32 First three event types can have one of the following three actions: 1. OpenUrl - Opens entered URL in default Web browser. 2. OpenFile - Opens a file within a default program associated with the file extension (defined by Windows). 3. None - Does nothing. The fourth event, OnMouseOver, has only 2 actions: 1. PreviewImage - Shows image when cursor is moved over a comment. 2. None - Does nothing. Attributes are tightly bounded with events.
-
mikroPascal PRO for PIC32 You can see the contents of the created XML file by expanding Active Comment Editor: As we mentioned above you can add image or file which are already included in project. If the the desired image or file aren't added, you can do it directly from here by clicking the 97 or button.
-
mikoPascal PRO for PIC32 Next file dialog will be opened: There, you should select the desired image to be added. In our example, Easy_GSM_GPRS.jpg image will be added.
-
mikroPascal PRO for PIC32 Now, when image has been selected, we can assign an event to it. For example, OnMouseOver will be used for PreviewImage action, and OnLeftClick + Alt will be assigned to OpenUrl action: Now we can save our changes to Active Comment by clicking the Save button. Note: Setting file attributes is same as for image, so it won't be explained separately.
-
mikoPascal PRO for PIC32 There is another way to add an active comment to an active project. You can do it simply by typing a comment in old fashion way, except with ac: prefix. So it would look like this: Notice that when you stop typing, Add Comment To Project button will show. By clicking on it, you will open Active Comment Editor and comment name will be already set, so you need only to adjust attributes and settings.
-
mikroPascal PRO for PIC32 If you click No, comment will be removed from the source code.
-
mikoPascal PRO for PIC32 Now click again Rename button. Now you have renamed your Active Comment in such a way that its filename, source code name are changed: Deleting Active Comment Deleting active comment works similar like renaming it. By clicking on delete button, you will remove an active comment from both code and Project Manager.
-
mikroPascal PRO for PIC32 Export Project This option is very convenient and finds its use in relocating your projects from one place to another (e.g. from your work computer to your home computer). Often, project contains complicated search paths (files involved within your project could be in a different folders, even on different hard disks), so it is very likely that some files will be forgotten during manual relocation.
-
mikoPascal PRO for PIC32 Jump To Interrupt Lets you choose which interrupt you want to jump to. Requirement: Interrupt routine is included in project. You can call Jump To Interrupt by selecting Run › Jump To Interrupt from the drop-down menu, or by clicking the Jump To Interrupt Icon , from the Watch Values Window. By checking the Only Used box, you can display only the used breakpoints.
-
mikroPascal PRO for PIC32 Regular Expressions Introduction Regular Expressions are a widely-used method of specifying patterns of text to search for. Special metacharacters allow you to specify, for instance, that a particular string you are looking for, occurs at the beginning, or end of a line, or contains n recurrences of a certain character. Simple matches Any single character matches itself, unless it is a metacharacter with a special meaning described below.
-
mikoPascal PRO for PIC32 Examples: count[aeiou]r finds strings 'countar', 'counter', etc. but not 'countbr', 'countcr', etc. count[^aeiou]r finds strings 'countbr', 'countcr', etc. but not 'countar', 'counter', etc. Within a list, the "-" character is used to specify a range, so that a-z represents all characters between "a" and "z", inclusive. If you want "-" itself to be a member of a class, put it at the start or end of the list, or precede it with a backslash.
-
mikroPascal PRO for PIC32 Metacharacters - Predefined classes \w - an alphanumeric character (including "_") \W - a nonalphanumeric character \d - a numeric character \D - a non-numeric character \s - any space (same as [\t\n\r\f]) \S - a non space You may use \w, \d and \s within custom character classes. Example: so on.
-
mikoPascal PRO for PIC32 Examples: count.*r ß- matches strings like 'counter', 'countelkjdflkj9r' and 'countr' count.+r - matches strings like 'counter', 'countelkjdflkj9r' but not 'countr' count.?r - matches strings like 'counter', 'countar' and 'countr' but not 'countelkj9r' counte{2}r - matches string 'counteer' counte{2,}r - matches strings like 'counteer', 'counteeer', 'counteeer' etc.
-
mikroPascal PRO for PIC32 Keyboard Shortcuts Below is a complete list of keyboard shortcuts available in mikroPascal PRO for PIC32 IDE.
-
mikoPascal PRO for PIC32 Ctrl+F5 Add to Watch List Ctrl+F8 Step Out Alt+D Disassembly View Shift+F5 Open Watch Window Ctrl+Shift+A Show Advanced Breakpoints MikroElektronika 110
-
mikroPascal PRO for PIC32 CHAPTER 3 mikroPascal PRO for PIC32 Command Line Options Usage: mPPIC32.exe [- [-]] [ [-]] [-]] Infile can be of *.c, *.emcl and *.pld type. The following parameters are valid: -P : MCU for which compilation will be done. -FO : Set oscillator [in MHz]. -SP : Add directory to the search path list. -N : Output files generated to file path specified by filename.
-
mikoPascal PRO for PIC32 Example: mPPIC32.exe -MSF -DBG -p32MX460F512L -Y -DL -O11111114 -fo80 -N”C:\Lcd\Lcd.mpp32” -SP”C:\Program Files\Mikroelektronika\mikroPascal PRO for PIC32\Defs” -SP”C:\Program Files\Mikroelektronika\mikroPascal PRO for PIC32\Uses” -SP”C:\Lcd\” “__Lib_Math.emcl” “__Lib_MathDouble.emcl” “__Lib_System.emcl” “__Lib_Delays.emcl” “__Lib_LcdConsts.emcl” “__Lib_Lcd. emcl” “Lcd.mpas” Parameters used in the example: -MSF : Short Message Format; used for internal purposes by IDE.
-
mikroPascal PRO for PIC32 CHAPTER 4 mikroICD (In-Circuit Debugger) Introduction The mikroICD is a highly effective tool for a Real-Time debugging on hardware level. The mikroICD debugger enables you to execute the mikroPascal PRO for PIC32 program on a host PIC32 microcontroller and view variable values, Special Function Registers (SFR), RAM, CODE and EEPROM memory along with the mikroICD code execution on hardware.
-
mikoPascal PRO for PIC32 If you have appropriate hardware and software for using the mikroICD select mikroICD Debug Build Type before compiling the project. Now, compile the project by pressing Ctrl + F9, or by pressing Build Icon on Build Toolbar. Run the mikroICD by selecting Run › Start Debugger from the drop-down menu or by clicking the Start Debugger Icon . Starting the Debugger makes more options available: Step Into, Step Over, Run to Cursor, etc.
-
mikroPascal PRO for PIC32 mikroICD Debugger Options Debugger Options Name Description Function Key Start Debugger Starts Debugger. F9 Stop Debugger Stop Debugger. Ctrl + F2 Run/Pause Debugger Run/Pause Debugger. F6 Step Into Executes the current program line, then halts. If the executed program line calls another routine, the debugger steps into the routine and halts after executing the first instruction within it. F7 Step Over Executes the current program line, then halts.
-
mikoPascal PRO for PIC32 mikroICD Debugger Example Here is a step-by-step mikroICD Debugger Example. First you have to write a program.
-
mikroPascal PRO for PIC32 After successful compilation and MCU programming press F9 to start the mikroICD. After the mikroICD initialization a blue active line should appear. We will debug the program line by line. Pressing [F8] we are executing code line by line. However, it is not recommended that user does not use Step Into [F7] and Step Over [F8] over Delays routines and routines containing delays. Instead use Run to cursor [F4] and Breakpoints functions.
-
mikoPascal PRO for PIC32 Step Into [F7], Step Over [F8] and Step Out [Ctrl+F8] are mikroICD debugger functions that are used in stepping mode. There is also a Real-Time mode supported by the mikroICD. Functions that are used in the Real-Time mode are Run/ Pause Debugger [F6] and Run to cursor [F4]. Pressing F4 executes the code until the program reaches the cursor position line. Run(Pause) Debugger [F6] and Toggle Breakpoints [F5] are mikroICD debugger functions that are used in the RealTime mode.
-
mikroPascal PRO for PIC32 Breakpoints are divided into two groups: hardware and software breakpoints. The hardware breakpoints are placed in the MCU and they provide fastest debugging. Number of hardware breakpoints is limited to 8 (6 instruction, 2 data). If all hardware brekpoints are used, then the next breakpoint will be software breakpoint. These breakpoints are placed inside the mikroICD and simulate hardware breakpoints. Software breakpoints are much slower than hardware breakpoints.
-
mikoPascal PRO for PIC32 mikroICD Debugger Windows Debug Windows This section provides an overview of available Debug Windows in mikroPascal PRO for PIC32: - Breakpoints Window - Watch Values Window - RAM Window - Stopwatch Window - EEPROM Watch Window - Code Watch Window Breakpoints Window The Breakpoints window manages the list of currently set breakpoints in the project. Doubleclicking the desired breakpoint will cause cursor to navigate to the corresponding location in source code.
-
mikroPascal PRO for PIC32 Also, it is possible to add all variables in the Watch Values Window by clicking button. To remove a variable from the Watch Values Window, just select the variable that you want to remove and then click the button, or press the Delete key. It is possible to remove all variables from the Watch Values Window by clicking button. You can also expand/collapse complex variables i.e.
-
mikoPascal PRO for PIC32 RAM Window The RAM Window is available from the drop-down menu, View › Debug Windows › RAM. The RAM Window displays the map of MCU’s RAM, with recently changed items colored red. The user can edit and change the values in the RAM window. mikroICD Specific: RAM window content will be written to the MCU before the next instruction execution. Stopwatch Window The Software Simulator Stopwatch Window is available from the drop-down menu, View › Debug Windows › Stopwatch.
-
mikroPascal PRO for PIC32 Notes: - The user can change the clock in the Stopwatch Window, which will recalculate values for the latest specified frequency. - Changing the clock in the Stopwatch Window does not affect actual project settings – it only provides a simulation. - Stopwatch is available only when Software Simulator is selected as a debugger. EEPROM Watch Window Note: EEPROM Watch Window is available only when mikroICD is selected as a debugger.
-
mikoPascal PRO for PIC32 Code Watch Window Note: Code Watch Window is available only when mikroICD is selected as a debugger. To show the Code Watch Window, select Debug Windows › Code from the View drop-down menu. The Code Watch Window shows code (hex format) written into the MCU. There is one action button concerning the Code Watch Window: - Reads code from the MCU and loads it up into the Code Window. Code reading is resources consuming operation so the user should wait until the reading is over.
-
mikroPascal PRO for PIC32 CHAPTER 5 Software Simulator Overview 125 MikroElektronika
-
mikoPascal PRO for PIC32 Software Simulator The Source-level Software Simulator is an integral component of the mikroPascal PRO for PIC32 environment. It is designed to simulate operations of the Microchip PIC32 MCUs and assist the users in debugging code written for these devices.
-
mikroPascal PRO for PIC32 Software Simulator Debug Windows Debug Windows This section provides an overview of available Debug Windows in mikroPascal PRO for PIC32: - Breakpoints Window - Watch Values Window - RAM Window - Stopwatch Window - EEPROM Watch Window - Code Watch Window Breakpoints Window The Breakpoints window manages the list of currently set breakpoints in the project. Doubleclicking the desired breakpoint will cause cursor to navigate to the corresponding location in source code.
-
mikoPascal PRO for PIC32 Also, it is possible to add all variables in the Watch Values Window by clicking button. To remove a variable from the Watch Values Window, just select the variable that you want to remove and then click the button, or press the Delete key. It is possible to remove all variables from the Watch Values Window by clicking button. You can also expand/collapse complex variables i.e.
-
mikroPascal PRO for PIC32 RAM Window The RAM Window is available from the drop-down menu, View › Debug Windows › RAM. The RAM Window displays the map of MCU’s RAM, with recently changed items colored red. The user can edit and change the values in the RAM window. mikroICD Specific: RAM window content will be written to the MCU before the next instruction execution. Stopwatch Window The Software Simulator Stopwatch Window is available from the drop-down menu, View › Debug Windows › Stopwatch.
-
mikoPascal PRO for PIC32 Notes: - The user can change the clock in the Stopwatch Window, which will recalculate values for the latest specified frequency. - Changing the clock in the Stopwatch Window does not affect actual project settings – it only provides a simulation. - Stopwatch is available only when Software Simulator is selected as a debugger. EEPROM Watch Window Note: EEPROM Watch Window is available only when mikroICD is selected as a debugger.
-
mikroPascal PRO for PIC32 Code Watch Window Note: Code Watch Window is available only when mikroICD is selected as a debugger. To show the Code Watch Window, select Debug Windows › Code from the View drop-down menu. The Code Watch Window shows code (hex format) written into the MCU. There is one action button concerning the Code Watch Window: - Reads code from the MCU and loads it up into the Code Window. Code reading is resources consuming operation so the user should wait until the reading is over.
-
mikoPascal PRO for PIC32 Software Simulator Debugger Options Debugger Options Name Description Function Key Start Debugger Starts Debugger. F9 Stop Debugger Stop Debugger. Ctrl + F2 Run/Pause Debugger Run/Pause Debugger. F6 Step Into Executes the current program line, then halts. If the executed program line calls another routine, the debugger steps into the routine and halts after executing the first instruction within it. F7 Step Over Executes the current program line, then halts.
-
mikroPascal PRO for PIC32 CHAPTER 6 mikroPascal PRO for PIC32 Specifics The following topics cover the specifics of mikroPascal PRO for PIC32 compiler: - ANSI Standard Issues - Predefined Globals and Constants - Accessing Individual Bits - Interrupts - Linker Directives - Built-in Routines - Code Optimization 133 MikroElektronika
-
mikoPascal PRO for PIC32 Predefined Globals and Constants To facilitate PIC32 programming, the mikroPascal PRO for PIC32 implements a number of predefined globals and constants. All PIC32 SFRs are implicitly declared as global variables of volatile word. These identifiers have an external linkage, and are visible in the entire project. When creating a project, the mikroPascal PRO for PIC32 will include an appropriate (*.
-
mikroPascal PRO for PIC32 Accessing Individual Bits The mikroPascal PRO for PIC32 allows you to access individual bits of 32-bit variables. It also supports sbit and bit data types. Lets use the Zero bit as an example. This bit is defined in the definition file of the particular MCU as : const Z = 1; var Z_bit : sbit at SR.B1; To access this bit in your code by its name, you can write something like this: // Clear Zero Bit SR.
-
mikoPascal PRO for PIC32 sbit type The mikroPascal PRO for PIC32 compiler has sbit data type which provides access to bit-addressable SFRs. You can declare a sbit varible in a unit in such way that it points to a specific bit in SFR register: unit MyUnit; var Abit: sbit; sfr; external; // Abit is precisely defined in some external file, for example in the main program unit ... implementation .... end.
-
mikroPascal PRO for PIC32 at keyword You can use the keyword “at” to make an alias to a variable, for example, you can write a library without using register names, and later in the main program to define those registers, for example: unit MyUnit; var PORTAlias: byte; external; // here in the library we can use its symbolic name ... implementation ... end. program MyProgram; ... var PORTAlias: byte at PORTB; // this is where PORTAlias is fully defined ... begin ... end.
-
mikoPascal PRO for PIC32 Interrupts The PIC32MX generates interrupt requests in response to interrupt events from peripheral modules. The Interrupt module exists external to the CPU logic and prioritizes the interrupt events before presenting them to the CPU. The PIC32MX Interrupts module includes the following features: - Up to 96 interrupt sources. - Up to 64 interrupt vectors. - Single and Multi-Vector mode operations. - Five external interrupts with edge polarity control. - Interrupt proximity timer.
-
mikroPascal PRO for PIC32 Interrupt Priorities In the Multi Vector Mode, the user is able to assign a group priority and group subpriority level to each of the interrupt vectors. The user-selectable priority levels range from 1 (the lowest priority) to 7 (the highest). If an interrupt priority is set to zero, the interrupt vector is disabled for both interrupt and wake-up purposes. Interrupt vectors with a higher priority level preempt lower priority interrupts.
-
mikoPascal PRO for PIC32 where: - iv - reserved word that inform the compiler that it is an interrupt service routine. - IVT_ADC - appropriate Interrupt Vector. - ilevel 7 - Interrupt priority level 7. - ics Interrupt Context Saving; Interrupt Context Saving can be performed in several ways: 1. ICS_SOFT - Context saving is carried out by the software. 2. ICS_SRS - Shadow Register set is use for context saving. 3. ICS_OFF - No context saving 4.
-
mikroPascal PRO for PIC32 Interrupt Example Here is a simple example of handling the interrupts from Timer1 (if no other interrupts are allowed): program Timer1_interrupt; procedure Timer1Int(); iv IVT_TIMER_1; ilevel 7; ics ICS_SRS; begin T1IF_bit := 0; // Clear T1IF LATB := not PORTB; // Invert PORTB end; begin AD1PCFG := 0xFFFF; TRISB := 0; LATB := 0xAAAA; // Initialize AN pins as digital // initialize PORTB as output // Initialize PORTB value TMR1 := 0; PR1 := 65000; // reset timer value to zero // L
-
mikoPascal PRO for PIC32 Linker Directives mikroPascal PRO for PIC32 uses an internal algorithm to distribute objects within memory. If you need to have a variable, constant or a routine at the specific predefined address, use the linker directives absolute and org. When using these directives, be sure to use them in proper memory segments, i.e. for functions it is the KSEG0 and for variables it is the KSEG1. Linker directives are used with the virtual addresses.
-
mikroPascal PRO for PIC32 In first case, compiler will recognize your attempt, but in order to save Flash space, and boost performance, it will automatically replace all instances of this constant in code with it’s literal value. In the second case your constant will be placed in Flash in the exact location specified. To place a routine on a specific address in Flash memory you should write the following : procedure proc(par : byte); org 0x9D000000; begin // Procedure will start at address 0x9D000000; ...
-
mikoPascal PRO for PIC32 Built-in Routines mikroPascal PRO for PIC32 compiler provides a set of useful built-in utility functions. Built-in functions do not have any special requirements. You can use them in any part of your project. The Delay_us and Delay_ms routines are implemented as “inline”; i.e. code is generated in the place of a call, so the call doesn’t count against the nested call limit.
-
mikroPascal PRO for PIC32 - KVA0_TO_KVA1 - KVA1_TO_KVA0 - KVA_TO_PA - PA_TO_KVA0 - PA_TO_KVA1 - CP0_Get - CP0_Set - EnableInterrupts - DisableInterrupts Lo Prototype Description function Lo(number: longint): byte; Function returns the lowest byte of number. Function does not interpret bit patterns of number – it merely returns 8 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
-
mikoPascal PRO for PIC32 Higher Prototype Description function Higher(number: longint): byte; Function returns next to the highest byte of number. Function does not interpret bit patterns of number – it merely returns 8 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. Parameters Returns Requires Example - number: input number Returns next to the highest byte of number, bits 16..23.
-
mikroPascal PRO for PIC32 LoWord Prototype Description function LoWord(val : longint) : word; The function returns low word of val. The function does not interpret bit patterns of val – it merely returns 16 bits as found in register. Parameters : Parameters Returns Requires Example - val: input value number Low word of val, bits 15..0. Nothing. d := 0x12345678; tmp := LoWord(d); // Equals 0x5678 LoWord(d) := 0xAAAA; // d equals 0x1234AAAA Notes None.
-
mikoPascal PRO for PIC32 Inc Prototype Description Parameters Returns procedure Inc(var par : longint); Increases parameter par by 1. - par: value which will be incremented by 1 Nothing. Requires Nothing. Example p := 4; Inc(p); Notes None. // p is now 5 Dec Prototype Description Parameters Returns procedure Dec(var par : longint); Decreases parameter par by 1. - par: value which will be decremented by 1 Nothing. Requires Nothing. Example p := 4; Dec(p); Notes None.
-
mikroPascal PRO for PIC32 Ord Prototype Description function Ord(const character : char) : byte; Function returns ASCII code of the character. This is an “inline” routine; the code is generated in the place of the call. Parameters Returns - character: input character ASCII code of the character. Requires Nothing. Example c := Ord(‘A’); Notes None. // returns 65 SetBit Prototype Description procedure SetBit(var register_ : word; rbit : byte); Function sets the bit rbit of register_.
-
mikoPascal PRO for PIC32 TestBit Prototype Description function TestBit(register_, rbit : byte) : byte; Function tests if the bit rbit of register is set. If set, function returns 1, otherwise returns 0. Parameter rbit needs to be a variable or literal with value 0..7. See Predefined globals and constants for more information on register identifiers. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
-
mikroPascal PRO for PIC32 VDelay_ms Prototype Description Parameters Returns Requires Example Notes procedure VDelay_ms(Time_ms : word); Creates a software delay in duration of Time_ms milliseconds. Generated delay is not as precise as the delay created by Delay_ms. - Time_ms: delay time in milliseconds Nothing. Nothing. var pause : word; ... VDelay_ms(pause); None.
-
mikoPascal PRO for PIC32 Delay_Cyc_Long Prototype Description Parameters Returns procedure Delay_Cyc_Long(CycNo : word); Creates a delay based on MCU clock. Delay lasts for CycNo MCU clock cycles. - CycNo: number of MCU cycles Nothing. Requires Nothing. Example Delay_Cyc_Long(16384); Notes Delay_Cyc_Long is a library function rather than a built-in routine; it is presented in this topic for the sake of convenience.
-
mikroPascal PRO for PIC32 Get_Fosc_kHz Prototype Description function Get_Fosc_kHz() : longint; Function returns device clock in kHz, rounded to the nearest integer. Parameters None. Returns Device clock in kHz. Requires Nothing. Example clk := Get_Fosc_kHz(); Notes - Get_Fosc_kHz is a library function rather than a built-in routine; it is presented in this topic for the sake of convenience.
-
mikoPascal PRO for PIC32 ClrWdt Prototype Description Parameters procedure ClrWdt(); This procedure is equal to assembler instruction clrwdt. None. Returns Nothing. Requires Nothing. Example ClrWdt(); // Clears WDT Notes None. DisableContextSaving Prototype Description procedure DisableContextSaving(); Use the DisableContextSaving() to instruct the compiler not to automatically perform contextswitching.
-
mikroPascal PRO for PIC32 SetFuncCall Prototype Description procedure SetFuncCall(FuncName: string); If the linker encounters an indirect function call (by a pointer to function), it assumes that any routine whose address was taken anywhere in the program can be called at that point if it’s prototype matches the pointer declaration. Use the SetFuncCall directive within routine body to instruct the linker which routines can be called indirectly from that routine : SetFunCCall (called_func[, ,...
-
mikoPascal PRO for PIC32 DoGetDateTime Prototype Description Parameters function DoGetDateTime() : string; Use the GetDateTime() to get date and time of compilation as string in your code. None. Returns String with date and time when this routine is compiled. Requires Nothing. Example str := GetDateTime(); Notes None. GetVersion Prototype Description Parameters function GetVersion() : string; Use the GetVersion(); to get the current version of compiler. None.
-
mikroPascal PRO for PIC32 KVA1_TO_KVA0 Prototype Description function KVA1_TO_KVA0(Address: dword) : dword; Function converts virtual address from KSEG1 to the virtual address in the KSEG0. Parameters Desired Virtual address in the KSEG1. Returns Virtual address in the KSEG0. Requires Nothing. Example address := KVA1_TO_KVA0(0xBFC00000); Notes None.
-
mikoPascal PRO for PIC32 CP0_GET Prototype Description function CP0_GET(const register: TCP0REG): dword; Function returns the value of the coprocessor register or part of the register, based upon the argument entered. Parameters Parameter must be a constant from the enumerated built-in constants list, which can be found at the bottom of this page. Returns Value of the coprocessor register or part of the register. Requires Nothing.
-
mikroPascal PRO for PIC32 DisableInterrupts Prototype Description procedure DisableInterrupts(); Function disables interrupts. Parameters None. Returns Nothing. Requires Nothing. Example EnableInterrupts(); Notes None.
-
mikoPascal PRO for PIC32 Copressor Register Fields CP0_HWRENA_MASK CP0_STATUS_IE CP0_STATUS_EXL CP0_STATUS_ERL CP0_STATUS_UM CP0_STATUS_IM0 CP0_STATUS_IM1 CP0_STATUS_IPL CP0_STATUS_IM2 CP0_STATUS_IM3 CP0_STATUS_IM4 CP0_STATUS_IM5 CP0_STATUS_IM6 CP0_STATUS_IM7 CP0_STATUS_CEE CP0_STATUS_NMI _CPO_STATUS_SR CP0_STATUS_TS CP0_STATUS_BEV CP0_STATUS_RE CP0_STATUS_FR CP0_STATUS_RP CP0_STATUS_CU0 CP0_STATUS_CU1 CP0_STATUS_CU2 CP0_STATUS_CU3 CP0_INTCTL_VS CP0_INTCTL_IPPCI CP0_INTCTL_IPTI
-
mikroPascal PRO for PIC32 Code Optimization Optimizer has been added to extend the compiler usability, cut down the amount of code generated and speed-up its execution. The main features are: Constant folding All expressions that can be evaluated in the compile time (i.e. constant) are being replaced by their results.
-
mikoPascal PRO for PIC32 Single Static Assignment Optimization Introduction In compiler design, static single assignment form (often abbreviated as SSA form or SSA) is an intermediate representation (IR) in which every variable is assigned exactly once. An SSA-based compiler modifies the program representation so that every time a variable is assigned in the original program, a new version of the variable is created.
-
mikroPascal PRO for PIC32 ;Example.mpas, 29 :: 0x9D000000 0x033A1021 ADDU 0x9D000004 0x10400002 BEQ 0x9D000008 0x70000000 NOP if (y+k) then R2, R25, R26 R2, R0, L__SSA_Test2 Without SSA enabled, procedure SSA_Test is consisted of 5 asm instructions : ;Example.
-
mikoPascal PRO for PIC32 Asm code and SSA optimization If converting code from an earlier version of the compiler, which consists of mixed asm code with the Pascal code, keep in mind that the generated code can substantially differ when SSA optimization option is enabled or disabled. This is due to the fact that SSA optimization uses certain working registers to store routine parameters (W10-W13), rather than storing them onto the function frame.
-
mikroPascal PRO for PIC32 165 MikroElektronika
-
CHAPTER 7 mikoPascal PRO for PIC32 PIC32 Specifics In order to get the most from the mikroPascal PRO for PIC32 compiler, the user should be familiar with certain aspects of PIC32 MCU. This knowledge is not essential, but it can provide a better understanding of the PIC32’s capabilities and limitations, and their impact on the code writing as well.
-
mikroPascal PRO for PIC32 Types Efficiency First of all, the user should know that PIC32’s ALU, which performs arithmetic operations, is optimized for working with 32-bit types. Also, it performs hardware multiplication and division on the integer level, so the floating multiplication and division is slower and consumes more memory comparing it to the integer. The PIC32 supports 64-bit data types, but they are less efficient. They provide higher precision, but lack the code size and the execution.
-
mikoPascal PRO for PIC32 PIC32 Memory Organization The PIC32MX microcontrollers provide 4 GB of unified virtual memory address space. All memory regions, including program memory, data memory, SFRs and Configuration registers reside in this address space at their respective unique addresses. The program and data memories can be optionally partitioned into user and kernel memories. In addition, the data memory can be made executable, allowing the PIC32MX to execute from data memory.
-
mikroPascal PRO for PIC32 PIC32MX Memory Layout The PIC32MX microcontrollers implement two address spaces: virtual and physical. All hardware resources, such as program memory, data memory and peripherals, are located at their respective physical addresses. Peripherals, such as DMA and Flash controllers, use physical addresses and access memory independently of the CPU. Virtual addresses are exclusively used by the CPU to fetch and execute instructions.
-
mikoPascal PRO for PIC32 As it can be seem, the entire 4 GB virtual address space is divided into two primary regions: User and Kernel space. The lower 2 GB of space called USEG/KUSEG, and the upper 2 GB are divided into KSEG0, KSEG1, KSEG2 and KSEG3. Virtual vs Physical Addresses The PIC32MX’s CPU uses virtual addresses to address the peripherals, which means that to access the PIC32MX’s peripherals we (and the CPU) must be operating within the virtual boundaries of KSEG1.
-
mikroPascal PRO for PIC32 Memory Type Specifiers The mikroPascal PRO for PIC32 supports usage of all memory areas. Each variable may be explicitly assigned to a specific memory space by including a memory type specifier in the declaration, or implicitly assigned. The following memory type specifiers can be used: - code data rx (reserved for compiler purposes only) sfr code Description The code memory type may be used for allocating constants in program memory.
-
mikoPascal PRO for PIC32 Read Modify Write Problem The Microchip microcontrollers use a sequence known as Read-Modify-Write (RMW) when changing an output state (1 or 0) on a pin. This can cause unexpected behavior under certain circumstances. When your program changes the state on a specific pin, for example RB0 in PORTB, the microcontroller first READs all 8 bits of the PORTB register which represents the states of all 8 pins in PORTB (RB7-RB0). The microcontroller then stores this data in the MCU.
-
mikroPascal PRO for PIC32 Actual voltage levels on MCU pins are relevant. MODIFY Data is modified to set the RB0 bit: WRITE PORTB is written with the modified data. The output driver for RB0 turns on, and the capacitor starts to charge: The second line, PORTB.
-
mikoPascal PRO for PIC32 To correct the problem in the code, insert a delay after each PORTB.Bx = 1 line, or modify the entire PORTB register in a single line PORTB = 0b00000011. This problem can be avoided by using LATx register when writing to ports, rather than using PORTx registers. Writing to a LATx register is equivalent to writing to a PORTx register, but readings from LATx registers return the data value held in the port latch, regardless of the state of the actual pin.
-
mikroPascal PRO for PIC32 The second line, LATB.B1 = 1; will be decoded like in this way: READ LATB is read: STORE Since the voltage levels on MCU pins are no longer relevant, we get the expected value: Actual voltage levels on MCU pins are no longer relevant when using LATx for output MODIFY Data is modified to set the bit: WRITE LATB is written with the new data.
-
CHAPTER 8 mikoPascal PRO for PIC32 mikroPascal PRO for PIC32 Language Reference - Lexical Elements - Whitespace - Comments - Tokens - Literals - Keywords - Identifiers - Punctuators - Program Organization - Program Organization - Scope and Visibility - Units - Variables - Constants - Labels - Functions and Procedures - Functions - Procedures - Types - Simple Types - Arrays - Strings - Pointers MikroElektronika 176
-
mikroPascal PRO for PIC32 - Introduction to Pointers - Function Pointers - Pointer Arithmetic - Records - Types Conversions - Implicit Conversion - Explicit Conversion - Operators - Introduction to Operators - Operators Precedence and Associativity - Arithmetic Operators - Relational Operators - Bitwise Operators - Boolean Operators - Expressions - Expressions - Statements - Introduction to Statements - Assignment Statements - Compound Statements (Blocks) - Conditional Statements -
-
mikoPascal PRO for PIC32 Lexical Elements Overview The following topics provide a formal definition of the mikroPascal PRO for PIC32 lexical elements. They describe different categories of word-like units (tokens) recognized by the language. In the tokenizing phase of compilation, the source code file is parsed (i.e. broken down) into tokens and whitespace. The tokens in mikroPascal PRO for PIC32 are derived from a series of operations performed on your programs by the compiler.
-
mikroPascal PRO for PIC32 some_string := 'mikro foo'; parses into four tokens, including a single string literal token: some_string := 'mikro foo' ; Comments Comments are pieces of a text used to annotate a program, and are technically another form of whitespace. Comments are for the programmer’s use only. They are stripped from the source text before parsing. There are two ways to create comments in mikroPascal.
-
mikoPascal PRO for PIC32 Tokens Token is the smallest element of a mikroPascal PRO for PIC32 program, meaningful to the compiler. The parser separates tokens from the input stream by creating the longest token possible using the input characters in a left–to– right scan. mikroPascal PRO for PIC32 recognizes the following kinds of tokens: - keywords - identifiers - constants - operators - punctuators (also known as separators) Token Extraction Example Here is an example of token extraction.
-
mikroPascal PRO for PIC32 Literals Literals are tokens representing fixed numeric or character values. The data type of a constant is deduced by the compiler using such clues as numeric value and format used in the source code. Integer Literals Integral values can be represented in decimal, hexadecimal or binary notation. In decimal notation, numerals are represented as a sequence of digits (without commas, spaces or dots), with optional prefix + or - operator to indicate the sign.
-
mikoPascal PRO for PIC32 Character Literals Character literal is one character from the extended ASCII character set, enclosed with apostrophes. Character literal can be assigned to variables of the byte and char type (variable of byte will be assigned the ASCII value of the character). Also, you can assign character literal to a string variable. Note : Quotes ("") have no special meaning in mikroPascal PRO for PIC32.
-
mikroPascal PRO for PIC32 Keywords Keywords are words reserved for special purposes and must not be used as normal identifier names. Beside standard Pascal keywords, all relevant SFRs are defined as global variables and represent reserved words that cannot be redefined (for example: W0, TMR1, T1CON, etc). Probe the Code Assistant for specific letters (Ctrl+Space in Editor) or refer to Predefined Globals and Constants.
-
mikoPascal PRO for PIC32 Identifiers Identifiers are arbitrary names of any length given to functions, variables, symbolic constants, user-defined data types and labels. All these program elements will be referred to as objects throughout the help (don't get confused about the meaning of object in object-oriented programming). Identifiers can contain the letters a to z and A to Z, underscore character “_”, and digits from 0 to 9.
-
mikroPascal PRO for PIC32 Punctuators The mikroPascal PRO for PIC32 punctuators (also known as separators) are: [ ] – Brackets ( ) – Parentheses , – Comma ; – Semicolon : – Colon . – Dot Brackets Brackets [ ] indicate single and multidimensional array subscripts: var alphabet : array[1..30] of byte; // ... alphabet[3] := 'c'; For more information, refer to Arrays.
-
mikoPascal PRO for PIC32 Semicolon Semicolon (;) is a statement terminator. Every statement in Pascal must be terminated with a semicolon. The exceptions are: the last (outer most) end statement in the program which is terminated with a dot and the last statement before end which doesn't need to be terminated with a semicolon. For more information, see Statements. Colon Colon (:) is used in declarations to separate identifier list from type identifier.
-
mikroPascal PRO for PIC32 Program Organization mikroPascal PRO for PIC32 imposes strict program organization. Below you can find models for writing legible and organized source files. For more information on file inclusion and scope, refer to Units and Scope and Visibility. Organization of Main Unit Basically, the main source file has two sections: declaration and program body. Declarations should be in their proper place in the code, organized in an orderly manner.
-
mikoPascal PRO for PIC32 Organization of Other Units Units other than main start with the keyword unit. Implementation section starts with the keyword implementation. Follow the model presented below: unit { unit name } uses { include other units } //******************************************************** //* Interface (globals): //******************************************************** { constants declarations } const ... { types declarations } type ... { variables declarations } var Name[, Name2...
-
mikroPascal PRO for PIC32 { functions declarations } function function_name([var] [const] ParamName : [^]type; [var] [const] ParamName2, ParamName3 : [^]type) : [^]type; [ilevel 0x123;] [overload;] [forward;] { local declarations } begin ... end; end. Note : - Constants, types and variables used in the implementation section are inaccessible to other units. This feature is not applied to the procedures and functions in the current version, but it will be added to the future ones.
-
mikoPascal PRO for PIC32 Name Spaces Name space is a scope within which an identifier must be unique. The mikroPascal PRO for PIC32 uses two distinct categories of identifiers: 1. Global variables are visible throughout the whole unit, from the place of declaration. Also. they can be seen in other units, if they are declared above the Implementation section. 2. Local variables, parameters, types, function results - must be unique within the block in which they are declared.
-
mikroPascal PRO for PIC32 Units In mikroPascal PRO for PIC32, each project consists of a single project file and one or more unit files. Project file, with extension .mpp32 contains information about the project, while unit files, with extension .mpas, contain the actual source code.
-
mikoPascal PRO for PIC32 Nothing should precede the keyword program except comments. After the program name, you can optionally place the uses clause. Place all global declarations (constants, variables, types, labels, routines) before the keyword begin. Other Units Units other than main start with the keyword unit. Newly created blank unit contains the bare-bones: unit MyUnit; implementation end. Other than comments, nothing should precede the keyword unit.
-
mikroPascal PRO for PIC32 Variables Variable is an object whose value can be changed during the runtime. Every variable is declared under unique name which must be a valid identifier. This name is used for accessing the memory location occupied by a variable. Variables are declared in the declaration part of the file or routine — each variable needs to be declared before being used.
-
mikoPascal PRO for PIC32 In the First_Unit we will define and declare routine called pi_r_squared (calculates pi multiplied by the radius squared): unit First_Unit; procedure pi_r_squared(rr : real); // Declaration of the pi_r_squared routine implementation procedure pi_r_squared(rr : real); var res : real; // Definition of the pi_r_squared routine begin res := rr*3.14; end; end. In the Second_Unit we will make a call to the routines defined externally (r_squared and pi_r_squared).
-
mikroPascal PRO for PIC32 Constants Constant is a data whose value cannot be changed during the runtime. Using a constant in a program consumes no RAM memory. Constants can be used in any expression, but cannot be assigned a new value. Constants are declared in the declaration part of a program or routine. You can declare any number of constants after the keyword const: const constant_name [: type] = value; Every constant is declared under unique constant_name which must be a valid identifier.
-
mikoPascal PRO for PIC32 Labels Labels serve as targets for goto statements. Mark the desired statement with a label and colon like this: label_identifier : statement Before marking a statement, you must declare a label. Labels are declared in declaration part of unit or routine, similar to variables and constants. Declare labels using the keyword label: label label1, ..., labeln; Name of the label needs to be a valid identifier.
-
mikroPascal PRO for PIC32 Functions and Procedures Functions and procedures, collectively referred to as routines, are subprograms (self-contained statement blocks) which perform a certain task based on a number of input parameters. When executed, a function returns a value while procedure does not.
-
mikoPascal PRO for PIC32 Now we could call it to calculate, say, 312: tmp := power(3, 12); Procedures Procedure is declared like this: procedure procedure_name(parameter_list); { local declarations } begin { procedure body } end; procedure_name represents a procedure’s name and can be any valid identifier. Within parentheses, parameter_ list is a formal parameter list very similar to variable declaration.
-
mikroPascal PRO for PIC32 Example: This example shows how to declare a function which returns a complex type. program Example; type TCircle = record // Record CenterX, CenterY: word; Radius: byte; end; var MyCircle: TCircle; // Global variable function DefineCircle(x, y: word; r: byte): TCircle; // DefineCircle function returns a Record begin result.CenterX := x; result.CenterY := y; result.Radius := r; end; begin MyCircle := DefineCircle(100, 200, 30); // Get a Record via function call MyCircle.
-
mikoPascal PRO for PIC32 function First(a, b : word) : word; begin result := a * b; end; begin Volume := Second(4); end. Functions reentrancy Functions reentrancy is allowed. Remember that the PIC32 have memory limitations that can vary between MCUs. Types Pascal is strictly typed language, which means that every variable and constant need to have a strictly defined type, known at the time of compilation.
-
mikroPascal PRO for PIC32 Simple Types Simple types represent types that cannot be divided into more basic elements and are the model for representing elementary data on machine level. Basic memory unit in mikroPascal PRO for PIC32 has 32 bits. Here is an overview of simple types in mikroPascal PRO for PIC32: Type bit sbit byte, char short word integer dword longint Size Range 1–bit 0 or 1 1–bit 0 or 1 8–bit 0 .. 255 8–bit -127 .. 128 16–bit 0 .. 65535 16–bit -32768 .. 32767 32–bit 0 .
-
mikoPascal PRO for PIC32 Arrays An array represents an indexed collection of elements of the same type (called the base type). Because each element has a unique index, arrays, unlike sets, can meaningfully contain the same value more than once. Array Declaration Array types are denoted by constructions in the following form: array[index_start .. index_end] of type Each of the elements of an array is numbered from index_start through index_end.
-
mikroPascal PRO for PIC32 Strings A string represents a sequence of characters equivalent to an array of char. It is declared like this: string_name : string[length] The specifier length is a number of characters the string consists of. The string is stored internally as the given sequence of characters plus a final null character (zero) which is introduced to terminate the string. It does not count against the string’s total length. A null string ('') is stored as a single null character.
-
mikoPascal PRO for PIC32 var msg : string[20]; res_txt : string[5]; res, channel : word; begin //... // Get result of ADC res := Adc_Read(channel); // Create string out of numeric result WordToStr(res, res_txt); // Prepare message for output msg := 'Result is ' + // Text "Result is" res_txt ; // Result of ADC //... Notes : - In current version plus operator for concatenating strings will accept at most two operands.
-
mikroPascal PRO for PIC32 var ptr1: ^const byte; // ptr1 pointer in data space pointing to a byte in code space var ptr2: ^const ^volatile sfr byte; rx; // ptr2 is pointer in rx space pointing to a pointer in code space pointing to volatile byte in sfr space var ptr3: ^data byte; code; // error, pointers can not be placed in code space Due to backward compatibility, pointers to program memory space can also be declared within constant declaration block (using keyword const): program const_ptr; // constant a
-
mikoPascal PRO for PIC32 program Example; type TMyFunctionType = function (param1, param2: byte; param3: word) : word; // First, define the procedural type var MyPtr: ^TMyFunctionType; // This is a pointer to previously defined type Sample: word; function Func1(p1, p2: byte; p3: word): word; // Now, define few functions which will be pointed to.
-
mikroPascal PRO for PIC32 @ Operator The @ operator constructs a pointer to its operand. The following rules are applied to @: - If X is a variable, @X returns a pointer to X. Note : If variable X is of array type, the @ operator will return pointer to it's first basic element, except when the left side of the statement in which X is used is an array pointer. In this case, the @ operator will return pointer to array, not to it's first basic element.
-
mikoPascal PRO for PIC32 var ptr1 : ^byte; ptr2 : ^byte; a : array[10] of byte; // array a containing 10 elements of type byte begin ptr1 := @a[4]; ptr2 := @a[2]; if (ptr1 = ptr2) then ... if (ptr1 > ptr2) then ... if (ptr1^ = pointed to by if (ptr1^ > pointed to by end. // won't be executed as 4 is not equal to 2 // will be executed as 4 is greater than 2 ptr2^) then ... // if the value pointed to by ptr1 is equal to the value ptr2 ... ptr2^) then ...
-
mikroPascal PRO for PIC32 j := 5; // assign value 10 to variable; j is at the address 0x003A ptr1 := @i; ptr2 := @j; // ptr1 is pointer to byte, pointing to i // ptr2 is a pointer pointing to j x := ptr1^ + ptr2^; end. // result is equal to the sum of the values pointed to; x = 5 Pointer Subtraction Similar to addition, you can use Dec to subtract an integral value from a pointer.
-
mikoPascal PRO for PIC32 Records A record (analogous to a structure in some languages) represents a heterogeneous set of elements. Each element is called a field. The declaration of the record type specifies a name and type for each field. The syntax of a record type declaration is type recordTypeName = record fieldList1 : type1; ...
-
mikroPascal PRO for PIC32 circle1.radius := 3.7; circle1.center.x := 0; circle1.center.y := 0; Accessing the fields is possible via the with statement as well. You can also commit assignments between complex variables, if they are of the same type: circle2 := circle1; // This will copy values of all fields Types Conversions Conversion of variable of one type to a variable of another type is typecasting. mikroPascal PRO for PIC32 supports both implicit and explicit conversions for built-in types.
-
mikoPascal PRO for PIC32 Clipping In assignments and statements that require an expression of particular type, destination will store the correct value only if it can properly represent the result of expression, i.e. if the result fits in destination range. If expression evaluates to a more complex type than expected, excess of data will be simply clipped (higher bytes are lost). var i : byte; j : word; //...
-
mikroPascal PRO for PIC32 begin a := 241; b := 128; cc cc dd := a + b; := word(a + b); := a + b; // equals 113 // equals 113 // equals 369 ptr := TBytePtr(@arr); ptr := ^byte(@arr); end. Type Specifier The specifier type introduces a synonym for a specified type. The type declarations are used to construct shorter or more convenient names for types already defined by the language or declared by the user.
-
mikoPascal PRO for PIC32 Type Qualifiers The type qualifiers const and volatile are optional in declarations and do not actually affect the type of declared object. Qualifier const The qualifier const implies that a declared object will not change its value during runtime. In declarations with the const qualifier all objects need to be initialized. The mikroPascal PRO for PIC32 treats objects declared with the const qualifier the same as literals or preprocessor constants.
-
mikroPascal PRO for PIC32 Operators Precedence and Associativity There are 4 precedence categories in mikroPascal PRO for PIC32. Operators in the same category have equal precedence with each other. Each category has an associativity rule: left-to-right (→), or right-to-left (←). In the absence of parentheses, these rules resolve the grouping of expressions with operators of equal precedence.
-
mikoPascal PRO for PIC32 Unary Arithmetic Operators Operator - can be used as a prefix unary operator to change sign of a signed value. Unary prefix operator + can be used, but it doesn’t affect data. For example: b := -a; Relational Operators Use relational operators to test equality or inequality of expressions. All relational operators return TRUE or FALSE. All relational operators associate from left to right.
-
mikroPascal PRO for PIC32 Bitwise Operators Use bitwise operators to modify individual bits of numerical operands. Bitwise operators associate from left to right. The only exception is the bitwise complement operator not which associates from right to left.
-
mikoPascal PRO for PIC32 Unsigned and Conversions If a number is converted from less complex to more complex data type, the upper bytes are filled with zeroes. If a number is converted from more complex to less complex data type, the data is simply truncated (the upper bytes are lost). For example: var ...
-
mikroPascal PRO for PIC32 Boolean Operators Although mikroPascal PRO for PIC32 does not support boolean type, you have Boolean operators at your disposal for building complex conditional expressions. These operators conform to standard Boolean logic and return either TRUE (all ones) or FALSE (zero): Operator Operation and logical AND or xor not logical OR logical exclusive OR (XOR) logical negation Boolean operators associate from left to right. Negation operator not associates from right to left.
-
mikoPascal PRO for PIC32 Operator Operation ^ accesses a value indirectly, through a pointer; result is the value at the address to which operand points @ constructs a pointer to its operand See Pointers for more details on this subject Note : Besides these, sizeof and explicit conversion unary operators are supported also.
-
mikroPascal PRO for PIC32 Expressions An expression is a sequence of operators, operands and punctuators that returns a value. The primary expressions include: literals, constants, variables and function calls. More complex expressions can be created from primary expressions by using operators. Formally, expressions are defined recursively: subexpressions can be nested up to the limits of memory.
-
mikoPascal PRO for PIC32 Conditional expressions Conditional expressions may differ from the same code in assignment expressions (due to left side exception). Example : a: dword; b: byte if b*5 then... // byte level - general rule will not give same result as a := b * 5 if a then... // word level - general rule + left side exception if b*5 exceeds byte range. Explicit Typecasting Any expression can be evaluated at specific level by using explicit typecasting.
-
mikroPascal PRO for PIC32 Assignment Statements Assignment statements have the following form: variable := expression; The statement evaluates expression and assigns its value to variable. All the rules of implicit conversion are applied. Variable can be any declared variable or array element, and expression can be any expression. Do not confuse the assignment with relational operator = which tests for equality.
-
mikoPascal PRO for PIC32 If Statement Use the keyword if to implement a conditional statement. The syntax of the if statement has the following form: if expression then statement1 [else statement2] If expression evaluates to true then statement1 executes. If expression is false then statement2 executes. The expression must convert to a boolean type; otherwise, the condition is ill-formed. The else keyword with an alternate statement (statement2) is optional.
-
mikroPascal PRO for PIC32 Case Statement Use the case statement to pass control to a specific program branch, based on a certain condition. The case statement consists of a selector expression (a condition) and a list of possible values. The syntax of the case statement is: case selector of value_1 : statement_1 ... value_n : statement_n [else default_statement] end; selector is an expression which should evaluate as integral value.
-
mikoPascal PRO for PIC32 Iteration Statements Iteration statements let you loop a set of statements. There are three forms of iteration statements in mikroPascal PRO for PIC32: - for - while...do - repeat You can use the statements break and continue to control the flow of a loop statement. break terminates the statement in which it occurs, while continue begins executing the next iteration of the sequence.
-
mikroPascal PRO for PIC32 While Statement Use the while keyword to conditionally iterate a statement. The syntax of the while statement is: while expression do statement statement is executed repeatedly as long as expression evaluates true. The test takes place before the statement is executed. Thus, if expression evaluates false on the first pass, the loop does not execute.
-
mikoPascal PRO for PIC32 Jump Statements The jump statement, when executed, transfers control unconditionally. There are four such statements in mikroPascal PRO for PIC32: - break - continue - exit - goto asm Statement mikroPascal PRO for PIC32 allows embedding assembly in the source code by means of the asm statement. Note that you cannot use numerals as absolute addresses for register variables in assembly instructions.
-
mikroPascal PRO for PIC32 Here is an example of using asm instructions : program asm_example; var myvar : word; absolute 0x2678; const msg = 'Hello'; org 0x3678; var myvar1 : dword; procedure proc(); org 0x1234; begin asm nop end; end; begin myvar := 5; myvar1 := 0xABCD1234; asm MOV _myvar, w0 nop MOV #6, W0 MOV W0, _myvar MOV #lo_addr(_myvar), w1 it to W1 (0x2678 -> W1) MOV #hi_addr(_myvar), W1 move it to W1 (0x0000 -> W1) MOV #lo_addr(_proc), W0 move it to W0 (0x0001 -> W1) MOV #lo_addr(_msg), W0 and mov
-
mikoPascal PRO for PIC32 With Statement The With statement is a convenient method for referencing elements of a complex variable, such as a record. It simplifies the code by removing the need to prefix each referenced element with the complex variable name; i.e. accessing all of the record's fields with only one reference.
-
mikroPascal PRO for PIC32 Directives $DEFINE and $UNDEFINE Use directive $DEFINE to define a conditional compiler constant (“flag”). You can use any identifier for a flag, with no limitations. No conflicts with program identifiers are possible because the flags have a separate name space. Only one flag can be set per directive. For example: {$DEFINE Extended_format} Use $UNDEFINE to undefine (“clear”) previously defined flag.
-
mikoPascal PRO for PIC32 Unlike $IFDEF, $IFNDEF checks if flag is not defined by means of $DEFINE, thus producing the opposite results. Include Directive $I The $I parameter directive instructs mikroPascal PRO for PIC32 to include the named text file in the compilation. In effect, the file is inserted in the compiled text right after the {$I filename} directive.
-
mikroPascal PRO for PIC32 Directive org Directive org specifies the starting address of a constant or a routine in ROM. It is appended to the constant or a routine declaration. To place a constant array in Flash memory, write the following : // Constant array MONTHS will be placed starting from the address 0x9D000000 const MONTHS : array[1..
-
CHAPTER 9 mikoPascal PRO for PIC32 mikroPascal PRO for PIC32 Libraries mikroPascal PRO for PIC32 provides a set of libraries which simplify the initialization and use of PIC32 and their modules: Use Library manager to include mikroPascal PRO for PIC32 Libraries in you project.
-
mikroPascal PRO for PIC32 Hardware Libraries - ADC Library - CANSPI Library - Compact Flash Library - Epson S1D13700 Graphic Lcd Library - Flash Memory Library - Graphic Lcd Library - I²C Library - Keypad Library - Lcd Library - Manchester Code Library - Memory Manager Library - Multi Media Card Library - OneWire Library - Port Expander Library - PS/2 Library - PWM Library - RS-485 Library - Software I²C Library - Software SPI Library - Software UART Library - Sound Library - SPI Library - SPI Ethernet Lib
-
mikoPascal PRO for PIC32 Hardware Libraries - ADC Library - CANSPI Library - Compact Flash Library - Epson S1D13700 Graphic Lcd Library - Flash Memory Library - Graphic Lcd Library - I²C Library - Keypad Library - Lcd Library - Manchester Code Library - Memory Manager Library - Multi Media Card Library - OneWire Library - Port Expander Library - PS/2 Library - PWM Library - RS-485 Library - Software I²C Library - Software SPI Library - Software UART Library - Sound Library - SPI Library - SPI Ethernet Libr
-
mikroPascal PRO for PIC32 ADC Library ADC (Analog to Digital Converter) module is available with a number of PIC32 MCU modules. ADC is an electronic circuit that converts continuous signals to discrete digital numbers. ADC Library provides you a comfortable work with the module. Library Routines - ADC1_Init - ADC1_Init_Advanced - ADC1_Get_Sample - ADC1_Read ADC1_Init Prototype procedure ADC1_Init(); Description This routines configures ADC module to work with default settings.
-
mikoPascal PRO for PIC32 ADC1_Init_Advanced Prototype procedure ADC1_Init_Advanced(Reference : word); Description This routine configures the internal ADC module to work with user defined settings. Parameters - Reference: voltage reference used in ADC process. Description Predefined library const Voltage reference: Internal voltage reference _ADC_INTERNAL_REF External voltage reference _ADC_EXTERNAL_REF Returns Nothing. Requires - The MCU with built-in ADC module.
-
mikroPascal PRO for PIC32 ADC1_Read Prototype function ADC1_Read(channel : word) : word; Description The function initializes, enables ADC module and reads the specified analog channel input. Parameters - channel represents the channel from which the analog value is to be acquired. Returns Requires Example Notes 239 10-bit unsigned value from the specified channel. - The MCU with built-in ADC module.
-
mikoPascal PRO for PIC32 Library Example This code snippet reads analog value from the channel 1 and sends readings as a text over UART1.
-
mikroPascal PRO for PIC32 CANSPI Library The SPI module is available with a number of the PIC32 MCUs. The mikroPascal PRO for PIC32 provides a library (driver) for working with mikroElektronika’s CANSPI Add-on boards (with MCP2515 or MCP2510) via SPI interface. The CAN is a very robust protocol that has error detection and signalization, selfchecking and fault confinement. Faulty CAN data and remote frames are re-transmitted automatically, similar to the Ethernet. Data transfer rates depend on distance.
-
mikoPascal PRO for PIC32 Library Routines - CANSPISetOperationMode - CANSPIGetOperationMode - CANSPIInit - CANSPISetBaudRate - CANSPISetMask - CANSPISetFilter - CANSPIRead - CANSPIWrite CANSPISetOperationMode Prototype procedure CANSPISetOperationMode(mode : byte; WAIT: byte); Description Sets the CANSPI module to requested mode. Parameters - mode: CANSPI module operation mode. Valid values: CANSPI_OP_MODE constants. See CANSPI_ OP_MODE constants. - WAIT: CANSPI mode switching verification request.
-
mikroPascal PRO for PIC32 CANSPIGetOperationMode Prototype function CANSPIGetOperationMode() : byte; Description The function returns current operation mode of the CANSPI module. Check CANSPI_OP_MODE constants or device datasheet for operation mode codes. Parameters None. Returns Current operation mode. Requires The CANSPI routines are supported only by MCUs with the SPI module. MCU has to be properly connected to mikroElektronika’s CANSPI Extra Board or similar hardware.
-
mikoPascal PRO for PIC32 Requires Global variables: - CanSpi_CS: Chip Select line - CanSpi_Rst: Reset line - CanSpi_CS_Direction: Direction of the Chip Select pin - CanSpi_Rst_Direction: Direction of the Reset pin must be defined before using this function. The CANSPI routines are supported only by MCUs with the SPI module. The SPI module needs to be initialized. See the SPIx_Init and SPIx_Init_Advanced routines. MCU has to be properly connected to mikroElektronika’s CANSPI Extra Board or similar hardware.
-
mikroPascal PRO for PIC32 CANSPISetBaudRate Prototype Returns procedure CANSPISetBaudRate(SJW, CONFIG_FLAGS : char); BRP, PHSEG1, PHSEG2, PROPSEG, CANSPI_ Nothing. Description Sets the CANSPI module baud rate. Due to complexity of the CAN protocol, you can not simply force a bps value. Instead, use this function when the CANSPI module is in Config mode. SAM, SEG2PHTS and WAKFIL bits are set according to CANSPI_CONFIG_FLAGS value. Refer to datasheet for details.
-
mikoPascal PRO for PIC32 CANSPISetMask Prototype procedure CANSPISetMask(CANSPI_MASK : byte; val : longint; CANSPI_CONFIG_ FLAGS : byte); Description Configures mask for advanced filtering of messages. The parameter value is bit-adjusted to the appropriate mask registers. Parameters - CANSPI_MASK: CAN module mask number. Valid values: CANSPI_MASK constants. See CANSPI_ MASK constants. - val: mask register value.
-
mikroPascal PRO for PIC32 CANSPISetFilter Prototype procedure CANSPISetFilter(CAN_FILTER : as byte, val : longint, CANSPI_ CONFIG_FLAGS : as byte); Description Configures message filter. The parameter value is bit-adjusted to the appropriate filter registers. Parameters - CANSPI_FILTER: CAN module filter number. Valid values: CANSPI_FILTER constants. See CANSPI_FILTER constants. - val: filter register value.
-
mikoPascal PRO for PIC32 CANSPIRead Prototype function CANSPIRead(var id : longint; var Data_ : array[8] of byte; var DataLen: byte; var CAN_RX_MSG_FLAGS : byte) : byte; Description If at least one full Receive Buffer is found, it will be processed in the following way: - Message ID is retrieved and stored to location provided by the id parameter - Message data is retrieved and stored to a buffer provided by the data parameter - Message length is retrieved and stored to location provided by the dataLen p
-
mikroPascal PRO for PIC32 CANSPIWrite Prototype function CANSPIWrite(id : longint; var Data_ : array[8] of byte; DataLen, CANSPI_TX_MSG_FLAGS : byte) : byte; Description If at least one empty Transmit Buffer is found, the function sends message in the queue for transmission. Parameters - id: CAN message identifier. Valid values: 11 or 29 bit values, depending on message type (standard or extended) - Data: data to be sent - DataLen: data length. Valid values: 0..8 - CANSPI_TX_MSG_FLAGS: message flags.
-
mikoPascal PRO for PIC32 Copy Code To Clipboard const _CANSPI_MODE_BITS _CANSPI_MODE_NORMAL _CANSPI_MODE_SLEEP _CANSPI_MODE_LOOP _CANSPI_MODE_LISTEN _CANSPI_MODE_CONFIG : : : : : : byte byte byte byte byte byte = = = = = = $E0; 0; $20; $40; $60; $80; // Use this to access opmode bits CANSPI_CONFIG_FLAGS Constants The CANSPI_CONFIG_FLAGS constants define flags related to the CANSPI module configuration.
-
mikroPascal PRO for PIC32 You may use bitwise AND (&) to form config byte out of these values. For example: Copy Code To Clipboard init := _CANSPI_CONFIG_SAMPLE_THRICE and _CANSPI_CONFIG_PHSEG2_PRG_ON and _CANSPI_CONFIG_STD_MSG and _CANSPI_CONFIG_DBL_BUFFER_ON and _CANSPI_CONFIG_VALID_XTD_MSG and _CANSPI_CONFIG_LINE_FILTER_OFF; ...
-
mikoPascal PRO for PIC32 Copy Code To Clipboard const _CANSPI_RX_FILTER_BITS _CANSPI_RX_FILTER_1 _CANSPI_RX_FILTER_2 _CANSPI_RX_FILTER_3 _CANSPI_RX_FILTER_4 _CANSPI_RX_FILTER_5 _CANSPI_RX_FILTER_6 _CANSPI_RX_OVERFLOW _CANSPI_RX_INVALID_MSG _CANSPI_RX_XTD_FRAME _CANSPI_RX_RTR_FRAME _CANSPI_RX_DBL_BUFFERED buffered : : : : : : : byte byte byte byte byte byte byte = = = = = = = $07; $00; $01; $02; $03; $04; $05; : : : : : byte byte byte byte byte = = = = = $08; $10; $20; $40; $80; // Use this to acces
-
mikroPascal PRO for PIC32 Library Example The code is a simple demonstration of CANSPI protocol. This node initiates the communication with the 2nd node by sending some data to its address. The 2nd node responds by sending back the data incremented by 1. This (1st) node then does the same and sends incremented data back to the 2nd node, etc.
-
mikoPascal PRO for PIC32 CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG); // set all mask2 bits to ones CANSPISetFilter(_CANSPI_FILTER_B2_F4,ID_2nd,_CANSPI_CONFIG_XTD_MSG); // set id of filter B2_F4 to 2nd node ID CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF); // set NORMAL mode // Set initial data to be sent RxTx_Data[0] := 9; CANSPIWrite(ID_1st, RxTx_Data, 1, Can_Send_Flags); // send initial message while (TRUE) do begin // endless loop Msg_Rcvd := CANSPIRead(Rx_ID , RxTx_Data , Rx_Data_Le
-
mikroPascal PRO for PIC32 PORTB := 0; TRISB := 0; // clear PORTB // set PORTB as output Can_Init_Flags := 0; Can_Send_Flags := 0; Can_Rcv_Flags := 0; // // clear flags // Can_Send_Flags := _CANSPI_TX_PRIORITY_0 and _CANSPI_TX_XTD_FRAME and _CANSPI_TX_NO_RTR_FRAME; // form value to be used // with CANSPIWrite Can_Init_Flags := _CANSPI_CONFIG_SAMPLE_THRICE and _CANSPI_CONFIG_PHSEG2_PRG_ON and _CANSPI_CONFIG_XTD_MSG and _CANSPI_CONFIG_DBL_BUFFER_ON and _CANSPI_CONFIG_VALID_XTD_MSG and _CANSPI_CONFIG_LINE
-
mikoPascal PRO for PIC32 HW Connection Example of interfacing CAN transceiver MCP2510 with MCU via SPI interface MikroElektronika 256
-
mikroPascal PRO for PIC32 Compact Flash Library The Compact Flash Library provides routines for accessing data on Compact Flash card (abbr. CF further in text). CF cards are widely used memory elements, commonly used with digital cameras. Great capacity and excellent access time of only a few microseconds make them very attractive for microcontroller applications. In CF card, data is divided into sectors. One sector usually comprises 512 bytes.
-
mikoPascal PRO for PIC32 External dependencies of Compact Flash Library The following variables must be defined in all projects Description: using Compact Flash Library: Example: var CF_Data_Port : byte; sfr; external; Compact Flash Data Port. var CF_Data_Port : byte at PORTD; Ready signal line. var CF_RDY : sbit at RB7_bit; Write Enable signal line. var CF_WE : sbit at LATB6_bit; Output Enable signal line. var CF_OE : sbit at LATB5_bit; Chip Detect signal line.
-
mikroPascal PRO for PIC32 Library Routines - Cf_Init - Cf_Detect - Cf_Enable - Cf_Disable - Cf_Read_Init - Cf_Read_Byte - Cf_Write_Init - Cf_Write_Byte - Cf_Read_Sector - Cf_Write_Sector Routines for file handling: - Cf_Fat_Init - Cf_Fat_QuickFormat - Cf_Fat_Assign - Cf_Fat_Reset - Cf_Fat_Read - Cf_Fat_Rewrite - Cf_Fat_Append - Cf_Fat_Delete - Cf_Fat_Write - Cf_Fat_Set_File_Date - Cf_Fat_Get_File_Date - Cf_Fat_Get_File_Date_Modified - Cf_Fat_Get_File_Size - Cf_Fat_Get_Swap_File The following routine is for
-
mikoPascal PRO for PIC32 Cf_Init Prototype procedure Cf_Init(); Description Initializes ports appropriately for communication with CF card. Parameters None. Returns Nothing.
-
mikroPascal PRO for PIC32 Cf_Detect Prototype function CF_Detect() : word ; Description Checks for presence of CF card by reading the chip detect pin. Parameters None. Returns Requires Example Notes - 1 - if CF card was detected - 0 - otherwise The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. // Wait until CF card is inserted: while (Cf_Detect() = 0) do nop; PIC32 family MCU and CF card voltage levels are different.
-
mikoPascal PRO for PIC32 Cf_Read_Init Prototype procedure Cf_Read_Init(address : dword; sectcnt : byte); Description Initializes CF card for reading. Parameters - address: the first sector to be prepared for reading operation. - sector_count: number of sectors to be prepared for reading operation. Returns Nothing. Requires The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init.
-
mikroPascal PRO for PIC32 Cf_Write_Byte Prototype procedure Cf_Write_Byte(data_ : byte) ; Description Writes a byte to Compact Flash sector buffer location currently pointed to by writing pointers. These pointers will be autoicremented upon reading. When sector buffer is full, its contents will be transfered to appropriate flash memory sector. Parameters - data_: byte to be written. Returns Nothing. Requires The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init.
-
mikoPascal PRO for PIC32 Cf_Fat_Init Prototype function Cf_Fat_Init(): word; Description Initializes CF card, reads CF FAT16 boot sector and extracts necessary data needed by the library. Parameters None. Returns Requires - 0 - if CF card was detected and successfully initialized - 1 - if FAT16 boot sector was not found - 255 - if card was not detected Nothing. Example // init the FAT library if (Cf_Fat_Init() = 0) then begin ... end Notes None.
-
mikroPascal PRO for PIC32 Cf_Fat_Assign Prototype function Cf_Fat_Assign(var filename: array[12] of char; file_cre_attr: byte): word; Description Assigns file for file operations (read, write, delete...). All subsequent file operations will be applied over the assigned file. Parameters - filename: name of the file that should be assigned for file operations. The file name should be in DOS 8.3 (file_name.extension) format.
-
mikoPascal PRO for PIC32 Cf_Fat_Reset Prototype procedure Cf_Fat_Reset(var size: dword); Description Opens currently assigned file for reading. Parameters - size: buffer to store file size to. After file has been open for reading its size is returned through this parameter. Returns Nothing. Requires CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. Example Notes var size : dword; ... Cf_Fat_Reset(size); None.
-
mikroPascal PRO for PIC32 Cf_Fat_Rewrite Prototype procedure Cf_Fat_Rewrite(); Description Opens currently assigned file for writing. If the file is not empty its content will be erased. Parameters None. Returns Nothing. Requires CF card and CF library must be initialized for file operations. See Cf_Fat_Init. The file must be previously assigned. See Cf_Fat_Assign. Example Notes // open file for writing Cf_Fat_Rewrite(); None.
-
mikoPascal PRO for PIC32 Cf_Fat_Write Prototype procedure Cf_Fat_Write(var fdata: array[512] of byte; data_len: word); Description Writes requested number of bytes to currently assigned file opened for writing. Parameters - fdata: data to be written. - data_len: number of bytes to be written. Returns Nothing. Requires CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. File must be open for writing.
-
mikroPascal PRO for PIC32 Cf_Fat_Get_File_Date Prototype procedure Cf_Fat_Get_File_Date(var year: word; var month: byte; var day: byte; var hours: byte; var mins: byte); Description Reads time/date attributes of currently assigned file. Parameters - year: buffer to store year attribute to. Upon function execution year attribute is returned through this parameter. - month: buffer to store month attribute to. Upon function execution month attribute is returned through this parameter.
-
mikoPascal PRO for PIC32 Cf_Fat_Get_File_Size Prototype function Cf_Fat_Get_File_Size(): dword; Description This function reads size of currently assigned file in bytes. Parameters None. Returns Size of the currently assigned file in bytes. Requires CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. Example Notes var my_file_size : dword; ... my_file_size := Cf_Fat_Get_File_Size(); None.
-
mikroPascal PRO for PIC32 Parameters Returns Requires Bit Mask Description 0 0x01 Read Only 1 0x02 Hidden 2 0x04 System 3 0x08 Volume Label 4 0x10 Subdirectory 5 0x20 Archive 6 0x40 Device (internal use only, never found on disk) 7 0x80 Not used - Number of the start sector for the newly created swap file, if there was enough free space on CF card to create file of required size. - 0 - otherwise. CF card and CF library must be initialized for file operations. See Cf_Fat_Init.
-
mikoPascal PRO for PIC32 Library Example This project consists of several blocks that demonstrate various aspects of usage of the Cf_Fat16 library.
-
mikroPascal PRO for PIC32 begin UART1_Write_Text(uart_text); UART1_Write(13); UART1_Write(10); end; //-------------- Creates new file and writes some data to it procedure M_Create_New_File(); begin filename[7] := ‘A’; Cf_Fat_Set_File_Date(2005,6,21,10,35,0); // Set file date & time info Cf_Fat_Assign(filename, 0xA0); // Will not find file and then create file Cf_Fat_Rewrite(); // To clear file and start with new data for loop:=1 to 99 do // We want 5 files on the MMC card begin UART1_Write(‘.
-
mikoPascal PRO for PIC32 //-------------- Opens an existing file and appends data to it // (and alters the date/time stamp) procedure M_Open_File_Append(); begin filename[7] := ‘B’; Cf_Fat_Assign(filename, 0); Cf_Fat_Set_File_Date(2009, 1, 23, 17, 22, 0); Cf_Fat_Append; file_contents := ‘ for mikroElektronika 2009’; // Prepare file for append file_contents[26] := 13; // CR file_contents[27] := 10; // LF Cf_Fat_Write(file_contents, 27); // Write data to assigned file end; //-------------- Opens an existing f
-
mikroPascal PRO for PIC32 UART1_Write_Text(outstr); WordToStr(day, outstr); UART1_Write_Text(outstr); WordToStr(hour, outstr); UART1_Write_Text(outstr); WordToStr(minute, outstr); UART1_Write_Text(outstr); //--- file has been found - get its modified date Cf_Fat_Get_File_Date_Modified(year, month, day, hour, minute); UART1_Write_Text(‘ modified: ‘); WordToStr(year, outstr); UART1_Write_Text(outstr); ByteToStr(month, outstr); UART1_Write_Text(outstr); WordToStr(day, outstr); UART1_Write_Text(outstr); WordToS
-
mikoPascal PRO for PIC32 end; Inc(size); UART1_Write(‘.’); end; end; //-------------- Main.
-
mikroPascal PRO for PIC32 HW Connection Pin diagram of CF memory card 277 MikroElektronika
-
mikoPascal PRO for PIC32 Epson S1D13700 Graphic Lcd Library The mikroPascal PRO for PIC32 provides a library for working with Glcds based on Epson S1D13700 controller. The S1D13700 Glcd is capable of displaying both text and graphics on an LCD panel. The S1D13700 Glcd allows layered text and graphics, scrolling of the display in any direction, and partitioning of the display into multiple screens.
-
mikroPascal PRO for PIC32 Library Routines - S1D13700_Init - S1D13700_Write_Command - S1D13700_Write_Parameter - S1D13700_Read_Parameter - S1D13700_Fill - S1D13700_GrFill - S1D13700_TxtFill - S1D13700_Display_GrLayer - S1D13700_Display_TxtLayer - S1D13700_Set_Cursor - S1D13700_Display_Cursor - S1D13700_Write_Char - S1D13700_Write_Text - S1D13700_Dot - S1D13700_Line - S1D13700_H_Line - S1D13700_V_Line - S1D13700_Rectangle - S1D13700_Box - S1D13700_Rectangle_Round_Edges - S1D13700_Rectangle_Round_Edges_Fill -
-
mikoPascal PRO for PIC32 S1D13700_Init Prototype procedure S1D13700_Init(width : word; height : word); Returns Nothing. Description Initializes S1D13700 Graphic Lcd controller. Parameters: Requires - width: width of the Glcd panel. - height: height of the Glcd panel. Global variables: - S1D13700_Data_Port: Data Bus Port. - S1D13700_WR: Write signal pin. - S1D13700_RD: Read signal pin. - S1D13700_A0: Command/Data signal pin. - S1D13700_RES: Reset signal pin. - S1D13700_CS: Chip Select signal pin.
-
mikroPascal PRO for PIC32 S1D13700_Write_Command Prototype procedure S1D13700_Write_Command(command : byte); Returns Nothing. Description Writes a command to S1D13700 controller. Parameters: - command: command to be issued: Value Description S1D13700_SYSTEM_SET General system settings. S1D13700_POWER_SAVE Enter into power saving mode. S1D13700_DISP_ON Turn the display on. S1D13700_DISP_OFF Turn the display off. S1D13700_SCROLL Setup text and graphics address regions.
-
mikoPascal PRO for PIC32 S1D13700_Write_Parameter Prototype procedure S1D13700_Write_Parameter(parameter : byte); Returns Nothing. Description Writes a parameter to S1D13700 controller. Parameters: Requires - parameter: parameter to be written. Glcd module needs to be initialized. See the S1D13700_Init routine. Previously, a command must be sent through S1D13700_Write_Command routine.
-
mikroPascal PRO for PIC32 S1D13700_GrFill Prototype procedure S1D13700_GrFill(d : byte); Returns Nothing. Description Fill graphic layer with appropriate value (0 to clear). Parameters: Requires Example - d: value to fill graphic layer with. Glcd module needs to be initialized. See the S1D13700_Init routine. // clear current graphic panel S1D13700_GrFill(0); S1D13700_TxtFill Prototype procedure S1D13700_TxtFill(d : byte); Returns Nothing.
-
mikoPascal PRO for PIC32 S1D13700_Display_TxtLayer Prototype procedure S1D13700_Display_TxtLayer(mode : byte); Returns Nothing. Description Display selected text layer. Parameters: - mode: text layer mode. Valid values: Value Description S1D13700_LAYER_OFF Turn off graphic layer. S1D13700_LAYER_ON Turn on graphic layer. S1D13700_LAYER_FLASH_2Hz Turn on graphic layer and flash it at the rate of 2 Hz. S1D13700_LAYER_FLASH_16Hz Turn on graphic layer and flash it at the rate of 16 Hz.
-
mikroPascal PRO for PIC32 S1D13700_Display_Cursor Prototype procedure S1D13700_Display_Cursor(mode : byte); Returns Nothing. Description Displays cursor. Parameters: - mode: mode parameter. Valid values: Value Description S1D13700_CURSOR_OFF Turn off graphic layer. S1D13700_CURSOR_ON Turn on graphic layer. S1D13700_CURSOR_FLASH_2Hz Turn on graphic layer and flash it at the rate of 2 Hz. S1D13700_CURSOR_FLASH_16Hz Turn on graphic layer and flash it at the rate of 16 Hz.
-
mikoPascal PRO for PIC32 S1D13700_Write_Text Prototype Returns procedure S1D13700_Write_Text(var str : string; x, y : word; mode : byte); Nothing. Description Writes text in the current text panel of Glcd at coordinates (x, y). Parameters: - str: text to be written. - x: text position on x-axis (column). - y: text position on y-axis (row). - mode: mode parameter. Valid values : Value Description S1D13700_OVERLAY_OR In the OR-Mode, text and graphics can be displayed and the data is logically “OR-ed”.
-
mikroPascal PRO for PIC32 S1D13700_Line Prototype procedure S1D13700_Line(x0, y0, x1, y1 : word; pcolor : byte); Returns Nothing. Description Draws a line from (x0, y0) to (x1, y1). Parameters: - x0: x coordinate of the line start. - y0: y coordinate of the line end. - x1: x coordinate of the line start. - y1: y coordinate of the line end. - pcolor: color parameter. Valid values: Value Description S1D13700_BLACK Black color. S1D13700_WHITE White color.
-
mikoPascal PRO for PIC32 S1D13700_V_Line Prototype procedure S1D13700_V_Line(y_start, y_end, x_pos : word; color : byte); Returns Nothing. Description Draws a horizontal line. Parameters: - y_start: y coordinate of the line start. - y_end: y coordinate of the line end. - x_pos: line position on the x axis. - pcolor: color parameter. Valid values: Value Description S1D13700_BLACK Black color. S1D13700_WHITE White color. Requires Glcd module needs to be initialized. See the S1D13700_Init routine.
-
mikroPascal PRO for PIC32 S1D13700_Box Prototype procedure S1D13700_Box(x0, y0, x1, y1 : word; pcolor : byte); Returns Nothing. Description Draws a rectangle on Glcd. Parameters: - x0: x coordinate of the upper left rectangle corner. - y0: y coordinate of the upper left rectangle corner. - x1: x coordinate of the lower right rectangle corner. - y1: y coordinate of the lower right rectangle corner. - pcolor: color parameter. Valid values : Value Description S1D13700_BLACK Black color.
-
mikoPascal PRO for PIC32 S1D13700_Rectangle_Round_Edges_Fill Prototype Returns procedure S1D13700_Rectangle_Round_Edges_Fill(x_upper_left : word; y_upper_ left : word; x_bottom_right : word; y_bottom_right : word; round_radius : word; color : byte); Nothing. Description Draws a filled rounded edge rectangle on Glcd. Parameters: - x_upper_left: x coordinate of the upper left rectangle corner. - y_upper_left: y coordinate of the upper left rectangle corner.
-
mikroPascal PRO for PIC32 S1D13700_Circle_Fill Prototype Returns procedure S1D13700_Circle_Fill(x_center: word; color : byte); word; y_center: word; radius: Nothing. Description Draws a filled circle on Glcd. Parameters: - x_center: x coordinate of the circle center. - y_center: y coordinate of the circle center. - radius: radius size. - color: color parameter. Valid values : Value Description S1D13700_BLACK Black color. S1D13700_WHITE White color. Requires Glcd module needs to be initialized.
-
mikoPascal PRO for PIC32 S1D13700_PartialImage Prototype Returns procedure S1D13700_PartialImage(x_left, y_top, width, width, picture_height : word; const image : ^byte); height, picture_ Nothing. Description Displays a partial area of the image on a desired location. Parameters: - x_left: x coordinate of the desired location (upper left coordinate). - y_top: y coordinate of the desired location (upper left coordinate). - width: desired image width. - height: desired image height.
-
mikroPascal PRO for PIC32 Flash_Write_Word Prototype procedure FLASH_Erase32(flash_address : longint); Description Writes one 32-bit word in the program Flash memory on the designated address. Parameters - address: address of the FLASH memory word - wdata: data to be written Returns Nothing. Requires Nothing. Example Notes None.
-
mikoPascal PRO for PIC32 Graphic Lcd Library mikroPascal PRO for PIC32 provides a library for operating Graphic Lcd 128x64 (with commonly used Samsung KS108/KS107 controller). For creating a custom set of Glcd images use Glcd Bitmap Editor Tool.
-
mikroPascal PRO for PIC32 External dependencies of Graphic Lcd Library The following variables must be defined in all projects using Graphic Lcd Library: Description: Example: var GLCD_D0 : sbit; sfr; external; Data 0 line.
-
mikoPascal PRO for PIC32 Library Routines Basic routines: - Glcd_Init - Glcd_Set_Side - Glcd_Set_X - Glcd_Set_Page - Glcd_Read_Data - Glcd_Write_Data Advanced routines: - Glcd_Fill - Glcd_Dot - Glcd_Line - Glcd_V_Line - Glcd_H_Line - Glcd_Rectangle - Glcd_Rectangle_Round_Edges - Glcd_Rectangle_Round_Edges_Fill - Glcd_Box - Glcd_Circle - Glcd_Circle_Fill - Glcd_Set_Font - Glcd_Write_Char - Glcd_Write_Text - Glcd_Image - Glcd_PartialImage Glcd_Init Prototype procedure Glcd_Init(); Description Initializes t
-
mikroPascal PRO for PIC32 Requires - GLCD_EN : Enable signal pin - GLCD_RST : Reset signal pin - GLCD_D0_Direction : Direction of the Data pin 0 - GLCD_D1_Direction : Direction of the Data pin 1 - GLCD_D2_Direction : Direction of the Data pin 2 - GLCD_D3_Direction : Direction of the Data pin 3 - GLCD_D4_Direction : Direction of the Data pin 4 - GLCD_D5_Direction : Direction of the Data pin 5 - GLCD_D6_Direction : Direction of the Data pin 6 - GLCD_D7_Direction : Direction of the Data pin 7 - GLCD_CS1_Direc
-
mikoPascal PRO for PIC32 Glcd_Set_Side Prototype procedure Glcd_Set_Side(x_pos: byte); Description Selects Glcd side. Refer to the Glcd datasheet for detailed explanation. Parameters - x_pos: Specifies position on x-axis of the Glcd. Valid values: 0..127. Values from 0 to 63 specify the left side, values from 64 to 127 specify the right side of the Glcd. Returns Nothing. Requires Glcd needs to be initialized, see Glcd_Init routine.
-
mikroPascal PRO for PIC32 Glcd_Read_Data Prototype function Glcd_Read_Data() : byte; Description Reads data from from the current location of Glcd memory and moves to the next location. Parameters None. Returns One byte from Glcd memory, formatted as a word (16-bit). Requires Glcd needs to be initialized, see Glcd_Init routine. Glcd side, x-axis position and page should be set first. See functions Glcd_Set_Side, Glcd_Set_X, and Glcd_Set_Page. Example Notes var data_ : byte; ...
-
mikoPascal PRO for PIC32 Glcd_Fill Prototype procedure Glcd_Fill(pattern: byte); Description Fills Glcd memory with the byte pattern. To clear the Glcd screen, use Glcd_Fill(0). To fill the screen completely, use Glcd_Fill(0xFF). Parameters - pattern: byte to fill Glcd memory with. Returns Nothing. Requires Glcd needs to be initialized, see Glcd_Init routine. Example // Clear screen Glcd_Fill(0); Notes None.
-
mikroPascal PRO for PIC32 Glcd_V_Line Prototype procedure Glcd_V_Line(y_start, y_end, x_pos, color: byte); Description Draws a vertical line on Glcd. Parameters - y_start: y coordinate of the line start. Valid values: 0..63 - y_end: y coordinate of the line end. Valid values: 0..63 - x_pos: x coordinate of vertical line. Valid values: 0..127 - color: color parameter. Valid values: 0..2 Returns The parameter color determines the line color: 0 white, 1 black, and 2 inverts each dot. Nothing.
-
mikoPascal PRO for PIC32 Glcd_Rectangle Prototype procedure Glcd_Rectangle(x_upper_left, bottom_right, color: byte); y_upper_left, x_bottom_right, y_ Description Draws a rectangle on Glcd. Parameters - x_upper_left: x coordinate of the upper left rectangle corner. Valid values: 0..127 - y_upper_left: y coordinate of the upper left rectangle corner. Valid values: 0..63 - x_bottom_right: x coordinate of the lower right rectangle corner. Valid values: 0..
-
mikroPascal PRO for PIC32 Glcd_Rectangle_Round_Edges_Fill Prototype procedure Glcd_Rectangle_Round_Edges_Fill(x_upper_left: byte; y_upper_left: byte; x_bottom_right: byte; y_bottom_right: byte; radius: byte; color: byte); Description Draws a filled rounded edge rectangle on Glcd with color. Parameters - x_upper_left: x coordinate of the upper left rectangle corner. Valid values: 0..127 - y_upper_left: y coordinate of the upper left rectangle corner. Valid values: 0..
-
mikoPascal PRO for PIC32 Glcd_Circle Prototype procedure Glcd_Circle(x_center, y_center, radius: integer; color: byte); Description Draws a circle on Glcd. Parameters - x_center: x coordinate of the circle center. Valid values: 0..127 - y_center: y coordinate of the circle center. Valid values: 0..63 - radius: radius size - color: color parameter. Valid values: 0..2 Returns The parameter color determines the color of the circle line: 0 white, 1 black, and 2 inverts each dot. Nothing.
-
mikroPascal PRO for PIC32 Glcd_Set_Font Prototype procedure Glcd_Set_Font(const activeFont: ^byte; aFontWidth, aFontHeight : byte; aFontOffs : byte); Description Sets font that will be used with Glcd_Write_Char and Glcd_Write_Text routines. Parameters - activeFont: font to be set. Needs to be formatted as an array of char - aFontWidth: width of the font characters in dots. - aFontHeight: height of the font characters in dots.
-
mikoPascal PRO for PIC32 Glcd_Write_Char Prototype procedure Glcd_Write_Char(character, x_pos, page_num, color : byte); Description Prints character on the Glcd. Parameters - character: character to be written - x_pos: character starting position on x-axis. Valid values: 0..(127-FontWidth) - page_num: the number of the page on which character will be written. Valid values: 0..7 - color: color parameter. Valid values: 0..
-
mikroPascal PRO for PIC32 Glcd_Image Prototype procedure Glcd_Image(const image: ^byte); Description Displays bitmap on Glcd. Parameters - image: image to be displayed. Bitmap array can be located in both code and RAM memory (due to the mikroPascal PRO for PIC32 pointer to const and pointer to RAM equivalency). Returns Nothing. Requires Glcd needs to be initialized, see Glcd_Init routine.
-
mikoPascal PRO for PIC32 I²C Library The I²C full master I²C module is available with a number of the PIC32 MCU models. The mikroPascal PRO for PIC32 provides a library which supports the master I²C mode. Important : - I²C library routines require you to specify the module you want to use. To select the desired I²C module, simply change the letter x in the routine prototype for a number from 1 to 3. - Number of I²C modules per MCU differs from chip to chip.
-
mikroPascal PRO for PIC32 I2Cx_Init_Advanced Prototype procedure I2Cx_Init_Advanced(Fclk_Khz, scl : dword); Description This function configures and initializes the desired I²C module using Peripheral Bus Clock and default initialization settings. As per the I²C standard, SCL clock may be 100 kHz or 400 kHz. However, the user can specify any clock rate up to 1 MHz. Parameters - Fclk_Khz: Peripheral Bus Clock frequency in kHz. - scl: requested serial clock rate. Returns Nothing.
-
mikoPascal PRO for PIC32 I2Cx_Restart Prototype procedure I2Cx_Restart(); Description Issues repeated START signal. Parameters None. Returns Nothing. Requires MCU with at least one I²C module. Used I²C module must be initialized before using this function. See I2Cx_Init routine. Example Notes // Issue RESTART signal I2C1_Restart(); - I²C library routines require you to specify the module you want to use.
-
mikroPascal PRO for PIC32 I2Cx_Read Prototype function I2Cx_Read(ack : word) : byte; Description Reads a byte from the I²C bus. Parameters - ack: acknowledge signal parameter. If the ack = 0, acknowledge signal will be sent after reading, otherwise the not acknowledge signal will be sent. Returns Received data. Requires MCU with at least one I²C module. Used I²C module must be initialized before using this function. See I2Cx_Init routine.
-
mikoPascal PRO for PIC32 I2Cx_Stop Prototype procedure I2Cx_Stop(); Description Issues STOP signal. Parameters None. Returns Nothing. Requires MCU with at least one I²C module. Used I²C module must be initialized before using this function. See I2Cx_Init routine. Example Notes // Issue STOP signal I2C1_Stop(); - I²C library routines require you to specify the module you want to use. To select the desired I²C module, simply change the letter x in the routine prototype for a number from 1 to 5.
-
mikroPascal PRO for PIC32 result := I2C2_Read(1); I2C2_Stop(); end; // Read the data (NO acknowledge) begin CHECON := 0x30; AD1PCFG := 0xFFFFFFFF; LATB := 0; TRISB := 0; TRISA := 0; TRISD := 0; LATD := 0; LATF := 0; TRISF := 0; // Set PORTB value to zero // Configure PORTB as output EEPROM_24C02_Init(); // performs I2C initialization b := 0x00; for i := 0x00 to 0x80 do begin EEPROM_24C02_WrSingle(i,b); Inc(b); Delay_ms(5); //max vrednost za upis u eeprom end; for i := 0x00 to 0x80 do begin LATD := i; LA
-
mikoPascal PRO for PIC32 Keypad Library mikroPascal PRO for PIC32 provides a library for working with 4x4 keypad. The library routines can also be used with 4x1, 4x2, or 4x3 keypad. For connections explanation see schematic at the bottom of this page. External dependencies of Keypad Library The following variable must be defined in all projects using Keypad Library: Description: Example: var keypadPort external; Keypad Port. var keypadPort : byte at PORTB; Keypad Port.
-
mikroPascal PRO for PIC32 Keypad_Key_Press Prototype function Keypad_Key_Press(): word; Description Reads the key from keypad when key gets pressed. Parameters None. Returns The code of a pressed key (1..16). If no key is pressed, returns 0. Requires Example Notes Port needs to be initialized for working with the Keypad library, see Keypad_Init. var kp : word; ...
-
mikoPascal PRO for PIC32 Library Example The following code can be used for testing the keypad. It is written for keypad_4x3 or _4x4. The code returned by the keypad functions (1..16) is transformed into ASCII codes [0..9,A..F], and then sent via UART1.
-
mikroPascal PRO for PIC32 13: 14: 15: 16: kp kp kp kp := := := := 42; 48; 35; 68; // // // // * 0 # D end; end.
-
mikoPascal PRO for PIC32 Lcd Library mikroPascal PRO for PIC32 provides a library for communication with Lcds (with HD44780 compliant controllers) through the 4-bit interface. An example of Lcd connections is given on the schematic at the bottom of this page. For creating a set of custom Lcd characters use Lcd Custom Character Tool.
-
mikroPascal PRO for PIC32 Lcd_Init Prototype procedure Lcd_Init(); Description Initializes Lcd module. Parameters None. Returns Nothing.
-
mikoPascal PRO for PIC32 Lcd_Out Prototype procedure Lcd_Out(row, column: word; var text: string); Description Prints text on Lcd starting from specified position. Both string variables and literals can be passed as a text. Parameters - row: starting position row number - column: starting position column number - text: text to be written Returns Nothing. Requires The Lcd module needs to be initialized. See Lcd_Init routine.
-
mikroPascal PRO for PIC32 Lcd_Chr_Cp Prototype procedure Lcd_Chr_Cp(out_char: byte); Description Prints character on Lcd at current cursor position. Both variables and literals can be passed as a character. Parameters - out_char: character to be written Returns Nothing. Requires The Lcd module needs to be initialized. See Lcd_Init routine.
-
mikoPascal PRO for PIC32 Library Example The following code demonstrates usage of the Lcd Library routines: Copy Code To Clipboard program Lcd_COG_2x16; // LCD module connections var LCD_RS : sbit at LATB2_bit; var LCD_EN : sbit at LATB3_bit; var LCD_D4 : sbit at LATB4_bit; var LCD_D5 : sbit at LATB5_bit; var LCD_D6 : sbit at LATB6_bit; var LCD_D7 : sbit at LATB7_bit; var LCD_RS_Direction : sbit at var LCD_EN_Direction : sbit at var LCD_D4_Direction : sbit at var LCD_D5_Direction : sbit at var LCD_D6_Direct
-
mikroPascal PRO for PIC32 // Moving text for i:=0 to 3 do begin Lcd_Cmd(_LCD_SHIFT_RIGHT); Move_Delay(); end; // Move text to the right 4 times while TRUE do begin for i:=0 to 7 do begin Lcd_Cmd(_LCD_SHIFT_LEFT); Move_Delay(); end; // Endless loop // Move text to the left 7 times for i:=0 to 7 do // Move text to the right 7 times begin Lcd_Cmd(_LCD_SHIFT_RIGHT); Move_Delay(); end; end; end.
-
mikoPascal PRO for PIC32 Memory Manager Library This library provides routines for accessing microcontroller’s (internal) Flash memory. Library Routines - Heap_Init - malloc - free - LargestFreeMemBlock - TotalFreeMemSize Heap_Init Prototype procedure Heap_Init(); Description Sets Heap size. Parameters None. Returns Nothing. Requires Nothing. Example Notes const HEAP_SIZE = 3000; Heap_Init(); None.
-
mikroPascal PRO for PIC32 FreeMem Prototype procedure FreeMem(var P: ^dword; ActualSize: word); Description FreeMem destroys the variable referenced by P and returns its memory to the heap. Parameters - P: variable of any pointer type previously assigned by the Getmem procedure. - ActualSize: specifies the size in bytes of the dynamic variable to dispose of and should be the same as the one used to Getmem. Returns Nothing. Requires Nothing.
-
mikoPascal PRO for PIC32 Multi Media Card Library The Multi Media Card (MMC) is a Flash memory card standard. MMC cards are currently available in sizes up to and including 32 GB and are used in cellular phones, digital audio players, digital cameras and PDA’s. mikroPascal PRO for PIC32 provides a library for accessing data on Multi Media Card via SPI communication. This library also supports SD (Secure Digital) and high capacity SDHC (Secure Digital High Capacity) memory cards.
-
mikroPascal PRO for PIC32 Library Dependency Tree External dependencies of MMC Library The following variable must be defined in all projects using MMC library: Description: Example: var Mmc_Chip_Select : sbit; sfr; external; Chip select pin. var Mmc_Chip_Select : sbit at LATF0_ bit; var Mmc_Chip_Select_Direction : sbit; sfr; external; Direction of the chip select pin.
-
mikoPascal PRO for PIC32 Mmc_Init Prototype function Mmc_Init(): word; Description Initializes MMC through hardware SPI interface. Mmc_Init needs to be called before using other functions of this library. Parameters None. Returns Requires - 0 - if MMC/SD card was detected and successfully initialized - 1 - otherwise The appropriate hardware SPI module must be previously initialized.
-
mikroPascal PRO for PIC32 Mmc_Read_Sector Prototype function Mmc_Read_Sector(sector: dword; var dbuff: array[512] of byte): word; Description The function reads one sector (512 bytes) from MMC card. Parameters - sector: MMC/SD card sector to be read. - dbuff: buffer of minimum 512 bytes in length for data storage. Returns Requires - 0 - if reading was successful - 1 - if an error occurred MMC/SD card must be initialized. See Mmc_Init.
-
mikoPascal PRO for PIC32 Mmc_Read_Cid Prototype function Mmc_Read_Cid(var data_cid: array[16] of byte): word; Description The function reads 16-byte CID register. Parameters - data_cid: buffer of minimum 16 bytes in length for storing CID register content. Returns Requires Example Notes - 0 - if CID register was read successfully - 1 - if there was an error while reading MMC/SD card must be initialized. See Mmc_Init. var error : word; dataBuffer : array[16] of byte; ...
-
mikroPascal PRO for PIC32 Mmc_Fat_Init Prototype function Mmc_Fat_Init(): word; Description Initializes MMC/SD card, reads MMC/SD FAT16 boot sector and extracts necessary data needed by the library. Parameters None.
-
mikoPascal PRO for PIC32 Mmc_Fat_QuickFormat Prototype function Mmc_Fat_QuickFormat(var mmc_fat_label : string[11]) : word; Description Formats to FAT16 and initializes MMC/SD card. Parameters - mmc_fat_label: volume label (11 characters in length). If less than 11 characters are provided, the label will be padded with spaces.
-
mikroPascal PRO for PIC32 Mmc_Fat_Assign Prototype function Mmc_Fat_Assign(var filename: array[12] of char; file_cre_attr: byte): word; Description Assigns file for file operations (read, write, delete...). All subsequent file operations will be applied on an assigned file. Parameters - filename: name of the file that should be assigned for file operations. File name should be in DOS 8.3 (file_name.extension) format.
-
mikoPascal PRO for PIC32 Mmc_Fat_Reset Prototype procedure Mmc_Fat_Reset(var size: dword); Description Procedure resets the file pointer (moves it to the start of the file) of the assigned file, so that the file can be read. Parameters - size: buffer to store file size to. After file has been opened for reading, its size is returned through this parameter. Returns Nothing. Requires MMC/SD card and MMC library must be initialized for file operations. See Mmc_Fat_Init.
-
mikroPascal PRO for PIC32 Mmc_Fat_Rewrite Prototype procedure Mmc_Fat_Rewrite(); Description Opens the currently assigned file for writing. If the file is not empty its content will be erased. Parameters None. Returns Nothing. Requires MMC/SD card and MMC library must be initialized for file operations. See Mmc_Fat_Init. The file must be previously assigned. See Mmc_Fat_Assign. Example Notes // open file for writing Mmc_Fat_Rewrite(); None.
-
mikoPascal PRO for PIC32 Mmc_Fat_Write Prototype procedure Mmc_Fat_Write(var fdata: array[512] of byte; data_len: word); Description Writes requested number of bytes to the currently assigned file opened for writing. Parameters - fdata: data to be written. - data_len: number of bytes to be written. Returns Nothing. Requires MMC/SD card and MMC library must be initialized for file operations. See Mmc_Fat_Init. The file must be previously assigned. See Mmc_Fat_Assign. The file must be opened for writing.
-
mikroPascal PRO for PIC32 Mmc_Fat_Get_File_Date Prototype procedure Mmc_Fat_Get_File_Date(var year: word; var month: byte; var day: byte; var hours: byte; var mins: byte); Description Reads time/date attributes of the currently assigned file. Parameters - year: buffer to store year attribute to. Upon function execution year attribute is returned through this parameter. - month: buffer to store month attribute to. Upon function execution month attribute is returned through this parameter.
-
mikoPascal PRO for PIC32 Mmc_Fat_Get_File_Date_Modified Prototype procedure Mmc_Fat_Get_File_Date_Modified(var year: word; var month: byte; var day: byte; var hours: byte; var mins: byte); Description Retrieves the last modification date/time for the currently selected file. Seconds are not being retrieved since they are written in 2-sec increments. Parameters - year: buffer to store year attribute to. Upon function execution year attribute is returned through this parameter.
-
mikroPascal PRO for PIC32 Mmc_Fat_Get_Swap_File Prototype function Mmc_Fat_Get_Swap_File(sectors_cnt: dword; var filename : string[11]; file_attr : byte) : dword; Description This function is used to create a swap file of predefined name and size on the MMC/SD media. If a file with specified name already exists on the media, search for consecutive sectors will ignore sectors occupied by this file. Therefore, it is recommended to erase such file if it already exists before calling this function.
-
mikoPascal PRO for PIC32 Example //-------------- Try to create a swap file with archive atribute, whose size will be at least 1000 sectors. // If it succeeds, it sends No. of start sector over UART var size : dword; ... size := Mmc_Fat_Get_Swap_File(1000, ‘mikroE.txt’, 0x20); if (size <> 0) then begin UART1_Write(0xAA); UART1_Write(Lo(size)); UART1_Write(Hi(size)); UART1_Write(Higher(size)); UART1_Write(Highest(size)); UART1_Write(0xAA); end; Notes Long File Names (LFN) are not supported.
-
mikroPascal PRO for PIC32 // UART write text and new line (carriage return + line feed) procedure UART_Write_Line( var uart_text : string); begin UART1_Write_Text(uart_text); UART1_Write(13); UART1_Write(10); end; //-------------- Creates new file and writes some data to it procedure M_Create_New_File(); begin filename[7] := ‘A’; // Set filename for single-file tests Mmc_Fat_Set_File_Date(2011,1,12,11,9,0); // Set file date & time info Mmc_Fat_Assign(filename, 0xA0); // Will not find file and then create fi
-
mikoPascal PRO for PIC32 //-------------- Opens an existing file and appends data to it // (and alters the date/time stamp) procedure M_Open_File_Append(); begin filename[7] := ‘B’; Mmc_Fat_Assign(filename, 0); Mmc_Fat_Set_File_Date(2009, 1, 23, 17, 22, 0); Mmc_Fat_Append(); // Prepare file for append file_contents := ‘ for mikroElektronika 2009’; // Prepare file for append file_contents[26] := 10; // LF Mmc_Fat_Write(file_contents, 27); // Write data to assigned file end; //-------------- Opens an existing
-
mikroPascal PRO for PIC32 UART1_Write_Text(outstr); WordToStr(hour, outstr); UART1_Write_Text(outstr); WordToStr(minute, outstr); UART1_Write_Text(outstr); //--- file has been found - get its modified date Mmc_Fat_Get_File_Date_Modified(year, month, day, hour, minute); UART1_Write_Text(‘ modified: ‘); WordToStr(year, outstr); UART1_Write_Text(outstr); ByteToStr(month, outstr); UART1_Write_Text(outstr); WordToStr(day, outstr); UART1_Write_Text(outstr); WordToStr(hour, outstr); UART1_Write_Text(outstr); WordT
-
mikoPascal PRO for PIC32 //-------------- Main.
-
mikroPascal PRO for PIC32 HW Connection Pin diagram of MMC memory card OneWire Library The OneWire library provides routines for communication via the Dallas OneWire protocol, for example with DS18x20 digital thermometer. OneWire is a Master/Slave protocol, and all communication cabling required is a single wire. OneWire enabled devices should have open collector drivers (with single pull-up resistor) on the shared data line. Slave devices on the OneWire bus can even get their power supply from data line.
-
mikoPascal PRO for PIC32 Ow_Reset Prototype function Ow_Reset(var port: word; pin: word): word; Description Issues OneWire reset signal for DS18x20. Parameters - port: OneWire bus port - pin: OneWire bus pin Returns Requires Example Notes - 0 if the device is present - 1 if the device is not present Devices compliant with the Dallas OneWire protocol. // Issue Reset signal on One-Wire Bus connected to pin RF6 Ow_Reset(&PORTF,6); None.
-
mikroPascal PRO for PIC32 Port Expander Library mikroPascal PRO for PIC32 provides a library for communication with the Microchip’s Port Expander MCP23S17 via SPI interface. Connections of the PIC32 MCU and MCP23S17 is given on the schematic at the bottom of this page. Important: - The library uses the SPI module for communication. User must initialize the appropriate SPI module before using the Port Expander Library.
-
mikoPascal PRO for PIC32 Expander_Init Prototype procedure Expander_Init(ModuleAddress : byte); Description Initializes Port Expander using SPI communication. Port Expander module settings: - hardware addressing enabled - automatic address pointer incrementing disabled (byte mode) - BANK_0 register adressing - slew rate enabled Parameters - ModuleAddress: Port Expander hardware address, see schematic at the bottom of this page Returns Nothing.
-
mikroPascal PRO for PIC32 Expander_Init_Advanced Prototype procedure Expander_Init_Advanced(var rstPort : byte; rstPin : byte; haen : byte); Description Initializes Port Expander using SPI communication. Parameters - rstPort: Port Expander’s reset port - rstPin: Port Expander’s reset pin - haen: Port Expander’s hardware address Returns Nothing.
-
mikoPascal PRO for PIC32 Expander_Read_Byte Prototype function Expander_Read_Byte(ModuleAddress, RegAddress : byte) : byte; Description The function reads byte from Port Expander. Parameters - ModuleAddress: Port Expander hardware address, see schematic at the bottom of this page - RegAddress: Port Expander’s internal register address Returns Byte read. Requires Port Expander must be initialized. See Expander_Init. Example // Read a byte from Port Expander’s register var read_data : byte; ...
-
mikroPascal PRO for PIC32 Expander_Read_PortB Prototype function Expander_Read_PortB(ModuleAddress : byte) : byte; Description The function reads byte from Port Expander’s PortB. Parameters - ModuleAddress: Port Expander hardware address, see schematic at the bottom of this page Returns Byte read. Requires Port Expander must be initialized. See Expander_Init. Port Expander’s PortB should be configured as input. See Expander_Set_DirectionPortB and Expander_Set_DirectionPortAB routines.
-
mikoPascal PRO for PIC32 Expander_Write_PortA Prototype procedure Expander_Write_PortA(ModuleAddress, Data : byte); Description The function writes byte to Port Expander’s PortA. Parameters - ModuleAddress: Port Expander hardware address, see schematic at the bottom of this page - Data: data to be written Returns Nothing. Requires Port Expander must be initialized. See Expander_Init. Port Expander’s PortA should be configured as output.
-
mikroPascal PRO for PIC32 Expander_Write_PortAB Prototype procedure Expander_Write_PortAB(ModuleAddress : byte; Data : word); Description The function writes word to Port Expander’s ports. Parameters - ModuleAddress: Port Expander hardware address, see schematic at the bottom of this page - Data: data to be written. Data to be written to PortA are passed in Data’s higher byte. Data to be written to PortB are passed in Data’s lower byte Returns Nothing. Requires Port Expander must be initialized.
-
mikoPascal PRO for PIC32 Expander_Set_DirectionPortB Prototype procedure Expander_Set_DirectionPortB(ModuleAddress, Data : byte); Description The function sets Port Expander’s PortB direction. Parameters - ModuleAddress: Port Expander hardware address, see schematic at the bottom of this page - Data: data to be written to the PortB direction register. Each bit corresponds to the appropriate pin of the PortB register. Set bit designates corresponding pin as input.
-
mikroPascal PRO for PIC32 Expander_Set_PullUpsPortB Prototype procedure Expander_Set_PullUpsPortB(ModuleAddress, Data : byte); Description The function sets Port Expander’s PortB pull up/down resistors. Parameters - ModuleAddress: Port Expander hardware address, see schematic at the bottom of this page - Data: data for choosing pull up/down resistors configuration. Each bit corresponds to the appropriate pin of the PortB register. Set bit enables pull-up for corresponding pin. Returns Nothing.
-
mikoPascal PRO for PIC32 Library Example The example demonstrates how to communicate with Port Expander MCP23S17. Note that Port Expander pins A2 A1 A0 are connected to GND so Port Expander Hardware Address is 0.
-
mikroPascal PRO for PIC32 HW Connection Port Expander HW connection 357 MikroElektronika
-
mikoPascal PRO for PIC32 PS/2 Library The mikroPascal PRO for PIC32 provides a library for communication with the common PS/2 keyboard. Important: - The library does not utilize interrupts for data retrieval, and requires the oscillator clock to be at least 6MHz. - The pins to which a PS/2 keyboard is attached should be connected to the pull-up resistors. - Although PS/2 is a two-way communication bus, this library does not provide MCU-to-keyboard communication; e.g.
-
mikroPascal PRO for PIC32 Ps2_Config Prototype procedure Ps2_Config(); Description Initializes the MCU for work with the PS/2 keyboard. Parameters None. Returns Nothing. Requires Global variables: - PS2_Data: Data signal line - PS2_Clock: Clock signal line - PS2_Data_Direction: Direction of the Data pin - PS2_Clock_Direction: Direction of the Clock pin must be defined before using this function.
-
mikoPascal PRO for PIC32 Special Function Keys Key Value returned F1 1 F2 2 F3 3 F4 4 F5 5 F6 6 F7 7 F8 8 F9 9 F10 10 F11 11 F12 12 Enter 13 Page Up 14 Page Down 15 Backspace 16 Insert 17 Delete 18 Windows 19 Ctrl 20 Shift 21 Alt 22 Print Screen 23 Pause 24 Caps Lock 25 End 26 Home 27 Scroll Lock 28 Num Lock 29 Left Arrow 30 Right Arrow 31 Up Arrow 32 Down Arrow 33 Escape 34 Tab 35 MikroElektronika 360
-
mikroPascal PRO for PIC32 Library Example This simple example reads values of the pressed keys on the PS/2 keyboard and sends them via UART.
-
mikoPascal PRO for PIC32 HW Connection Example of PS2 keyboard connection PWM Library The CCP module is available with a number of PIC32 MCUs. mikroPascal PRO for PIC32 provides a library which simplifies using of the PWM HW Module. Important : PWM module uses either Timer2 or Timer3 module.
-
mikroPascal PRO for PIC32 PWM_Init Prototype function PWM_Init(freq_hz : dword; enable_channel_x, timer_prescale, use_ timer_x : word) : word; Description Initializes the PWM module with duty ratio 0. Parameters - freq_hz: PWM frequency in Hz (refer to device datasheet for correct values in respect with Fosc) - enable_channel_x: number of PWM channel to be initialized. Refer to MCU’s datasheet for available PWM channels - timer_prescale: timer prescaler parameter.
-
mikoPascal PRO for PIC32 PWM_Set_Duty Prototype procedure PWM_Set_Duty(duty, channel : word); Description The function changes PWM duty ratio. Parameters - duty: PWM duty ratio. Valid values: 0 to timer period returned by the PWM_Init function. - channel: number of PWM channel to change duty to. Returns Nothing. Requires MCU must have the HW PWM Module. PWM channel must be properly initialized. See PWM_Init routine. Example // Set channel 1 duty ratio to 50%: var pwm_period1 : word; ...
-
mikroPascal PRO for PIC32 Library Example The example changes PWM duty ratio on channels 1 and 2 continuously. If LEDs are connected to channels 1 and 2, a gradual change of emitted light will be noticeable.
-
mikoPascal PRO for PIC32 PWM_Set_Duty(current_duty, end; 1); if RB2_bit = 1 then begin Delay_ms(1); current_duty1 := current_duty1 + 5; if (current_duty1 > pwm_period2) then then possible pwm_period2 value current_duty1 := 0; PWM_Set_Duty(current_duty1, end; 2); // set newly acquired duty ratio // button on RB2 pressed // increment current_duty1 // if we increase current_duty1 greater // reset current_duty1 value to zero // set newly acquired duty ratio if RB3_bit = 1 then // button on RB3 pressed begi
-
mikroPascal PRO for PIC32 RS-485 Library RS-485 is a multipoint communication which allows multiple devices to be connected to a single bus. mikroPascal PRO for PIC32 provides a set of library routines for comfortable work with RS485 system using Master/Slave architecture. Master and Slave devices interchange packets of information. Each of these packets contains synchronization bytes, CRC byte, address byte and the data. Each Slave has unique address and receives only packets addressed to it.
-
mikoPascal PRO for PIC32 Library Routines - RS485Master_Init - RS485Master_Receive - RS485Master_Send - RS485Slave_Init - RS485Slave_Receive - RS485Slave_Send RS485Master_Init Prototype procedure RS485Master_Init(); Description Initializes MCU as a Master for RS-485 communication. Parameters None. Returns Nothing. Requires Global variables: - RS485_rxtx_pin - this pin is connected to RE/DE input of RS-485 transceiver(see schematic at the bottom of this page).
-
mikroPascal PRO for PIC32 RS485Master_Receive Prototype procedure RS485Master_Receive(var data : array[10] of byte); Description Receives messages from Slaves. Messages are multi-byte, so this routine must be called for each byte received. Parameters - data_buffer: 7 byte buffer for storing received data. Data will be stored in the following manner: - data_buffer[0..
-
mikoPascal PRO for PIC32 RS485Slave_Init Prototype procedure RS485Slave_Init(slave_address : byte); Description Initializes MCU as a Slave for RS-485 communication. Parameters - Slave_address: Slave address Returns Nothing. Requires Global variables: - RS485_rxtx_pin - this pin is connected to RE/DE input of RS-485 transceiver(see schematic at the bottom of this page). RE/DE signal controls RS-485 transceiver operation mode.
-
mikroPascal PRO for PIC32 RS485Slave_Receive Prototype procedure RS485Slave_Receive(var data_buffer : array[20] of byte); Description Receives messages from Master. If Slave address and Message address field don’t match then the message will be discarded. Messages are multi-byte, so this routine must be called for each byte received. Parameters - data_buffer: 6 byte buffer for storing received data, in the following manner: - data_buffer[0..
-
mikoPascal PRO for PIC32 Library Example The example demonstrates working with the PIC32 as a Master node in RS-485 communication. Master sends message to Slave with address 160 and waits for a response. After the response is received, the first byte of received data is incremented and sent back to the Slave. The received data is displayed on PORTB while error on receiving (0xAA) and number of consecutive unsuccessful retries are displayed on PORTD.
-
mikroPascal PRO for PIC32 MVEC_bit := 1; asm ei R0; end; U2RXIE_bit := 1; // Interrupt controller configured for multi vectored mode // Enable all interrupts // enable intterupt RS485Master_Send(dat,1,160); while (TRUE) do begin Inc(cnt); if (dat[5] <> 0) then PORTD := 0xAA; if (dat[4] <> 0) then begin cnt := 0; dat[4] := 0; j := dat[3]; for i := 1 to dat[3] do PORTB := dat[i-1]; dat[0] := dat[0]+1; Delay_ms(1); RS485Master_Send(dat,1,160); end; // upon completed valid message receiving // data[4] is set
-
mikoPascal PRO for PIC32 U2RXIF_bit := 0; end; // ensure interrupt not pending begin CHECON := 0x32; AD1PCFG := 0xFFFF; TRISB TRISD PORTB PORTD := := := := 0; 0; 0; 0; UART2_Init(19200); Delay_ms(100); // initialize UART2 module RS485Slave_Init(160); // Intialize MCU as slave, address 160 dat[0] dat[1] dat[2] dat[4] dat[5] dat[6] := := := := := := 0xAA; 0xF0; 0x0F; 0; 0; 0; U2IP0_bit := 1; U2IP1_bit := 1; U2IP2_bit := 1; // ensure that message received flag is 0 // ensure that error flag is 0 /
-
mikroPascal PRO for PIC32 HW Connection Example of interfacing PC to PIC32 MCU via RS485 bus with LTC485 as RS-485 transceiver 375 MikroElektronika
-
mikoPascal PRO for PIC32 Message format and CRC calculations Q: How is CRC checksum calculated on RS485 master side? Copy Code To Clipboard const START_BYTE : byte = 0x96; const STOP_BYTE : byte = 0xA9; PACKAGE: -------START_BYTE 0x96 ADDRESS DATALEN [DATA1] [DATA2] [DATA3] CRC STOP_BYTE 0xA9 // 10010110 // 10101001 // if exists // if exists // if exists DATALEN bits -----------bit7 = 1 MASTER SENDS 0 SLAVE SENDS bit6 = 1 ADDRESS WAS XORed 0 ADDRESS UNCHANGED bit5 = 0 FIXED bit4 = 1 DATA3 (if exists) 0 D
-
mikroPascal PRO for PIC32 Software I²C Library The mikroPascal PRO for PIC32 provides routines for implementing Software I²C communication. These routines are hardware independent and can be used with any MCU. The Software I²C library enables you to use MCU as Master in I²C communication. Multi-master mode is not supported. Important: - This library implements time-based activities, so interrupts need to be disabled when using Software I²C.
-
mikoPascal PRO for PIC32 Soft_I2C_Init Prototype procedure Soft_I2C_Init(); Description Configures the software I²C module. Parameters None. Returns Nothing. Requires Global variables: - Soft_I2C_Scl: Soft I²C clock line - Soft_I2C_Sda: Soft I²C data line - Soft_I2C_Scl_Pin_Direction: Direction of the Soft I²C clock pin - Soft_I2C_Sda_Pin_Direction: Direction of the Soft I²C data pin must be defined before using this function.
-
mikroPascal PRO for PIC32 Soft_I2C_Read Prototype function Soft_I2C_Read(ack : word) : byte; Description Reads one byte from the slave. Parameters - ack: acknowledge signal parameter. If the ack==0 not acknowledge signal will be sent after reading, otherwise the acknowledge signal will be sent. Returns One byte from the Slave. Requires Soft I²C must be configured before using this function. See Soft_I2C_Init routine. Also, START signal needs to be issued in order to use this function.
-
mikoPascal PRO for PIC32 Soft_I2C_Break Prototype procedure Soft_I2C_Break(); Description All Software I²C Library functions can block the program flow (see note at the top of this page). Calling this routine from interrupt will unblock the program execution. This mechanism is similar to WDT. Parameters None. Returns Nothing. Requires Nothing.
-
mikroPascal PRO for PIC32 Library Example The example demonstrates use of the Software I²C Library. The PIC32 MCU is connected (SCL, SDA pins) to PCF8583 RTC (real-time clock). Program sends date/time to RTC.
-
mikoPascal PRO for PIC32 //-------------------- Formats date and time procedure Transform_Time(); begin seconds := ((seconds and 0xF0) shr 4)*10 + (seconds and 0x0F);// minutes := ((minutes and 0xF0) shr 4)*10 + (minutes and 0x0F);// hours := ((hours and 0xF0) shr 4)*10 + (hours and 0x0F); // year := (day and 0xC0) shr 6; // day := ((day and 0x30) shr 4)*10 + (day and 0x0F); // month := ((month and 0x10) shr 4)*10 + (month and 0x0F); // end; Transform Transform Transform Transform Transform Transform seco
-
mikroPascal PRO for PIC32 Software SPI Library The mikroPascal PRO for PIC32 provides routines for implementing Software SPI communication. These routines are hardware independent and can be used with any MCU. The Software SPI Library provides easy communication with other devices via SPI: A/D converters, D/A converters, MAX7219, LTC1290, etc. Library configuration: - SPI to Master mode - Clock value = 20 kHz. - Data sampled at the middle of interval. - Clock idle state low.
-
mikoPascal PRO for PIC32 Soft_SPI_Init Prototype procedure Soft_SPI_Init(); Description Routine initializes the software SPI module. Parameters None. Returns Nothing. Requires Global variables: - SoftSpi_SDI: Data in line - SoftSpi_SDO: Data out line - SoftSpi_CLK: Data clock line - SoftSpi_SDI_Direction: Direction of the Data in pin - SoftSpi_SDO_Direction: Direction of the Data out pin - SoftSpi_CLK_Direction: Direction of the Data clock pin must be defined before using this function.
-
mikroPascal PRO for PIC32 Soft_SPI_Read Prototype function Soft_SPI_Read(data_ : byte) : byte; Description This routine performs 3 operations simultaneously. It provides clock for the Software SPI bus, reads a byte and sends a byte. Parameters - sdata: data to be sent. Returns Byte received via the SPI bus. Requires Soft SPI must be initialized before using this function. See Soft_SPI_Init routine. Example Notes var data_read, data_send : byte; ...
-
mikoPascal PRO for PIC32 var value : word; procedure InitMain(); begin TRISB0_bit := 1; TRISB1_bit := 1; Chip_Select := 1; Chip_Select_Direction := 0; Soft_Spi_Init(); end; // // // // // Set RB0 pin as input Set RB1 pin as input Deselect DAC Set CS# pin as Output Initialize Soft_SPI // DAC increments (0..4095) --> output voltage (0..
-
mikroPascal PRO for PIC32 Software UART Library The mikroPascal PRO for PIC32 provides routines for implementing Software UART communication. These routines are hardware independent and can be used with any MCU. The Software UART Library provides easy communication with other devices via the RS232 protocol. Important: The Software UART library implements time-based activities, so interrupts need to be disabled when using it.
-
mikoPascal PRO for PIC32 Soft_UART_Read Prototype function Soft_UART_Read(var error : byte) : byte; Description The function receives a byte via software UART. This is a blocking function call (waits for start bit). Programmer can unblock it by calling Soft_UART_ Break routine. Parameters - error: Error flag. Error code is returned through this variable. Values : - 0 - no error - 1 - stop bit error - 255 - user abort, Soft_UART_Break called Returns Byte received via UART.
-
mikroPascal PRO for PIC32 Soft_UART_Break Prototype procedure Soft_UART_Break(); Description Soft_UART_Read is blocking routine and it can block the program flow. Calling Soft_UART_Break routine from the interrupt will unblock the program execution. This mechanism is similar to WDT. Parameters None. Returns Nothing. Requires Nothing.
-
mikoPascal PRO for PIC32 Library Example This example demonstrates simple data exchange via software UART. If MCU is connected to the PC, you can test the example from the mikroPascal PRO for PIC32 USART communication terminal, launch it from the drop-down menu Tools › USART Terminal or simply click the USART Terminal Icon .
-
mikroPascal PRO for PIC32 Sound Library The mikroPascal PRO for PIC32 provides a Sound Library to supply users with routines necessary for sound signalization in their applications. Sound generation needs additional hardware, such as piezo-speaker (example of piezo-speaker interface is given on the schematic at the bottom of this page).
-
mikoPascal PRO for PIC32 Library Example The example is a simple demonstration of how to use the Sound Library for playing tones on a piezo speaker.
-
mikroPascal PRO for PIC32 end; begin ToneA(); ToneC(); ToneE(); end; begin CHECON := 0x32; AD1PCFG := 0xFFFF; TRISB := 0xF8; // Configure AN pins as digital I/O // Configure RB7..RB3 as input Sound_Init(PORTD, 3); Sound_Play(880, 1000); while TRUE do begin if (Button(PORTB,7,1,1)) then begin Tone1(); while (RB7_bit <> 0) do nop; end; // endless loop // If PORTB.
-
mikoPascal PRO for PIC32 HW Connection Example of Sound Library MikroElektronika 394
-
mikroPascal PRO for PIC32 SPI Library The SPI module is available with all PIC32 MCUs. mikroPascal PRO for PIC32 provides a library for initializing the Slave mode and initializing and comfortable work with the Master mode. The PIC32 can easily communicate with other devices via SPI: A/D converters, D/A converters, MAX7219, LTC1290, etc. Important: - SPI library routines require you to specify the module you want to use.
-
mikoPascal PRO for PIC32 SPIx_Init Prototype procedure SPIx_Init(); Description Configures and initializes the SPI module with default settings. Default settings: - Master mode. - 8-bit data mode. - Serial clock set to System clock/64. - Slave Select disabled. - Input data sampled in the middle of interval. - Clock idle state low. - Serial output data changes on transition from idle clock state to active clock state Parameters None. Returns Nothing. Requires MCU must have the SPI1 module.
-
mikroPascal PRO for PIC32 SPIx_Init_Advanced Prototype procedure SPIx_Init_Advanced(master_mode, data_mode, clock_divider, slave_ select, data_sample, clock_idle, edge: word); Description Configures and initializes the SPI module with user defined settings. Parameters Parameters master_mode, data_mode, clock_divider, slave_select, data_sample, clock_idle and determine the working mode for SPI. The master_mode parameter determines the working mode for SPI module.
-
mikoPascal PRO for PIC32 Parameters The parameter clock_idle determines the behaviour of the SPI clock (CLK) line in IDLE phase. Clock Polarity Description Predefined library const IDLE state is Lo, ACTIVE state is Hi IDLE state is Hi, ACTIVE state is Lo _SPI_CLK_IDLE_LOW _SPI_CLK_IDLE_HIGH The parameter edge determines on which clock edge data is considered to be valid.
-
mikroPascal PRO for PIC32 SPIx_Read Prototype function SPIx_Read(data_out: word): word; Description Reads one word or byte (depending on mode set by init routines) from the SPI bus. Parameters - data_out: dummy data for clock generation (see device Datasheet for SPI modules implementation details) Returns Received data. Requires Routine requires at least one SPI module. Used SPI module must be initialized before using this function. See the SPIx_Init and SPIx_Init_ Advanced routines.
-
mikoPascal PRO for PIC32 SPI_Set_Active Prototype procedure SPI_Set_Active(read_ptr : ^TSPI_Rd_Ptr; write_ptr : ^TSPI_Wr_ Ptr); Description Sets the active SPI module which will be used by the SPIx_Read and SPIx_Write routines. Parameters Parameters: Returns Requires - read_ptr: SPI1_Read handler - write_ptr: SPI1_Write handler Nothing. Routine is available only for MCUs with multiple SPI modules. Used SPI module must be initialized before using this function.
-
mikroPascal PRO for PIC32 // Send High Byte temp := word(valueDAC shr 8) and 0x0F; // Store valueDAC[11..8] to temp[3..0] temp := temp or 0x30; // Define DAC setting, see MCP4921 datasheet SPI2_Write(temp); // Send high byte via SPI // Send Low Byte temp := valueDAC; SPI2_Write(temp); // Store valueDAC[7..0] to temp[7..
-
mikoPascal PRO for PIC32 HW Connection SPI HW connection MikroElektronika 402
-
mikroPascal PRO for PIC32 SPI Ethernet Library The ENC28J60 is a stand-alone Ethernet controller with an industry standard Serial Peripheral Interface (SPI). It is designed to serve as an Ethernet network interface for any controller equipped with SPI. The ENC28J60 meets all of the IEEE 802.3 specifications. It incorporates a number of packet filtering schemes to limit incoming packets. It also provides an internal DMA module for fast data throughput and hardware assisted IP checksum calculations.
-
mikoPascal PRO for PIC32 External dependencies of SPI Ethernet Library The following variables must be defined in all projects Description: using SPI Ethernet Library: Example: var SPI_Ethernet_CS : sbit; sfr; external; ENC28J60 chip select pin. var SPI_Ethernet_CS : sbit at LATF1_bit; var SPI_Ethernet_RST : sbit; sfr; external; ENC28J60 reset pin. var SPI_Ethernet_CS_Direction : sbit; sfr; Direction of the ENC28J60 external; chip select pin.
-
mikroPascal PRO for PIC32 Library Routines - SPI_Ethernet_Init - SPI_Ethernet_Enable - SPI_Ethernet_Disable - SPI_Ethernet_doPacket - SPI_Ethernet_putByte - SPI_Ethernet_putBytes - SPI_Ethernet_putString - SPI_Ethernet_putConstString - SPI_Ethernet_putConstBytes - SPI_Ethernet_getByte - SPI_Ethernet_getBytes - SPI_Ethernet_UserTCP - SPI_Ethernet_UserUDP - SPI_Ethernet_setUserHandlers - SPI_Ethernet_getIpAddress - SPI_Ethernet_getGwIpAddress - SPI_Ethernet_getDnsIpAddress - SPI_Ethernet_getIpMask - SPI_Ether
-
mikoPascal PRO for PIC32 Parameters - mac: RAM buffer containing valid MAC address. - ip: RAM buffer containing valid IP address. - fullDuplex: ethernet duplex mode switch. Valid values: 0 (half duplex mode) and 1 (full duplex mode). Returns Nothing. Requires Global variables: - SPI_Ethernet_CS: Chip Select line - SPI_Ethernet_CS_Direction: Direction of the Chip Select pin - SPI_Ethernet_RST: Reset line - SPI_Ethernet_RST_Direction: Direction of the Reset pin must be defined before using this function.
-
mikroPascal PRO for PIC32 SPI_Ethernet_Enable Prototype procedure SPI_Ethernet_Enable(enFlt : byte); Description This is MAC module routine. This routine enables appropriate network traffic on the ENC28J60 module by the means of it’s receive filters (unicast, multicast, broadcast, crc). Specific type of network traffic will be enabled if a corresponding bit of this routine’s input parameter is set. Therefore, more than one type of network traffic can be enabled at the same time.
-
mikoPascal PRO for PIC32 SPI_Ethernet_Disable Prototype procedure SPI_Ethernet_Disable(disFlt : byte); Description This is MAC module routine. This routine disables appropriate network traffic on the ENC28J60 module by the means of it’s receive filters (unicast, multicast, broadcast, crc). Specific type of network traffic will be disabled if a corresponding bit of this routine’s input parameter is set. Therefore, more than one type of network traffic can be disabled at the same time.
-
mikroPascal PRO for PIC32 SPI_Ethernet_doPacket Prototype function SPI_Ethernet_doPacket() : byte; Description This is MAC module routine. It processes next received packet if such exists. Packets are processed in the following manner: - ARP & ICMP requests are replied automatically. - upon TCP request the SPI_Ethernet_UserTCP function is called for further processing. - upon UDP request the SPI_Ethernet_UserUDP function is called for further processing. Parameters None.
-
mikoPascal PRO for PIC32 SPI_Ethernet_putBytes Prototype procedure SPI_Ethernet_putBytes(ptr : ^byte; n : word); Description This is MAC module routine. It stores requested number of bytes into ENC28J60 RAM starting from current ENC28J60 write pointer (EWRPT) location. Parameters - ptr: RAM buffer containing bytes to be written into ENC28J60 RAM. - n: number of bytes to be written. Returns Nothing. Requires Ethernet module has to be initialized. See SPI_Ethernet_Init.
-
mikroPascal PRO for PIC32 SPI_Ethernet_putString Prototype function SPI_Ethernet_putString(ptr : ^byte) : word; Description This is MAC module routine. It stores whole string (excluding null termination) into ENC28J60 RAM starting from current ENC28J60 write pointer (EWRPT) location. Parameters - ptr: string to be written into ENC28J60 RAM. Returns Requires Example Notes Number of bytes written into ENC28J60 RAM. Ethernet module has to be initialized. See SPI_Ethernet_Init. var buffer : string[16]; .
-
mikoPascal PRO for PIC32 SPI_Ethernet_getBytes Prototype procedure SPI_Ethernet_getBytes(ptr : ^byte; addr : word; n : word); Description This is MAC module routine. It fetches equested number of bytes from ENC28J60 RAM starting from given address. If value of 0xFFFF is passed as the address parameter, the reading will start from current ENC28J60 read pointer (ERDPT) location. Parameters - ptr: buffer for storing bytes read from ENC28J60 RAM. - addr: ENC28J60 RAM start address. Valid values: 0..8192.
-
mikroPascal PRO for PIC32 SPI_Ethernet_UserUDP Prototype function SPI_Ethernet_UserUDP(var remoteHost : array[4] of byte; remotePort, destPort, reqLength : word; var flags: TEthPktFlags) : word; Description This is UDP module routine. It is internally called by the library. The user accesses to the UDP request by using some of the SPI_Ethernet_get routines. The user puts data in the transmit buffer by using some of the SPI_Ethernet_put routines.
-
mikoPascal PRO for PIC32 SPI_Ethernet_getIpAddress Prototype function SPI_Ethernet_getIpAddress() : word; Description This routine should be used when DHCP server is present on the network to fetch assigned IP address. Parameters None. Returns Pointer to the global variable holding IP address. Requires Ethernet module has to be initialized. See SPI_Ethernet_Init. Example Notes var ipAddr : array[4] of byte; // user IP address buffer ...
-
mikroPascal PRO for PIC32 SPI_Ethernet_getIpMask Prototype function SPI_Ethernet_getIpMask() : word; Description This routine should be used when DHCP server is present on the network to fetch assigned IP subnet mask. Parameters None. Returns Pointer to the global variable holding IP subnet mask. Requires Ethernet module has to be initialized. See SPI_Ethernet_Init. Example Notes var IpMask : array[4] of byte; // user IP subnet mask buffer ...
-
mikoPascal PRO for PIC32 SPI_Ethernet_arpResolve Prototype function SPI_Ethernet_arpResolve(var ip : array[4] of byte; tmax : byte) : word; Description This is ARP module routine. It sends an ARP request for given IP address and waits for ARP reply. If the requested IP address was resolved, an ARP cash entry is used for storing the configuration. ARP cash can store up to 3 entries. For ARP cash structure refer to “eth_enc28j60LibDef.h” header file in the compiler’s Uses folder.
-
mikroPascal PRO for PIC32 SPI_Ethernet_dnsResolve Prototype function SPI_Ethernet_dnsResolve(var host : string; tmax : byte) : word; Description This is DNS module routine. It sends an DNS request for given host name and waits for DNS reply. If the requested host name was resolved, it’s IP address is stored in library global variable and a pointer containing this address is returned by the routine. UDP port 53 is used as DNS port. Parameters - host: host name to be resolved.
-
mikoPascal PRO for PIC32 SPI_Ethernet_initDHCP Prototype function SPI_Ethernet_initDHCP(tmax : byte) : byte; Description This is DHCP module routine. It sends an DHCP request for network parameters (IP, gateway, DNS addresses and IP subnet mask) and waits for DHCP reply. If the requested parameters were obtained successfully, their values are stored into the library global variables.
-
mikroPascal PRO for PIC32 SPI_Ethernet_renewDHCP Prototype function SPI_Ethernet_renewDHCP(tmax : byte) : byte; Description This is DHCP module routine. It sends IP address lease time renewal request to DHCP server. Parameters - tmax: time in seconds to wait for an reply. Returns Requires Example Notes 419 - 1 - upon success (lease time was renewed). - 0 - otherwise (renewal request timed out). Ethernet module has to be initialized. See SPI_Ethernet_Init. while true do begin ...
-
mikoPascal PRO for PIC32 Library Example This code shows how to use the Ethernet mini library: - the board will reply to ARP & ICMP echo requests - the board will reply to UDP requests on any port: - returns the request in upper char with a header made of remote host IP & port number - the board will reply to HTTP requests on port 80, GET method with pathnames: - / will return the HTML main page - /s will return board status as text string - /t0 ...
-
mikroPascal PRO for PIC32 ‘’ + ‘
’+ ‘PIC32 + ENC28J60 Mini Web Server
’+ ‘Reload’+ ‘’+ ‘’+ ‘ADC | ’+ ‘AN0 | | tr>’+ ‘ AN1 |
| |