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

/* This is a header file for the Phillips Microcontrollers
	P83C576
	P87C576

***	Note that to avoid repetition of variable names, IE0 & IE1	***
***	(within TCON register) have been renamed IE_0 & IE_1		***
*/


#ifndef __P8XC576_H
#define __P8XC576_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;
// 16 bit definition
static		unsigned char P0M1	@ 0x84;
static		unsigned char P0M2	@ 0x85;
static volatile unsigned char UCS	@ 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;
static 		unsigned char AUXR	@ 0x8E;
static volatile unsigned char P1	@ 0x90;
static		unsigned char CMPE	@ 0x92;
static		unsigned char P1M1	@ 0x94;
static		unsigned char P1M2	@ 0x95;
static volatile unsigned char SCON	@ 0x98;
static volatile unsigned char SBUF	@ 0x99;
static volatile unsigned char ADC0L	@ 0x9A;
static volatile unsigned char ADC1L	@ 0x9B;
static volatile unsigned char ADC2L	@ 0x9C;
static volatile unsigned char ADC3L	@ 0x9D;
static volatile unsigned char ADC4L	@ 0x9E;
static volatile unsigned char ADC5L	@ 0x9F;
static volatile unsigned char P2	@ 0xA0;
static		unsigned char P2M1	@ 0xA4;
static		unsigned char P2M2	@ 0xA5;
static		unsigned char IE0	@ 0xA8;
static		unsigned char SADDR	@ 0xA9;
static volatile unsigned char ADC0H	@ 0xAA;
static volatile unsigned char ADC1H	@ 0xAB;
static volatile unsigned char ADC2H	@ 0xAC;
static volatile unsigned char ADC3H	@ 0xAD;
static volatile unsigned char ADC4H	@ 0xAE;
static volatile unsigned char ADC5H	@ 0xAF;
static volatile unsigned char P3	@ 0xB0;
static volatile unsigned char ADCON	@ 0xB1;
static		unsigned char ADCS	@ 0xB2;
static		unsigned char P3M1	@ 0xB4;
static		unsigned char P3M2	@ 0xB5;
static		unsigned char IP0	@ 0xB8;
static		unsigned char SADEN	@ 0xB9;
static volatile unsigned char PWCON	@ 0xBC;
static		unsigned char PWMP	@ 0xBD;
static		unsigned char PWM0	@ 0xBE;
static		unsigned char PWM1	@ 0xBF;
static volatile unsigned char CMP	@ 0xC0;
static		unsigned char WDL	@ 0xC1;
static volatile unsigned char WFEED1	@ 0xC2;
static volatile unsigned char WFEED2	@ 0xC3;
static		unsigned char WDCON	@ 0xC4;
static volatile unsigned char T2CON	@ 0xC8;
static		unsigned char T2MOD	@ 0xC9;
static volatile unsigned char RACAP2L	@ 0xCA;
static volatile unsigned char RACAP2H	@ 0xCB;
static volatile unsigned char TL2	@ 0xCC;
static volatile unsigned char TH2	@ 0xCD;
static volatile unsigned char PSW	@ 0xD0;
static volatile unsigned char CCON	@ 0xD8;
static		unsigned char CMOD	@ 0xD9;
static		unsigned char CCAPM0	@ 0xDA;
static		unsigned char CCAPM1	@ 0xDB;
static		unsigned char CCAPM2	@ 0xDC;
static		unsigned char CCAPM3	@ 0xDD;
static		unsigned char CCAPM4	@ 0xDE;
static volatile unsigned char ACC	@ 0xE0;
static		unsigned char IE1	@ 0xE8;
static volatile unsigned char CL	@ 0xE9;
static volatile unsigned char CCAP0L	@ 0xEA;
static volatile unsigned char CCAP1L	@ 0xEB;
static volatile unsigned char CCAP2L	@ 0xEC;
static volatile unsigned char CCAP3L	@ 0xED;
static volatile unsigned char CCAP4L	@ 0xEE;
static volatile unsigned char B		@ 0xF0;
static		unsigned char IP1	@ 0xF8;
static volatile unsigned char CH	@ 0xF9;
static volatile unsigned char CCAP0H	@ 0xFA;
static volatile unsigned char CCAP1H	@ 0xFB;
static volatile unsigned char CCAP2H	@ 0xFC;
static volatile unsigned char CCAP3H	@ 0xFD;
static volatile unsigned char CCAP4H	@ 0xFE;

static volatile SFR_BITS P0_BITS		@ 0x80;
static		SFR_BITS P0M1_BITS		@ 0x84;
static		SFR_BITS P0M2_BITS		@ 0x85;
static volatile SFR_BITS UCS_BITS		@ 0x86;
static volatile SFR_BITS PCON_BITS		@ 0x87;
static volatile SFR_BITS TCON_BITS		@ 0x88;
static		SFR_BITS TMOD_BITS		@ 0x89;
static		SFR_BITS AUXR_BITS		@ 0x8E;
static volatile SFR_BITS P1_BITS		@ 0x90;
static		SFR_BITS CMPE_BITS		@ 0x92;
static		SFR_BITS P1M1_BITS		@ 0x94;
static		SFR_BITS P1M2_BITS		@ 0x95;
static volatile SFR_BITS SCON_BITS		@ 0x98;
static volatile SFR_BITS P2_BITS		@ 0xA0;
static		SFR_BITS P2M1_BITS		@ 0xA4;
static		SFR_BITS P2M2_BITS		@ 0xA5;
static		SFR_BITS IE0_BITS		@ 0xA8;
static volatile SFR_BITS P3_BITS		@ 0xB0;
static volatile SFR_BITS ADCON_BITS		@ 0xB1;
static		SFR_BITS ADCS_BITS		@ 0xB2;
static		SFR_BITS P3M1_BITS		@ 0xB4;
static		SFR_BITS P3M2_BITS		@ 0xB5;
static		SFR_BITS IP0_BITS		@ 0xB8;
static		SFR_BITS SADEN_BITS		@ 0xB9;
static volatile SFR_BITS PWCON_BITS		@ 0xBC;
static volatile SFR_BITS CMP_BITS		@ 0xC0;
static		SFR_BITS WDCON_BITS		@ 0xC4;
static volatile SFR_BITS T2CON_BITS		@ 0xC8;
static		SFR_BITS T2MOD_BITS		@ 0xC9;
static volatile SFR_BITS PSW_BITS		@ 0xD0;
static volatile SFR_BITS CCON_BITS		@ 0xD8;
static		SFR_BITS CMOD_BITS		@ 0xD9;
static		SFR_BITS CCAPM0_BITS		@ 0xDA;
static		SFR_BITS CCAPM1_BITS		@ 0xDB;
static		SFR_BITS CCAPM2_BITS		@ 0xDC;
static		SFR_BITS CCAPM3_BITS		@ 0xDD;
static		SFR_BITS CCAPM4_BITS		@ 0xDE;
static volatile SFR_BITS ACC_BITS		@ 0xE0;
static		SFR_BITS IE1_BITS		@ 0xE8;
static volatile SFR_BITS B_BITS			@ 0xF0;
static		SFR_BITS IP1_BITS		@ 0xF8;

//Bit Addressable Locations
//Port 0 P0
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 	AD5	@ 0x85;
static volatile bit 	AD6	@ 0x86;
static volatile bit 	AD7	@ 0x87;

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

//Port 1 P1
static volatile bit 	ADIN0	@ 0x90;
static volatile bit 	ADIN1	@ 0x91;
static volatile bit 	ADIN2	@ 0x92;
static volatile bit 	ADIN3	@ 0x93;
static volatile bit 	ADIN4	@ 0x94;
static volatile bit 	ADIN5	@ 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;

//Port 2 P2
static volatile bit 	CEX0	@ 0xA0;
static volatile bit 	CEX1	@ 0xA1;
static volatile bit 	CEX2	@ 0xA2;
static volatile bit 	CEX3	@ 0xA3;
static volatile bit 	T2EX	@ 0xA4;
static volatile bit 	T2	@ 0xA5;
static volatile bit 	CEX4	@ 0xA6;
static volatile bit 	ECI	@ 0xA7;

//Interrupt Enable 0 IE0
static 		bit 	EX0	@ 0xA8;
static 		bit 	ET0	@ 0xA9;
static 		bit 	EX1	@ 0xAA;
static 		bit 	ET1	@ 0xAB;
static 		bit 	ES	@ 0xAC;
static 		bit 	ET2	@ 0xAD;
static 		bit 	EC	@ 0xAE;
static 		bit 	EA	@ 0xAF;

//Port 3 P3
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 0 IP0
static 		bit 	PX0 	@ 0xB8;
static 		bit 	PT0 	@ 0xB9;
static 		bit 	PX1 	@ 0xBA;
static 		bit 	PT1 	@ 0xBB;
static 		bit 	PS 	@ 0xBC;
static 		bit 	PT2 	@ 0xBD;
static 		bit 	PPC 	@ 0xBE;

//Comparator CMP
static volatile bit 	C0RO	@ 0xC0;
static volatile bit 	C1RO	@ 0xC1;
static volatile bit 	C2RO	@ 0xC2;
static volatile bit 	C3RO	@ 0xC3;
static		bit 	EC0DP	@ 0xC4;
static		bit 	EC1DP	@ 0xC5;
static		bit 	EC2DP	@ 0xC6;
static		bit 	EC3DP	@ 0xC7;

//Timer 2 Control T2CON
static 		bit 	CPRL2	@ 0xC8;
static 		bit 	CT2	@ 0xC9;
static 		bit 	TR2	@ 0xCA;
static 		bit 	EXEN2	@ 0xCB;
static		bit 	TCLK	@ 0xCC;
static		bit 	RCLK	@ 0xCD;
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;

//Counter Control CCON
static volatile	bit 	CCF0	@ 0xD8;
static volatile	bit 	CCF1	@ 0xD9;
static volatile	bit 	CCF2	@ 0xDA;
static volatile	bit 	CCF3	@ 0xDB;
static volatile	bit 	CCF4	@ 0xDC;
static		bit 	CR	@ 0xDE;
static volatile	bit 	CF	@ 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 IE1
static 		bit 	EC0	@ 0xE8;
static 		bit 	EC1	@ 0xE9;
static 		bit 	EC2	@ 0xEA;
static 		bit 	EC3	@ 0xEB;
static 		bit 	EC4	@ 0xEC;
static 		bit 	EAD	@ 0xED;
static 		bit 	EIB	@ 0xEE;
static 		bit 	EOB	@ 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 	PC0	@ 0xF8;
static 		bit 	PC1	@ 0xF9;
static 		bit 	PC2	@ 0xFA;
static 		bit 	PC3	@ 0xFB;
static 		bit 	PC4	@ 0xFC;
static 		bit 	PAD	@ 0xFD;
static 		bit 	PIB	@ 0xFE;
static 		bit 	POB	@ 0xFF;


//Interrupt Vectors
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	SERIAL	0x23
#define	TIMER2	0x2B
#define	PCA	0x33
#define	ADC	0x3B
#define	PCA0	0x43
#define	PCA1	0x4B
#define	PCA2	0x53
#define	PCA3	0x5B
#define	PCA4	0x63
#define	UPIB	0x6B
#define	UPOB	0x73

#endif
