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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

16-Bit C <strong>Compiler</strong> User’s Guide<br />

• The peripheral should be initialized to 16-bit mode:<br />

PMMODEbits.MODE16 = 1<br />

The compiler will modify this setting during run-time as needed.<br />

• The peripheral should be configured <strong>for</strong> one of the MASTER modes:<br />

PMMODEbits.MODE = 2 or PMMODEbits.MODE = 3<br />

• Set the wait-states PMMODEbits.WAITB, PMMODEbits.WAITM, <strong>and</strong><br />

PMMODEbits.WAITE as appropriate <strong>for</strong> the device being connected.<br />

• The PMCON SFR should be configured as appropriate making sure that the chip<br />

select function bits PMCONbits.CSF match the in<strong>for</strong>mation communicated to the<br />

compiler when defining memory spaces.<br />

A partial example might be:<br />

void __init_PMP(void) {<br />

PMMODEbits.IRQM = 0;<br />

PMMODEbits.INCM = 0;<br />

PMMODEbits.MODE16 = 1;<br />

PMMODEbits.MODE = 3;<br />

/* device specific configuration of PMMODE <strong>and</strong> PMCCON follows */<br />

}<br />

6.3.2 Declare a New Memory Space<br />

The compiler toolsuite requires in<strong>for</strong>mation about each additional memory being<br />

attached via the PMP. In order <strong>for</strong> the 16-bit device linker to be able to properly assign<br />

memory, in<strong>for</strong>mation about the size of memory available <strong>and</strong> the number of<br />

chip-selects needs to be provided.<br />

In Chapter 2. “Differences Between 16-Bit Device C <strong>and</strong> ANSI C” the new pmp<br />

memory space was introduced. This attribute serves two purposes: declaring extended<br />

memory spaces <strong>and</strong> assigning C variable declarations to external memory (this will be<br />

covered in the next subsection).<br />

Declaring an extended memory requires providing the size of the memory. You may<br />

optionally assign the memory to a particular chip-select pin; if none is assigned it will<br />

be assumed that chip-selects are not being used. These memory declarations look like<br />

normal external C declarations:<br />

extern int external_PMP_memory<br />

__attribute__((space(pmp(size(1024),cs(0)))));<br />

Above we defined an external memory of size 1024 bytes <strong>and</strong> there are no<br />

chip-selects. The compiler only supports one PMP memory unless chip-selects are<br />

being used:<br />

extern int PMP_bank1 __attribute__((space(pmp(size(1024),cs(1)))));<br />

extern int PMP_bank2 __attribute__((space(pmp(size(2048),cs(2)))));<br />

Above PMP_bank1 will be activated using chip-select pin 1 (address pin 14 will be<br />

asserted when accessing variables in this bank). PMP_bank2 will be activated using<br />

chip-select pin 2 (address pin 15 will be asserted).<br />

Note that when using chip-selects, the largest amount of memory is 16Kbytes per bank.<br />

It is recommended that these declaration appear in a common header file so that the<br />

declaration is available to all translation units.<br />

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

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

Saved successfully!

Ooh no, something went wrong!