1 /*-------------------------------------------------------------------------
2 p89lpc9351.h - Register Declarations for NXP the P89LPC9351/P89LPC9361
3 (Based on user manual (UM10308_3) Rev. 03 - 17 June 2009)
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_P89LPC9351_H
31 #define REG_P89LPC9351_H
35 SFR(ACC
, 0xe0); // Accumulator
44 SFR(ADCON0
, 0x8e); // A/D control register 0
53 SFR(ADCON1
, 0x97); // A/D control register 1
62 SFR(ADINS
, 0xa3); // A/D input select
71 SFR(ADMODA
, 0xc0); // A/D mode register A
72 SBIT(ADMODA_7
, 0xc0, 7);
73 SBIT(ADMODA_6
, 0xc0, 6);
74 SBIT(ADMODA_5
, 0xc0, 5);
75 SBIT(ADMODA_4
, 0xc0, 4);
76 SBIT(ADMODA_3
, 0xc0, 3);
77 SBIT(ADMODA_2
, 0xc0, 2);
78 SBIT(ADMODA_1
, 0xc0, 1);
79 SBIT(ADMODA_0
, 0xc0, 0);
81 SBIT(BURST1
, 0xc0, 6);
85 SBIT(BURST0
, 0xc0, 2);
88 SFR(ADMODB
, 0xa1); // A/D mode register B
97 SFR(AD0BH
, 0xbb); // A/D_0 boundary high register
98 SFR(AD0BL
, 0xa6); // A/D_0 boundary low register
99 SFR(AD0DAT0
, 0xc5); // A/D_0 data register 0
100 SFR(AD0DAT1
, 0xc6); // A/D_0 data register 1
101 SFR(AD0DAT2
, 0xc7); // A/D_0 data register 2
102 SFR(AD0DAT3
, 0xf4); // A/D_0 data register 3
103 SFR(AD1BH
, 0xc4); // A/D_1 boundary high register
104 SFR(AD1BL
, 0xbc); // A/D_1 boundary low register
105 SFR(AD1DAT0
, 0xd5); // A/D_1 data register 0
106 SFR(AD1DAT1
, 0xd6); // A/D_1 data register 1
107 SFR(AD1DAT2
, 0xd7); // A/D_1 data register 2
108 SFR(AD1DAT3
, 0xf5); // A/D_1 data register 3
109 SFR(AUXR1
, 0xa2); // Auxiliary function register
116 SFR(B
, 0xf0); // B register
125 SFR(BRGR0
, 0xbe); // Baud rate generator 0 rate low
126 SFR(BRGR1
, 0xbf); // Baud rate generator 0 rate high
127 SFR(BRGCON
, 0xbd); // Baud rate generator 0 control
130 SFR(CCCRA
, 0xea); // Capture compare A control register
139 SFR(CCCRB
, 0xeb); // Capture compare B control register
148 SFR(CCCRC
, 0xec); // Capture compare C control register
152 SFR(CCCRD
, 0xed); // Capture compare D control register
156 SFR(CMP1
, 0xac); // Comparator 1 control register
163 SFR(CMP2
, 0xad); // Comparator 2 control register
170 SFR(DEECON
, 0xf1); // Data EEPROM control register
178 SFR(DEEDAT
, 0xf2); // Data EEPROM data register
179 SFR(DEEADR
, 0xf3); // Data EEPROM address register
180 SFR(DIVM
, 0x95); // CPU clock divide-by-M control
181 SFR(DPH
, 0x83); // Data pointer high
182 SFR(DPL
, 0x82); // Data pointer low
183 SFR(FMADRH
, 0xe7); // Program flash address high
184 SFR(FMADRL
, 0xe6); // Program flash address low
185 SFR(FMCON
, 0xe4); // Program flash control Read
199 SFR(FMDATA
, 0xe5); // Program flash data
200 SFR(I2ADR
, 0xdb); // I2C-bus slave address register
209 SFR(I2CON
, 0xd8); // I2C-bus control register
210 SBIT(I2CON_7
, 0xd8, 7);
211 SBIT(I2CON_6
, 0xd8, 6);
212 SBIT(I2CON_5
, 0xd8, 5);
213 SBIT(I2CON_4
, 0xd8, 4);
214 SBIT(I2CON_3
, 0xd8, 3);
215 SBIT(I2CON_2
, 0xd8, 2);
216 SBIT(I2CON_1
, 0xd8, 1);
217 SBIT(I2CON_0
, 0xd8, 0);
223 SBIT(CRSEL
, 0xd8, 0);
224 SFR(I2DAT
, 0xda); // I2C-bus data register
225 SFR(I2SCLH
, 0xdd); // Serial clock generator/SCL duty cycle register high
226 SFR(I2SCLL
, 0xdc); // Serial clock generator/SCL duty cycle register low
227 SFR(I2STAT
, 0xd9); // I2C-bus status register
233 SFR(ICRAH
, 0xab); // Input capture A register high
234 SFR(ICRAL
, 0xaa); // Input capture A register low
235 SFR(ICRBH
, 0xaf); // Input capture B register high
236 SFR(ICRBL
, 0xae); // Input capture B register low
237 SFR(IEN0
, 0xa8); // Interrupt enable 0
238 SBIT(IEN0_7
, 0xa8, 7);
239 SBIT(IEN0_6
, 0xa8, 6);
240 SBIT(IEN0_5
, 0xa8, 5);
241 SBIT(IEN0_4
, 0xa8, 4);
242 SBIT(IEN0_3
, 0xa8, 3);
243 SBIT(IEN0_2
, 0xa8, 2);
244 SBIT(IEN0_1
, 0xa8, 1);
245 SBIT(IEN0_0
, 0xa8, 0);
247 SBIT(EWDRT
, 0xa8, 6);
255 SFR(IEN1
, 0xe8); // Interrupt enable 1
256 SBIT(IEN1_7
, 0xe8, 7);
257 SBIT(IEN1_6
, 0xe8, 6);
258 SBIT(IEN1_5
, 0xe8, 5);
259 SBIT(IEN1_4
, 0xe8, 4);
260 SBIT(IEN1_3
, 0xe8, 3);
261 SBIT(IEN1_2
, 0xe8, 2);
262 SBIT(IEN1_1
, 0xe8, 1);
263 SBIT(IEN1_0
, 0xe8, 0);
264 SBIT(EADEE
, 0xe8, 7);
271 SFR(IP0
, 0xb8); // Interrupt priority 0
272 SBIT(IP0_7
, 0xb8, 7);
273 SBIT(IP0_6
, 0xb8, 6);
274 SBIT(IP0_5
, 0xb8, 5);
275 SBIT(IP0_4
, 0xb8, 4);
276 SBIT(IP0_3
, 0xb8, 3);
277 SBIT(IP0_2
, 0xb8, 2);
278 SBIT(IP0_1
, 0xb8, 1);
279 SBIT(IP0_0
, 0xb8, 0);
280 SBIT(PWDRT
, 0xb8, 6);
288 SFR(IP0H
, 0xb7); // Interrupt priority 0 high
297 SFR(IP1
, 0xf8); // Interrupt priority 1
298 SBIT(IP1_7
, 0xf8, 7);
299 SBIT(IP1_6
, 0xf8, 6);
300 SBIT(IP1_5
, 0xf8, 5);
301 SBIT(IP1_4
, 0xf8, 4);
302 SBIT(IP1_3
, 0xf8, 3);
303 SBIT(IP1_2
, 0xf8, 2);
304 SBIT(IP1_1
, 0xf8, 1);
305 SBIT(IP1_0
, 0xf8, 0);
306 SBIT(PADEE
, 0xf8, 7);
313 SFR(IP1H
, 0xf7); // Interrupt priority 1 high
321 SFR(KBCON
, 0x94); // Keypad control register
324 SFR(KBMASK
, 0x86); // Keypad interrupt mask register
325 SFR(KBPATN
, 0x93); // Keypad pattern register
326 SFR(OCRAH
, 0xef); // Output compare A register high
327 SFR(OCRAL
, 0xee); // Output compare A register low
328 SFR(OCRBH
, 0xfb); // Output compare B register high
329 SFR(OCRBL
, 0xfa); // Output compare B register low
330 SFR(OCRCH
, 0xfd); // Output compare C register high
331 SFR(OCRCL
, 0xfc); // Output compare C register low
332 SFR(OCRDH
, 0xff); // Output compare D register high
333 SFR(OCRDL
, 0xfe); // Output compare D register low
334 SFR(P0
, 0x80); // Port 0
345 SBIT(CMP_1
, 0x80, 6);
347 SBIT(CMPREF
, 0x80, 5);
349 SBIT(CIN1A
, 0x80, 4);
351 SBIT(CIN1B
, 0x80, 3);
353 SBIT(CIN2A
, 0x80, 2);
355 SBIT(CIN2B
, 0x80, 1);
357 SBIT(CMP_2
, 0x80, 0);
359 SFR(P1
, 0x90); // Port 1
378 SFR(P2
, 0xa0); // Port 2
389 SBIT(SPICLK
, 0xa0, 5);
395 SFR(P3
, 0xb0); // Port 3
404 SBIT(XTAL1
, 0xb0, 1);
405 SBIT(XTAL2
, 0xb0, 0);
406 SFR(P0M1
, 0x84); // Port 0 output mode 1
415 SFR(P0M2
, 0x85); // Port 0 output mode 2
424 SFR(P1M1
, 0x91); // Port 1 output mode 1
432 SFR(P1M2
, 0x92); // Port 1 output mode 2
440 SFR(P2M1
, 0xa4); // Port 2 output mode 1
449 SFR(P2M2
, 0xa5); // Port 2 output mode 2
458 SFR(P3M1
, 0xb1); // Port 3 output mode 1
461 SFR(P3M2
, 0xb2); // Port 3 output mode 2
464 SFR(PCON
, 0x87); // Power control register
472 SFR(PCONA
, 0xb5); // Power control register A
481 SFR(PSW
, 0xd0); // Program status word
482 SBIT(PSW_7
, 0xd0, 7);
483 SBIT(PSW_6
, 0xd0, 6);
484 SBIT(PSW_5
, 0xd0, 5);
485 SBIT(PSW_4
, 0xd0, 4);
486 SBIT(PSW_3
, 0xd0, 3);
487 SBIT(PSW_2
, 0xd0, 2);
488 SBIT(PSW_1
, 0xd0, 1);
489 SBIT(PSW_0
, 0xd0, 0);
498 SFR(PT0AD
, 0xf6); // Port 0 digital input disable
504 SFR(RSTSRC
, 0xdf); // Reset source register
512 SFR(RTCCON
, 0xd1); // RTC control
518 SFR(RTCH
, 0xd2); // RTC register high
519 SFR(RTCL
, 0xd3); // RTC register low
520 SFR(SADDR
, 0xa9); // Serial port address register
521 SFR(SADEN
, 0xb9); // Serial port address enable
522 SFR(SBUF
, 0x99); // Serial Port data buffer register
523 SFR(SCON
, 0x98); // Serial port control
524 SBIT(SCON_7
, 0x98, 7);
525 SBIT(SCON_6
, 0x98, 6);
526 SBIT(SCON_5
, 0x98, 5);
527 SBIT(SCON_4
, 0x98, 4);
528 SBIT(SCON_3
, 0x98, 3);
529 SBIT(SCON_2
, 0x98, 2);
530 SBIT(SCON_1
, 0x98, 1);
531 SBIT(SCON_0
, 0x98, 0);
541 SFR(SSTAT
, 0xba); // Serial port extended status register
550 SFR(SP
, 0x81); // Stack pointer
551 SFR(SPCTL
, 0xe2); // SPI control register
560 SFR(SPSTAT
, 0xe1); // SPI status register
563 SFR(SPDAT
, 0xe3); // SPI data register
564 SFR(TAMOD
, 0x8f); // Timer 0 and 1 auxiliary mode
567 SFR(TCON
, 0x88); // Timer 0 and 1 control
568 SBIT(TCON_7
, 0x88, 7);
569 SBIT(TCON_6
, 0x88, 6);
570 SBIT(TCON_5
, 0x88, 5);
571 SBIT(TCON_4
, 0x88, 4);
572 SBIT(TCON_3
, 0x88, 3);
573 SBIT(TCON_2
, 0x88, 2);
574 SBIT(TCON_1
, 0x88, 1);
575 SBIT(TCON_0
, 0x88, 0);
584 SFR(TCR20
, 0xc8); // CCU control register 0
585 SBIT(TCR20_7
, 0xc8, 7);
586 SBIT(TCR20_6
, 0xc8, 6);
587 SBIT(TCR20_5
, 0xc8, 5);
588 SBIT(TCR20_4
, 0xc8, 4);
589 SBIT(TCR20_3
, 0xc8, 3);
590 SBIT(TCR20_2
, 0xc8, 2);
591 SBIT(TCR20_1
, 0xc8, 1);
592 SBIT(TCR20_0
, 0xc8, 0);
593 SBIT(PLEEN
, 0xc8, 7);
594 SBIT(HLTRN
, 0xc8, 6);
595 SBIT(HLTEN
, 0xc8, 5);
596 SBIT(ALTCD
, 0xc8, 4);
597 SBIT(ALTAB
, 0xc8, 3);
598 SBIT(TDIR2
, 0xc8, 2);
599 SBIT(TMOD21
, 0xc8, 1);
600 SBIT(TMOD20
, 0xc8, 0);
601 SFR(TCR21
, 0xf9); // CCU control register 1
607 SFR(TH0
, 0x8c); // Timer 0 high
608 SFR(TH1
, 0x8d); // Timer 1 high
609 SFR(TH2
, 0xcd); // CCU timer high
610 SFR(TICR2
, 0xc9); // CCU interrupt control register
618 SFR(TIFR2
, 0xe9); // CCU interrupt flag register
626 SFR(TISE2
, 0xde); // CCU interrupt status encode register
627 #define ENCINT_2 0x04
628 #define ENCINT_1 0x02
629 #define ENCINT_0 0x01
630 SFR(TL0
, 0x8a); // Timer 0 low
631 SFR(TL1
, 0x8b); // Timer 1 low
632 SFR(TL2
, 0xcc); // CCU timer low
633 SFR(TMOD
, 0x89); // Timer 0 and 1 mode
642 SFR(TOR2H
, 0xcf); // CCU reload register high
643 SFR(TOR2L
, 0xce); // CCU reload register low
644 SFR(TPCR2H
, 0xcb); // Prescaler control register high
645 #define TPCR2H_1 0x02
646 #define TPCR2H_0 0x01
647 SFR(TPCR2L
, 0xca); // Prescaler control register low
648 #define TPCR2L_7 0x80
649 #define TPCR2L_6 0x40
650 #define TPCR2L_5 0x20
651 #define TPCR2L_4 0x10
652 #define TPCR2L_3 0x08
653 #define TPCR2L_2 0x04
654 #define TPCR2L_1 0x02
655 #define TPCR2L_0 0x01
656 SFR(TRIM
, 0x96); // Internal oscillator trim register
665 SFR(WDCON
, 0xa7); // Watchdog control register
672 SFR(WDL
, 0xc1); // Watchdog load
673 SFR(WFEED1
, 0xc2); // Watchdog feed 1
674 SFR(WFEED2
, 0xc3); // Watchdog feed 2
675 SFRX(BODCFG
, 0xffc8); // BOD configuration register
678 SFRX(CLKCON
, 0xffde); // CLOCK Control register
685 SFRX(PGACON1
, 0xffe1); // PGA1 control register
687 #define PGASEL1_1 0x40
688 #define PGASEL1_0 0x20
689 #define PGATRIM_1 0x10
692 SFRX(PGACON1B
, 0xffe4); // PGA1 control register B
695 SFRX(PGA1TRIM8X16X
, 0xffe3); // PGA1 trim register
696 #define PGA1_16XTRIM3 0x80
697 #define PGA1_16XTRIM2 0x40
698 #define PGA1_16XTRIM1 0x20
699 #define PGA1_16XTRIM0 0x10
700 #define PGA1_8XTRIM3 0x08
701 #define PGA1_8XTRIM2 0x04
702 #define PGA1_8XTRIM1 0x02
703 #define PGA1_8XTRIM0 0x01
704 SFRX(PGA1TRIM2X4X
, 0xffe2); // PGA1 trim register
705 #define PGA1_4XTRIM3 0x80
706 #define PGA1_4XTRIM2 0x40
707 #define PGA1_4XTRIM1 0x20
708 #define PGA1_4XTRIM0 0x10
709 #define PGA1_2XTRIM3 0x08
710 #define PGA1_2XTRIM2 0x04
711 #define PGA1_2XTRIM1 0x02
712 #define PGA1_2XTRIM0 0x01
713 SFRX(PGACON0
, 0xffca); // PGA0 control register
715 #define PGASEL0_1 0x40
716 #define PGASEL0_0 0x20
717 #define PGATRIM_0 0x10
722 SFRX(PGACON0B
, 0xffce); // PGA0 control register B
725 SFRX(PGA0TRIM8X16X
, 0xffcd); // PGA0 trim register
726 #define PGA0_16XTRIM3 0x80
727 #define PGA0_16XTRIM2 0x40
728 #define PGA0_16XTRIM1 0x20
729 #define PGA0_16XTRIM0 0x10
730 #define PGA0_8XTRIM3 0x08
731 #define PGA0_8XTRIM2 0x04
732 #define PGA0_8XTRIM1 0x02
733 #define PGA0_8XTRIM0 0x01
734 SFRX(PGA0TRIM2X4X
, 0xffcc); // PGA0 trim register
735 #define PGA0_4XTRIM3 0x80
736 #define PGA0_4XTRIM2 0x40
737 #define PGA0_4XTRIM1 0x20
738 #define PGA0_4XTRIM0 0x10
739 #define PGA0_2XTRIM3 0x08
740 #define PGA0_2XTRIM2 0x04
741 #define PGA0_2XTRIM1 0x02
742 #define PGA0_2XTRIM0 0x01
743 SFRX(RTCDATH
, 0xffbf); // Real-time clock data register high
744 SFRX(RTCDATL
, 0xffbe); // Real-time clock data register low
745 #endif /*REG_P89LPC9351_H*/