Professional Documents
Culture Documents
Start With Mikrobasic: What Is A Program Made With?
Start With Mikrobasic: What Is A Program Made With?
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.
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].
1 S uro
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
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,
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
no
Action 1 End if
if (condition) then
no
Action 1 else
Action
Action 2 End if
no
1 S uro
4/4