1 / 17

Chapter 1 The First Flight

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; }

leanne
Download Presentation

Chapter 1 The First Flight

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1 The First Flight Creating the first project and saying “Hello to the Embedded World” Part 2

  2. Debugging and the Watches window

  3. I/O ports

  4. 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)

  5. 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

  6. 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

  7. 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

  8. 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; }

  9. 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; }

  10. AD1PCFG register

  11. 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; }

  12. Notes for Assembly Experts • You can still take a look at the assembly code generated by the compiler • Learn to trust it!

  13. Meet the Dashboard • All the information about your project at a glance

  14. 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!

  15. 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.

  16. 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

  17. 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.

More Related