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