Hardware Reference
In-Depth Information
#define PTA _IO8(0x00) // alternate name for PORTA
#define ATD0DR0 _IO16(0x90) // ADC result 0 register (a 16-bit register)
The header file is usually stored under the include directory. For example, the hcs12.h file
is stored in the directory c:\iccv712\include (c:\cwHCS12\include and c:\egnu\include) . The directory
cwHCS12 is the installation directory for CodeWarrior used by this author whereas the include di-
rectory is created under the cwHCS12 directory. One should add one of the following statements
to the C program if one is developing application programs that involve peripheral registers:
#include “c:\iccv712\include\hcs12.h”
#include “c:\cwHCS12\include\hcs12.h”
#include “c:\egnu\include\hcs12.h”
5.10.2 Peripheral Register Bit Definitions
In addition to the association of register names and addresses, the header file hcs12.h also
contains the bit values for many registers. Each bit is associated with a value that is equal to its
position weight. For example, the seventh bit of the ATD0CTL2 register is defined as follows:
#define ADPU 0x80
With this defi nition, you can use the following statement to set the ADPU bit of the ATD0CTL2
register:
ATD0CTL2 | 5 ADPU; // set the ADPU bit (bit 7)
To clear the ADPU bit, use the following statement:
ATD0CTL2 & 5 , ADPU; // clear the ADPU bit
All register names and all bit names are in uppercase. The user can change the case to sat-
isfy his or her preference. The header file provided by ImageCraft C compiler and the hcs12.h
file provided in the complementary CD use the same bit names as defined by Freescale. Header
files for other HCS12 members can be derived by editing the hcs12.h file.
5.10.3 Inline Assembly Instructions
Most C compilers allow the user to add inline assembly instructions in the C program. The
syntax for inline assembly is
asm(“<string>”);
For example, adding the following statement will cause the program control to return to the
D-Bug12 monitor when the program is running on a demo board with the D-Bug12 monitor:
asm(“swi”);
Adding the following statement will enable interrupt globally:
asm(“cli”);
5.11 Using the CodeWarrior IDE to Develop C Programs
CodeWarrior supports program debugging for demo boards programmed with the serial
monitor or through the BDM debugger. CodeWarrior can be started by clicking on its icon.
5.11.1 Entering C Programs in CodeWarrior
The startup screen of CodeWarrior is shown in Figure 5.3. The user has four options to choose
from. If the user wants to enter one or more C functions before creating a new project, she or he
 
Search WWH ::




Custom Search