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

/*
   Header file for the Phillips microcontrollers
 	P87CL881H
 	P83CL882
	P83CL883
 	P87CL883
 	P83CL884
 	P87CL884
 */

#ifndef	__P8XCL88X_H

#define	__P8XCL88X_H
	
#if defined(_P83CL883) || defined(_P87CL883) ||\
    defined(_P83CL884) || defined(_P87CL884) 
#define _TELX

#elif defined(_P83CL882)
#define _VTELX
#endif
	
typedef struct {
	unsigned B7:1;	/* this is the most significant 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;
// 16 bit definition
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;
static		unsigned char	P0CFGA	@ 0x8E;
static		unsigned char	P0CFGB	@ 0x8F;
static volatile	unsigned char	P1	@ 0x90;
#if !defined(_VTELX)
static volatile	unsigned char	S0CON	@ 0x98;
static volatile	unsigned char	S0BUF	@ 0x99;
#endif
static		unsigned char	P1CFGA	@ 0x9E;
static		unsigned char	P1CFGB	@ 0x9F;
#if defined(_P87CL881H)
static volatile	unsigned char	P2	@ 0xA0;
static		unsigned char	ALTP	@ 0xA3;
#elif defined(_TELX)
static volatile	unsigned char	LGF	@ 0xA1;
static volatile	unsigned char	HGF	@ 0xA2;
static		unsigned char	ALTP	@ 0xA3;
#endif
static volatile	unsigned char	WDCON	@ 0xA5;
#if defined(_VTELX)
static volatile	unsigned char	WDTIM	@ 0xA6;
#endif
static 		unsigned char	IEN0	@ 0xA8;
#if !defined(_VTELX)
static volatile	unsigned char	COMP2L	@ 0xAA;
static volatile	unsigned char	COMP2H	@ 0xAB;
#endif
#if defined(_P87CL881H)
static		unsigned char	P2CFGA	@ 0xAE;
static		unsigned char	P2CFGB	@ 0xAF;
#endif
static volatile	unsigned char	P3	@ 0xB0;
#if defined(_VTELX)
static		unsigned char	SYSCON	@ 0xB4;
#endif
static 		unsigned char	IP0 	@ 0xB8;
static		unsigned char	P3CFGA	@ 0xBE;
static		unsigned char	P3CFGB	@ 0xBF;
static volatile	unsigned char	IRQ1	@ 0xC0;
#if defined(_TELX)
static volatile	unsigned char	P4	@ 0xC1;
#endif
static volatile	unsigned char	T2CON	@ 0xC8;
#if defined(_VTELX)
static volatile	unsigned char	T2MOD	@ 0xC9;
static		unsigned char	T2RCL	@ 0xCA;
static		unsigned char	T2RCH	@ 0xCB;
#else
static volatile	unsigned char	RCAP2L	@ 0xCA;
static volatile	unsigned char	RCAP2H	@ 0xCB;
#endif
static volatile	unsigned char	TL2	@ 0xCC;
static volatile	unsigned char	TH2	@ 0xCD;
static volatile	unsigned char	PSW	@ 0xD0;
#if defined(_TELX) || defined(_VTELX)
static volatile	unsigned char	MBUF	@ 0xD1;
static volatile	unsigned char	MSTAT	@ 0xD2;
static volatile	unsigned char	MCON	@ 0xD3;
#endif
#if !defined(_VTELX)
static		unsigned char	OAL	@ 0xD4;
static		unsigned char	OAH	@ 0xD5;
static volatile	unsigned char	ODATA	@ 0xD6;
static volatile	unsigned char	OTEST	@ 0xD7;
#endif
static volatile	unsigned char	S1CON	@ 0xD8;
static volatile	unsigned char	S1STA	@ 0xD9;
static volatile	unsigned char	S1DAT	@ 0xDA;
static		unsigned char	S1ADR	@ 0xDB;
#if !defined(_VTELX)
static volatile	unsigned char	OISYS	@ 0xDC;
static volatile	unsigned char	RSTAT	@ 0xE6;
#else
static		unsigned char	WKCON	@ 0xDD;
#endif
static volatile	unsigned char	ACC	@ 0xE0;
static		unsigned char	ISE1	@ 0xE1;
static 		unsigned char	IEN1	@ 0xE8;
static volatile	unsigned char	IX1	@ 0xE9;
static volatile	unsigned char	B	@ 0xF0;
static		unsigned char	IEN2	@ 0xF1;
static volatile	unsigned char	LVDCON	@ 0xF2;
static		unsigned char	PRESC	@ 0xF3;
static 		unsigned char	IP1	@ 0xF8;
static		unsigned char	IP2	@ 0xF9;
#if defined(_P87CL881H)
static		unsigned char	XPAGE	@ 0xFA;
static volatile	unsigned char	WDTIM	@ 0xFF;
#elif defined(_TELX)
static volatile	unsigned char	EECON	@ 0xFB;
static volatile	unsigned char	WDTIM	@ 0xFF;
#endif

static volatile	SFR_BITS	P0_BITS		@ 0x80;
static volatile	SFR_BITS	PCON_BITS	@ 0x87;
static volatile	SFR_BITS	TCON_BITS	@ 0x88;
static 		SFR_BITS	TMOD_BITS	@ 0x89;
static		SFR_BITS	P0CFGA_BITS	@ 0x8E;
static		SFR_BITS	P0CFGB_BITS	@ 0x8F;
static volatile	SFR_BITS	P1_BITS		@ 0x90;
#if !defined(_VTELX)
static volatile	SFR_BITS	S0CON_BITS	@ 0x98;
#endif
static		SFR_BITS	P1CFGA_BITS	@ 0x9E;
static		SFR_BITS	P1CFGB_BITS	@ 0x9F;
#if defined(_P87CL881H)
static volatile	SFR_BITS	P2_BITS		@ 0xA0;
static		SFR_BITS	ALTP_BITS	@ 0xA3;
#elif defined(_TELX)
static volatile	SFR_BITS	LGF_BITS	@ 0xA1;
static volatile	SFR_BITS	HGF_BITS	@ 0xA2;
static		SFR_BITS	ALTP_BITS	@ 0xA3;
#endif
static volatile	SFR_BITS	WDCON_BITS	@ 0xA5;
static 		SFR_BITS	IEN0_BITS	@ 0xA8;
#if defined(_P87CL881H)
static		SFR_BITS	P2CFGA_BITS	@ 0xAE;
static		SFR_BITS	P2CFGB_BITS	@ 0xAF;
#endif
static volatile	SFR_BITS	P3_BITS		@ 0xB0;
#if defined(_VTELX)
static		SFR_BITS	SYSCON_BITS	@ 0xB4;
#endif
static 		SFR_BITS	IP0_BITS 	@ 0xB8;
static		SFR_BITS	P3CFGA_BITS	@ 0xBE;
static		SFR_BITS	P3CFGB_BITS	@ 0xBF;
static volatile	SFR_BITS	IRQ1_BITS	@ 0xC0;
#if defined(_TELX)
static volatile	SFR_BITS	P4_BITS		@ 0xC1;
#endif
static volatile	SFR_BITS	T2CON_BITS	@ 0xC8;
#if defined(_VTELX)
static volatile	SFR_BITS	T2MOD_BITS	@ 0xC9;
#endif
static volatile	SFR_BITS	PSW_BITS	@ 0xD0;
#if defined(_TELX) || defined(_VTELX)
static volatile	SFR_BITS	MSTAT_BITS	@ 0xD2;
static volatile	SFR_BITS	MCON_BITS	@ 0xD3;
#endif
#if !defined(_VTELX)
static volatile	SFR_BITS	OTEST_BITS	@ 0xD7;
static volatile	SFR_BITS	OISYS_BITS	@ 0xDC;
static volatile	SFR_BITS	RSTAT_BITS	@ 0xE6;
#endif
static volatile	SFR_BITS	S1CON_BITS	@ 0xD8;
static volatile	SFR_BITS	S1STA_BITS	@ 0xD9;
static volatile	SFR_BITS	ACC_BITS	@ 0xE0;
static		SFR_BITS	ISE1_BITS	@ 0xE1;
static 		SFR_BITS	IEN1_BITS	@ 0xE8;
static volatile	SFR_BITS	IX1_BITS	@ 0xE9;
static volatile	SFR_BITS	B_BITS		@ 0xF0;
static		SFR_BITS	IEN2_BITS	@ 0xF1;
static volatile	SFR_BITS	LVDCON_BITS	@ 0xF2;
static 		SFR_BITS	IP1_BITS	@ 0xF8;
static		SFR_BITS	IP2_BITS	@ 0xF9;
#if defined(_P87CL881H)
static		SFR_BITS	XPAGE_BITS	@ 0xFA;
#elif defined(_TELX)
static volatile	SFR_BITS	EECON_BITS	@ 0xFB;
#endif

//bit addressable locations
//Port 0
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 	P06	@ 0x85;
static volatile bit 	P07	@ 0x86;
static volatile bit 	P08	@ 0x87;
// Alternate Functions
static volatile bit 	AD0	@ 0x80;
static volatile bit 	AD1	@ 0x81;
static volatile bit 	AD2	@ 0x82;
static volatile bit 	AD3	@ 0x83;
static volatile bit 	AD4	@ 0x84;
static volatile bit 	AD6	@ 0x85;
static volatile bit 	AD7	@ 0x86;
static volatile bit 	AD8	@ 0x87;

//Timer Control TCON
static 		bit 	IT0	@ 0x88;
static volatile bit 	IE0	@ 0x89;
static 		bit 	IT1	@ 0x8A;
static volatile bit 	IE1 	@ 0x8B;
static		bit 	TR0 	@ 0x8C;
static volatile bit 	TF0 	@ 0x8D;
static		bit 	TR1 	@ 0x8E;
static volatile bit 	TF1 	@ 0x8F;

//Port 1
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 	P16	@ 0x95;
static volatile bit 	P17	@ 0x96;
static volatile bit 	P18	@ 0x97;
// Alternate Functions
static volatile bit 	INT2	@ 0x90;
static volatile bit 	INT3	@ 0x91;
static volatile bit 	INT4	@ 0x92;
static volatile bit 	INT5	@ 0x93;
static volatile bit 	INT6	@ 0x94;
static volatile bit 	INT7	@ 0x95;
static volatile bit 	INT8	@ 0x96;
static volatile bit 	INT9	@ 0x97;
static volatile bit 	T2	@ 0x90;
static volatile bit 	T2EX	@ 0x91;
static volatile bit 	T2COMP	@ 0x92;
static volatile bit 	CLK	@ 0x94;
static volatile bit 	SCL	@ 0x96;
static volatile bit 	SDA	@ 0x97;

#if !defined(_VTELX)
//Serial Control Register 0 S0CON
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 		bit 	SM0 	@ 0x9F;
#endif

#if defined(_P87CL881H)
// Port 2
static volatile bit	P20	@ 0xA0;
static volatile bit	P21	@ 0xA1;
static volatile bit	P22	@ 0xA2;
static volatile bit	P23	@ 0xA3;
static volatile bit	P24	@ 0xA4;
static volatile bit	P25	@ 0xA5;
static volatile bit	P26	@ 0xA6;
static volatile bit	P27	@ 0xA7;
// Alternate Functions
static volatile bit	A8	@ 0xA0;
static volatile bit	A9	@ 0xA1;
static volatile bit	A10	@ 0xA2;
static volatile bit	A11	@ 0xA3;
static volatile bit	A12	@ 0xA4;
static volatile bit	A13	@ 0xA5;
static volatile bit	A14	@ 0xA6;
static volatile bit	A15	@ 0xA7;
#endif

//Interrupt Enable Register 0 IEN0
static 		bit 	EX0 	@ 0xA8;
static 		bit 	ET0 	@ 0xA9;
static 		bit 	EX1 	@ 0xAA;
static 		bit 	ET1 	@ 0xAB;
#if !defined(_VTELX)
static 		bit 	ES0 	@ 0xAC;
#endif
static 		bit 	ES1 	@ 0xAD;
static 		bit 	ET2 	@ 0xAE;
static 		bit 	EA 	@ 0xAF;

//Port 3
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 	P36	@ 0xB5;
static volatile bit 	P37	@ 0xB6;
static volatile bit 	P38	@ 0xB7;
// Alternate Functions
static volatile bit 	RXD	@ 0xB0;
static volatile bit 	TXD	@ 0xB1;
static volatile bit 	INT0	@ 0xB2;
static volatile bit 	INT1	@ 0xB3;
static volatile bit 	T0	@ 0xB4;
static volatile bit 	T1	@ 0xB5;
static volatile bit 	WR	@ 0xB6;
static volatile bit 	RD	@ 0xB7;

//Interrupt Priority Register 0 IP0
static 		bit 	PX0	@ 0xB8;
static 		bit 	PT0	@ 0xB9;
static 		bit 	PX1	@ 0xBA;
static 		bit 	PT1	@ 0xBB;
#if !defined(_VTELX)
static 		bit 	PS0	@ 0xBC;
#endif
static 		bit 	PS1	@ 0xBD;
static 		bit 	PT2	@ 0xBE;

//Interrupt Request Flag Register IRQ1
static volatile bit 	IQ2	@ 0xC0;
static volatile bit 	IQ3	@ 0xC1;
static volatile bit 	IQ4	@ 0xC2;
static volatile bit 	IQ5	@ 0xC3;
static volatile bit 	IQ6	@ 0xC4;
static volatile bit 	IQ7	@ 0xC5;
static volatile bit 	IQ8	@ 0xC6;
static volatile bit 	IQ9	@ 0xC7;

//Timer 2 Control Register T2CON
static		bit 	CPRL2	@ 0xC8;
static		bit 	CT2	@ 0xC9;
static		bit 	TR2	@ 0xCA;
static		bit 	EXEN2	@ 0xCB;
#if !defined(_VTELX)
static		bit 	ECOMP	@ 0xCC;
static volatile bit 	COMP	@ 0xCD;
#endif
static volatile bit 	EXF2	@ 0xCE;
static volatile bit 	TF2	@ 0xCF;

//Program Status Word PSW
static volatile bit 	P 	@ 0xD0;
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;

//Serial Control register 1 S1CON
static 		bit 	CR0 	@ 0xD8;
static 		bit 	CR1 	@ 0xD9;
static volatile bit 	AA 	@ 0xDA;
static volatile bit 	SI 	@ 0xDB;
static volatile bit 	STO 	@ 0xDC;
static volatile bit 	STA 	@ 0xDD;
static 		bit 	ENS1	@ 0xDE;
static 		bit 	CR2 	@ 0xDF;

//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 Register 1 IEN1
static		bit 	EX2	@ 0xE8;
static		bit 	EX3	@ 0xE9;
static		bit 	EX4	@ 0xEA;
static		bit 	EX5	@ 0xEB;
static		bit 	EX6	@ 0xEC;
static		bit 	EX7	@ 0xED;
static		bit 	EX8	@ 0xEE;
static		bit 	EX9	@ 0xEF;

//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 	PX2	@ 0xF8;
static 		bit 	PX3	@ 0xF9;
static 		bit 	PX4	@ 0xFA;
static 		bit 	PX5	@ 0xFB;
static 		bit 	PX6	@ 0xFC;
static 		bit 	PX7	@ 0xFD;
static 		bit 	PX8	@ 0xFE;
static 		bit 	PX9	@ 0xFF;

/*	Interrupt vectors */
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0 	0x0B
#define	EXTINT1	0x13
#define TIMER1 	0x1B
#if !defined(_VTELX)
#define SOR	0x23
#endif	
#define S1	0x2B
#define TIMER2 	0x33
#define	EXTINT2	0x3B
#define	EXTINT3	0x43
#define	EXTINT4	0x4B
#define	EXTINT5	0x53
#define	EXTINT6	0x5B
#define	EXTINT7	0x63
#define	EXTINT8	0x6B
#define	EXTINT9	0x73
#if !defined(_VTELX)
#define SOT	0x7B
#endif	
#define MTI	0x83
#define MRI	0x8B
#if !defined(_VTELX)
#define LVD 	0x93
#define RTC 	0x9B
#else
#define WDI	0xB3
#endif	

#endif	
