Appendix A: mikroBasic IDE


Introduction

As already stated, any text editor that can save program file as pure ASCII text (without special symbols for formatting) can be used for writing your BASIC code. Still, there is no need to do it “by hand” — there are specialized environments, such as mikroBasic, that take care of the code syntax, free the memory and provide all the necessary tools for writing a program.

mikroBasic is a Windows-based Integrated Development Environment, and is much more than just BASIC compiler for PIC MCUs. With mikroBasic, you can:

mikroBasic IDE includes highly adaptable Code Editor, fashioned to satisfy needs of both novice users and experienced programmers. Syntax Highlighting, Code Templates, Code & Parameter Assistant, Auto Correct for common typos, and other features provide comfortable environment for writing a program.

In combination with comprehensive help, integrated tools, extensive libraries, and Code Explorer which allows you to easily monitor program items, all the necessary tools are at hand.

A.1 Installation of mikroBasic

mikroBasic is simple to install. Just start the Setup file and follow the installation steps.

Step 1

Installation step 1: Welcome

First you will be welcomed by the following screen. Click on next to continue.

Step 2

Installation step 2: License Agreement

You will be asked to review the License Agreement before installing mikroBasic. If you understand and accept the terms in the agreement, select “I accept the terms…” and click “Next” to proceed with the installation.

Step 3

Installation step 3: Components

Select the components you would like to install. Examples included with mikroBasic are optional, but we higly recommend installing them. Without taking much space on hard disk, the included set of pracical examples can be highly useful when developing applications. Also, beginners might find it very hepful.

Step 4

Installation step 4: Location

Choose the location where you want mikroBasic to be installed.

Step 5

Installation step 5: Process

Installation process itself takes less than a minute.

Step 6

Installation step 6: Finish

mikroBasic has been installed on your computer. Click “Finish” to confirm.

A.2 First Contact with mikroBasic

Upon starting mikroBasic for the first time, simple project “LED_Blinking” will be automatically started to help you to get to know IDE more quickly. You can compile the code (CTRL + F9), modify it, toy with Debugger or check the Statistics.

First contact with mikroBasic

As with any modern environment, you may customize layout of mikroBasic to best suit your needs – toolbars are fully dockable and your arrangement of windows is saved upon exit.

By default, the largest part of the screen is taken by Code Editor which contains the program code. This is the advanced text editor where you will be writing your programs. It features Syntax Highlighting to help you differentiate code elements. Try typing one of BASIC’s keywords and watch it go bold, or type an aposhtophe to see the comments go italic and change color.

Code Editor features many other advanced features such as Code & Parameter Assistants, Auto Correct for common typos, Code Templates, etc.

mikroBasic IDE

If you had no previous experience with advanced IDEs, you may wonder what Code and Parameter Assistants do. These are utilities which facilitate the code writing. For example, if you type first few letter of a word in Code Editor and then press CTRL+SPACE, all valid identifiers matching the letters you typed will be prompted to you in a floating panel. Now you can keep typing to narrow the choice, or you can select one from the list using keyboard arrows and Enter.

You don’t have to memorize the exact order or type of the routine parameters. Type CTRL+SHIFT+SPACE to activate the Parameter Assistant which will guide you in filling the appropriate parameters. This feature is automatically invoked upon opening a parenthesis.

To the left of the Code Editor, you will see a treeview of declared program elements. This is the Code Explorer which allows you to monitor variables, constants, routines, etc. Double click the element to jump to its declaration in code. You can click tabs over Code Explorer to change view to Keyboard shortcut browser for a list of all IDE shortcuts or to Quick Help browser with complete list of available built-in and library routines.

For setting other IDE features, click Tools > Options. In the Options window you can customize the look and feel of mikroBasic, enter your own list of recognized typos, write your own templates, etc.

If you get stuck at any point, consult the included help files. You can get help on F1, by right-clicking a specific word in code, or from Quick Help tab in Code Explorer. Help files are syntax and context sensitive.

A.3 Creating First Project

We will create a simple project similar to the included LED_Blinking, but we’ll start from scratch. Before we do, close any open files in Code Editor by clicking on File > Close.

Step 1

From a drop-down menu, select: Project > New Project, or click New Project icon

Step 2

Fill the New Project Wizard dialog with correct values to set up your new project.

After you have set up your project, click OK. mikroBasic will create project for you and automatically open the program file in Code Editor. Now we can write the source code.

Step 3

Upon creating a new project, Code Editor will display an empty program file, named same as your project. This is shown in the following figure.

First contact with mikroBasic

Now we are about to write the code for this simple example. We want to make LED diode blink once per second. Assuming the configuration given in the following figure, LED diodes are connected to PIC16F877 PORTB pins (it can be any other PIC that has PORTB).

Connection scheme for My_LED program

In this configuration, LED will emit light when voltage on pin is high (5V), and will be off when voltage on pin is low (0V). We have to designate PORTD as output, and change its value every second. Listing of the program is given below. Once you are comfortable with each line, feel free to experiment with it and improve the code.

program My_LED

main:

  TRISB = 0             ' PORTB is output
  eloop:
      PORTB = $FF       ' Turn on diodes on PORTB
      Delay_ms(1000)    ' Wait 1 second
      PORTB = 0         ' Turn of diodes on PORTB
      Delay_ms(1000)    ' Wait 1 second
  goto eloop            ' Stay in loop

end.

Step 4

Before compiling, it is recommended to save your project (menu choice File > Save All). Now you can compile your code by clicking CTRL+F9, or by selecting menu Run > Compile, or by clicking the Compile icon

mikroBasic will generate list and assembly file, and a hex file which can be used to program PIC MCU. But before trying out our program on PIC, let's test it with the Debugger.

Step 5

After successful compiling, we can use mikroBasic Debugger to check our program behavior before we feed it to the device (PIC16F877 or other). For a simple program such as this, simulation is not really necessary, but it is a requirement for more complex projects.

To start the Debugger, select Run > Debug, or click the Debug icon , or simply hit F9.

Upon starting the Debugger, Watch Window appears, and the active line in Code Editor marks the instruction to be executed next. We will set the breakpoint at line 9 by positioning the cursor to that line and toggling the breakpoint (Run > Toggle Breakpoint or F5). See the image below:

mikroBasic Debugger: Toggle Breakpoint

We will use the Step Over option (Run > Step Over or F8) to execute the current program line. Now, you can see the changes in variables, SFR registers, etc, in the Watch Window – items that have changed are marked red, as shown in the image below.

mikroBasic Debugger: Step Over

We could have used Run/Pause (F6) option to execute all the instructions between the active line and the breakpoint (Run > Run/Pause Debugger).

Step 6

Now we can use our hex file and feed it to the device (PIC16F877 or other). In order to do so, hex file must be loaded in programmer (PIC Flash by mikroElektronika or other).

For advanced users:

You can set any configuration for PIC MCUs config word(s). Set configuration bits (Device Flags) by clicking appropriate check boxes.

If you use internal PLL (Phase Locked Loop), device clock equals 4 x oscillator clock (be sure that appropriate value is in edit box ).