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


 /* header file for the microcontrollers
	C8051F330
	C8051F330D
	C8051F331
 */

#ifndef	__8051F33X_H

#define	__8051F33X_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 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          unsigned char PSCTL	@ 0x8F;
static volatile unsigned char P1	@ 0x90;
static volatile unsigned char TMR3CN	@ 0x91;
static          unsigned char TMR3RLL	@ 0x92;
static          unsigned char TMR3RLH	@ 0x93;
static volatile unsigned char TMR3L	@ 0x94;
static volatile unsigned char TMR3H	@ 0x95;
#if defined(_C8051F330) || defined(_C8051F330D)
static		unsigned char IDA0L	@ 0x96;
static		unsigned char IDA0H	@ 0x97;
#endif
static volatile unsigned char SCON0	@ 0x98;
static volatile unsigned char SBUF0	@ 0x99;
static volatile unsigned char CPT0CN	@ 0x9B;
static          unsigned char CPT0MD	@ 0x9D;
static          unsigned char CPT0MX	@ 0x9F;
static volatile unsigned char P2	@ 0xA0;
static volatile unsigned char SPI0CFG	@ 0xA1;
static          unsigned char SPI0CKR	@ 0xA2;
static volatile unsigned char SPI0DAT	@ 0xA3;
static          unsigned char P0MDOUT	@ 0xA4;
static          unsigned char P1MDOUT	@ 0xA5;
static          unsigned char P2MDOUT	@ 0xA6;
static          unsigned char IE	@ 0xA8;
static          unsigned char CLKSEL	@ 0xA9;
static          unsigned char EMI0CN	@ 0xAA;
static volatile unsigned char OSCXCN	@ 0xB1;
static volatile unsigned char OSCICN	@ 0xB2;
static          unsigned char OSCICL	@ 0xB3;
static          unsigned char FLSCL	@ 0xB6;
static volatile unsigned char FLKEY	@ 0xB7;
static          unsigned char IP	@ 0xB8;
#if defined(_C8051F330) || defined(_C8051F330D)
static		unsigned char IDA0CN	@ 0xB9;
static		unsigned char AMX0N	@ 0xBA;
static		unsigned char AMX0P	@ 0xBB;
static volatile unsigned char ADC0CF	@ 0xBC;
static volatile unsigned char ADC0L	@ 0xBD;
static volatile unsigned char ADC0H	@ 0xBE;
#endif
static volatile unsigned char SMB0CN	@ 0xC0;
static volatile unsigned char SMB0CF	@ 0xC1;
static volatile unsigned char SMB0DAT	@ 0xC2;
static          unsigned char ADC0GTL	@ 0xC3;
static          unsigned char ADC0GTH	@ 0xC4;
static          unsigned char ADC0LTL	@ 0xC5;
static          unsigned char ADC0LTH	@ 0xC6;
static volatile unsigned char TMR2CN	@ 0xC8;
static volatile unsigned char TMR2RLL	@ 0xCA;
static volatile unsigned char TMR2RLH	@ 0xCB;
static volatile unsigned char TMR2L	@ 0xCC;
static volatile unsigned char TMR2H	@ 0xCD;
static volatile unsigned char PSW	@ 0xD0;
#if defined(_C8051F330) || defined(_C8051F330D)
static          unsigned char REF0CN	@ 0xD1;
#endif
static		unsigned char P0SKIP	@ 0xD4;
static		unsigned char P1SKIP	@ 0xD5;
static volatile unsigned char PCA0CN	@ 0xD8;
static          unsigned char PCA0MD	@ 0xD9;
static          unsigned char PCA0CPM0	@ 0xDA;
static          unsigned char PCA0CPM1	@ 0xDB;
static          unsigned char PCA0CPM2	@ 0xDC;
static volatile unsigned char ACC	@ 0xE0;
static          unsigned char XBR0	@ 0xE1;
static          unsigned char XBR1	@ 0xE2;
static volatile unsigned char OSCLCN	@ 0xE3;
static		unsigned char IT01CF	@ 0xE4;
static          unsigned char EIE1	@ 0xE6;
static volatile unsigned char ADC0CN	@ 0xE8;
static volatile unsigned char PCA0CPL1	@ 0xE9;
static volatile unsigned char PCA0CPH1	@ 0xEA;
static volatile unsigned char PCA0CPL2	@ 0xEB;
static volatile unsigned char PCA0CPH2	@ 0xEC;
static volatile unsigned char RSTSRC	@ 0xEF;
static volatile unsigned char B		@ 0xF0;
static          unsigned char P0MDIN	@ 0xF1;
static          unsigned char P1MDIN	@ 0xF2;
static          unsigned char EIP1	@ 0xF6;
static volatile unsigned char SPI0CN	@ 0xF8;
static volatile unsigned char PCA0L	@ 0xF9;
static volatile unsigned char PCA0H	@ 0xFA;
static volatile unsigned char PCA0CPL0	@ 0xFB;
static volatile unsigned char PCA0CPH0	@ 0xFC;
static volatile unsigned char VDM0CN	@ 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          SFR_BITS	 CKCON_BITS	@ 0x8E;
static          SFR_BITS	 PSCTL_BITS	@ 0x8F;
static volatile SFR_BITS	 P1_BITS	@ 0x90;
static volatile SFR_BITS	 TMR3CN_BITS	@ 0x91;
static volatile SFR_BITS	 SCON0_BITS	@ 0x98;
static volatile SFR_BITS	 CPT0CN_BITS	@ 0x9B;
static          SFR_BITS	 CPT0MD_BITS	@ 0x9D;
static          SFR_BITS	 CPT0MX_BITS	@ 0x9F;
static volatile SFR_BITS	 P2_BITS	@ 0xA0;
static volatile SFR_BITS	 SPI0CFG_BITS	@ 0xA1;
static          SFR_BITS	 P0MDOUT_BITS	@ 0xA4;
static          SFR_BITS	 P1MDOUT_BITS	@ 0xA5;
static          SFR_BITS	 P2MDOUT_BITS	@ 0xA6;
static          SFR_BITS	 IE_BITS	@ 0xA8;
static          SFR_BITS	 CLKSEL_BITS	@ 0xA9;
static volatile SFR_BITS	 OSCXCN_BITS	@ 0xB1;
static volatile SFR_BITS	 OSCICN_BITS	@ 0xB2;
static          SFR_BITS	 FLSCL_BITS	@ 0xB6;
static          SFR_BITS	 IP_BITS	@ 0xB8;
#if defined(_C8051F330) || defined(_C8051F330D)
static		SFR_BITS	 IDA0CN_BITS	@ 0xB9;
static		SFR_BITS	 AMX0N_BITS	@ 0xBA;
static		SFR_BITS	 AMX0P_BITS	@ 0xBB;
static volatile SFR_BITS	 ADC0CF_BITS	@ 0xBC;
#endif
static volatile SFR_BITS	 SMB0CN_BITS	@ 0xC0;
static volatile SFR_BITS	 SMB0CF_BITS	@ 0xC1;
static volatile SFR_BITS	 TMR2CN_BITS	@ 0xC8;
static volatile SFR_BITS	 PSW_BITS	@ 0xD0;
static		SFR_BITS	 P0SKIP_BITS	@ 0xD4;
static		SFR_BITS	 P1SKIP_BITS	@ 0xD5;
static volatile SFR_BITS	 PCA0CN_BITS	@ 0xD8;
static          SFR_BITS	 PCA0MD_BITS	@ 0xD9;
static          SFR_BITS	 PCA0CPM0_BITS	@ 0xDA;
static          SFR_BITS	 PCA0CPM1_BITS	@ 0xDB;
static          SFR_BITS	 PCA0CPM2_BITS	@ 0xDC;
static volatile SFR_BITS	 ACC_BITS	@ 0xE0;
static          SFR_BITS	 XBR0_BITS	@ 0xE1;
static          SFR_BITS	 XBR1_BITS	@ 0xE2;
static volatile SFR_BITS	 OSCLCN_BITS	@ 0xE3;
static		SFR_BITS	 IT01CF_BITS	@ 0xE4;
static          SFR_BITS	 EIE1_BITS	@ 0xE6;
static volatile SFR_BITS	 ADC0CN_BITS	@ 0xE8;
static volatile SFR_BITS	 RSTSRC_BITS	@ 0xEF;
static volatile SFR_BITS	 B_BITS		@ 0xF0;
static          SFR_BITS	 P0MDIN_BITS	@ 0xF1;
static          SFR_BITS	 P1MDIN_BITS	@ 0xF2;
static          SFR_BITS	 EIP1_BITS	@ 0xF6;
static volatile SFR_BITS	 SPI0CN_BITS	@ 0xF8;
static volatile SFR_BITS	 VDM0CN_BITS	@ 0xFF;


// Bit Addressable Locations
// Port 0 P0
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 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	RI0	@ 0x98;
static volatile bit	TI0	@ 0x99;
static volatile bit	RB80	@ 0x9A;
static 		bit	TB80	@ 0x9B;
static 		bit	REN0	@ 0x9C;
static 		bit	MCE0	@ 0x9D;
static 		bit	S0MODE	@ 0x9F;

// Port 2 P2
static volatile bit	P20	@ 0xA0;

// 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	ESPIO	@ 0xAE;
static 		bit	EA	@ 0xAF;

// Interrupt Priority
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	PSPIO	@ 0xBE;

// SM Bus Control Register SMB0CN
static volatile bit	SI	@ 0xC0;
static volatile bit	ACK	@ 0xC1;
static volatile bit	ARBLOST	@ 0xC2;
static volatile bit	ACKRQ	@ 0xC3;
static volatile bit	STO	@ 0xC4;
static volatile bit	STA	@ 0xC5;
static volatile bit	TXMODE	@ 0xC6;
static volatile bit	MASTER	@ 0xC7;

// Timer 2 Control TMR2CN
static 		bit	T2XCLK	@ 0xC8;
static 		bit	TR2	@ 0xCA;
static 		bit	T2SPLIT	@ 0xCB;
static 		bit	TF2CEN	@ 0xCC;
static		bit	TF2LEN	@ 0xCD;
static volatile	bit	TF2L	@ 0xCE;
static volatile	bit	TF2H	@ 0xCF;

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

// PCA Control Register PCA0CN
static volatile bit	CCF0	@ 0xD8;
static volatile bit	CCF1	@ 0xD9;
static volatile bit	CCF2	@ 0xDA;
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;

#if defined(_C8051F330) || defined(_C8051F330D)
// ADC Control Register ADC0CN
static		bit	AD0CM0	@ 0xE8;
static		bit	AD0CM1	@ 0xE9;
static		bit	AD0CM2	@ 0xEA;
static volatile bit	AD0WINT	@ 0xEB;
static volatile bit	AD0BUSY	@ 0xEC;
static volatile bit	AD0INT	@ 0xED;
static		bit	AD0TM	@ 0xEE;
static		bit	AD0EN	@ 0xEF;
#endif

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

// SPI Control Register SPI0CN
static		bit	SPIEN	@ 0xF8;
static volatile bit	TXBMT	@ 0xF9;
static		bit	NSSMD0	@ 0xFA;
static		bit	NSSMD1	@ 0xFB;
static volatile bit	RXOVRN	@ 0xFC;
static volatile bit	MODF	@ 0xFD;
static volatile bit	WCOL	@ 0xFE;
static volatile bit	SPIF	@ 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	SPI	0x33
#define	SMB0	0x3B
#if defined(_C8051F330) || defined(_C8051F330D)
#define	ADCWIN	0x4B
#define	ADC	0x53
#endif
#define	PCA	0x5B
#define	COMP0	0x63
#define	TIMER3	0x73

#endif
