07.04.2013 Views

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.5 USING SFRS<br />

Device Support Files<br />

There are three steps to follow when using SFR’s in an application.<br />

1. Include the processor header file <strong>for</strong> the appropriate device. This provides the<br />

source code with the SFR’s that are available <strong>for</strong> that device. For instance, the<br />

following statement includes the header files <strong>for</strong> the <strong>dsPIC</strong>30F6014 part:<br />

#include <br />

2. Access SFR’s like any other C variables. The source code can write to <strong>and</strong>/or<br />

read from the SFR’s.<br />

For example, the following statement clears all the bits to zero in the special<br />

function register <strong>for</strong> Timer1.<br />

TMR1 = 0;<br />

This next statement represents the 15th bit in the T1CON register which is the<br />

“timer on” bit. It sets the bit named TON to 1 which starts the timer.<br />

T1CONbits.TON = 1;<br />

3. Link with the register definition file or linker script <strong>for</strong> the appropriate device. The<br />

linker provides the addresses of the SFR’s. (Remember the bit structure will have<br />

the same address as the SFR at link time.) Example 6.1 would use:<br />

p30f6014.gld<br />

See “<strong>MPLAB</strong> ® Assembler, Linker <strong>and</strong> Utilities <strong>for</strong> <strong>PIC24</strong> <strong>MCUs</strong> <strong>and</strong> <strong>dsPIC</strong> ® <strong>DSCs</strong><br />

User’s Guide” (DS51317) <strong>for</strong> more in<strong>for</strong>mation on using linker scripts.<br />

The following example is a sample real time clock. It uses several SFR’s. Descriptions<br />

<strong>for</strong> these SFR’s are found in the p30f6014.h file. This file would be linked with the<br />

device specific linker script which is p30f6014.gld.<br />

© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 93

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!