231/317
8 - C Language and the C Compiler
8.3.3.1 First method: using macros
The method that the documentation of the compiler suggests relies on the definition of a
macro that produces a pointer definition, as in the following example that defines PADR that is
located at address 8:
#define PADR * ((unsigned char *)(8))
This notation is almost equivalent to a variable definition; it allows the following syntaxes:
PADR = 0x10 ;
/* Set port A to 10 h */
PADR &= ~0x10 ;
/* Reset bit 4 of PA */
8.3.3.2 Second method: defining variables
This method is the one that is recommended by STMicroelectronics. Several definition files
are already written and are available in the example files that come with this book. It consists
of defining a segment for each peripheral, and within this segment, the list of the registers as
a series of variables of the unsigned character type:
/* Serial Peripheral Interface */
#pragma DATA_SEG SHORT SPI
volatile unsigned char SPIDR;
/* SPI Data Register */
volatile unsigned char SPICR;
/* SPI Control Register */
volatile unsigned char SPISR;
/* SPI Status Register */
All the register definitions are conveniently grouped in an include file named
MAP_7225.C;
and the corresponding external declarations are grouped in the header file
MAP_7225.H
.
On linking, these segments will be positioned at the right addresses by declarations like:
SECTIONS
/* some declarations... */
ASPI
= READ_WRITE
0x21 TO
0x23;
/* more declarations... */
PLACEMENT
/* some declarations... */
SPI
INTO
ASPI;
/* more declarations... */
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...