Imported Upstream version 2.9.0
[debian/cc1111] / device / include / mcs51 / p89lpc933_4.h
1 /*--------------------------------------------------------------------------
2 p89lpc933_4.h
3
4 This header allows to use the microcontrolers NXP (formerly Philips)
5 p89lpc933, 934.
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/lpc900/datasheet/p89lpc933.p89lpc934.p89lpc935.p89lpc936.pdf
25
26
27 --------------------------------------------------------------------------*/
28 #ifndef __P89LPC933_4_H__
29 #define __P89LPC933_4_H__
30 #include <compiler.h>
31
32 /*BYTE Registers*/
33 SFR(ACC, 0xE0); // Accumulator
34         SBIT(ACC_7, 0xE0, 7);
35         SBIT(ACC_6, 0xE0, 6);
36         SBIT(ACC_5, 0xE0, 5);
37         SBIT(ACC_4, 0xE0, 4);
38         SBIT(ACC_3, 0xE0, 3);
39         SBIT(ACC_2, 0xE0, 2);
40         SBIT(ACC_1, 0xE0, 1);
41         SBIT(ACC_0, 0xE0, 0);
42 SFR(ADCON0, 0x8E); // A/D control register 0
43         #define  ENADC0   0x04
44 SFR(ADCON1, 0x97); // A/D control register 1
45         #define  ENBI1    0x80
46         #define  ENADCI1  0x40
47         #define  TMM1     0x20
48         #define  EDGE1    0x10
49         #define  ADCI1    0x08
50         #define  ENADC1   0x04
51         #define  ADCS11   0x02
52         #define  ADCS10   0x01
53 SFR(ADINS, 0xA3); // A/D input select
54         #define  ADI13    0x80
55         #define  ADI12    0x40
56         #define  ADI11    0x20
57         #define  ADI10    0x10
58 SFR(ADMODA, 0xC0); // A/D mode register A
59         SBIT(BNDI1,  0xC0, 7);
60         SBIT(BURST1, 0xC0, 6);
61         SBIT(SCC1,   0xC0, 5);
62         SBIT(SCAN1,  0xC0, 4);
63 SFR(ADMODB, 0xA1); // A/D mode register B
64         #define  CLK2     0x80
65         #define  CLK1     0x40
66         #define  CLK0     0x20
67         #define  ENDAC1   0x08
68         #define  ENDAC0   0x04
69         #define  BSA1     0x02
70 SFR(AD0DAT3, 0xF4); // A/D_0 data register 3
71 SFR(AD1BH,   0xC4); // A/D_1 boundary high register
72 SFR(AD1BL,   0xBC); // A/D_1 boundary low register
73 SFR(AD1DAT0, 0xD5); // A/D_1 data register 0
74 SFR(AD1DAT1, 0xD6); // A/D_1 data register 1
75 SFR(AD1DAT2, 0xD7); // A/D_1 data register 2
76 SFR(AD1DAT3, 0xF5); // A/D_1 data register 3
77 SFR(AUXR1,   0xA2); // Auxilary function register
78         #define  CLKLP    0x80
79         #define  EBRR     0x40
80         #define  ENT1     0x20
81         #define  ENT0     0x10
82         #define  SRST     0x08  // Bit 2 is always 0
83         #define  DPS      0x01
84 SFR(B, 0xF0); // B register
85         SBIT(B7, 0xF0, 7);
86         SBIT(B6, 0xF0, 6);
87         SBIT(B5, 0xF0, 5);
88         SBIT(B4, 0xF0, 4);
89         SBIT(B3, 0xF0, 3);
90         SBIT(B2, 0xF0, 2);
91         SBIT(B1, 0xF0, 1);
92         SBIT(B0, 0xF0, 0);
93 SFR(BRGR0,  0xBE); // Baud rate generator rate low
94 SFR(BRGR1,  0xBF); // Baud rate generator rate high
95 SFR(BRGCON, 0xBD); // Baud rate generator control
96         #define  SBRGS    0x02
97         #define  BRGEN    0x01
98 SFR(CMP1,   0xAC); // Comparator 1 control register
99         #define  CE1      0x20
100         #define  CP1      0x10
101         #define  CN1      0x08
102         #define  OE1      0x04
103         #define  CO1      0x02
104         #define  CMF1     0x01
105 SFR(CMP2,   0xAD); // Comparator 2 control register
106         #define  CE2      0x20
107         #define  CP2      0x10
108         #define  CN2      0x08
109         #define  OE2      0x04
110         #define  CO2      0x02
111         #define  CMF2     0x01
112 SFR(DIVM,   0x95); // CPU clock divide-by-M control
113 SFR(DPH,  0x83); // Data Pointer High
114 SFR(DPL,  0x82); // Data Pointer Low
115 SFR(FMADRH, 0xE7); // Program flash address high
116 SFR(FMADRL, 0xE6); // Program flash address low
117 SFR(FMCON,  0xE4);
118         // Program flash control (Read)
119         #define  BUSY     0x80
120         #define  HVA      0x08
121         #define  HVE      0x04
122         #define  SV       0x02
123         #define  OI       0x01
124         // Program flash control (Write)
125         #define  FMCMD_7  0x80
126         #define  FMCMD_6  0x40
127         #define  FMCMD_5  0x20
128         #define  FMCMD_4  0x10
129         #define  FMCMD_3  0x08
130         #define  FMCMD_2  0x04
131         #define  FMCMD_1  0x02
132         #define  FMCMD_0  0x01
133 SFR(FMDATA,  0xE5); // Program flash data
134 SFR(I2ADR,   0xDB); // I2C slave address register
135         #define I2ADR_6  0x80
136         #define I2ADR_5  0x40
137         #define I2ADR_4  0x20
138         #define I2ADR_3  0x10
139         #define I2ADR_2  0x08
140         #define I2ADR_1  0x04
141         #define I2ADR_0  0x02
142         #define GC       0x01
143 SFR(I2CON,  0xD8); // I2C control register
144         SBIT(I2EN,  0xD8, 6);
145         SBIT(STA,   0xD8, 5);
146         SBIT(STO,   0xD8, 4);
147         SBIT(SI,    0xD8, 3);
148         SBIT(AA,    0xD8, 2);
149         SBIT(CRSEL, 0xD8, 0);
150 SFR(I2DAT,  0xDA); // I2C data register
151 SFR(I2SCLH, 0xDD); // I2C serial clock generator/SCL duty cycle register high
152 SFR(I2SCLL, 0xDC); // I2C serial clock generator/SCL duty cycle register low
153 SFR(I2STAT, 0xD9); // I2C status register
154         #define STA_4   0x80
155         #define STA_3   0x40
156         #define STA_2   0x20
157         #define STA_1   0x10
158         #define STA_0   0x08    // Only write 0 to the lowest three bits
159 SFR(ICRAH,  0xAB); // Input capture A register high
160 SFR(ICRAL,  0xAA); // Input capture A register low
161 SFR(ICRBH,  0xAF); // Input capture B register high
162 SFR(ICRBL,  0xAE); // Input capture B register low
163 SFR(IEN0,   0xA8); // Interrupt Enable 0
164         SBIT(EA,     0xA8, 7);
165         SBIT(EWDRT,  0xA8, 6);
166         SBIT(EBO,    0xA8, 5);
167         SBIT(ES_ESR, 0xA8, 4);
168         SBIT(ET1,    0xA8, 3);
169         SBIT(EX1,    0xA8, 2);
170         SBIT(ET0,    0xA8, 1);
171         SBIT(EX0,    0xA8, 0);
172 SFR(IEN1,  0xE8); // Interrupt Enable 1
173         SBIT(EAD,    0xE8, 7);
174         SBIT(EST,    0xE8, 6);
175         SBIT(ESPI,   0xE8, 3);
176         SBIT(EC,     0xE8, 2);
177         SBIT(EKBI,   0xE8, 1);
178         SBIT(EI2C,   0xE8, 0);
179 SFR(IP0, 0xB8); // Interrupt Priority 0
180         SBIT(PWDRT,  0xB8, 6);
181         SBIT(PBO,    0xB8, 5);
182         SBIT(PS_PSR, 0xB8, 4);
183         SBIT(PT1,    0xB8, 3);
184         SBIT(PX1,    0xB8, 2);
185         SBIT(PT0,    0xB8, 1);
186         SBIT(PX0,    0xB8, 0);
187 SFR(IP0H, 0xB7); // Interrupt Priority 0 high
188         #define PWDRTH    0x40
189         #define PBOH      0x20
190         #define PSH_PSRH  0x10
191         #define PT1H      0x08
192         #define PX1H      0x04
193         #define PT0H      0x02
194         #define PX0H      0x01
195 SFR(IP1,  0xF8); // Interrupt Priority 1
196         SBIT(PAD,   0xF8, 7);
197         SBIT(PST,   0xF8, 6);
198         SBIT(PSPI,  0xF8, 3);
199         SBIT(PC,    0xF8, 2);
200         SBIT(PKBI,  0xF8, 1);
201         SBIT(PI2C,  0xF8, 0);
202 SFR(IP1H, 0xF7); // Interrupt Priority 1 High
203         #define PADH   0x80
204         #define PSTH   0x40
205         #define PSPIH  0x08
206         #define PCH    0x04
207         #define PKBIH  0x02
208         #define PI2CH  0x01
209 SFR(KBCON, 0x94); // Keypad control register
210         #define PATN_SEL 0x02
211         #define KBIF     0x01
212 SFR(KBMASK, 0x86); // Keypad interrupt mask register
213 SFR(KBPATN, 0x93); // Keypad pattern register
214 SFR(P0, 0x80); // Port 0
215         SBIT(P0_7,  0x80, 7);
216         SBIT(T1,    0x80, 7);
217         SBIT(KB7,   0x80, 7);
218         SBIT(P0_6,  0x80, 6);
219         SBIT(CMP_1, 0x80, 6); // Renamed, not to conflict with the CMP1 register
220         SBIT(KB6,   0x80, 6);
221         SBIT(P0_5,  0x80, 5);
222         SBIT(CMPREF,0x80, 5);
223         SBIT(KB5,   0x80, 5);
224         SBIT(P0_4,  0x80, 4);
225         SBIT(CIN1A, 0x80, 4);
226         SBIT(KB4,   0x80, 4);
227         SBIT(P0_3,  0x80, 3);
228         SBIT(CIN1B, 0x80, 3);
229         SBIT(KB3,   0x80, 3);
230         SBIT(P0_2,  0x80, 2);
231         SBIT(CIN2A, 0x80, 2);
232         SBIT(KB2,   0x80, 2);
233         SBIT(P0_1,  0x80, 1);
234         SBIT(CIN2B, 0x80, 1);
235         SBIT(KB1,   0x80, 1);
236         SBIT(P0_0,  0x80, 0);
237         SBIT(CMP_2, 0x80, 0); // Renamed, not to conflict with the CMP2 register
238         SBIT(KB0,   0x80, 0);
239 SFR(P1, 0x90); // Port 1
240         SBIT(P1_7,    0x90, 7);
241         SBIT(P1_6,    0x90, 6);
242         SBIT(P1_5,    0x90, 5);
243         SBIT(RST,     0x90, 5);
244         SBIT(P1_4,    0x90, 4);
245         SBIT(INT1,    0x90, 4);
246         SBIT(P1_3,    0x90, 3);
247         SBIT(INT0,    0x90, 3);
248         SBIT(SDA,     0x90, 3);
249         SBIT(P1_2,    0x90, 2);
250         SBIT(T0,      0x90, 2);
251         SBIT(SCL,     0x90, 2);
252         SBIT(P1_1,    0x90, 1);
253         SBIT(RXD,     0x90, 1);
254         SBIT(P1_0,    0x90, 0);
255         SBIT(TXD,     0x90, 0);
256 SFR(P2, 0xA0); // Port 2
257         SBIT(P2_7,   0xA0, 7);
258         SBIT(P2_6,   0xA0, 6);
259         SBIT(P2_5,   0xA0, 5);
260         SBIT(SPICLK, 0xA0, 5);
261         SBIT(P2_4,   0xA0, 4);
262         SBIT(SS,     0xA0, 4);
263         SBIT(P2_3,   0xA0, 3);
264         SBIT(MISO,   0xA0, 3);
265         SBIT(P2_2,   0xA0, 2);
266         SBIT(MOSI,   0xA0, 2);
267         SBIT(P2_1,   0xA0, 1);
268         SBIT(P2_0,   0xA0, 0);
269 SFR(P3, 0xB0); // Port 3
270         SBIT(P3_7, 0xB0, 7);
271         SBIT(P3_6, 0xB0, 6);
272         SBIT(P3_5, 0xB0, 5);
273         SBIT(P3_4, 0xB0, 4);
274         SBIT(P3_3, 0xB0, 3);
275         SBIT(P3_2, 0xB0, 2);
276         SBIT(P3_1, 0xB0, 1);
277         SBIT(XTAL1,0xB0, 1);
278         SBIT(P3_0, 0xB0, 0);
279         SBIT(XTAL2,0xB0, 0);
280 SFR(P0M1, 0x84); // Port 0 output mode 1
281         #define P0M1_7  0x80
282         #define P0M1_6  0x40
283         #define P0M1_5  0x20
284         #define P0M1_4  0x10
285         #define P0M1_3  0x08
286         #define P0M1_2  0x04
287         #define P0M1_1  0x02
288         #define P0M1_0  0x01
289 SFR(P0M2, 0x85); // Port 0 output mode 2
290         #define P0M2_7  0x80
291         #define P0M2_6  0x40
292         #define P0M2_5  0x20
293         #define P0M2_4  0x10
294         #define P0M2_3  0x08
295         #define P0M2_2  0x04
296         #define P0M2_1  0x02
297         #define P0M2_0  0x01
298 SFR(P1M1, 0x91); // Port 1 output mode 1
299         #define P1M1_7  0x80
300         #define P1M1_6  0x40
301         #define P1M1_4  0x10
302         #define P1M1_3  0x08
303         #define P1M1_2  0x04
304         #define P1M1_1  0x02
305         #define P1M1_0  0x01
306 SFR(P1M2, 0x92); // Port 1 output mode 2
307         #define P1M2_7  0x80
308         #define P1M2_6  0x40
309         #define P1M2_4  0x10
310         #define P1M2_3  0x08
311         #define P1M2_2  0x04
312         #define P1M2_1  0x02
313         #define P1M2_0  0x01
314 SFR(P2M1, 0xA4); // Port 2 output mode 1
315         #define P2M1_7  0x80
316         #define P2M1_6  0x40
317         #define P2M1_5  0x20
318         #define P2M1_4  0x10
319         #define P2M1_3  0x08
320         #define P2M1_2  0x04
321         #define P2M1_1  0x02
322         #define P2M1_0  0x01
323 SFR(P2M2, 0xA5); // Port 2 output mode 2
324         #define P2M2_7  0x80
325         #define P2M2_6  0x40
326         #define P2M2_5  0x20
327         #define P2M2_4  0x10
328         #define P2M2_3  0x08
329         #define P2M2_2  0x04
330         #define P2M2_1  0x02
331         #define P2M2_0  0x01
332 SFR(P3M1, 0xB1); // Port 3 output mode 1
333         #define P3M1_1  0x02
334         #define P3M1_0  0x01
335 SFR(P3M2, 0xB2); // Port 3 output mode 2
336         #define P3M2_1  0x02
337         #define P3M2_0  0x01
338 SFR(PCON,  0x87); // Power control register
339         #define SMOD1   0x80
340         #define SMOD0   0x40
341         #define BOPD    0x20
342         #define BOI     0x10
343         #define GF1     0x08
344         #define GF0     0x04
345         #define PMOD1   0x02
346         #define PMOD0   0x01
347 SFR(PCONA, 0xB5); // Power control register A
348         #define RTCPD   0x80
349         #define VCPD    0x20
350         #define ADPD    0x10
351         #define I2PD    0x08
352         #define SPPD    0x04
353         #define SPD     0x02
354 SFR(PSW, 0xD0); // Program Status Word
355         SBIT(CY,  0xD0, 7);
356         SBIT(AC,  0xD0, 6);
357         SBIT(F0,  0xD0, 5);
358         SBIT(RS1, 0xD0, 4);
359         SBIT(RS0, 0xD0, 3);
360         SBIT(OV,  0xD0, 2);
361         SBIT(F1,  0xD0, 1);
362         SBIT(P,   0xD0, 0);
363 SFR(PT0AD, 0xF6); // Port 0 digital input disable
364         #define PT0AD_5   0x20
365         #define PT0AD_4   0x10
366         #define PT0AD_3   0x08
367         #define PT0AD_2   0x04
368         #define PT0AD_1   0x02
369 SFR(RSTSRC, 0xDF); // Reset source register
370         #define BOF    0x20
371         #define POF    0x10
372         #define R_BK   0x08
373         #define R_WD   0x04
374         #define R_SF   0x02
375         #define R_EX   0x01
376 SFR(RTCCON, 0xD1); // Real-time clock control
377         #define RTCF   0x80
378         #define RTCS1  0x40
379         #define RTCS0  0x20
380         #define ERTC   0x02
381         #define RTCEN  0x01
382 SFR(RTCH,  0xD2); // Real-time clock register high
383 SFR(RTCL,  0xD3); // Real-time clock register low
384 SFR(SADDR, 0xA9); // Serial port address register
385 SFR(SADEN, 0xB9); // Serial port address enable
386 SFR(SBUF,  0x99); // Serial port data buffer register
387 SFR(SCON,  0x98); // Serial port control
388         SBIT(SM0_FE, 0x98, 7);
389         SBIT(SM1,    0x98, 6);
390         SBIT(SM2,    0x98, 5);
391         SBIT(REN,    0x98, 4);
392         SBIT(TB8,    0x98, 3);
393         SBIT(RB8,    0x98, 2);
394         SBIT(TI,     0x98, 1);
395         SBIT(RI,     0x98, 0);
396 SFR(SSTAT, 0xBA); // Serial port extended status register
397         #define DBMOD  0x80
398         #define INTLO  0x40
399         #define CIDIS  0x20
400         #define DBISEL 0x10
401         #define FE     0x08
402         #define BR     0x04
403         #define OE     0x02
404         #define STINT  0x01
405 SFR(SP,     0x81); // Stack Pointer
406 SFR(SPCTL,  0xE2); // SPI control register
407         #define SSIG  0x80
408         #define SPEN  0x40
409         #define DORD  0x20
410         #define MSTR  0x10
411         #define CPOL  0x08
412         #define CPHA  0x04
413         #define SPR1  0x02
414         #define SPR0  0x01
415 SFR(SPSTAT, 0xE1); // SPI status register
416         #define SPIF  0x80
417         #define WCOL  0x40
418 SFR(SPDAT,  0xE3); // SPI data register
419 SFR(TAMOD,  0x8F); // Timer 0 and 1 auxiliary mode
420         #define T1M2  0x10
421         #define T0M2  0x01
422 SFR(TCON,   0x88); // Timer 0 and 1 control
423         SBIT(TF1, 0x88, 7);
424         SBIT(TR1, 0x88, 6);
425         SBIT(TF0, 0x88, 5);
426         SBIT(TR0, 0x88, 4);
427         SBIT(IE1, 0x88, 3);
428         SBIT(IT1, 0x88, 2);
429         SBIT(IE0, 0x88, 1);
430         SBIT(IT0, 0x88, 0);
431 SFR(TH0,  0x8C); // Timer 0 high
432 SFR(TH1,  0x8D); // Timer 1 high
433 SFR(TL0,  0x8A); // Timer 0 low
434 SFR(TL1,  0x8B); // Timer 1 low
435 SFR(TMOD, 0x89); // Timer 0 and 1 mode
436         #define T1GATE  0x80
437         #define T1C_T   0x40
438         #define T1M1    0x20
439         #define T1M0    0x10
440         #define T0GATE  0x08
441         #define T0C_T   0x04
442         #define T0M1    0x02
443         #define T0M0    0x01
444 SFR(TRIM, 0x96); // Internal oscillator trim register
445         #define RCCLK   0x80
446         #define ENCLK   0x40
447         #define TRIM_5  0x20
448         #define TRIM_4  0x10
449         #define TRIM_3  0x08
450         #define TRIM_2  0x04
451         #define TRIM_1  0x02
452         #define TRIM_0  0x01
453 SFR(WDCON, 0xA7); // Watchdog control register
454         #define PRE2    0x80
455         #define PRE1    0x40
456         #define PRE0    0x20
457         #define WDRUN   0x04
458         #define WDTOF   0x02
459         #define WDCLK   0x01
460 SFR(WDL,    0xC1); // Watchdog load
461 SFR(WFEED1, 0xC2); // Watchdog feed 1
462 SFR(WFEED2, 0xC3); // Watchdog feed 2
463 #endif // __P89LPC933_4_H__