chapter 1 the first flight
DESCRIPTION
Chapter 1 The First Flight. Creating the first project and saying “ Hello to the Embedded World ” Part 2. Debugging and the Watches window. I/O ports. Debugging PORTA. int main( void) { PORTA = 0xff; TRISA = 0; // all PORTA pins output return 0; } - PowerPoint PPT PresentationTRANSCRIPT
Chapter 1Chapter 1 The First Flight The First Flight
Creating the first project and saying “Hello to the Embedded World”
Part 2
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Debugging and the Watches windowDebugging and the Watches window
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
I/O portsI/O ports
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Debugging PORTADebugging PORTAint main( void) { PORTA = 0xff; TRISA = 0; // all PORTA pins output return 0;}
Debugging functions: Build Project for debugging and enter Debug Mode: Exit Debug Mode Step Over Run (Debug Mode)
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Configuring the PIC24Configuring the PIC24/*** config.h** ** "Flying PIC24" projects device configuration*/#include <xc.h> _CONFIG1( JTAGEN_OFF // disable JTAG interface & GCP_OFF // disable general code protection & GWRP_OFF // disable flash write protection & ICS_PGx2 // ICSP interface (2=default) & FWDTEN_OFF) // disable watchdog timer _CONFIG2( IESO_OFF // two speed start up disabled & FCKSM_CSDCMD // disable clk-swithcing/monitor & FNOSC_PRIPLL // primary oscillator: enable PLL & POSCMOD_XT) // primary oscillator: XT mode
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Creating an Creating an IncludeInclude folder folder Create a folder called “include” at the top
level of your working directory (Flyingpic24) Save the config.h file in it Example:
FlyingPIC24/ include/ config.h 1-HelloWorld.X/ Hello1.c nbproject/ ...
To calculate a path, start from the nbproject folder:
../../include
To calculate a path, start from the nbproject folder:
../../include
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Add the Add the Include PathInclude Path Add the Include Path to the project properties
2-Select the Preprocessing and Messages options
2-Select the Preprocessing and Messages options
3-Provide a path to the Include folder
3-Provide a path to the Include folder
1-Select the xc16-gcc options1-Select the xc16-gcc options
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Hello2.c – Using Hello2.c – Using config.hconfig.h/*** Hello Embedded World**** Hello2.c controlling PORTA pin direction*/#include <config.h> // set the configuration bits int main( void){ PORTA = 0xff; TRISA = 0; // configure all PORTA pins as outputs return 0;}
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Hello3.c – Using Port BHello3.c – Using Port B/*** Hello Embedded World**** Hello3.c Testing PORTB, another surprise!*/#include <config.h>
int main( void){ PORTB = 0xff; TRISB = 0; // configure all PORTB pins as outputs return 0;}
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
AD1PCFG registerAD1PCFG register
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Hello4.c – Port B under ControlHello4.c – Port B under Control/*** Hello Embedded World**** Hello4.c learning to control the Analog Pins*/#include <config.h> int main( void){ PORTB = 0xff; AD1PCFG = 0xffff; // all PORTB as digital TRISB = 0; // all PORTB as output return 0;}
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Notes for Assembly ExpertsNotes for Assembly Experts You can still take a look at the assembly code
generated by the compiler Learn to trust it!
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Meet the Meet the DashboardDashboard All the information about your project at a
glance
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Tips and TricksTips and Tricks Interfacing to 5V input and output signals is
possible with some caution: Digital Input pins are 5V tolerant Digital Output pins can be configured as Open Drain Use the ODCx registers to configure an output pin for
Open Drain mode. Watch Out! Pins that are multiplexed with analog
functions are NOT 5V tolerant!
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Suggested ExcercisesSuggested Excercises To test the PORTB example (Hello4.c):
Connect a Voltmeter to pin RB0 Watch the needle move as you single step through the code.
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Recommended ReadingsRecommended ReadingsKernighan, B. & Ritchie, D.The C Programming LanguagePrentice-Hall, Englewood Cliffs, NJ
When you read or hear a programmer talk about the “K&R” … they mean this book!
Also known as “the white book”, the C language has evolved quite a bit since the first edition was published in 1978!
The second edition (1988) includes the more recent ANSI C standard definitions of the language
The MPLAB C32 compiler adheres to the ISO/IEC 9899:1990 (also known as C90) standard
Di Jasio – Programming 16-bit Microcontrollers in C (Second Edition)
Online ResourcesOnline Resources http://en.wikibooks.org/wiki/C_Programming
This is a Wiki-book on C programming and as such it is a bit of a work in progress. It’s convenient if you don’t mind doing all your reading online.
Hint: look for the chapter called “A taste of C” to find the omnipresent “Hello World!” example.
http://publications.gbdirect.co.uk/c_book/ This is the online version of The C Book, second
edition by Mike Banahan, Declan Brady and Mark Doran, originally published by Addison Wesley in 1991. This version is made freely available.