0% found this document useful (0 votes)
158 views4 pages

Start With MikroBasic

This document provides an introduction to programming with MikroBasic, including: - MikroBasic is a software for programming PIC microcontrollers. - A basic program is compiled into machine code and assembly code that the microcontroller can understand. - Variables can be defined as local or global, and different variable types like byte, word, integer are described. - The program is downloaded to the PIC microcontroller using a bootloader tool by making a connection while resetting the PIC. - Control structures like if/else and while/wend statements are explained for iterations in a basic program.

Uploaded by

Emidio Carreño
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views4 pages

Start With MikroBasic

This document provides an introduction to programming with MikroBasic, including: - MikroBasic is a software for programming PIC microcontrollers. - A basic program is compiled into machine code and assembly code that the microcontroller can understand. - Variables can be defined as local or global, and different variable types like byte, word, integer are described. - The program is downloaded to the PIC microcontroller using a bootloader tool by making a connection while resetting the PIC. - Control structures like if/else and while/wend statements are explained for iterations in a basic program.

Uploaded by

Emidio Carreño
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Start with MikroBasic

MikroBasic is a Mikroelectronica software "http://www.mikroe.com/"

You can find help when F1 is pressed (or click on


help), click on Index, and indicate what you need.

For example ask for byte, the help shows you the
different types a variable can be define.

This help is very useful, don't hesitate to call it.

What is a program made with?

A project contains two main files:


- the *.pbp defines the type of PIC, how it works (programming method, crystal type…)
- the *.pbas file contains the basic code

A program is created from the "main" function, which may call other procedures or functions.
- a procedure is a sub routine which execute a part of the program
- a function is like a procedure, but it returns a result.

See the help contents…

1 S €uro Beginning with MikroBasic 1/4


When the program is completed, you have to compile it. This operation translates the basic
program in an assembly program and defines the machine code which is made with hex symbols
(the only thing a micro-controller is able to understand)

Basic program machine program assembly


sub procedure my_procedure $0027 $ _my_procedure:
dim var as byte ;PIC_877.pbas,13 :: dim var as byte
var = not(PORTB) ;PIC_877.pbas,14 :: var = not(PORTB)
PORTD = var $0027 $1303 BCF STATUS, RP1
$0028 $1283 BCF STATUS, RP0
end sub $0029 $0906 COMF PORTB, W
$002A $0088 MOVWF PORTD

Many years ago, people directly programmed in machine code. I let you imagine the requested
time.

To compile the program, press [CTRL] + [F9].

How to download the program in the PIC?

In the PIC, there is already a software called "boot loader" which test, after a reset, if a PC is
connected to download.
If the computer is present, the PIC waits to be programmed, else after 1.25 s, it begins the
program download before.

To proceed downloading, you have to


- Open the mikroBootloader tool.
- Select 19200 bds (Setup Port)
- Open the HEX file to download
- Make a RESET on the PIC board and
simultaneously click on [Connect]
- If the message is "connected" click on
[Start bootloader].

1 S €uro Beginning with MikroBasic 2/4


Uses of variables:

To define a variable you have to specify the type. You can define a local variable (in a function or
in a procedure) or a global variable which can be used in the entire program:

Local variable Global variable


sub procedure my_procedure program CM_877
dim var as byte
dim var as byte

sub…

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.
Here is an overview of simple types in mikroBasic:

Type Size Range


Byte 8–bit 0 – 255
char* 8–bit 0 – 255
Word 16–bit 0 – 65535
Short 8–bit -128 – 127
Integer 16–bit -32768 – 32767
Longword 32–bit 0 – 4294967295
Longint 32–bit -2147483648 – 2147483647
±1.17549435082 * 10-38 ..
Float 32–bit
±6.80564774407 * 1038
* char type can be treated as byte type in every aspect

Constants
Constant is 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 program or routine. Declare a constant like this:
const constant_name [as type] = value
The type is optional; in the absence of type, compiler assumes the “smallest” type that can
accommodate value.

Note: You cannot omit type if declaring a constant array.

Here are a few examples:

const MAX as longint = 10000


const MIN = 1000 ' compiler will assume word type
const SWITCH = "n" ' compiler will assume char type
const MSG = "Hello" ' compiler will assume string type
const MONTHS as byte[12] = (31,28,31,30,31,30,31,31,30,31,30,31)

Note: 11 ' decimal literal


$11 ' hex literal, equals decimal 17
0x11 ' hex literal, equals decimal 17
%11 ' binary literal, equals decimal 3

1 S €uro Beginning with MikroBasic 3/4


Iterations:

if (condition) then

condition no
Action 1

yes End if
Action

if (condition) then

condition no
Action 1

yes else
Action Action Action 2

End if

condition no
while (condition)

yes Action
Action wend

do
Action
Action

condition yes Loop until (condition)

no

1 S €uro Beginning with MikroBasic 4/4

You might also like