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

1st Project Dspic Basic

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

mikroElektronika

Development tools - Books - Compilers

mikroBasic for dsPIC

Creating First Project in


mikroBasic for dsPIC
In this simple tutorial, we will create a new project, write some code and compile it
in mikroBasic for dsPIC and test the results. Our project will make LED diodes
blink, so it can be easily tested on dsPIC microcontrollers.

Software and Hardware


solutions for Embedded World

Creating first project in mikroBasic for dsPIC


Hardware Connection
Here is the connection scheme youll need to test the code for microcontroller. We have used common
chip in our examples, but you may use any other microcontroller. LED diodes are connected to
PORTB, but you can use any other available port you would need to replace few lines in the code,
as explained in the following pages.

MCLR

AVDD

RB0

AVSS

RB1

RB9

RB2

RB10

RB5

LD0
LD1
LD2
LD3
LD4
LD5
LD6
LD7

RB6

1K

RB7

1K

RB8
VDD

1K

VSS
OSC1

1K
1K
1K
1K
1K

X1
10MHz

OSC2
RC13

C1
22pF

C2
22pF

RC14

RB11
RB12
RD0
RD1

VCC

Reset

RB4

dsPIC30Fxxxx

RB3

10K

VCC

dsPIC MCU
(PIC30F4013)

VDD
VSS
RF0
RF1
RF4
RF5
RF2
RF3

RA11

RF6

RD9

RD8

RD3

RD2

VSS

VDD

Step 1: Install the compiler


Install the mikroBasic for dsPIC compiler. Desktop shortcut and start menu shortcuts will be created.

Step 2: Run the compiler


Run the mikroBasic for dsPIC compiler. mikroBasic IDE (Integrated Development Environment) will
appear.

Step 3: Start the Wizard


Click the New Project icon or select Project > New Project from the drop-down menu:

New Project.

page

making it simple...

MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

Creating first project in mikroBasic for dsPIC


Step 4: Set up your project
Project Wizard dialog will appear - fill the dialog with appropriate settings for your project:
- Enter a name for your new project,
- Choose project path,
- Enter short text which describes your project (this is optional),
- Choose the microcontroller from drop-down menu (we have chosen
the one that is used in schematic for selected microcontroller, you may select
any other),
- Set the device clock by entering the value in edit box (we have set the same value
as drawn in schematic),
- Set configuration bits (Device Flags) by clicking Default,
- After you have set up your project, click OK to continue.

New Project window for


mikroBasic for dsPIC

Step 5: Write the code

Compiler will create the project file and


an accompanying source file, named
same as your project. This source file
will be automaticaly opened in the
Code Editor, so we can write the source
code. This is the Code Editor:

page
MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

making it simple...

Creating first project in mikroBasic for dsPIC


Led blinking for mikroBasic for dsPIC:
Here is the code that will make LEDs on PORTB blink every second. Type it in the Code Editor (if
there is any default code you can over write it):

File:
Page:

program Led_blinking
main:
while TRUE
TRISB = 0
LATB = %11111111
while true
LATB = not PORTB
delay_ms(1000)
wend
wend
end.

ProjName.dbas
1 od 1

' Endless loop


' Configure pins of PORTB as output
' Turn ON diodes on PORTB
' Toggle diodes on portb

Note: If you want to try another port, just replace each instance of LATB and TRISB in code with
your port, e.g. LATC/TRISC.

Step 6: Build!
Now its time to build our project. First, save your file by clicking on the Save Icon, or click Ctrl+S.
Select Project > Build from the drop-down menu, or click the Build Icon. You can also use the shortcut Ctrl+F9.
Build.

Compiler will generate output files in the project folder. There should be 4 new files: ProjectName.asm,
ProjectName.lst, ProjectName.mcl, and
ProjectName.hex. The last one will be used to
program the microcontroller directly.

Step 7: Real World test


To burn the dsPIC you can use the compilers integrated (dsPICprog) programmer (default shortcut
is F11) or any other programmer for selected microcontroller. As a result, LEDs connected to PORTB
of programmed microcontroller should blink indefinitely.

page

making it simple...

MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

You might also like