Download as pdf or txt
Download as pdf or txt
You are on page 1of 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
sub procedure my_procedure dim var as byte var = not(PORTB) PORTD = var end sub

machine program
$0027 $ _my_procedure: ;PIC_877.pbas,13 :: ;PIC_877.pbas,14 :: $0027 $1303 BCF $0028 $1283 BCF $0029 $0906 COMF $002A $0088 MOVWF

assembly
dim var as byte var = not(PORTB) STATUS, RP1 STATUS, RP0 PORTB, W 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
sub procedure my_procedure dim var as byte

Global variable
program CM_877 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 Byte char* Word Short Integer Longword Longint Float * char 8bit 8bit 16bit 8bit 16bit 32bit 32bit 32bit Size Range 0 255 0 255 0 65535 -128 127 -32768 32767 0 4294967295 -2147483648 2147483647 1.17549435082 * 10-38 .. 6.80564774407 * 1038

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 const const const const MAX as longint = 10000 MIN = 1000 ' compiler will assume word type SWITCH = "n" ' compiler will assume char type MSG = "Hello" ' compiler will assume string type MONTHS as byte[12] = (31,28,31,30,31,30,31,31,30,31,30,31) 11 $11 0x11 %11 ' ' ' ' decimal literal hex literal, equals decimal 17 hex literal, equals decimal 17 binary literal, equals decimal 3 Beginning with MikroBasic 3/4

Note:

1 S uro

Iterations:
if (condition) then

condition yes Action

no

Action 1 End if

if (condition) then

condition yes Action

no

Action 1 else

Action

Action 2 End if

condition yes Action

no

while (condition) Action wend

Action condition no yes

do Action Loop until (condition)

1 S uro

Beginning with MikroBasic

4/4

You might also like