chapter 1 the first flight creating the first project and saying “hello to the world”

16
Chapter 1 Chapter 1 The First Flight The First Flight Creating the first project and saying “Hello to the World”

Upload: angelica-harmon

Post on 24-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Chapter 1Chapter 1 The First Flight The First Flight

Creating the first project and saying “Hello to the World”

Page 2: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

ChecklistChecklistThe following tools will be used throughout the course: MPLAB X, Integrated Development Environment (v1.8 or later,

free) MPLAB XC16, C compiler (v1.11 or later, free)

The following pieces of documentation will be used during this lesson:

PIC24FJ128GA010 Datasheet –DS39747 (latest rev.) PIC24 Family Reference Manual - Section 12. I/O Ports

Make sure they are available and/or installed and ready to use on your computer.

You can download them from Microchip web site at: http://www.microchip.com/mplabx

And http://www.microchip.com/xc16

Page 3: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

Creating the First ProjectCreating the First Project Use the New Project wizard:

Page 4: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New Project Wizard: step 2New Project Wizard: step 2 Select the PIC24 model:

Page 5: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New Project Wizard: step 3New Project Wizard: step 3 No Header is required:

Page 6: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New Project Wizard: step 4New Project Wizard: step 4 Select the programmer/debugger of choice:

ICD3 PICKit3 Real ICE ...

Page 7: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New Project Wizard: step 5New Project Wizard: step 5 Select the XC16 compiler (and version):

Page 8: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New Project Wizard: step 6New Project Wizard: step 6 Define the project location (folder) and

assign the Project Name:

Page 9: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New File Wizard:New File Wizard: Use the New File wizard to create a new main

file from a Microchip Embedded template:

Page 10: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New File Wizard: Alternate step1New File Wizard: Alternate step1 Use the New File wizard to create a new

empty file:

Page 11: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

New File Wizard: step 2New File Wizard: step 2 Assign the name: Hello1.c

Page 12: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

The First Program: Hello1.cThe First Program: Hello1.c/* * File: Hello1.c * * Author: your name here * * Created: current date here */

#include <xc.h>

int main( void) { return 0;}

Replaces previously used: #include <p24Fxxxx.h>Replaces previously used: #include <p24Fxxxx.h>

Page 13: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

What’s in <xc.h> What’s in <xc.h> After a selection based on the PIC24 model you

chose for your project, you will find the definitions of the program counter and other special-function registers of the microcontroller:...extern volatile unsigned int PCL __attribute__((__sfr__));extern volatile unsigned char PCH __attribute__((__sfr__));extern volatile unsigned char TBLPAG __attribute__((__sfr__));extern volatile unsigned char PSVPAG __attribute__((__sfr__));extern volatile unsigned int RCOUNT __attribute__((__sfr__));extern volatile unsigned int SR __attribute__((__sfr__));...

Page 14: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

Meet the Meet the Project WindowProject Window It contains a “logical” grouping of all the files

that belong to the project

Note: Like most MPLAB X windows, it can be free floating or docked!

right-click here to “dock” the windowright-click here to “dock” the window

Page 15: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

Meet: PORTAMeet: PORTA/*** Hello Embedded World**** Hello1.c my first PIC24 program in C*/#include <xc.h>

int main( void){ PORTA = 0xff; return 0;}

don’t forget the semicolon!don’t forget the semicolon!

Page 16: Chapter 1 The First Flight Creating the first project and saying “Hello to the World”

Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)

Building the ProjectBuilding the Project There are several ways to achieve the same

result in MPLAB X, select: Run > Build Project

Will compile all new and changed source files

Or: Run > Clean and Build Project

Produces a forced recompile of all source files

Or: Run > Run Project

Will compile all new and changed source files, if successful it will also program the part using the selected programmer/debugger

Or: Use the corresponding buttons in the top toolbar: