Page 185 - Programming Microcontrollers in C
P. 185

170    Chapter 4  Small 8-Bit Systems

                              Good programming practice dictates that microcontroller-specific
                          information be placed in a header file like that shown here:
                   #pragma portrw PORTA @ 0x00;
                   #pragma portrw PORTB @ 0x01;
                   #pragma portrw DDRA @ 0x04;
                   #pragma portrw DDRB @ 0x05;
                   #pragma portrw TCST @ 0x08;
                   #pragma portrw TCR @ 0x09;


                   #pragma portrw __COPSVS @ 0x7f0;
                   #pragma vector __TIMER @ 0x07f8;
                   #pragma vector __IRQ @ 0x07fa;
                   #pragma vector __SWI @ 0x07fc ;
                   #pragma vector __RESET @ 0x07fe;
                   #pragma has STOP ;
                   #pragma has WAIT ;
                   #pragma has MUL ;


                   #pragma memory RAMPAGE0 [64] @ 0xc0;
                   #pragma memory ROMPROG [1024] @ 0x300;


                   #define RT0 0 /* TSCR Bits */
                   #define RT1 1
                   #define RTIE 4
                   #define TOFE 5
                   #define RTIF 6
                   #define TOF 7


                              Listing 4-3: Header File For The M68HC05J1
                              The #pragma and several important #define commands are
                          microcontroller specific. Therefore, to change the program from one
                          microcontroller to another, the programmer need only change the
                          microcontroller header file. Listing 4-3 is a header file for the
                          M68HC05JJ1 controller. The first six entries identify the locations
                          of the I/O ports, the data direction registers, timer status/control reg­
                          ister, and the timer counter Register. The next five entries specify the
                          COP service address and the vector locations for this part. Note that
                          the names associated with the vector locations all start with a double
   180   181   182   183   184   185   186   187   188   189   190