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

/*
   Header file for the Phillips Microcontrollers
   P80CE598
   P83CE598
 */

#ifndef	__P8XCE598_H

#define	__P8XCE598_H
	

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 volatile	unsigned char	P1	@ 0x90;
static volatile	unsigned char	S0CON	@ 0x98;
static volatile	unsigned char	S0BUF	@ 0x99;
static volatile	unsigned char	P2	@ 0xA0;
static 		unsigned char	IEN0	@ 0xA8;
static 		unsigned char	CML0	@ 0xA9;
static 		unsigned char	CML1	@ 0xAA;
static 		unsigned char	CML2	@ 0xAB;
static 		unsigned char	CTL0	@ 0xAC;
static 		unsigned char	CTL1	@ 0xAD;
static 		unsigned char	CTL2	@ 0xAE;
static 		unsigned char	CTL3	@ 0xAF;
static volatile	unsigned char	P3	@ 0xB0;
static 		unsigned char	IP0 	@ 0xB8;
static volatile	unsigned char	P4	@ 0xC0;
static volatile	unsigned char	P5	@ 0xC4;
static volatile	unsigned char	ADCON	@ 0xC5;
static volatile	unsigned char	ADCH	@ 0xC6;
static volatile	unsigned char	TM2IR	@ 0xC8;
static 		unsigned char	CMH0	@ 0xC9;
static 		unsigned char	CMH1	@ 0xCA;
static 		unsigned char	CMH2	@ 0xCB;
static 		unsigned char	CTH0	@ 0xCC;
static 		unsigned char	CTH1	@ 0xCD;
static 		unsigned char	CTH2	@ 0xCE;
static 		unsigned char	CTH3	@ 0xCF;
static volatile	unsigned char	PSW	@ 0xD0;
static volatile	unsigned char	CANSTA	@ 0xD8;
static volatile	unsigned char	CANCON	@ 0xD9;
static volatile	unsigned char	CANDAT	@ 0xDA;
static		unsigned char	CANADR	@ 0xDB;
static volatile	unsigned char	ACC	@ 0xE0;
static 		unsigned char	IEN1	@ 0xE8;
static volatile	unsigned char	TM2CON	@ 0xEA;
static 		unsigned char	CTCON	@ 0xEB;
static volatile	unsigned char	TML2	@ 0xEC;
static volatile	unsigned char	TMH2	@ 0xED;
static 		unsigned char	STE	@ 0xEE;
static 		unsigned char	RTE	@ 0xEF;
static volatile	unsigned char	B	@ 0xF0;
static 		unsigned char	IP1	@ 0xF8;
static 		unsigned char	PWM0	@ 0xFC;
static 		unsigned char	PWM1	@ 0xFD;
static 		unsigned char	PWMP	@ 0xFE;
static volatile	unsigned char	T3	@ 0xFF;

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 volatile SFR_BITS P1_BITS		@ 0x90;
static volatile SFR_BITS S0CON_BITS		@ 0x98;
static volatile SFR_BITS P2_BITS		@ 0xA0;
static 		SFR_BITS IEN0_BITS		@ 0xA8;
static volatile SFR_BITS P3_BITS		@ 0xB0;
static 		SFR_BITS IP0_BITS		@ 0xB8;
static volatile SFR_BITS P4_BITS		@ 0xC0;
static volatile	SFR_BITS P5_BITS		@ 0xC4;
static volatile	SFR_BITS ADCON_BITS		@ 0xC5;
static volatile	SFR_BITS ADCH_BITS		@ 0xC6;
static volatile SFR_BITS TM2IR_BITS		@ 0xC8;
static volatile SFR_BITS PSW_BITS		@ 0xD0;
static volatile	SFR_BITS CANSTA_BITS		@ 0xD8;
static volatile	SFR_BITS CANCON_BITS		@ 0xD9;
static volatile	SFR_BITS CANDAT_BITS		@ 0xDA;
static		SFR_BITS CANADR_BITS		@ 0xDB;
static volatile SFR_BITS ACC_BITS		@ 0xE0;
static 		SFR_BITS IEN1_BITS		@ 0xE8;
static volatile	SFR_BITS TM2CON_BITS		@ 0xEA;
static 		SFR_BITS CTCON_BITS		@ 0xEB;
static 		SFR_BITS STE_BITS		@ 0xEE;
static 		SFR_BITS RTE_BITS		@ 0xEF;
static volatile SFR_BITS B_BITS			@ 0xF0;
static 		SFR_BITS IP1_BITS		@ 0xF8;
static 		SFR_BITS PWMP_BITS		@ 0xFE;
static volatile	SFR_BITS T3_BITS		@ 0xFF;

//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 	P05	@ 0x85;
static volatile bit 	P06	@ 0x86;
static volatile bit 	P07	@ 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 	P15	@ 0x95;
static volatile bit 	P16	@ 0x96;
static volatile bit 	P17	@ 0x97;

//Serial Control 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;

//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;

//Interrupt Enable 0 IEN0
static 		bit 	EX0 	@ 0xA8;
static 		bit 	ET0 	@ 0xA9;
static 		bit 	EX1 	@ 0xAA;
static 		bit 	ET1 	@ 0xAB;
static 		bit 	ES0 	@ 0xAC;
static 		bit 	ES1 	@ 0xAD;
static 		bit 	EAD 	@ 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 	P35	@ 0xB5;
static volatile bit 	P36	@ 0xB6;
static volatile bit 	P37	@ 0xB7;

//Interrupt Priority 0 IP0
static 		bit 	PX0	@ 0xB8;
static 		bit 	PT0	@ 0xB9;
static 		bit 	PX1	@ 0xBA;
static 		bit 	PT1	@ 0xBB;
static 		bit 	PS0	@ 0xBC;
static 		bit 	PS1	@ 0xBD;
static 		bit 	PAD	@ 0xBE;

//Port 4
static volatile bit 	P40	@ 0xC0;
static volatile bit 	P41	@ 0xC1;
static volatile bit 	P42	@ 0xC2;
static volatile bit 	P43	@ 0xC3;
static volatile bit 	P44	@ 0xC4;
static volatile bit 	P45	@ 0xC5;
static volatile bit 	P46	@ 0xC6;
static volatile bit 	P47	@ 0xC7;

//Timer Interrupt Priority Request Register TM2IR
static volatile bit 	CTI0	@ 0xC8;
static volatile bit 	CTI1	@ 0xC9;
static volatile bit 	CTI2	@ 0xCA;
static volatile bit 	CTI3	@ 0xCB;
static volatile bit 	CMI0	@ 0xCC;
static volatile bit 	CMI1	@ 0xCD;
static volatile bit 	CMI2	@ 0xCE;
static volatile bit 	T2OV	@ 0xCF;

//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;

/*CAN Status CANSTA BITS
these bits have different meaning,
depending whether in READ or WRITE mode*/
//Read
static volatile	bit 	RBS 	@ 0xD8;
static volatile	bit 	DO 	@ 0xD9;
static volatile bit 	TBS	@ 0xDA;
static volatile bit 	TCS	@ 0xDB;
static volatile bit 	RS 	@ 0xDC;
static volatile bit 	TS 	@ 0xDD;
static volatile	bit 	ES	@ 0xDE;
static volatile	bit 	BS 	@ 0xDF;
// Write
static volatile	bit 	RAMA0 	@ 0xD8;
static volatile	bit 	RAMA1 	@ 0xD9;
static volatile	bit 	RAMA2 	@ 0xDA;
static volatile	bit 	RAMA3 	@ 0xDB;
static volatile	bit 	RAMA4 	@ 0xDC;
static volatile	bit 	RAMA5 	@ 0xDD;
static volatile	bit 	RAMA6 	@ 0xDE;
static volatile	bit 	RAMA7 	@ 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 1 IEN1
static 		bit 	ECT0	@ 0xE8;
static 		bit 	ECT1	@ 0xE9;
static 		bit 	ECT2	@ 0xEA;
static 		bit 	ECT3	@ 0xEB;
static 		bit 	ECM0	@ 0xEC;
static 		bit 	ECM1	@ 0xED;
static 		bit 	ECM2	@ 0xEE;
static 		bit 	ET2 	@ 0xEF;

//Register B
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 	PCT0	@ 0xF8;
static 		bit 	PCT1	@ 0xF9;
static 		bit 	PCT2	@ 0xFA;
static 		bit 	PCT3	@ 0xFB;
static 		bit 	PCM0	@ 0xFC;
static 		bit 	PCM1	@ 0xFD;
static 		bit 	PCM2	@ 0xFE;
static 		bit 	PT2 	@ 0xFF;

/*	Interrupt vectors */
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0 	0x0B
#define	EXTINT1	0x13
#define TIMER1 	0x1B
#define	SERIAL	0x23
#define S1 	0x2B
#define CT0 	0x33
#define CT1 	0x3B
#define CT2 	0x43
#define CT3 	0x4B
#define ADC 	0x53
#define CM0 	0x5B
#define CM1	0x63
#define CM2 	0x6B
#define TIMER2 	0x73

#endif	
