4
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 mikroBasic for dsPIC mikroElektronika Development tools - Books - Compilers

1st Project Dspic Basic

Embed Size (px)

Citation preview

Page 1: 1st Project Dspic Basic

Creating First Project inmikroBasic for dsPIC

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

Software and Hardwaresolutions for Embedded World

mikroBasic for dsPICmikroElektronikaDevelopment tools - Books - Compilers

Page 2: 1st Project Dspic Basic

Creating ffirst pproject iin mmikroBasic ffor ddsPIC

2 making it simple... M I K R O E L E K T R O N I K A S O F T W A R E A N D H A R D W A R E S O L U T I O N S F O R T H E E M B E D D E D W O R L D

page

Here is the connection scheme you’ll need to test the code for microcontroller. We have used commonchip in our examples, but you may use any other microcontroller. LED diodes are connected toPORTB, but you can use any other available port – you would need to replace few lines in the code,as explained in the following pages.

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

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

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

dsPIC MCU(PIC30F4013)

Hardware Connection

Step 1: Install the compiler

Step 2: Run the compiler

New Project.

Step 3: Start the Wizard

dsP

IC30F

xxxx

RB0

RB1

RB2

RB3

RC13

RC14

RB4

RB5

RB6

RB7

RB8

RD9

RD3

VSS

RD8

RD2

VDD

RF6

RF3

RF2

RF5

RF4

RF1

RF0

RD1

RD0

RB12

RB11

RB10

RB9

AVDD

AVSS

RA11

VDD

VSS

OSC1

OSC2

MCLR

VDD

VSS

X110MHz

C122pF

C222pF

LD0

LD1

LD2

LD3

LD4

LD5

LD6

LD7

10K

Re

se

t

VCC

VCC

1K

1K

1K

1K

1K

1K

1K

1K

Page 3: 1st Project Dspic Basic

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 selectany other),

- Set the device clock by entering the value in edit box (we have set the same valueas drawn in schematic),

- Set configuration bits (Device Flags) by clicking Default,- After you have set up your project, click OK to continue.

Creating ffirst pproject iin mmikroBasic ffor ddsPIC

New Project window formikroBasic for dsPIC

Step 4: Set up your project

Step 5: Write the codeCompiler will create the project file andan accompanying source file, namedsame as your project. This source filewill be automaticaly opened in theCode Editor, so we can write the sourcecode. This is the Code Editor: (

M I K R O E L E K T R O N I K A S O F T W A R E A N D H A R D W A R E S O L U T I O N S F O R T H E E M B E D D E D W O R L D making it simple... 3page

Page 4: 1st Project Dspic Basic

Creating ffirst pproject iin mmikroBasic ffor ddsPIC

4 making it simple... M I K R O E L E K T R O N I K A S O F T W A R E A N D H A R D W A R E S O L U T I O N S F O R T H E E M B E D D E D W O R L D

page

Here is the code that will make LED’s on PORTB blink every second. Type it in the Code Editor (ifthere is any default code you can over write it):

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

Now it’s 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 short-cut Ctrl+F9.

Build.

Led blinking for mikroBasic for dsPIC:

program Led_blinkingmain:

while TRUE ' Endless loopTRISB = 0 ' Configure pins of PORTB as outputLATB = %11111111 ' Turn ON diodes on PORTBwhile true

LATB = not PORTB ' Toggle diodes on portbdelay_ms(1000)

wendwend

end.

File: ProjName.dbasPage: 1 od 1

Step 6: Build!

Compiler will generate output files in the project fold-er. There should be 4 new files: ProjectName.asm,ProjectName.lst, ProjectName.mcl, andProjectName.hex. The last one will be used toprogram the microcontroller directly.

Step 7: Real World testTo “burn” the dsPIC you can use the compiler’s integrated (dsPICprog) programmer (default shortcutis F11) or any other programmer for selected microcontroller. As a result, LED’s connected to PORTBof programmed microcontroller should blink indefinitely.