Imported Upstream version 2.9.0
[debian/cc1111] / device / include / mcs51 / p89v66x.h
1 /*--------------------------------------------------------------------------
2 p89v66x.h
3
4 This header allows to use the microcontroler NXP (formerly Philips) p89v66x
5 where x stands for 0,2,4.
6
7 Copyright (c) 2008 Gudjon I. Gudjonsson <gudjon AT gudjon.org>
8
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
17  Lesser General Public License for more details.
18
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA
22
23  The registered are ordered in the same way as in the NXP data sheet:
24  http://www.standardics.nxp.com/products/80c51/datasheet/p89v660.p89v662.p89v664.pdf
25
26 --------------------------------------------------------------------------*/
27 #ifndef __P89V66X_H__
28 #define __P89V66X_H__
29 #include <compiler.h>
30
31 /*BYTE Registers*/
32 SFR(ACC, 0xE0); // Accumulator
33         SBIT(ACC_7, 0xE0, 7);
34         SBIT(ACC_6, 0xE0, 6);
35         SBIT(ACC_5, 0xE0, 5);
36         SBIT(ACC_4, 0xE0, 4);
37         SBIT(ACC_3, 0xE0, 3);
38         SBIT(ACC_2, 0xE0, 2);
39         SBIT(ACC_1, 0xE0, 1);
40         SBIT(ACC_0, 0xE0, 0);
41 SFR(AUXR, 0x8E); // Auxiliary
42         #define  EXTRAM   0x02
43         #define  AO       0x01
44 SFR(AUXR1, 0xA2); // Auxiliary 1
45         #define  ENBOOT   0x20
46         #define  GF2      0x08
47         // Bit 2 must be zero
48         #define  DPS      0x01
49 SFR(B, 0xF0); // B register
50         SBIT(B7, 0xF0, 7);
51         SBIT(B6, 0xF0, 6);
52         SBIT(B5, 0xF0, 5);
53         SBIT(B4, 0xF0, 4);
54         SBIT(B3, 0xF0, 3);
55         SBIT(B2, 0xF0, 2);
56         SBIT(B1, 0xF0, 1);
57         SBIT(B0, 0xF0, 0);
58 SFR(CCAP0H, 0xFA); // Module 0 Capture High
59 SFR(CCAP1H, 0xFB); // Module 1 Capture High
60 SFR(CCAP2H, 0xFC); // Module 2 Capture High
61 SFR(CCAP3H, 0xFD); // Module 3 Capture High
62 SFR(CCAP4H, 0xFE); // Module 4 Capture High
63 SFR(CCAP0L, 0xEA); // Module 0 Capture Low
64 SFR(CCAP1L, 0xEB); // Module 1 Capture Low
65 SFR(CCAP2L, 0xEC); // Module 2 Capture Low
66 SFR(CCAP3L, 0xED); // Module 3 Capture Low
67 SFR(CCAP4L, 0xEE); // Module 4 Capture Low
68 SFR(CCAPM0, 0xC2); // Module 0 Mode
69         #define ECOM_0   0x40
70         #define CAPP_0   0x20
71         #define CAPN_0   0x10
72         #define  MAT_0   0x08
73         #define  TOG_0   0x04
74         #define  PWM_0   0x02
75         #define ECCF_0   0x01
76 SFR(CCAPM1, 0xC3); // Module 1 Mode
77         #define ECOM_1   0x40
78         #define CAPP_1   0x20
79         #define CAPN_1   0x10
80         #define  MAT_1   0x08
81         #define  TOG_1   0x04
82         #define  PWM_1   0x02
83         #define ECCF_1   0x01
84 SFR(CCAPM2, 0xC4); // Module 2 Mode
85         #define ECOM_2   0x40
86         #define CAPP_2   0x20
87         #define CAPN_2   0x10
88         #define  MAT_2   0x08
89         #define  TOG_2   0x04
90         #define  PWM_2   0x02
91         #define ECCF_2   0x01
92 SFR(CCAPM3, 0xC5); // Module 3 Mode
93         #define ECOM_3   0x40
94         #define CAPP_3   0x20
95         #define CAPN_3   0x10
96         #define  MAT_3   0x08
97         #define  TOG_3   0x04
98         #define  PWM_3   0x02
99         #define ECCF_3   0x01
100 SFR(CCAPM4, 0xC6); // Module 4 Mode
101         #define ECOM_4   0x40
102         #define CAPP_4   0x20
103         #define CAPN_4   0x10
104         #define  MAT_4   0x08
105         #define  TOG_4   0x04
106         #define  PWM_4   0x02
107         #define ECCF_4   0x01
108         #define ECOM     0x40
109         #define CAPP     0x20
110         #define CAPN     0x10
111         #define MAT      0x08
112         #define TOG      0x04
113         #define PWM      0x02
114         #define ECCF     0x01
115 SFR(CCON,   0xC0); // PCA Counter Control
116         SBIT(CF,   0xC0, 7);
117         SBIT(CR,   0xC0, 6);
118         SBIT(CCF4, 0xC0, 4);
119         SBIT(CCF3, 0xC0, 3);
120         SBIT(CCF2, 0xC0, 2);
121         SBIT(CCF1, 0xC0, 1);
122         SBIT(CCF0, 0xC0, 0);
123 SFR(CH,   0xF9); // PCA Counter High
124 SFR(CL,   0xE9); // PCA Counter Low
125 SFR(CMOD, 0xC1); // PCA Counter Mode
126         #define CIDL    0x80
127         #define WDTE    0x40
128         #define CPS1    0x04
129         #define CPS0    0x02
130         #define  ECF    0x01
131 SFR(DPH,  0x83); // Data Pointer High
132 SFR(DPL,  0x82); // Data Pointer Low
133 SFR(IEN0, 0xA8); // Interrupt Enable 0
134         SBIT(EA,  0xA8, 7);
135         SBIT(EC,  0xA8, 6);
136         SBIT(ES1, 0xA8, 5);
137         SBIT(ES0, 0xA8, 4);
138         SBIT(ET1, 0xA8, 3);
139         SBIT(EX1, 0xA8, 2);
140         SBIT(ET0, 0xA8, 1);
141         SBIT(EX0, 0xA8, 0);
142 SFR(IEN1, 0xE8); // Interrupt Enable 1
143         SBIT(ES3, 0xE8, 2);
144         SBIT(ES2, 0xE8, 1);
145         SBIT(ET2, 0xE8, 0);
146 SFR(IP0, 0xB8); // Interrupt Priority 0
147         SBIT(PT2, 0xB8, 7);
148         SBIT(PPC, 0xB8, 6);
149         SBIT(PS1, 0xB8, 5);
150         SBIT(PS0, 0xB8, 4);
151         SBIT(PT1, 0xB8, 3);
152         SBIT(PX1, 0xB8, 2);
153         SBIT(PT0, 0xB8, 1);
154         SBIT(PX0, 0xB8, 0);
155 SFR(IP0H, 0xB7); // Interrupt Priority 0 High
156         #define PT2H  0x80
157         #define PPCH  0x40
158         #define PS1H  0x20
159         #define PS0H  0x10
160         #define PT1H  0x08
161         #define PX1H  0x04
162         #define PT0H  0x02
163         #define PX0H  0x01
164 SFR(IP1, 0x91); // Interrupt Priority 1
165         #define PS3  0x02
166         #define PS2  0x01
167 SFR(IP1H, 0x92); // Interrupt Priority 1 High
168         #define PS3H  0x02
169         #define PS2H  0x01
170 SFR(P0, 0x80); // Port 0
171         SBIT(AD7,  0x80, 7);
172         SBIT(P0_7, 0x80, 7);
173         SBIT(AD6,  0x80, 6);
174         SBIT(P0_6, 0x80, 6);
175         SBIT(AD5,  0x80, 5);
176         SBIT(P0_5, 0x80, 5);
177         SBIT(AD4,  0x80, 4);
178         SBIT(P0_4, 0x80, 4);
179         SBIT(AD3,  0x80, 3);
180         SBIT(P0_3, 0x80, 3);
181         SBIT(AD2,  0x80, 2);
182         SBIT(P0_2, 0x80, 2);
183         SBIT(AD1,  0x80, 1);
184         SBIT(P0_1, 0x80, 1);
185         SBIT(AD0,  0x80, 0);
186         SBIT(P0_0, 0x80, 0);
187 SFR(P1, 0x90); // Port 1
188         SBIT(T1_CEX4, 0x90, 7);
189         SBIT(P1_7,    0x90, 7);
190         SBIT(T0_CEX3, 0x90, 6);
191         SBIT(P1_6,    0x90, 6);
192         SBIT(CEX2,    0x90, 5);
193         SBIT(P1_5,    0x90, 5);
194         SBIT(CEX1,    0x90, 4);
195         SBIT(P1_4,    0x90, 4);
196         SBIT(CEX0,    0x90, 3);
197         SBIT(P1_3,    0x90, 3);
198         SBIT(ECI,     0x90, 2);
199         SBIT(P1_2,    0x90, 2);
200         SBIT(T2EX,    0x90, 1);
201         SBIT(P1_1,    0x90, 1);
202         SBIT(T2,      0x90, 0);
203         SBIT(P1_0,    0x90, 0);
204 SFR(P2, 0xA0); // Port 2
205         SBIT(AD15, 0xA0, 7);
206         SBIT(P2_7, 0xA0, 7);
207         SBIT(AD14, 0xA0, 6);
208         SBIT(P2_6, 0xA0, 6);
209         SBIT(AD13, 0xA0, 5);
210         SBIT(P2_5, 0xA0, 5);
211         SBIT(AD12, 0xA0, 4);
212         SBIT(P2_4, 0xA0, 4);
213         SBIT(AD11, 0xA0, 3);
214         SBIT(P2_3, 0xA0, 3);
215         SBIT(AD10, 0xA0, 2);
216         SBIT(P2_2, 0xA0, 2);
217         SBIT(AD9,  0xA0, 1);
218         SBIT(P2_1, 0xA0, 1);
219         SBIT(AD8,  0xA0, 0);
220         SBIT(P2_0, 0xA0, 0);
221 SFR(P3, 0xB0); // Port 3
222         SBIT(RD,   0xB0, 7);
223         SBIT(P3_7, 0xB0, 7);
224         SBIT(WR,   0xB0, 6);
225         SBIT(P3_6, 0xB0, 6);
226         SBIT(T1,   0xB0, 5);
227         SBIT(P3_5, 0xB0, 5);
228         SBIT(T0,   0xB0, 4);
229         SBIT(P3_4, 0xB0, 4);
230         SBIT(INT1, 0xB0, 3);
231         SBIT(P3_3, 0xB0, 3);
232         SBIT(INT0, 0xB0, 2);
233         SBIT(P3_2, 0xB0, 2);
234         SBIT(TXD,  0xB0, 1);
235         SBIT(P3_1, 0xB0, 1);
236         SBIT(RXD,  0xB0, 0);
237         SBIT(P3_0, 0xB0, 0);
238 SFR(P4, 0xA1); // Port 3
239         #define SS    0x08
240         #define P4_3  0x08
241         #define MOSI  0x04
242         #define P4_2  0x04
243         #define MISO  0x02
244         #define SDA_1 0x02
245         #define P4_1  0x02
246         #define SCK   0x01
247         #define SCL_1 0x01
248         #define P4_0  0x01
249 SFR(PCON, 0x87); // Power Control
250         #define SMOD1  0x80
251         #define SMOD0  0x40
252         #define POF    0x10
253         #define GF1    0x08
254         #define GF0    0x04
255         #define PD     0x02
256         #define IDL    0x01
257 SFR(PSW, 0xD0); // Program Status Word
258         SBIT(CY,  0xD0, 7);
259         SBIT(AC,  0xD0, 6);
260         SBIT(F0,  0xD0, 5);
261         SBIT(RS1, 0xD0, 4);
262         SBIT(RS0, 0xD0, 3);
263         SBIT(OV,  0xD0, 2);
264         SBIT(F1,  0xD0, 1);
265         SBIT(P,   0xD0, 0);
266 SFR(RCAP2H, 0xCB); // Timer 2 Capture High
267 SFR(RCAP2L, 0xCA); // Timer 2 Capture Low
268 SFR(S0CON,  0x98); // Serial Control 
269         SBIT(SM0_FE,0x98, 7);
270         SBIT(SM1,   0x98, 6);
271         SBIT(SM2,   0x98, 5);
272         SBIT(REN,   0x98, 4);
273         SBIT(TB8,   0x98, 3);
274         SBIT(RB8,   0x98, 2);
275         SBIT(TI,    0x98, 1);
276         SBIT(RI,    0x98, 0);
277 SFR(S0BUF, 0x99); // Serial Data Buffer
278 SFR(SADDR, 0xA9); // I2C Slave Address
279 SFR(SADEN, 0xB9); // I2C Slave Address Mask
280 SFR(SPCR,  0xD5); // SPI Control Register
281         #define SPIE  0x80
282         #define SPEN  0x40
283         #define DORD  0x20
284         #define MSTR  0x10
285         #define CPOL  0x08
286         #define CPHA  0x04
287         #define SPR1  0x02
288         #define SPR0  0x01
289 /*      SBIT(SPIE,   0x80, 7);   // SPCR is not bit addressable, not yet at least, according to the manual.
290         SBIT(SPEN,   0x80, 6);
291         SBIT(DORD,   0x80, 5);
292         SBIT(MSTR,   0x80, 4);
293         SBIT(CPOL,   0x80, 3);
294         SBIT(CPHA,   0x80, 2);
295         SBIT(SPR1,   0x80, 1);
296         SBIT(SPR0,   0x80, 0);*/
297 SFR(SPSR,  0xAA); // SPI Configuration Register
298         #define SPIF  0x80
299         #define WCOL  0x40
300 SFR(SPDAT, 0x86); // SPI Data
301 SFR(SP,    0x81); // Stack Pointer
302 SFR(S1DAT, 0xDA); // I2C Serial 1 Data
303 SFR(S1ADR, 0xDB); // I2C Serial 1 Address 
304         #define S1ADR_6  0x80
305         #define S1ADR_5  0x40
306         #define S1ADR_4  0x20
307         #define S1ADR_3  0x10
308         #define S1ADR_2  0x08
309         #define S1ADR_1  0x04
310         #define S1ADR_0  0x02
311         #define S1GC     0x01
312 SFR(S1STA, 0xD9); // I2C Serial 1 Status 
313         #define SC4  0x80
314         #define SC3  0x40
315         #define SC2  0x20
316         #define SC1  0x10
317         #define SC0  0x08    // Only write 0 to the lowest three bits
318 SFR(S1CON, 0xD8); // I2C Serial 1 Control
319         SBIT(CR2,  0xD8, 7);
320         SBIT(ENS1, 0xD8, 6);
321         SBIT(STA,  0xD8, 5);
322         SBIT(STO,  0xD8, 4);
323         SBIT(SI,   0xD8, 3);
324         SBIT(AA,   0xD8, 2);
325         SBIT(CR1,  0xD8, 1);
326         SBIT(CR0,  0xD8, 0);
327 SFR(S2DAT, 0xE2); // I2C Serial 1 Data
328 SFR(S2ADR, 0xE3); // I2C Serial 1 Address 
329         #define S2ADR_6  0x80
330         #define S2ADR_5  0x40
331         #define S2ADR_4  0x20
332         #define S2ADR_3  0x10
333         #define S2ADR_2  0x08
334         #define S2ADR_1  0x04
335         #define S2ADR_0  0x02
336         #define S2GC     0x01
337 SFR(S2STA, 0xE1); // I2C Serial 1 Status 
338         #define SC24  0x80
339         #define SC23  0x40
340         #define SC22  0x20
341         #define SC21  0x10
342         #define SC20  0x08  // Only write 0 to the lowest three bits
343 SFR(S2CON, 0xF8); // I2C Serial 1 Control
344         SBIT(CR22,  0xF8, 7);
345         SBIT(ENS21, 0xF8, 6);
346         SBIT(STA2,  0xF8, 5);
347         SBIT(STO2,  0xF8, 4);
348         SBIT(SI2,   0xF8, 3);
349         SBIT(AA2,   0xF8, 2);
350         SBIT(CR21,  0xF8, 1);
351         SBIT(CR20,  0xF8, 0);
352 SFR(TCON, 0x88); // Timer Control
353         SBIT(TF1, 0x88, 7);
354         SBIT(TR1, 0x88, 6);
355         SBIT(TF0, 0x88, 5);
356         SBIT(TR0, 0x88, 4);
357         SBIT(IE1, 0x88, 3);
358         SBIT(IT1, 0x88, 2);
359         SBIT(IE0, 0x88, 1);
360         SBIT(IT0, 0x88, 0);
361 SFR(T2CON, 0xC8); // Timer 2 Control
362         SBIT(TF2,    0xC8, 7);
363         SBIT(EXF2,   0xC8, 6);
364         SBIT(RCLK,   0xC8, 5);
365         SBIT(TCLK,   0xC8, 4);
366         SBIT(EXEN2,  0xC8, 3);
367         SBIT(TR2,    0xC8, 2);
368         SBIT(C_T2,   0xC8, 1);
369         SBIT(CP_RL2, 0xC8, 0);
370 SFR(T2MOD,  0xC9); // Timer 2 Mode Control
371         #define ENT2  0x20
372         #define T2OE  0x02
373         #define DCEN  0x01
374 SFR(TH0,  0x8C); // Timer High 0
375 SFR(TH1,  0x8D); // Timer High 1
376 SFR(TH2,  0xCD); // Timer High 2
377 SFR(TL0,  0x8A); // Timer Low 0
378 SFR(TL1,  0x8B); // Timer Low 1
379 SFR(TL2,  0xCC); // Timer Low 2
380 SFR(TMOD, 0x89); // Timer Mode
381         #define GATE_1  0x80
382         #define  C_T_1  0x40
383         #define   M1_1  0x20
384         #define   M0_1  0x10
385         #define GATE_0  0x08
386         #define  C_T_0  0x04
387         #define   M1_0  0x02
388         #define   M0_0  0x01
389 SFR(WDTRST, 0xA6); // Watchdog Timer Reset
390
391 #endif  //__P89V66X_H__