180 likes | 408 Views
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; }
E N D
Chapter 1 The First Flight Creating the first project and saying “Hello to the Embedded World” Part 2
Debugging PORTA int 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)
Configuring 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
Creating an Include 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 nbprojectfolder: ../../include
Add the Include Path • Add the Include Path to the project properties 1-Select the xc16-gcc options 3-Provide a path to the Include folder 2-Select the Preprocessing and Messages options
Hello2.c – Using config.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; }
Hello3.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; }
Hello4.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; }
Notes for Assembly Experts • You can still take a look at the assembly code generated by the compiler • Learn to trust it!
Meet the Dashboard • All the information about your project at a glance
Tips 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!
Suggested 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.
Recommended Readings Kernighan, B. & Ritchie, D. The C Programming Language Prentice-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
Online 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.