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


 /* header file for the ST microcontrollers
	UPSD3312D
	UPSD3312DV
	UPSD3333D
	UPSD3333DV
	UPSD3334D
	UPSD3334DV
	UPSD3354D
	UPSD3354DV
 */

#ifndef	__UPSD33XX_H

#define	__UPSD33XX_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 SP	@ 0x81;
static volatile unsigned char DPL	@ 0x82;
static volatile unsigned char DPH	@ 0x83;
static          unsigned char DPTC	@ 0x85;
static          unsigned char DPTM	@ 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 P1SFS0	@ 0x8E;
static          unsigned char P1SFS1	@ 0x8F;
static volatile unsigned char P1	@ 0x90;
static          unsigned char P3SFS	@ 0x91;
static          unsigned char P4SFS0	@ 0x92;
static          unsigned char P4SFS1	@ 0x93;
static          unsigned char ADCPS	@ 0x94;
static volatile unsigned char ADAT0	@ 0x95;
static volatile unsigned char ADAT1	@ 0x96;
static volatile unsigned char ACON	@ 0x97;
static volatile unsigned char SCON0	@ 0x98;
static volatile unsigned char SBUF0	@ 0x99;
static          unsigned char BUSCON	@ 0x9D;
static volatile unsigned char PCACL0	@ 0xA2;
static volatile unsigned char PCACH0	@ 0xA3;
static          unsigned char PCACON0	@ 0xA4;
static volatile unsigned char PCASTA	@ 0xA5;
static volatile unsigned char WDTRST	@ 0xA6;
static          unsigned char IEA	@ 0xA7;
static          unsigned char IE	@ 0xA8;
static          unsigned char TCMMODE0	@ 0xA9;
static          unsigned char TCMMODE1	@ 0xAA;
static          unsigned char TCMMODE2	@ 0xAB;
static volatile unsigned char CAPCOML0	@ 0xAC;
static volatile unsigned char CAPCOMH0	@ 0xAD;
static          unsigned char WDTKEY	@ 0xAE;
static volatile unsigned char CAPCOML1	@ 0xAF;
static volatile unsigned char P3	@ 0xB0;
static volatile unsigned char CAPCOMH1	@ 0xB1;
static volatile unsigned char CAPCOML2	@ 0xB2;
static volatile unsigned char CAPCOMH2	@ 0xB3;
static          unsigned char PWMF0	@ 0xB4;
static          unsigned char IPA	@ 0xB7;
static          unsigned char IP	@ 0xB8;
static volatile unsigned char PCACL1	@ 0xBA;
static volatile unsigned char PCACH1	@ 0xBB;
static          unsigned char PCACON1	@ 0xBC;
static          unsigned char TCMMODE3	@ 0xBD;
static          unsigned char TCMMODE4	@ 0xBE;
static          unsigned char TCMMODE5	@ 0xBF;
static volatile unsigned char P4	@ 0xC0;
static volatile unsigned char CAPCOML3	@ 0xC1;
static volatile unsigned char CAPCOMH3	@ 0xC2;
static volatile unsigned char CAPCOML4	@ 0xC3;
static volatile unsigned char CAPCOMH4	@ 0xC4;
static volatile unsigned char CAPCOML5	@ 0xC5;
static volatile unsigned char CAPCOMH5	@ 0xC6;
static          unsigned char PWMF1	@ 0xC7;
static volatile unsigned char T2CON	@ 0xC8;
static volatile unsigned char RCAP2L	@ 0xCA;
static volatile unsigned char RCAP2H	@ 0xCB;
static volatile unsigned char TL2	@ 0xCC;
static volatile unsigned char TH2	@ 0xCD;
static          unsigned char IRDACON	@ 0xCE;
static volatile unsigned char PSW	@ 0xD0;
static          unsigned char SPICLKD	@ 0xD2;
static volatile unsigned char SPISTAT	@ 0xD3;
static volatile unsigned char SPITDR	@ 0xD4;
static volatile unsigned char SPIRDR	@ 0xD5;
static          unsigned char SPICON0	@ 0xD6;
static          unsigned char SPICON1	@ 0xD7;
static volatile unsigned char SCON1	@ 0xD8;
static volatile unsigned char SBUF1	@ 0xD9;
static          unsigned char S1SETUP	@ 0xDB;
static volatile unsigned char S1CON	@ 0xDC;
static volatile unsigned char S1STA	@ 0xDD;
static volatile unsigned char S1DAT	@ 0xDE;
static          unsigned char S1ADR	@ 0xDF;
static volatile unsigned char A		@ 0xE0;
static volatile unsigned char B		@ 0xF0;

static          SFR_BITS	 DPTC_BITS	@ 0x85;
static          SFR_BITS	 DPTM_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	 P1SFS0_BITS	@ 0x8E;
static          SFR_BITS	 P1SFS1_BITS	@ 0x8F;
static volatile SFR_BITS	 P1_BITS	@ 0x90;
static          SFR_BITS	 P3SFS_BITS	@ 0x91;
static          SFR_BITS	 P4SFS0_BITS	@ 0x92;
static          SFR_BITS	 P4SFS1_BITS	@ 0x93;
static          SFR_BITS	 ADCPS_BITS	@ 0x94;
static volatile SFR_BITS	 ACON_BITS	@ 0x97;
static volatile SFR_BITS	 SCON0_BITS	@ 0x98;
static          SFR_BITS	 BUSCON_BITS	@ 0x9D;
static          SFR_BITS	 PCACON0_BITS	@ 0xA4;
static volatile SFR_BITS	 PCASTA_BITS	@ 0xA5;
static          SFR_BITS	 IEA_BITS	@ 0xA7;
static          SFR_BITS	 IE_BITS	@ 0xA8;
static          SFR_BITS	 TCMMODE0_BITS	@ 0xA9;
static          SFR_BITS	 TCMMODE1_BITS	@ 0xAA;
static          SFR_BITS	 TCMMODE2_BITS	@ 0xAB;
static volatile SFR_BITS	 P3_BITS	@ 0xB0;
static          SFR_BITS	 IPA_BITS	@ 0xB7;
static          SFR_BITS	 IP_BITS	@ 0xB8;
static          SFR_BITS	 PCACON1_BITS	@ 0xBC;
static          SFR_BITS	 TCMMODE3_BITS	@ 0xBD;
static          SFR_BITS	 TCMMODE4_BITS	@ 0xBE;
static          SFR_BITS	 TCMMODE5_BITS	@ 0xBF;
static volatile SFR_BITS	 P4_BITS	@ 0xC0;
static volatile SFR_BITS	 T2CON_BITS	@ 0xC8;
static          SFR_BITS	 IRDACON_BITS	@ 0xCE;
static volatile SFR_BITS	 PSW_BITS	@ 0xD0;
static volatile SFR_BITS	 SPISTAT_BITS	@ 0xD3;
static volatile SFR_BITS	 SPICON0_BITS	@ 0xD6;
static volatile SFR_BITS	 SPICON1_BITS	@ 0xD7;
static volatile SFR_BITS	 SCON1_BITS	@ 0xD8;
static          SFR_BITS	 S1SETUP_BITS	@ 0xDB;
static volatile SFR_BITS	 S1CON_BITS	@ 0xDC;
static volatile SFR_BITS	 S1STA_BITS	@ 0xDD;
static volatile SFR_BITS	 S1DAT_BITS	@ 0xDE;
static          SFR_BITS	 S1ADR_BITS	@ 0xDF;
static volatile SFR_BITS	 A_BITS		@ 0xE0;
static volatile SFR_BITS	 B_BITS		@ 0xF0;


// Bit Addressable Locations
// 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 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 Register 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 		bit	SM0_0	@ 0x9F;

// 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	ET2	@ 0xAD;
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;
// 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
static 		bit	PX0	@ 0xB8;
static 		bit	PT0	@ 0xB9;
static 		bit	PX1	@ 0xBA;
static 		bit	PT1	@ 0xBB;
static 		bit	PS0	@ 0xBC;
static 		bit	PT2	@ 0xBD;

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

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

// definitions for accumulator A
static volatile bit	A0	@ 0xE0;
static volatile bit	A1	@ 0xE1;
static volatile bit	A2	@ 0xE2;
static volatile bit	A3	@ 0xE3;
static volatile bit	A4	@ 0xE4;
static volatile bit	A5	@ 0xE5;
static volatile bit	A6	@ 0xE6;
static volatile bit	A7	@ 0xE7;

// 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 Vectors
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	SERIAL0	0x23
#define	TIMER2	0x2B
#define	ADC	0x3B
#define	I2C	0x43
#define	SERIAL1	0x4B
#define	SPI	0x53
#define	PCA	0x5B

#endif
