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

/*
   Header file for the Dallas Semiconductor microcontroller
	DS87C550
 */

#ifndef	__DS87C550_H

#define	__DS87C550_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	PORT0	@ 0x80;
static volatile	unsigned char	SP	@ 0x81;
static volatile	unsigned char	DPL	@ 0x82;
static volatile	unsigned char	DPH	@ 0x83;
// 16 bit definition
// Alternate definition
static volatile	unsigned char	DPL1	@ 0x84;
static volatile	unsigned char	DPH1	@ 0x85;
// 16 bit definition
static 		unsigned char	DPS	@ 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	CKCON	@ 0x8E;
static volatile	unsigned char	PORT1	@ 0x90;
static volatile	unsigned char	RCON	@ 0x91;
static volatile	unsigned char	SCON0	@ 0x98;
static volatile	unsigned char	SBUF0	@ 0x99;
static 		unsigned char	PMR	@ 0x9F;
static volatile	unsigned char	PORT2	@ 0xA0;
static 		unsigned char	SADDR0	@ 0xA1;
static 		unsigned char	SADDR1	@ 0xA2;
static volatile	unsigned char	IE	@ 0xA8;
static volatile	unsigned char	CMPL0	@ 0xA9;
static volatile	unsigned char	CMPL1	@ 0xAA;
static volatile	unsigned char	CMPL2	@ 0xAB;
static volatile	unsigned char	CPTL0	@ 0xAC;
static volatile	unsigned char	CPTL1	@ 0xAD;
static volatile	unsigned char	CPTL2	@ 0xAE;
static volatile	unsigned char	CPTL3	@ 0xAF;
static volatile	unsigned char	PORT3	@ 0xB0;
static volatile	unsigned char	ADCON1	@ 0xB2;
static volatile	unsigned char	ADCON2	@ 0xB3;
static volatile	unsigned char	ADMSB	@ 0xB4;
static volatile	unsigned char	ADLSB	@ 0xB5;
static 		unsigned char	WINHI	@ 0xB6;
static 		unsigned char	WINLO	@ 0xB7;
static 		unsigned char	IP 	@ 0xB8;
static 		unsigned char	SADEN0	@ 0xB9;
static 		unsigned char	SADEN1	@ 0xBA;
static volatile	unsigned char	T2CON	@ 0xBE;
static 		unsigned char	T2MOD	@ 0xBF;
static volatile	unsigned char	PORT4	@ 0xC0;
static 		unsigned char	ROMSIZE	@ 0xC2;
static volatile	unsigned char	PORT5	@ 0xC4;
static volatile	unsigned char	STATUS	@ 0xC5;
static 		unsigned char	TA	@ 0xC7;
static volatile	unsigned char	T2IR	@ 0xC8;
static volatile	unsigned char	CMPH0	@ 0xC9;
static volatile	unsigned char	CMPH1	@ 0xCA;
static volatile	unsigned char	CMPH2	@ 0xCB;
static volatile	unsigned char	CPTH0	@ 0xCC;
static volatile	unsigned char	CPTH1	@ 0xCD;
static volatile	unsigned char	CPTH2	@ 0xCE;
static volatile	unsigned char	CPTH3	@ 0xCF;
static volatile	unsigned char	PSW	@ 0xD0;
static 		unsigned char	PW0FG	@ 0xD2;
static 		unsigned char	PW1FG	@ 0xD3;
static 		unsigned char	PW2FG	@ 0xD4;
static 		unsigned char	PW3FG	@ 0xD5;
static 		unsigned char	PWMADR	@ 0xD6;
static volatile	unsigned char	SCON1	@ 0xD8;
static volatile	unsigned char	SBUF1	@ 0xD9;
static 		unsigned char	PWM0	@ 0xDC;
static 		unsigned char	PWM1	@ 0xDD;
static 		unsigned char	PWM2	@ 0xDE;
static 		unsigned char	PWM3	@ 0xDF;
static volatile	unsigned char	ACC	@ 0xE0;
static 		unsigned char	PW01CS	@ 0xE1;
static 		unsigned char	PW23CS	@ 0xE2;
static 		unsigned char	PW01CON	@ 0xE3;
static 		unsigned char	PW23CON	@ 0xE4;
static 		unsigned char	RLOADL	@ 0xE6;
static 		unsigned char	RLOADH	@ 0xE7;
static 		unsigned char	EIE	@ 0xE8;
static volatile	unsigned char	T2SEL	@ 0xEA;
static 		unsigned char	CTCON	@ 0xEB;
static volatile	unsigned char	TL2	@ 0xEC;
static volatile	unsigned char	TH2	@ 0xED;
static 		unsigned char	SETR	@ 0xEE;
static 		unsigned char	RSTR	@ 0xEF;
static volatile	unsigned char	B	@ 0xF0;
static volatile	unsigned char	PORT6	@ 0xF1;
static 		unsigned char	EIP	@ 0xF8;
static volatile	unsigned char	WDCON	@ 0xFF;

static volatile	SFR_BITS PORT0_BITS		@ 0x80;
static 		SFR_BITS DPS_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 CKCON_BITS		@ 0x8E;
static volatile	SFR_BITS PORT1_BITS		@ 0x90;
static volatile	SFR_BITS RCON_BITS		@ 0x91;
static volatile	SFR_BITS SCON0_BITS		@ 0x98;
static 		SFR_BITS PMR_BITS		@ 0x9F;
static volatile	SFR_BITS PORT2_BITS		@ 0xA0;
static 		SFR_BITS IE_BITS		@ 0xA8;
static volatile	SFR_BITS PORT3_BITS		@ 0xB0;
static volatile	SFR_BITS ADCON1_BITS		@ 0xB2;
static volatile	SFR_BITS ADCON2_BITS		@ 0xB3;
static 		SFR_BITS IP_BITS		@ 0xB8;
static volatile	SFR_BITS T2CON_BITS		@ 0xBE;
static 		SFR_BITS T2MOD_BITS		@ 0xBF;
static volatile	SFR_BITS PORT4_BITS		@ 0xC0;
static 		SFR_BITS ROMSIZE_BITS		@ 0xC2;
static volatile	SFR_BITS PORT5_BITS		@ 0xC4;
static volatile	SFR_BITS STATUS_BITS		@ 0xC5;
static volatile	SFR_BITS T2IR_BITS		@ 0xC8;
static volatile	SFR_BITS PSW_BITS		@ 0xD0;
static volatile	SFR_BITS SCON1_BITS		@ 0xD8;
static 		SFR_BITS PW01CS_BITS		@ 0xE1;
static 		SFR_BITS PW23CS_BITS		@ 0xE2;
static 		SFR_BITS PW01CON_BITS		@ 0xE3;
static 		SFR_BITS PW23CON_BITS		@ 0xE4;
static 		SFR_BITS EIE_BITS		@ 0xE8;
static volatile	SFR_BITS T2SEL_BITS		@ 0xEA;
static 		SFR_BITS CTCON_BITS		@ 0xEB;
static 		SFR_BITS SETR_BITS		@ 0xEE;
static 		SFR_BITS RSTR_BITS		@ 0xEF;
static volatile	SFR_BITS PORT6_BITS		@ 0xF1;
static 		SFR_BITS EIP_BITS		@ 0xF8;
static volatile	SFR_BITS WDCON_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;
// Alternate Function
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 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;
// 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 T2		@ 0x94;
static volatile bit T2EX	@ 0x95;
static volatile bit RXD1	@ 0x96;
static volatile bit TXD1	@ 0x97;
static volatile bit CT0		@ 0x90;
static volatile bit CT1		@ 0x91;
static volatile bit CT2		@ 0x92;
static volatile bit CT3		@ 0x93;

//Serial Control 0 SCON0
static volatile	bit RI_0	@ 0x98;
static volatile	bit TI_0	@ 0x99;
static volatile	bit RB8_0	@ 0x9A;
static 		bit TB8_0	@ 0x9B;
static 		bit REN_0	@ 0x9C;
static 		bit SM2_0	@ 0x9D;
static 		bit SM1_0	@ 0x9E;
static volatile	bit SM0_0	@ 0x9F;
// Alternate Function
static volatile	bit FE_0	@ 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;
// 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;

//Interrupt Enable IE
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;
// Alternate Functions
static volatile bit RXD0	@ 0xB0;
static volatile bit TXD0	@ 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 IP
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;
// Alternate Functions
static volatile bit CMSR0	@ 0xC0;
static volatile bit CMSR1	@ 0xC1;
static volatile bit CMSR2	@ 0xC2;
static volatile bit CMSR3	@ 0xC3;
static volatile bit CMSR4	@ 0xC4;
static volatile bit CMSR5	@ 0xC5;
static volatile bit CMT0	@ 0xC6;
static volatile bit CMT1	@ 0xC7;

//Timer 2 Interrupt Request register T2IR
static volatile	bit	IE2	@ 0xC8;
static volatile	bit	IE3	@ 0xC9;
static volatile	bit	IE4	@ 0xCA;
static volatile	bit	IE5	@ 0xCB;
static volatile	bit	CM0F	@ 0xCC;
static volatile	bit	CM1F	@ 0xCD;
static volatile	bit	CM2F	@ 0xCE;
// Alternate Functions
static volatile	bit	CF0	@ 0xC8;
static volatile	bit	CF1	@ 0xC9;
static volatile	bit	CF2	@ 0xCA;
static volatile	bit	CF3	@ 0xCB;

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

//Serial Control 1 SCON1
static volatile	bit RI_1	@ 0xD8;
static volatile	bit TI_1	@ 0xD9;
static volatile	bit RB8_1	@ 0xDA;
static 		bit TB8_1	@ 0xDB;
static 		bit REN_1	@ 0xDC;
static 		bit SM2_1	@ 0xDD;
static 		bit SM1_1	@ 0xDE;
static volatile	bit SM0_1	@ 0xDF;
// Alternate Function
static volatile	bit FE_1	@ 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;

//Extended Interrupt Enable EIE
static		bit	EX2	@ 0xE8;
static		bit	EX3	@ 0xE9;
static		bit	EX4	@ 0xEA;
static		bit	EX5	@ 0xEB;
static		bit	ECM0	@ 0xEC;
static		bit	ECM1	@ 0xED;
static		bit	ECM2	@ 0xEE;
static		bit	ET2	@ 0xEF;
// Alternate Functions
static		bit	EC0	@ 0xE8;
static		bit	EC1	@ 0xE9;
static		bit	EC2	@ 0xEA;
static		bit	EC3	@ 0xEB;

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

//Extended Interrupt Priority EIP
static		bit	PX2	@ 0xF8;
static		bit	PX3	@ 0xF9;
static		bit	PX4	@ 0xFA;
static		bit	PX5	@ 0xFB;
static		bit	PCM0	@ 0xFC;
static		bit	PCM1	@ 0xFD;
static		bit	PCM2	@ 0xFE;
static		bit	PT2	@ 0xFF;
// Alternate Functions
static		bit	PC0	@ 0xF8;
static		bit	PC1	@ 0xF9;
static		bit	PC2	@ 0xFA;
static		bit	PC3	@ 0xFB;

/*	Interrupt vectors */
#define	RESET	0
#define	EXTINT0	0x03
#define	S1	0x0B
#define	AD	0x13
#define	TIMER0	0x1B
#define	EXTINT2	0x23
#define	CP0	0x23
#define	CM0	0x2B
#define	PF	0x33
#define	EXTINT1	0x3B
#define	EXTINT3	0x43
#define	CP1	0x43
#define	CM1	0x4B
#define	TIMER1	0x53
#define	EXTINT4	0x5B
#define	CP2	0x5B
#define	CM2	0x63
#define	SERIAL	0x6B
#define	EXTINT5	0x73
#define	CP3	0x73
#define	TIMER2	0x7B

#endif	
