Mikroelektronika MIKROBASIC user guide

mikroBASIC

Develop your applications quickly and easily with the world's most intuitive BASIC compiler for PIC Microcontrollers (families PIC12, PIC16, and PIC18).
Highly sophisticated IDE provides the power you need with the simplicity of a Windows based point-and-click environment.
With useful implemented tools, many practical code examples, broad set of built-in routines, and a comprehensive Help, mikroBasic makes a fast and reliable tool, which can satisfy needs of experienced engineers and beginners alike.
BASIC Compiler for Microchip PIC microcontrollers
mikroElektronika
Development tools - Books - Compilers
www.mikroe.com
UUsseerr’ss mmaannuuaall
Making it simple
SUPPORTED from V5.0
ICD
ICD
mikro
mikro
IN-CIRCUIT
IN-CIRCUIT
DEBUGGER
DEBUGGER
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
iiii
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
DISCLAIMER:
mikroBasic and this manual are owned by mikroElektronika and are protected by copyright law and international copyright treaty. Therefore, you should treat this manual like any other copyrighted material (e.g., a book). The manual and the compiler may not be copied, par­tially or as a whole without the written consent from the mikroElektronika. The PDF-edition of the manual can be printed for private or local use, but not for distribution. Modifying the manual or the compiler is strictly prohibited.
HIGH RISK ACTIVITIES
The mikroBasic compiler is not fault-tolerant and is not designed, manufactured or intended for use or resale as on-line control equipment in hazardous environments requiring fail-safe performance, such as in the operation of nuclear facilities, aircraft navigation or communica­tion systems, air traffic control, direct life support machines, or weapons systems, in which the failure of the Software could lead directly to death, personal injury, or severe physical or environmental damage ("High Risk Activities"). mikroElektronika and its suppliers specifically disclaim any express or implied warranty of fitness for High Risk Activities.
LICENSE AGREEMENT:
By using the mikroBasic compiler, you agree to the terms of this agreement. Only one per­son may use licensed version of mikroBasic compiler at a time. Copyright © mikroElektronika 2003 - 2006.
This manual covers mikroBasic version 5.0.0.2 and the related topics. New versions may contain changes without prior notice.
COMPILER BUG REPORTS:
The compiler has been carefully tested and debugged. It is, however, not possible to guarantee a 100% error free product. If you would like to report a bug, please contact us at the address office@mikroe.com. Please include the following information in your bug report:
- Your operating system
- Version of mikroBasic
- Code sample
- Description of a bug
CONTACT US:
mikroElektronika Voice: + 381 (11) 30 66 377, + 381 (11) 30 66 378 Fax: + 381 (11) 30 66 379 Web: www.mikroe.com E-mail: office@mikroe.com

Reader’s note

PIC, PICmicro and MPLAB is a Registered trademark of Microchip company. Windows is a Registered trademark of Microsoft Corp. All other trade and/or services marks are the property of the respective owners.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss

Table of Contents

CHAPTER 1 mikroBasic IDE
CHAPTER 2 Building Applications
CHAPTER 3 mikroBasic Reference
CHAPTER 4 mikroBasic Libraries
mmiikkrrooBBAASSIICC UUsseerrss mmaannuuaall
CHAPTER 1: mikroBasic IDE 1
Quick Overview 1 Code Editor 3 Code Explorer 6 Debugger 7 Error Window 10 Statistics 11 Integrated Tools 14 Keyboard Shortcuts 17
CHAPTER 2: Building Applications 19
Projects 20 Source Files 21
Search Paths 21 Managing Source Files 21
Compilation 23
Output Files 23 Assembly View 23
Error Messages 24
CHAPTER 3: mikroBasic Language Reference 27
PIC Specifics 28 mikroBasic Specifics 30
Predefined Globals and Constants 30 Accessing Individual Bits 30 Interrupts 31 Linker Directives 32 Code Optimization 34
mikroICD (In-Circuit Debugger) 35
mikroICD Debugger Options 37 mikroICD Debugger Example 38 mikroICD Overview 42
Lexical Elements 44
Whitespace 44
Comments 45 Tokens 46 Literals 47
Integer Literals 47
Floating Point Literals 47
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
iivv
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
Character Literals 48
String Literals 48 Keywords 49 Identifiers 50 Punctuators 51 Program Organization 53 Scope and Visibility 56 Modules 57
Include Clause 57
Main Module 58
Other Modules 59 Variables 60 Constants 61 Labels 62 Symbols 63 Functions and Procedures 64
Functions 64
Procedures 65 Types 67
Simple Types 68
Arrays 69
Multidimensional Arrays 70
Strings 71
Pointers 72
Structures 73 Types Conversions 75
Implicit Conversion 75
Explicit Conversion 76
Arithmetic Conversion 77 Operators 78
Precedence and Associativity 78
Arithmetic Operators 79
Relational Operators 80
Bitwise Operators 81 Expressions 84 Statements 85
asm Statement 85
Migration from older versions (v2.x) 86
Assignment Statements 87
Conditional Statements 87
Iteration Statements 90
Jump Statements 92 Compiler Directives 95
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
vv
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
CHAPTER 4: mikroBasic Libraries 99
Built-in Routines 100 Library Routines 106
ADC Library 107
CAN Library 109
CAN Constants 115 CANSPI Library 121 Compact Flash Library 130 EEPROM Library 142 Ethernet Library 144 SPI Ethernet Library 156 Flash Memory Library 163 I2C Library 166 Keypad Library 171 LCD Library (4-bit interface) 175 LCD Library (8-bit interface) 181 Graphic LCD Library 186 Toshiba T6963C Graphic LCD Library 196 Manchester Code Library 212 Multi Media Card Library 219 OneWire Library 232 PS/2 Library 236 PWM Library 239 RS-485 Library 243 Software I2C Library 249 Software SPI Library 253 Software UART Library 256 Sound Library 259 SPI Library 261 USART Library 265 USB HID Library 269 Util Library 274 Conversions Library 275 Delays Library 281 Math Library 283 String Library 290 SPI Graphic LCD Library 298 Port Expander Library 309 SPI LCD Library (4-bit interface) 317 SPI LCD Library (8-bit interface) 322 SPI T6963C Graphic LCD Library 327
Contact Us 312
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
vv ii
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
CHAPTER
MMiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
1

mikroBasic IDE

mikroBasic is a powerful, feature rich development tool for PIC microcontrollers. It is designed to provide the customer with the easiest possible solution for developing applications for embedded systems, without compromising perform­ance or control.
Highly advanced IDE, broad set of hardware libraries, comprehensive documentation, and plenty of ready to run examples should be more than enough to get you started in programming microcontrollers.
QUICK OVERVIEW
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
22
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
mikroBasic allows you to quickly develop and deploy complex applications:
- Write your BASIC source code using the highly advanced Code Editor
- Use the included mikroBasic libraries to dramatically speed up the development: data acquisition, memory, displays, conversions, communications…
- Monitor your program structure, variables, and functions in the Code Explorer. Generate commented, human-readable assembly, and standard HEX compatible with all programmers.
- Inspect program flow and debug executable logic with the integrated Debugger. Get detailed reports and graphs on code statistics, assembly listing, calling tree…
- We have provided plenty of examples for you to expand, develop, and use as building bricks in your projects.
Code Explorer
Error Window
Watch Window
Code Editor
Breakpoints Window
Code Assistant
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
33
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
The Code Editor is advanced text editor fashioned to satisfy the needs of profes­sionals. General code editing is same as working with any standard text-editor, including familiar Copy, Paste, and Undo actions, common for Windows environ­ment.
Advanced Editor features include:
- Adjustable Syntax Highlighting
- Code Assistant
- Parameter Assistant
- Code Templates
- Auto Correct for common typos
- Bookmarks and Goto Line
You can customize these options from Editor Settings dialog. To access the set­tings, click Tools > Options from the drop-down menu, or click the Tools icon.

CODE EDITOR

Tools Icon.
Code Assistant [CTRL+SPACE]
If you type first few letter of a word and then press CTRL+SPACE, all valid iden­tifiers matching the letters you typed will be prompted to you in a floating panel (see the image). Now you can keep typing to narrow the choice, or you can select one from the list using the keyboard arrows and Enter.
Parameter Assistant [CTRL+SHIFT+SPACE]
The Parameter Assistant will be automatically invoked when you open a parenthe­sis "(" or press CTRL+SHIFT+SPACE. If name of valid function or procedure precedes the parenthesis, then the expected parameters will be prompted to you in a floating panel. As you type the actual parameter, next expected parameter will become bold.
Code Template [CTR+J]
You can insert the Code Template by typing the name of the template (for instance, whileb), then press CTRL+J, and Editor will automatically generate code. Or you can click button from Code toolbar and select template from the list.
You can add your own templates to the list. Just select Tools > Options from the drop-down menu, or click the Tools Icon from the Settings Toolbar, and then select the Auto Complete Tab. Here you can enter the appropriate keyword, description, and code of your template.
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
44
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
Auto Correct
The Auto Correct feature corrects some common typing mistakes. To access the list of recognized typos, select Tools > Options from the drop-down menu, or click Tools Icon from Settings Toolbar, and then select Auto Correct Tab. You can also add your own preferences to the list.
Comment/Uncomment
The Code Editor allows you to comment or uncomment selected block of code by a simple click of a mouse, using the Comment/Uncomment icons from the Code Toolbar.
Bookmarks
Bookmarks make navigation through large code easier.
CTRL+<number> : Goto bookmark CTRL+SHIFT+<number> : Set bookmark
Goto Line
Goto Line option makes navigation through large code easier. Select Search > Goto Line from the drop-down menu, or use the shortcut CTRL+G.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
55
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
Comment /
Uncomment Icon.
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
66
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
The Code Explorer is placed to the left of the main window by default, and gives clear view of every declared item in the source code. You can jump to declaration of any item by right clicking it, or by clicking the Find Declaration icon. To expand or collapse treeview in Code Explorer, use the Collapse/Expand All icon.
Also, two more tab windows are available in the Code Explorer. QHelp Tab lists all the available built-in and library functions, for a quick reference. Double-click­ing a routine in the QHelp Tab opens the relevant Help topic. Keyboard Tab lists all the available keyboard shortcuts in mikroBasic.

CODE EXPLORER

Collapse/Expand
All Icon.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
77
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
Source-level Debugger is an integral component of mikroBasic development envi­ronment. It is designed to simulate operations of Microchip Technology's PICmicros and to assist users in debugging software written for these devices.
Debugger simulates program flow and execution of instruction lines, but does not fully emulate PIC device behavior: it does not update timers, interrupt flags, etc.
After you have successfully compiled your project, you can run the Debugger by selecting Run > Debug from the drop-down menu, or by clicking Debug Icon . Starting the Debugger makes more options available: Step Into, Step Over, Run to Cursor, etc. Line that is to be executed is color highlighted.
Debug [F9]
Start the Debugger.
Run/Pause Debugger [F6]
Run or pause the Debugger.
Step Into [F7]
Execute the current BASIC (single– or multi–cycle) instruction, then halt. If the instruction is a routine call, enter the routine and halt at the first instruction fol­lowing the call.
Step Over [F8]
Execute the current BASIC (single– or multi–cycle) instruction, then halt. If the instruction is a routine call, skip it and halt at the first instruction following the call.
Step Out [Ctrl+F8]
Execute the current BASIC (single– or multi–cycle) instruction, then halt. If the instruction is within a routine, execute the instruction and halt at the first instruc­tion following the call.
Run to cursor [F4]
Executes all instructions between the current instruction and the cursor position.

DEBUGGER

Start Debugger.
Step Into.
Step Over.
Step Out.
Pause Debugger.
Run to Cursor.
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
88
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
Jump to Interrupt [F2]
Jump to address
$04 for PIC12/16 or to address $08 for PIC18 and execute the
procedure located at that address.
Toggle Breakpoint [F5]
Toggle breakpoint at the current cursor position. To view all the breakpoints, select Run > View Breakpoints from the drop-down menu. Double clicking an item in window list locates the breakpoint.
Watch Window
Debugger Watch Window is the main Debugger window which allows you to monitor program items while running your program. To show the Watch Window, select View > Debug Windows > Watch Window from the drop-down menu.
The Watch Window displays variables and registers of PIC, with their addresses and values. Values are updated as you go through the simulation. Use the drop­down menu to add and remove the items that you want to monitor. Recently changed items are colored red.
Double clicking an item opens the Edit Value window in which you can assign a new value to the selected variable/register. Also, you can change view to binary, hex, char, or decimal for the selected item.
Jump to Interrupt.
Toggle
Breakpoint.
Stopwatch Window
Debugger Stopwatch Window is available from the drop-down menu, View > Debug Windows > Stopwatch.
The Stopwatch Window displays the current count of cycles/time since the last Debugger action. Stopwatch measures the execution time (number of cycles) from the moment Debugger is started, and can be reset at any time. Delta represents the number of cycles between the previous instruction line (line where the Debugger action was performed) and the active instruction line (where the Debugger action landed).
Note: You can change the clock in the Stopwatch Window; this will recalculate values for the newly specified frequency. Changing the clock in the Stopwatch Window does not affect the actual project settings – it only provides a simulation.
View RAM Window
Debugger View RAM Window is available from the drop-down menu, View > Debug Windows > View RAM.
The View RAM Window displays the map of PIC’s RAM, with recently changed items colored red. You can change value of any field by double-clicking it.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
99
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
1100
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
In case that errors were encountered during compiling, compiler will report them and won't generate a hex file. The Error Window will be prompted at the bottom of the main window.
Error Window is located under message tab, and displays location and type of errors compiler has encountered. The compiler also reports warnings, but these do not affect generating hex code. Only errors can interefere with generation of hex.
Double click the message line in the Error Window to highlight the line where the error was encountered.
Consult the Error Messages for more information about errors recognized by the compiler.

ERROR WINDOW

mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
1111
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
After successful compilation, you can review statistics of your code. Select Project > View Statistics from the drop-down menu, or click the Statistics icon. There are six tab windows:
Memory Usage Window
Provides overview of RAM and ROM memory usage in form of histogram.
Procedures (Graph) Window
Displays functions in form of histogram, according to their memory allotment.

STATISTICS

Statistics Icon.
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
1122
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
Procedures (Locations) Window
Displays how functions are distributd in microcontroller’s memory.
Procedures (Details) Window
Displays complete call tree, along with details for each procedure and function:
size, start and end address, calling frequency, return type, etc.
RAM Window
Summarizes all GPR and SFR registers and their addresses. Also displays symbol­ic names of variables and their addresses.
ROM Window
Lists op-codes and their addresses in form of a human readable hex code.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
1133
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
1144
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
USART Terminal
mikroBasic includes the USART (Universal Synchronous Asynchronous Receiver Transmitter) communication terminal for RS232 communication. You can launch it from the drop-down menu Tools > Terminal or by clicking the Terminal icon.
ASCII Chart
ASCII Chart is a handy tool, particularly useful when working with LCD display. You can launch it from the drop-down menu Tools > ASCII chart.

INTEGRATED TOOLS

7 Segment Display Decoder
The 7seg Display Decoder is a convenient visual panel which returns decimal/hex value for any viable combination you would like to display on 7seg. Click on the parts of 7 segment image to the left to get the desired value in the edit boxes. You can launch it from the drop-down menu Tools > 7 Segment Display.
EEPROM Editor
EEPROM Editor allows you to easily manage EEPROM of PIC microcontroller.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
1155
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
mikroBootloader
mikroBootloader can be used only with PICmicros that support flash write.
1. Load the PIC with the appropriate hex file using the conventional programming
techniques (e.g. for PIC16F877A use p16f877a.hex).
2. Start mikroBootloader from the drop-down menu Tools > Bootoader.
3. Click on Setup Port and select the COM port that will be used. Make sure that
BAUD is set to 9600 Kpbs.
4. Click on Open File and select the HEX file you would like to upload.
5. Since the bootcode in the PIC only gives the computer 4-5 sec to connect, you
should reset the PIC and then click on the Connect button within 4-5 seconds.
6. The last line in then history window should now read “Connected”.
7. To start the upload, just click on the Start Bootloader button.
8. Your program will written to the PIC flash. Bootloader will report an errors that
may occur.
9. Reset your PIC and start to execute.
The boot code gives the computer 5 seconds to get connected to it. If not, it starts running the existing user code. If there is a new user code to be downloaded, the boot code receives and writes the data into program memory.
The more common features a bootloader may have are listed below:
- Code at the Reset location.
- Code elsewhere in a small area of memory.
- Checks to see if the user wants new user code to be loaded.
- Starts execution of the user code if no new user code is to be loaded.
- Receives new user code via a communication channel if code is to be loaded.
- Programs the new user code into memory.
Integrating User Code and Boot Code
The boot code almost always uses the Reset location and some additional program memory. It is a simple piece of code that does not need to use interrupts; therefore, the user code can use the normal interrupt vector at 0x0004. The boot code must avoid using the interrupt vector, so it should have a program branch in the address range 0x0000 to 0x0003. The boot code must be programmed into memory using conventional programming techniques, and the configuration bits must be pro­grammed at this time. The boot code is unable to access the configuration bits, since they are not mapped into the program memory space.
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
1166
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
1177
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
Below is the complete list of keyboard shortcuts available in mikroBasic IDE. You can also view keyboard shortcuts in the Code Explorer, tab Keyboard.
IDE Shortcuts
F1 Help CTRL+SHIFT+E Edit Project Ctrl+N New Module Ctrl+O Open SHIFT+F9 Build all Ctrl+F9 Compile F11 Program F12 Options CTRL+F11 Compile and program Ctrl+Shift+F5 View breakpoints
Basic Editor shortcuts
F3 Find, Find Next CTRL+A Select All CTRL+C Copy CTRL+F Find CTRL+P Print CTRL+R Replace CTRL+S Save module CTRL+SHIFT+S Save As CTRL+V Paste CTRL+X Cut CTRL+Y Redo CTRL+Z Undo

KEYBOARD SHORTCUTS

Advanced Editor shortcuts
Ctrl+Space Code Assistant Ctrl+Shift+Space Parameter Assistant Ctrl+D Find declaration CTRL+E Incremental search Ctrl+G Goto line Ctrl+J Insert Code Template Ctrl+L Procedures list CTRL+/ Toggle line comment Ctrl+number Goto bookmark Ctrl+Shift+number Set bookmark Ctrl+Shift+I Indent selection Ctrl+Shift+U Unindent selection Alt+Select Select columns Tab Indent selection Shift+Tab Unindent selection Ctrl+Alt+Select Select columns Alt+F3 Find in files
Debugger Shortcuts
F4 Run to Cursor F5 Toggle Breakpoint F6 Run/Pause Debugger F7 Step into F8 Step over Ctrl+F8 Step out F9 Debug F2 Jump to Interrupt Ctrl+F2 Reset Ctrl+F5 Add to watch
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
1188
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
CHAPTER
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
2

Building Applications

Creating applications in mikroBasic is easy and intuitive. Project Wizard allows you to set up your project in just few clicks: name your application, select chip, set flags, and get going.
mikroBasic allows you to distribute your projects in as many modules as you find appropriate. You can then share your mikroCompiled Libraries (
.mcl files) with
other developers without disclosing the source code. The best part is that you can use .mcl bundles created by mikroPascal or mikroC!
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
2200
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
mikroBasic organizes applications into projects, consisting of a single project file (extension .pbp) and one or more source files (extension .pbas). You can com­pile source files only if they are part of a project.
Project file carries the following information:
- project name and optional description
- target device
- device flags (config word) and device clock
- list of project source files with paths
New Project
The easiest way to create project is by means of New Project Wizard, drop-down menu Project > New Project. Just fill the dialog with desired values (project name and description, location, device, clock, config word) and mikroBasic will create the appropriate project file.
Also, an empty source file named after the project will be created by default. mikroBasic does not require you to have source file named same as the project, it’s just a matter of convenience.
Editing Project
Later, you can change project settings from the drop-down menu Project > Edit. You can add or remove source files from project, rename the project, modify its description, change chip, clock, config word, etc.
To delete a project, simply delete the folder in which the project file is stored.

PROJECTS

New Project.
Edit Project.
Source files containing BASIC code should have the extension .pbas. List of source files relevant for the application is stored in project file with extension .pbp, along with other project information. You can compile source files only if they are part of a project.
Search Paths
You can specify your own custom search paths. This can be configured by select­ing Tools > Options from the drop-down menu and Compiler > Search Paths.
When including source files with the
include clause, mikroBasic will look for
the file in following locations, in this particular order:
1. mikroBasic installation folder > “defs” folder
2. mikroBasic installation folder > “uses” folder
3. your custom search paths
4. the project folder (folder which contains the project file
.pbp)
Managing Source Files
Creating a new source file
To create a new source file, do the following:
Select File > New from the drop-down menu, or press CTRL+N, or click the New File icon. A new tab will open, named “Untitled1”. This is your new source file. Select File > Save As from the drop-down menu to name it the way you want.
If you have used New Project Wizard, an empty source file, named after the proj­ect with extension
.pbas, is created automatically. mikroBasic does not require
you to have the source file named same as the project, it’s just a matter of conven­ience.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
2211
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...

SOURCE FILES

New File.
Opening an Existing File
Select File > Open from the drop-down menu, or press CTRL+O, or click the Open File icon. The Select Input File dialog opens. In the dialog, browse to the location of the file you want to open and select it. Click the Open button. The selected file is displayed in its own tab. If the selected file is already open, its current Editor tab will become active.
Printing an Open File
Make sure that window containing the file you want to print is the active window. Select File > Print from the drop-down menu, or press CTRL+P, or click the Print icon. In the Print Preview Window, set the desired layout of the document and click the OK button. The file will be printed on the selected printer.
Saving File
Make sure that window containing the file you want to save is the active window. Select File > Save from the drop-down menu, or press CTRL+S, or click the Save icon. The file will be saved under the name on its window.
Saving File Under a Different Name
Make sure that window containing the file you want to save is the active window. Select File > Save As from the drop-down menu, or press SHIFT+CTRL+S. The New File Name dialog will be displayed. In the dialog, browse to the folder where you want to save the file. In the File Name field, modify the name of the file you want to save. Click the Save button.
Closing a File
Make sure that tab containing the file you want to close is the active tab. Select File > Close from the drop-down menu, or right click the tab of the file you want to close in Code Editor. If the file has been changed since it was last saved, you will be prompted to save your changes.
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
2222
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
Open File.
Print File.
Save File.
Save File As.
Close File.
When you have created the project and written the source code, you will want to compile it. Select Project > Build from the drop-down menu, or click the Build Icon, or simply hit CTRL+F9.
Progress bar will appear to inform you about the status of compiling. If there are errors, you will be notified in the Error Window. If no errors are encountered, mikroBasic will generate output files.
Output Files
Upon successful compilation, mikroBasic will generate output files in the project folder (folder which contains the project file
.pbp). Output files are summarized
below:
Intel HEX file (
.hex)
Intel style hex records. Use this file to program PIC MCU.
Binary mikro Compiled Library (
.mcl)
Binary distribution of application that can be included in other projects.
List File (
.lst)
Overview of PIC memory allotment: instruction addresses, registers, routines, etc.
Assembler File (
.asm)
Human readable assembly with symbolic names, extracted from the List File.
Assembly View
After compiling your program in mikroBasic, you can click View Assembly Icon or select Project > View Assembly from the drop-down menu to review generated assembly code (.asm file) in a new tab window. Assembly is human readable with symbolic names. All physical addresses and other information can be found in Statistics or in list file (.lst).
If the program is not compiled and there is no assembly file, starting this option will compile your code and then display assembly.
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
2233
page
mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
View Assembly
Icon.
Build Icon.

COMPILATION

Error Messages

mmiikkrrooBBAASSIICC
- BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
making it simple...
2244
mmiikkrrooEElleekkttrroonniikkaa:: DDeevveellooppmmeenntt ttoooollss -- BBooookkss -- CCoommppiilleerrss
page
ERROR MESSAGES
Message Message Number
Error: "%s" is not a valid identifier 1
Error: Unknown type "%s" 2
Error: Identifier "%s" was not declared 3
Error: Expected "%s" but "%s" found 4
Error: Argument is out of range 5
Error: Syntax error in additive expression 6
Error: File "%s" not found 7
Error: Invalid command "%s" 8
Error: Not enough parameters 9
Error: Too many parameters 10
Error: Too many characters 11
Error: Actual and formal parameters must be identical 12
Error: Invalid ASM instruction: "%s" 13
Error: Identifier "%s" has been already declared 14
Error: Syntax error in multiplicative expression 15
Error: Definition file for "%s" is corrupted 16
Loading...
+ 318 hidden pages