2 * \author Maarten Brock
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * In other words, you are welcome to use, share and improve this program.
19 * You are forbidden to forbid anyone else to use, share and improve
20 * what you give them. Help stamp out software-hoarding!
22 * Header file to overcome 8051 compiler differences for specifying
23 * special function registers. The following compilers are supported:
24 * SDCC, Keil, Raisonance, IAR, Hi-Tech, Tasking, Crossware, Wickenhäuser.
25 * Unfortunately not for use with Dunfield. The compilers are identified by
26 * their unique predefined macros. See also:
27 * http://predef.sourceforge.net/precomp.html
29 * SBIT and SFR define special bit and special function registers at the given
30 * address. SFR16 and SFR32 define sfr combinations at adjacent addresses in
31 * little-endian format. SFR16E and SFR32E define sfr combinations without
32 * prerequisite byte order or adjacency. None of these multi-byte sfr
33 * combinations will guarantee the order in which they are accessed when read
35 * SFR16X and SFR32X for 16 bit and 32 bit xdata registers are not defined
36 * to avoid portability issues because of compiler endianness.
37 * This file is to be included in every microcontroller specific header file.
40 * // my_mcu.h: sfr definitions for my mcu
41 * #include <compiler.h>
43 * SBIT (P0_1, 0x80, 1); // Port 0 pin 1
45 * SFR (P0, 0x80); // Port 0
47 * SFRX (CPUCS, 0xE600); // Cypress FX2 Control and Status register in xdata memory at 0xE600
49 * SFR16 (TMR2, 0xCC); // Timer 2, lsb at 0xCC, msb at 0xCD
51 * SFR16E(TMR0, 0x8C8A); // Timer 0, lsb at 0x8A, msb at 0x8C
53 * SFR32 (MAC0ACC, 0x93); // SiLabs C8051F120 32 bits MAC0 Accumulator, lsb at 0x93, msb at 0x96
55 * SFR32E(SUMR, 0xE5E4E3E2); // TI MSC1210 SUMR 32 bits Summation register, lsb at 0xE2, msb at 0xE5
62 /** SDCC - Small Device C Compiler
66 # define SBIT(name, addr, bit) __sbit __at(addr+bit) name
67 # define SFR(name, addr) __sfr __at(addr) name
68 # define SFRX(name, addr) xdata volatile unsigned char __at(addr) name
69 # define SFR16(name, addr) __sfr16 __at(((addr+1U)<<8) | addr) name
70 # define SFR16E(name, fulladdr) __sfr16 __at(fulladdr) name
71 # define SFR32(name, addr) __sfr32 __at(((addr+3UL)<<24) | ((addr+2UL)<<16) | ((addr+1UL)<<8) | addr) name
72 # define SFR32E(name, fulladdr) __sfr32 __at(fulladdr) name
77 #elif defined __CX51__
78 # define SBIT(name, addr, bit) sbit name = addr^bit
79 # define SFR(name, addr) sfr name = addr
80 # define SFRX(name, addr) volatile unsigned char xdata name _at_ addr
81 # define SFR16(name, addr) sfr16 name = addr
82 # define SFR16E(name, fulladdr) /* not supported */
83 # define SFR32(name, fulladdr) /* not supported */
84 # define SFR32E(name, fulladdr) /* not supported */
87 * http://www.raisonance.com
89 #elif defined __RC51__
90 # define SBIT(name, addr, bit) at (addr+bit) sbit name
91 # define SFR(name, addr) sfr at addr name
92 # define SFRX(name, addr) xdata at addr volatile unsigned char name
93 # define SFR16(name, addr) sfr16 at addr name
94 # define SFR16E(name, fulladdr) /* not supported */
95 # define SFR32(name, fulladdr) /* not supported */
96 # define SFR32E(name, fulladdr) /* not supported */
101 #elif defined __ICC8051__
102 # define SBIT(name, addr, bit) __bit __no_init volatile bool name @ (addr+bit)
103 # define SFR(name, addr) __sfr __no_init volatile unsigned char name @ addr
104 # define SFRX(name, addr) __xdata __no_init volatile unsigned char name @ addr
105 # define SFR16(name, addr) __sfr __no_init volatile unsigned int name @ addr
106 # define SFR16E(name, fulladdr) /* not supported */
107 # define SFR32(name, fulladdr) __sfr __no_init volatile unsigned long name @ addr
108 # define SFR32E(name, fulladdr) /* not supported */
111 * http://www.altium.com/tasking
114 # define SBIT(name, addr, bit) _sfrbit name _at(addr+bit)
115 # define SFR(name, addr) _sfrbyte name _at(addr)
116 # define SFRX(name, addr) _xdat volatile unsigned char name _at(addr)
118 # define SFR16(name, addr) _sfrword _little name _at(addr)
120 # define SFR16(name, addr) /* not supported */
122 # define SFR16E(name, fulladdr) /* not supported */
123 # define SFR32(name, fulladdr) /* not supported */
124 # define SFR32E(name, fulladdr) /* not supported */
127 * http://www.htsoft.com
129 #elif defined HI_TECH_C
130 # define SBIT(name, addr, bit) volatile bit name @ (addr+bit)
131 # define SFR(name, addr) volatile unsigned char name @ addr
132 # define SFRX(name, addr) volatile far unsigned char name @ addr
133 # define SFR16(name, addr) /* not supported */
134 # define SFR16E(name, fulladdr) /* not supported */
135 # define SFR32(name, fulladdr) /* not supported */
136 # define SFR32E(name, fulladdr) /* not supported */
139 * http://www.crossware.com
141 #elif defined _XC51_VER
142 # define SBIT(name, addr, bit) _sfrbit name = (addr+bit)
143 # define SFR(name, addr) _sfr name = addr
144 # define SFRX(name, addr) volatile unsigned char _xdata name _at addr
145 # define SFR16(name, addr) _sfrword name = addr
146 # define SFR16E(name, fulladdr) /* not supported */
147 # define SFR32(name, fulladdr) /* not supported */
148 # define SFR32E(name, fulladdr) /* not supported */
151 * http://www.wickenhaeuser.de
154 # define SBIT(name, addr, bit) unsigned char bit name @ (addr+bit)
155 # define SFR(name, addr) near unsigned char name @ addr
156 # define SFRX(name, addr) xdata volatile unsigned char name @ addr
157 # define SFR16(name, addr) /* not supported */
158 # define SFR16E(name, fulladdr) /* not supported */
159 # define SFR32(name, fulladdr) /* not supported */
160 # define SFR32E(name, fulladdr) /* not supported */
166 # warning unknown compiler
167 # define SBIT(name, addr, bit) volatile bool name
168 # define SFR(name, addr) volatile unsigned char name
169 # define SFRX(name, addr) volatile unsigned char name
170 # define SFR16(name, addr) volatile unsigned short name
171 # define SFR16E(name, fulladdr) volatile unsigned short name
172 # define SFR32(name, fulladdr) volatile unsigned long name
173 # define SFR32E(name, fulladdr) volatile unsigned long name