
#ifndef	_HTC_H_
#warning Header file p89lpc90x.h included directly. Use #include <htc.h> instead.
#endif


 /* header file for the Philips microcontrollers
	P89LPC901
	P89LPC902
	P89LPC903
	P89LPC906
	P89LPC907
	P89LPC908
 */

#ifndef	__P89LPC90X_H

#define	__P89LPC90X_H

typedef struct {
	unsigned B7:1; //This is the most signifigant bit
	unsigned B6:1;
	unsigned B5:1;
	unsigned B4:1;
	unsigned B3:1;
	unsigned B2:1;
	unsigned B1:1;
	unsigned B0:1;
}	SFR_BITS;

//Special Function Registers
static volatile unsigned char P0	@ 0x80;
static volatile unsigned char SP	@ 0x81;
static volatile unsigned char DPL	@ 0x82;
static volatile unsigned char DPH	@ 0x83;
static          unsigned char P0M1	@ 0x84;
static          unsigned char P0M2	@ 0x85;
static          unsigned char KBMASK	@ 0x86;
static volatile unsigned char PCON	@ 0x87;
static volatile unsigned char TCON	@ 0x88;
static          unsigned char TMOD	@ 0x89;
static volatile unsigned char TL0	@ 0x8A;
static volatile unsigned char TL1	@ 0x8B;
static volatile unsigned char TH0	@ 0x8C;
static volatile unsigned char TH1	@ 0x8D;
#if defined(_P89LPC901) || defined(_P89LPC906) || defined(_P89LPC907)
static          unsigned char TAMOD	@ 0x8F;
#endif
static volatile unsigned char P1	@ 0x90;
static          unsigned char P1M1	@ 0x91;
static          unsigned char P1M2	@ 0x92;
static          unsigned char KBPATN	@ 0x93;
static volatile unsigned char KBCON	@ 0x94;
static          unsigned char DIVM	@ 0x95;
static          unsigned char TRIM	@ 0x96;
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
static volatile unsigned char SCON	@ 0x98;
static volatile unsigned char SBUF	@ 0x99;
#endif
static          unsigned char AUXR1	@ 0xA2;
static volatile unsigned char WDCON	@ 0xA7;
static          unsigned char IEN0	@ 0xA8;
#if defined(_P89LPC903) || defined(_P89LPC908)
static          unsigned char SADDR	@ 0xA9;
#endif
static volatile unsigned char CMP1	@ 0xAC;
#if defined(_P89LPC902) || defined(_P89LPC903)
static volatile unsigned char CMP2	@ 0xAD;
#endif
#if defined(_P89LPC901) || defined(_P89LPC906)
static volatile unsigned char P3	@ 0xB0;
static          unsigned char P3M1	@ 0xB1;
static          unsigned char P3M2	@ 0xB2;
#endif
static volatile unsigned char PCONA	@ 0xB5;
#if !defined(_P89LPC906) && !defined(_P89LPC907) && !defined(_P89LPC908)
static volatile unsigned char PCONB	@ 0xB6;
#endif
static          unsigned char IP0H	@ 0xB7;
static          unsigned char IP0	@ 0xB8;
#if defined(_P89LPC903) || defined(_P89LPC908)
static          unsigned char SADEN	@ 0xB9;
#endif
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
static volatile unsigned char SSTAT	@ 0xBA;
static volatile unsigned char BRGCON	@ 0xBD;
static          unsigned char BRGR0	@ 0xBE;
static          unsigned char BRGR1	@ 0xBF;
#endif
static          unsigned char WDL	@ 0xC1;
static volatile unsigned char WFEED1	@ 0xC2;
static volatile unsigned char WFEED2	@ 0xC3;
static volatile unsigned char PSW	@ 0xD0;
static volatile unsigned char RTCCON	@ 0xD1;
static volatile unsigned char RTCH	@ 0xD2;
static volatile unsigned char RTCL	@ 0xD3;
static volatile unsigned char RSTSRC	@ 0xDF;
static volatile unsigned char ACC	@ 0xE0;
static volatile unsigned char FMCON	@ 0xE4;
static volatile unsigned char FMDATA	@ 0xE5;
static volatile unsigned char FMADRL	@ 0xE6;
static volatile unsigned char FMADRH	@ 0xE7;
static          unsigned char IEN1	@ 0xE8;
static volatile unsigned char B		@ 0xF0;
static          unsigned char PT0AD	@ 0xF6;
static          unsigned char IP1H	@ 0xF7;
static          unsigned char IP1	@ 0xF8;

static volatile SFR_BITS	 P0_BITS	@ 0x80;
static          SFR_BITS	 P0M1_BITS	@ 0x84;
static          SFR_BITS	 P0M2_BITS	@ 0x85;
static volatile SFR_BITS	 PCON_BITS	@ 0x87;
static volatile SFR_BITS	 TCON_BITS	@ 0x88;
static          SFR_BITS	 TMOD_BITS	@ 0x89;
#if defined(_P89LPC901) || defined(_P89LPC906) || defined(_P89LPC907)
static          SFR_BITS	 TAMOD_BITS	@ 0x8F;
#endif
static volatile SFR_BITS	 P1_BITS	@ 0x90;
static          SFR_BITS	 P1M1_BITS	@ 0x91;
static          SFR_BITS	 P1M2_BITS	@ 0x92;
static volatile SFR_BITS	 KBCON_BITS	@ 0x94;
static          SFR_BITS	 TRIM_BITS	@ 0x96;
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
static volatile SFR_BITS	 SCON_BITS	@ 0x98;
#endif
static          SFR_BITS	 AUXR1_BITS	@ 0xA2;
static volatile SFR_BITS	 WDCON_BITS	@ 0xA7;
static          SFR_BITS	 IEN0_BITS	@ 0xA8;
#if defined(_P89LPC903) || defined(_P89LPC908)
static          SFR_BITS	 SADDR_BITS	@ 0xA9;
#endif
static volatile SFR_BITS	 CMP1_BITS	@ 0xAC;
#if defined(_P89LPC902) || defined(_P89LPC903)
static volatile SFR_BITS	 CMP2_BITS	@ 0xAD;
#endif
#if defined(_P89LPC901) || defined(_P89LPC906)
static volatile SFR_BITS	 P3_BITS	@ 0xB0;
static          SFR_BITS	 P3M1_BITS	@ 0xB1;
static          SFR_BITS	 P3M2_BITS	@ 0xB2;
#endif
static volatile SFR_BITS	 PCONA_BITS	@ 0xB5;
#if !defined(_P89LPC906) && !defined(_P89LPC907) && !defined(_P89LPC908)
static volatile SFR_BITS	 PCONB_BITS	@ 0xB6;
#endif
static          SFR_BITS	 IP0H_BITS	@ 0xB7;
static          SFR_BITS	 IP0_BITS	@ 0xB8;
#if defined(_P89LPC903) || defined(_P89LPC908)
static          SFR_BITS	 SADEN_BITS	@ 0xB9;
#endif
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
static volatile SFR_BITS	 SSTAT_BITS	@ 0xBA;
static volatile SFR_BITS	 BRGCON_BITS	@ 0xBD;
#endif
static          SFR_BITS	 WDL_BITS	@ 0xC1;
static volatile SFR_BITS	 WFEED1_BITS	@ 0xC2;
static volatile SFR_BITS	 WFEED2_BITS	@ 0xC3;
static volatile SFR_BITS	 PSW_BITS	@ 0xD0;
static volatile SFR_BITS	 RTCCON_BITS	@ 0xD1;
static volatile SFR_BITS	 RTCH_BITS	@ 0xD2;
static volatile SFR_BITS	 RTCL_BITS	@ 0xD3;
static volatile SFR_BITS	 RSTSRC_BITS	@ 0xDF;
static volatile SFR_BITS	 ACC_BITS	@ 0xE0;
static volatile SFR_BITS	 FMCON_BITS	@ 0xE4;
static          SFR_BITS	 IEN1_BITS	@ 0xE8;
static volatile SFR_BITS	 B_BITS		@ 0xF0;
static          SFR_BITS	 IP1H_BITS	@ 0xF7;
static          SFR_BITS	 IP1_BITS	@ 0xF8;


// Bit Addressable Locations
// Port 0 P0
static volatile bit	P00	@ 0x80;
static volatile bit	P01	@ 0x81;
static volatile bit	P02	@ 0x82;
static volatile bit	P03	@ 0x83;
static volatile bit	P04	@ 0x84;
static volatile bit	P05	@ 0x85;
static volatile bit	P06	@ 0x86;
static volatile bit	P07	@ 0x87;

// Timer Control TCON
static 		bit	TR0	@ 0x8C;
static volatile bit	TF0	@ 0x8D;
static 		bit	TR1	@ 0x8E;
static volatile bit	TF1	@ 0x8F;

// Port 1 P1
static volatile bit	P10	@ 0x90;
static volatile bit	P11	@ 0x91;
static volatile bit	P12	@ 0x92;
static volatile bit	P13	@ 0x93;
static volatile bit	P14	@ 0x94;
static volatile bit	P15	@ 0x95;
static volatile bit	P16	@ 0x96;
static volatile bit	P17	@ 0x97;

// Serial Control SCON
static volatile bit	RI	@ 0x98;
static volatile bit	TI	@ 0x99;
static volatile bit	RB8	@ 0x9A;
static		bit	TB8	@ 0x9B;
static 		bit	REN	@ 0x9C;
static		bit	SM2	@ 0x9D;
static		bit	SM1	@ 0x9E;
static volatile bit	SM0	@ 0x9F;
// Alternate Function
static volatile bit	FE	@ 0x9F;

// Interrupt Enable 0 IEN0
static 		bit 	ET0 	@ 0xA9;
static 		bit 	ET1 	@ 0xAB;
static 		bit 	ES 	@ 0xAC;
// Alternate definition
static 		bit 	ESR 	@ 0xAC;
static 		bit 	EBO 	@ 0xAD;
static 		bit 	EWDRT 	@ 0xAE;
static 		bit 	EA	@ 0xAF;

// Port 3 P3
static volatile bit	P30	@ 0xB0;
static volatile bit	P31	@ 0xB1;
static volatile bit	P32	@ 0xB2;
static volatile bit	P33	@ 0xB3;
static volatile bit	P34	@ 0xB4;
static volatile bit	P35	@ 0xB5;
static volatile bit	P36	@ 0xB6;
static volatile bit	P37	@ 0xB7;

// Interrupt Priority 0 IP0
static 		bit 	PTO 	@ 0xB9;
static 		bit 	PT1 	@ 0xBB;
static 		bit 	PS 	@ 0xBC;
// Alternate definition
static 		bit 	PSR 	@ 0xBC;
static 		bit 	PBO 	@ 0xBD;
static 		bit 	PWDRT 	@ 0xBE;

// Program Status Word PSW
static volatile bit	P	@ 0xD0;
static volatile bit	F1	@ 0xD1;
static volatile bit	OV	@ 0xD2;
static 		bit	RS0	@ 0xD3;
static 		bit	RS1	@ 0xD4;
static volatile bit	F0	@ 0xD5;
static volatile bit	AC	@ 0xD6;
static volatile bit	CY	@ 0xD7;

// Accumulator ACC
static volatile bit	ACC0	@ 0xE0;
static volatile bit	ACC1	@ 0xE1;
static volatile bit	ACC2	@ 0xE2;
static volatile bit	ACC3	@ 0xE3;
static volatile bit	ACC4	@ 0xE4;
static volatile bit	ACC5	@ 0xE5;
static volatile bit	ACC6	@ 0xE6;
static volatile bit	ACC7	@ 0xE7;

// Interrupt Enable 1 IEN1
static 		bit 	EKBI	@ 0xE9;
static 		bit 	EC	@ 0xEA;
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
static 		bit 	EST	@ 0xEE;
#endif

// B register
static volatile bit	B0	@ 0xF0;
static volatile bit	B1	@ 0xF1;
static volatile bit	B2	@ 0xF2;
static volatile bit	B3	@ 0xF3;
static volatile bit	B4	@ 0xF4;
static volatile bit	B5	@ 0xF5;
static volatile bit	B6	@ 0xF6;
static volatile bit	B7	@ 0xF7;

// Interrupt Priority 1 IP1
static 		bit	PKBI	@ 0xF9;
static 		bit 	PC	@ 0xFA;
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
static 		bit 	PST	@ 0xFE;
#endif


// Interrupt Vectors
#define	RESET	0
#define TIMER0	0x0B
#define	TIMER1	0x1B
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
#define	SERIAL	0x23
#endif
#define	BROWN	0x2B
#define	KEYBOARD	0x3B
#define	COMPARATOR	0x43
#define	WDT	0x53
#if defined(_P89LPC903) || defined(_P89LPC907) || defined(_P89LPC908)
#define	SERIALTX	0x6B
#endif


#endif
