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


 /* header file for the Goal microcontrollers
	VERSAMIX
 */

#ifndef	__VERSAMIX_H

#define	__VERSAMIX_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 DPL0	@ 0x82;
static volatile unsigned char DPH0	@ 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 P1	@ 0x90;
static volatile unsigned char IRCON	@ 0x91;
static		unsigned char ANALOGPWREN	@ 0x92;
static		unsigned char DIGPWREN	@ 0x93;
static volatile unsigned char CLKDIVCTRL	@ 0x94;
static		unsigned char ADCCLKDIV	@ 0x95;
static		unsigned char S0RELL	@ 0x96;
static		unsigned char S0RELH	@ 0x97;
static volatile unsigned char S0CON	@ 0x98;
// alternate definition
static volatile unsigned char SCON	@ 0x98;
static volatile unsigned char S0BUF	@ 0x99;
// alternate definition
static volatile unsigned char SBUF	@ 0x99;
static		unsigned char IEN2	@ 0x9A;
static		unsigned char P0PINCFG	@ 0x9B;
static		unsigned char P2PINCFG	@ 0x9D;
static		unsigned char P3PINCFG	@ 0x9E;
static		unsigned char PORTIRQEN	@ 0x9F;
static volatile unsigned char P2	@ 0xA0;
static volatile unsigned char PORTIRQSTAT	@ 0xA1;
static volatile unsigned char ADCCTRL	@ 0xA2;
static		unsigned char ADCCONVRLOW	@ 0xA3;
static		unsigned char ADCCONVRMED	@ 0xA4;
static		unsigned char ADCCONVRHIGH	@ 0xA5;
static volatile unsigned char ADCD0LO	@ 0xA6;
static volatile unsigned char ADCD0HI	@ 0xA7;
static volatile unsigned char IEN0	@ 0xA8;
static volatile unsigned char ADCD1LO	@ 0xA9;
static volatile unsigned char ADCD1HI	@ 0xAA;
static volatile unsigned char ADCD2LO	@ 0xAB;
static volatile unsigned char ADCD2HI	@ 0xAC;
static volatile unsigned char ADCD3LO	@ 0xAD;
static volatile unsigned char ADCD3HI	@ 0xAE;
static volatile unsigned char P3	@ 0xB0;
static volatile unsigned char ADCFORCE	@ 0xB1;
static volatile unsigned char ADCALTBL	@ 0xB2;
static		unsigned char BGAPCAL	@ 0xB3;
static		unsigned char PGACAL	@ 0xB4;
static		unsigned char INMUXCTRL	@ 0xB5;
static		unsigned char OUTMUXCTRL	@ 0xB6;
static		unsigned char SWITCHCTRL	@ 0xB7;
static volatile unsigned char IP0	@ 0xB8;
static          unsigned char IP1	@ 0xB9;
static		unsigned char DIGPOT1	@ 0xBA;
static		unsigned char DIGPOT2	@ 0xBB;
static		unsigned char ISRCCAL1	@ 0xBC;
static		unsigned char ISRCCAL2	@ 0xBD;
static		unsigned char S1RELL	@ 0xBE;
static		unsigned char S1RELH	@ 0xBF;
static volatile unsigned char S1CON	@ 0xC0;
static volatile unsigned char S1BUF	@ 0xC1;
static volatile unsigned char CCL1	@ 0xC2;
static volatile unsigned char CCH1	@ 0xC3;
static volatile unsigned char CCL2	@ 0xC4;
static volatile unsigned char CCH2	@ 0xC5;
static volatile unsigned char CCL3	@ 0xC6;
static volatile unsigned char CCH3	@ 0xC7;
static		unsigned char T2CON	@ 0xC8;
static		unsigned char CCEN	@ 0xC9;
static volatile unsigned char CRCL	@ 0xCA;
static volatile unsigned char CRCH	@ 0xCB;
static volatile unsigned char TL2	@ 0xCC;
static volatile unsigned char TH2	@ 0xCD;
static		unsigned char MPAGE	@ 0xCF;
static volatile unsigned char PSW	@ 0xD0;
static volatile unsigned char BREAKP0L	@ 0xD1;
static volatile unsigned char BREAKP0H	@ 0xD2;
static volatile unsigned char BREAKP1L	@ 0xD3;
static volatile unsigned char BREAKP1H	@ 0xD4;
static volatile unsigned char BREAKPCTRL	@ 0xD5;
static volatile unsigned char DEBUGCTRL	@ 0xD6;
static volatile unsigned char DEBUGSTATUS	@ 0xD7;
static		unsigned char WDCON	@ 0xD8;
static          unsigned char WDTREL	@ 0xD9;
static volatile unsigned char I2CCONFIG	@ 0xDA;
static		unsigned char I2CCLKCTRL	@ 0xDB;
static		unsigned char I2CCHIPID	@ 0xDC;
static volatile unsigned char I2CIRQSTAT	@ 0xDD;
static volatile unsigned char I2CRXTX	@ 0xDE;
static volatile unsigned char ACC	@ 0xE0;
static volatile unsigned char SPIRXTX0	@ 0xE1;
static volatile unsigned char SPIRXTX1	@ 0xE2;
static volatile unsigned char SPIRXTX2	@ 0xE3;
static volatile unsigned char SPIRXTX3	@ 0xE4;
static volatile unsigned char SPICTRL1	@ 0xE5;
static volatile unsigned char SPICTRL2	@ 0xE6;
static		unsigned char SPISIZECTRL	@ 0xE7;
static          unsigned char IEN1	@ 0xE8;
static volatile unsigned char SPIIRQSTAT	@ 0xE9;
static volatile unsigned char MACCTRL	@ 0xEB;
static volatile unsigned char MACC0	@ 0xEC;
static volatile unsigned char MACC1	@ 0xED;
static volatile unsigned char MACC2	@ 0xEE;
static volatile unsigned char MACC3	@ 0xEF;
static volatile unsigned char B		@ 0xF0;
static volatile unsigned char MACCTRL2	@ 0xF1;
static		unsigned char MACA0	@ 0xF2;
static		unsigned char MACA1	@ 0xF3;
static volatile unsigned char MACRES0	@ 0xF4;
static volatile unsigned char MACRES1	@ 0xF5;
static volatile unsigned char MACRES2	@ 0xF6;
static volatile unsigned char MACRES3	@ 0xF7;
static		unsigned char USERFLAGS	@ 0xF8;
static		unsigned char MACB0	@ 0xF9;
static		unsigned char MACB1	@ 0xFA;
static		unsigned char MACSHIFTCTRL	@ 0xFB;
static volatile unsigned char MACPREV0	@ 0xFC;
static volatile unsigned char MACPREV1	@ 0xFD;
static volatile unsigned char MACPREV2	@ 0xFE;
static volatile unsigned char MACPREV3	@ 0xFF;

static volatile SFR_BITS	 P0_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	 P1_BITS	@ 0x90;
static volatile SFR_BITS	 IRCON_BITS	@ 0x91;
static		SFR_BITS	 ANALOGPWREN_BITS	@ 0x92;
static		SFR_BITS	 DIGPWREN_BITS	@ 0x93;
static		SFR_BITS	 CLKDIVCTRL_BITS	@ 0x94;
static volatile SFR_BITS	 S0CON_BITS	@ 0x98;
// alternate definition
static volatile SFR_BITS	 SCON_BITS	@ 0x98;
static volatile SFR_BITS	 S0BUF_BITS	@ 0x99;
static		SFR_BITS	 IEN2_BITS	@ 0x9A;
static		SFR_BITS	 P0PINCFG_BITS	@ 0x9B;
static		SFR_BITS	 P2PINCFG_BITS	@ 0x9D;
static		SFR_BITS	 P3PINCFG_BITS	@ 0x9E;
static		SFR_BITS	 PORTIRQEN_BITS	@ 0x9F;
static volatile SFR_BITS	 P2_BITS	@ 0xA0;
static volatile SFR_BITS	 PORTIRQSTAT_BITS	@ 0xA1;
static volatile SFR_BITS	 ADCCTRL_BITS	@ 0xA2;
static volatile SFR_BITS	 IEN0_BITS	@ 0xA8;
static volatile SFR_BITS	 P3_BITS	@ 0xB0;
static volatile SFR_BITS	 ADCFORCE_BITS	@ 0xB1;
static volatile SFR_BITS	 ADCALTBL_BITS	@ 0xB2;
static		SFR_BITS	 INMUXCTRL_BITS	@ 0xB5;
static		SFR_BITS	 OUTMUXCTRL_BITS	@ 0xB6;
static		SFR_BITS	 SWITCHCTRL_BITS	@ 0xB7;
static volatile SFR_BITS	 IP0_BITS	@ 0xB8;
static          SFR_BITS	 IP1_BITS	@ 0xB9;
static volatile SFR_BITS	 S1CON_BITS	@ 0xC0;
static		SFR_BITS	 T2CON_BITS	@ 0xC8;
static		SFR_BITS	 CCEN_BITS	@ 0xC9;
static volatile SFR_BITS	 PSW_BITS	@ 0xD0;
static volatile SFR_BITS	 BREAKPCTRL_BITS	@ 0xD5;
static volatile SFR_BITS	 DEBUGCTRL_BITS	@ 0xD6;
static volatile SFR_BITS	 DEBUGSTATUS_BITS	@ 0xD7;
static		SFR_BITS	 WDCON_BITS	@ 0xD8;
static volatile SFR_BITS	 I2CCONFIG_BITS	@ 0xDA;
static volatile SFR_BITS	 I2CIRQSTAT_BITS	@ 0xDD;
static volatile SFR_BITS	 ACC_BITS	@ 0xE0;
static volatile SFR_BITS	 SPICTRL1_BITS	@ 0xE5;
static volatile SFR_BITS	 SPICTRL2_BITS	@ 0xE6;
static		SFR_BITS	 SPISIZECTRL_BITS	@ 0xE7;
static          SFR_BITS	 IEN1_BITS	@ 0xE8;
static volatile SFR_BITS	 SPIIRQSTAT_BITS	@ 0xE9;
static volatile SFR_BITS	 MACCTRL_BITS	@ 0xEB;
static volatile SFR_BITS	 B_BITS		@ 0xF0;
static volatile SFR_BITS	 MACCTRL2_BITS	@ 0xF1;
static		SFR_BITS	 USERFLAGS_BITS	@ 0xF8;
static		SFR_BITS	 MACSHIFTCTRL_BITS	@ 0xFB;


// 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;
// Alternate Functions
static volatile bit	T2IN	@ 0x80;
static volatile bit	T2EX	@ 0x81;
static volatile bit	TX1	@ 0x82;
static volatile bit	RX1	@ 0x83;

//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 0 S0CON
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 	SM20 	@ 0x9D;
static 		bit 	SM10 	@ 0x9E;
static 		bit 	SM00 	@ 0x9F;
// alternate definition in datasheet
static 		bit 	SM2 	@ 0x9D;
static 		bit 	SM1 	@ 0x9E;
static 		bit 	SM0 	@ 0x9F;

//Port 2 P2
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	CS3	@ 0xA0;
static volatile bit	CS2	@ 0xA1;
static volatile bit	CS1	@ 0xA2;
static volatile bit	CS0	@ 0xA3;
static volatile bit	SS	@ 0xA4;
static volatile bit	SCK	@ 0xA5;
static volatile bit	SDO	@ 0xA6;
static volatile bit	SDI	@ 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 	ET2 	@ 0xAD;
static volatile bit 	WDT 	@ 0xAE;
static 		bit 	EA1	@ 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	TX0	@ 0xB0;
static volatile bit	RX0	@ 0xB1;
static volatile bit	T0IN	@ 0xB2;
static volatile bit	CCU0	@ 0xB3;
static volatile bit	CCU1	@ 0xB4;
static volatile bit	T1IN	@ 0xB5;
static volatile bit	SDA	@ 0xB6;
static volatile bit	SCL	@ 0xB7;

//Interrupt Priority 0 IP0
static volatile bit 	IP00 	@ 0xB8;
static volatile bit 	IP01 	@ 0xB9;
static volatile bit 	IP02 	@ 0xBA;
static volatile bit 	IP03 	@ 0xBB;
static volatile bit 	IP04 	@ 0xBC;
static volatile bit 	IP05 	@ 0xBD;
static volatile bit 	WDTS	@ 0xBE;
static volatile bit 	OWDS	@ 0xBF;

//Serial Control 1 S1CON
static volatile bit 	RI1 	@ 0xC0;
static volatile bit 	TI1 	@ 0xC1;
static volatile bit 	RB81	@ 0xC2;
static		bit 	TB81	@ 0xC3;
static		bit 	REN1 	@ 0xC4;
static		bit 	SM21 	@ 0xC5;
static 		bit 	SM 	@ 0xC7;

//Timer 2 Control T2CON
static 		bit	T2I0	@ 0xC8;
static 		bit	T2I1	@ 0xC9;
static 		bit	T2CM	@ 0xCA;
static 		bit	T2R0	@ 0xCB;
static		bit	T2R1	@ 0xCC;
static		bit	T2S	@ 0xCD;
static		bit	T2PSM	@ 0xCE;
static		bit	T2PS	@ 0xCF;

//Program Status Word PSW
static volatile bit	P	@ 0xD0;
static volatile bit	OV	@ 0xD2;
static 		bit	RS	@ 0xD3;
// alternate definition
static 		bit	RS0	@ 0xD3;
static 		bit	RS1	@ 0xD4;
static volatile bit	F0	@ 0xD5;
static volatile bit	AC	@ 0xD6;
static volatile bit	CY	@ 0xD7;

// Power fail control register WDCON
// the bit variable has been naed WDCONB to avoid
// conflict with SFR called WDCON
static volatile bit	WDCONB	@ 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 	EADC	@ 0xE8;
static 		bit 	EX2	@ 0xE9;
static 		bit 	EX3	@ 0xEA;
static 		bit 	EX4	@ 0xEB;
static 		bit 	EX5	@ 0xEC;
static 		bit 	EX6	@ 0xED;
static 		bit 	SWDT	@ 0xEE;
static 		bit 	EXEN2	@ 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;

// definitions for register USERFLAGS
static		bit	FLAG0	@ 0xF8;
static		bit	FLAG1	@ 0xF9;
static		bit	FLAG2	@ 0xFA;
static		bit	FLAG3	@ 0xFB;
static		bit	FLAG4	@ 0xFC;
static		bit	FLAG5	@ 0xFD;
static		bit	FLAG6	@ 0xFE;
static		bit	FLAG7	@ 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	DEBUG	0x43
#define	SPITX	0x4B
#define	SPIRX	0x53
#define	I2C	0x5B
#define	MAC	0x63
#define	A2D	0x6B
#define	S1	0x83

#endif
