1 /*-------------------------------------------------------------------------
2 p89lpc9321.h - Register Declarations for NXP the P89LPC9321
3 (Based on user manual (UM10310_1) Rev. 01 - 1 December 2008)
5 Copyright (C) 2009, Jesus Calvino-Fraga / jesusc at ece.ubc.ca
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 #ifndef REG_P89LPC9321_H
31 #define REG_P89LPC9321_H
35 SFR(ACC
, 0xe0); // Accumulator
44 SFR(AUXR1
, 0xa2); // Auxiliary function register
51 SFR(B
, 0xf0); // B register
60 SFR(BRGR0
, 0xbe); // Baud rate generator 0 rate low
61 SFR(BRGR1
, 0xbf); // Baud rate generator 0 rate high
62 SFR(BRGCON
, 0xbd); // Baud rate generator 0 control
65 SFR(CCCRA
, 0xea); // Capture compare A control register
74 SFR(CCCRB
, 0xeb); // Capture compare B control register
83 SFR(CCCRC
, 0xec); // Capture compare C control register
87 SFR(CCCRD
, 0xed); // Capture compare D control register
91 SFR(CMP1
, 0xac); // Comparator 1 control register
98 SFR(CMP2
, 0xad); // Comparator 2 control register
105 SFR(DEECON
, 0xf1); // Data EEPROM control register
113 SFR(DEEDAT
, 0xf2); // Data EEPROM data register
114 SFR(DEEADR
, 0xf3); // Data EEPROM address register
115 SFR(DIVM
, 0x95); // CPU clock divide-by-M control
116 SFR(DPH
, 0x83); // Data pointer high
117 SFR(DPL
, 0x82); // Data pointer low
118 SFR(FMADRH
, 0xe7); // Program flash address high
119 SFR(FMADRL
, 0xe6); // Program flash address low
120 SFR(FMCON
, 0xe4); // Program flash control Read
134 SFR(FMDATA
, 0xe5); // Program flash data
135 SFR(I2ADR
, 0xdb); // I2C-bus slave address register
144 SFR(I2CON
, 0xd8); // I2C-bus control register
145 SBIT(I2CON_7
, 0xd8, 7);
146 SBIT(I2CON_6
, 0xd8, 6);
147 SBIT(I2CON_5
, 0xd8, 5);
148 SBIT(I2CON_4
, 0xd8, 4);
149 SBIT(I2CON_3
, 0xd8, 3);
150 SBIT(I2CON_2
, 0xd8, 2);
151 SBIT(I2CON_1
, 0xd8, 1);
152 SBIT(I2CON_0
, 0xd8, 0);
158 SBIT(CRSEL
, 0xd8, 0);
159 SFR(I2DAT
, 0xda); // I2C-bus data register
160 SFR(I2SCLH
, 0xdd); // Serial clock generator/SCL duty cycle register high
161 SFR(I2SCLL
, 0xdc); // Serial clock generator/SCL duty cycle register low
162 SFR(I2STAT
, 0xd9); // I2C-bus status register
168 SFR(ICRAH
, 0xab); // Input capture A register high
169 SFR(ICRAL
, 0xaa); // Input capture A register low
170 SFR(ICRBH
, 0xaf); // Input capture B register high
171 SFR(ICRBL
, 0xae); // Input capture B register low
172 SFR(IEN0
, 0xa8); // Interrupt enable 0
173 SBIT(IEN0_7
, 0xa8, 7);
174 SBIT(IEN0_6
, 0xa8, 6);
175 SBIT(IEN0_5
, 0xa8, 5);
176 SBIT(IEN0_4
, 0xa8, 4);
177 SBIT(IEN0_3
, 0xa8, 3);
178 SBIT(IEN0_2
, 0xa8, 2);
179 SBIT(IEN0_1
, 0xa8, 1);
180 SBIT(IEN0_0
, 0xa8, 0);
182 SBIT(EWDRT
, 0xa8, 6);
190 SFR(IEN1
, 0xe8); // Interrupt enable 1
191 SBIT(IEN1_7
, 0xe8, 7);
192 SBIT(IEN1_6
, 0xe8, 6);
193 SBIT(IEN1_5
, 0xe8, 5);
194 SBIT(IEN1_4
, 0xe8, 4);
195 SBIT(IEN1_3
, 0xe8, 3);
196 SBIT(IEN1_2
, 0xe8, 2);
197 SBIT(IEN1_1
, 0xe8, 1);
198 SBIT(IEN1_0
, 0xe8, 0);
206 SFR(IP0
, 0xb8); // Interrupt priority 0
207 SBIT(IP0_7
, 0xb8, 7);
208 SBIT(IP0_6
, 0xb8, 6);
209 SBIT(IP0_5
, 0xb8, 5);
210 SBIT(IP0_4
, 0xb8, 4);
211 SBIT(IP0_3
, 0xb8, 3);
212 SBIT(IP0_2
, 0xb8, 2);
213 SBIT(IP0_1
, 0xb8, 1);
214 SBIT(IP0_0
, 0xb8, 0);
215 SBIT(PWDRT
, 0xb8, 6);
223 SFR(IP0H
, 0xb7); // Interrupt priority 0 high
232 SFR(IP1
, 0xf8); // Interrupt priority 1
233 SBIT(IP1_7
, 0xf8, 7);
234 SBIT(IP1_6
, 0xf8, 6);
235 SBIT(IP1_5
, 0xf8, 5);
236 SBIT(IP1_4
, 0xf8, 4);
237 SBIT(IP1_3
, 0xf8, 3);
238 SBIT(IP1_2
, 0xf8, 2);
239 SBIT(IP1_1
, 0xf8, 1);
240 SBIT(IP1_0
, 0xf8, 0);
248 SFR(IP1H
, 0xf7); // Interrupt priority 1 high
256 SFR(KBCON
, 0x94); // Keypad control register
259 SFR(KBMASK
, 0x86); // Keypad interrupt mask register
260 SFR(KBPATN
, 0x93); // Keypad pattern register
261 SFR(OCRAH
, 0xef); // Output compare A register high
262 SFR(OCRAL
, 0xee); // Output compare A register low
263 SFR(OCRBH
, 0xfb); // Output compare B register high
264 SFR(OCRBL
, 0xfa); // Output compare B register low
265 SFR(OCRCH
, 0xfd); // Output compare C register high
266 SFR(OCRCL
, 0xfc); // Output compare C register low
267 SFR(OCRDH
, 0xff); // Output compare D register high
268 SFR(OCRDL
, 0xfe); // Output compare D register low
269 SFR(P0
, 0x80); // Port 0
280 SBIT(CMP_1
, 0x80, 6);
282 SBIT(CMPREF
, 0x80, 5);
284 SBIT(CIN1A
, 0x80, 4);
286 SBIT(CIN1B
, 0x80, 3);
288 SBIT(CIN2A
, 0x80, 2);
290 SBIT(CIN2B
, 0x80, 1);
292 SBIT(CMP_2
, 0x80, 0);
294 SFR(P1
, 0x90); // Port 1
313 SFR(P2
, 0xa0); // Port 2
324 SBIT(SPICLK
, 0xa0, 5);
330 SFR(P3
, 0xb0); // Port 3
339 SBIT(XTAL1
, 0xb0, 1);
340 SBIT(XTAL2
, 0xb0, 0);
341 SFR(P0M1
, 0x84); // Port 0 output mode 1
350 SFR(P0M2
, 0x85); // Port 0 output mode 2
359 SFR(P1M1
, 0x91); // Port 1 output mode 1
367 SFR(P1M2
, 0x92); // Port 1 output mode 2
375 SFR(P2M1
, 0xa4); // Port 2 output mode 1
384 SFR(P2M2
, 0xa5); // Port 2 output mode 2
393 SFR(P3M1
, 0xb1); // Port 3 output mode 1
396 SFR(P3M2
, 0xb2); // Port 3 output mode 2
399 SFR(PCON
, 0x87); // Power control register
407 SFR(PCONA
, 0xb5); // Power control register A
415 SFR(PSW
, 0xd0); // Program status word
416 SBIT(PSW_7
, 0xd0, 7);
417 SBIT(PSW_6
, 0xd0, 6);
418 SBIT(PSW_5
, 0xd0, 5);
419 SBIT(PSW_4
, 0xd0, 4);
420 SBIT(PSW_3
, 0xd0, 3);
421 SBIT(PSW_2
, 0xd0, 2);
422 SBIT(PSW_1
, 0xd0, 1);
423 SBIT(PSW_0
, 0xd0, 0);
432 SFR(PT0AD
, 0xf6); // Port 0 digital input disable
438 SFR(RSTSRC
, 0xdf); // Reset source register
446 SFR(RTCCON
, 0xd1); // RTC control
452 SFR(RTCH
, 0xd2); // RTC register high
453 SFR(RTCL
, 0xd3); // RTC register low
454 SFR(SADDR
, 0xa9); // Serial port address register
455 SFR(SADEN
, 0xb9); // Serial port address enable
456 SFR(SBUF
, 0x99); // Serial Port data buffer register
457 SFR(SCON
, 0x98); // Serial port control
458 SBIT(SCON_7
, 0x98, 7);
459 SBIT(SCON_6
, 0x98, 6);
460 SBIT(SCON_5
, 0x98, 5);
461 SBIT(SCON_4
, 0x98, 4);
462 SBIT(SCON_3
, 0x98, 3);
463 SBIT(SCON_2
, 0x98, 2);
464 SBIT(SCON_1
, 0x98, 1);
465 SBIT(SCON_0
, 0x98, 0);
475 SFR(SSTAT
, 0xba); // Serial port extended status register
484 SFR(SP
, 0x81); // Stack pointer
485 SFR(SPCTL
, 0xe2); // SPI control register
494 SFR(SPSTAT
, 0xe1); // SPI status register
497 SFR(SPDAT
, 0xe3); // SPI data register
498 SFR(TAMOD
, 0x8f); // Timer 0 and 1 auxiliary mode
501 SFR(TCON
, 0x88); // Timer 0 and 1 control
502 SBIT(TCON_7
, 0x88, 7);
503 SBIT(TCON_6
, 0x88, 6);
504 SBIT(TCON_5
, 0x88, 5);
505 SBIT(TCON_4
, 0x88, 4);
506 SBIT(TCON_3
, 0x88, 3);
507 SBIT(TCON_2
, 0x88, 2);
508 SBIT(TCON_1
, 0x88, 1);
509 SBIT(TCON_0
, 0x88, 0);
518 SFR(TCR20
, 0xc8); // CCU control register 0
519 SBIT(TCR20_7
, 0xc8, 7);
520 SBIT(TCR20_6
, 0xc8, 6);
521 SBIT(TCR20_5
, 0xc8, 5);
522 SBIT(TCR20_4
, 0xc8, 4);
523 SBIT(TCR20_3
, 0xc8, 3);
524 SBIT(TCR20_2
, 0xc8, 2);
525 SBIT(TCR20_1
, 0xc8, 1);
526 SBIT(TCR20_0
, 0xc8, 0);
527 SBIT(PLEEN
, 0xc8, 7);
528 SBIT(HLTRN
, 0xc8, 6);
529 SBIT(HLTEN
, 0xc8, 5);
530 SBIT(ALTCD
, 0xc8, 4);
531 SBIT(ALTAB
, 0xc8, 3);
532 SBIT(TDIR2
, 0xc8, 2);
533 SBIT(TMOD21
, 0xc8, 1);
534 SBIT(TMOD20
, 0xc8, 0);
535 SFR(TCR21
, 0xf9); // CCU control register 1
541 SFR(TH0
, 0x8c); // Timer 0 high
542 SFR(TH1
, 0x8d); // Timer 1 high
543 SFR(TH2
, 0xcd); // CCU timer high
544 SFR(TICR2
, 0xc9); // CCU interrupt control register
552 SFR(TIFR2
, 0xe9); // CCU interrupt flag register
560 SFR(TISE2
, 0xde); // CCU interrupt status encode register
561 #define ENCINT_2 0x04
562 #define ENCINT_1 0x02
563 #define ENCINT_0 0x01
564 SFR(TL0
, 0x8a); // Timer 0 low
565 SFR(TL1
, 0x8b); // Timer 1 low
566 SFR(TL2
, 0xcc); // CCU timer low
567 SFR(TMOD
, 0x89); // Timer 0 and 1 mode
576 SFR(TOR2H
, 0xcf); // CCU reload register high
577 SFR(TOR2L
, 0xce); // CCU reload register low
578 SFR(TPCR2H
, 0xcb); // Prescaler control register high
579 #define TPCR2H_1 0x02
580 #define TPCR2H_0 0x01
581 SFR(TPCR2L
, 0xca); // Prescaler control register low
582 #define TPCR2L_7 0x80
583 #define TPCR2L_6 0x40
584 #define TPCR2L_5 0x20
585 #define TPCR2L_4 0x10
586 #define TPCR2L_3 0x08
587 #define TPCR2L_2 0x04
588 #define TPCR2L_1 0x02
589 #define TPCR2L_0 0x01
590 SFR(TRIM
, 0x96); // Internal oscillator trim register
599 SFR(WDCON
, 0xa7); // Watchdog control register
606 SFR(WDL
, 0xc1); // Watchdog load
607 SFR(WFEED1
, 0xc2); // Watchdog feed 1
608 SFR(WFEED2
, 0xc3); // Watchdog feed 2
609 SFRX(BODCFG
, 0xffc8); // BOD configuration register
612 SFRX(CLKCON
, 0xffde); // CLOCK Control register
619 SFRX(PGACON1
, 0xffe1); // PGA1 control register
621 #define PGASEL1_1 0x40
622 #define PGASEL1_0 0x20
623 #define PGATRIM_1 0x10
626 SFRX(PGACON1B
, 0xffe4); // PGA1 control register B
629 SFRX(PGA1TRIM8X16X
, 0xffe3); // PGA1 trim register
630 #define PGA1_16XTRIM3 0x80
631 #define PGA1_16XTRIM2 0x40
632 #define PGA1_16XTRIM1 0x20
633 #define PGA1_16XTRIM0 0x10
634 #define PGA1_8XTRIM3 0x08
635 #define PGA1_8XTRIM2 0x04
636 #define PGA1_8XTRIM1 0x02
637 #define PGA1_8XTRIM0 0x01
638 SFRX(PGA1TRIM2X4X
, 0xffe2); // PGA1 trim register
639 #define PGA1_4XTRIM3 0x80
640 #define PGA1_4XTRIM2 0x40
641 #define PGA1_4XTRIM1 0x20
642 #define PGA1_4XTRIM0 0x10
643 #define PGA1_2XTRIM3 0x08
644 #define PGA1_2XTRIM2 0x04
645 #define PGA1_2XTRIM1 0x02
646 #define PGA1_2XTRIM0 0x01
647 SFRX(RTCDATH
, 0xffbf); // Real-time clock data register high
648 SFRX(RTCDATL
, 0xffbe); // Real-time clock data register low
649 #endif /*REG_P89LPC9321_H*/