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


 /* header file for the Gencore microcontrollers
	GC87C520G0
	GC81C520G0
	GC80C520G0
	GC87C520A0
	GC81C520A0
	GC80C520A0
	GC87C510A0
	GC87C510A1
	GC81C510A0
	GC81C510A1
	GC89C591A0
	GC89C591G0
	GC81C591A0
	GC81C591G0
 */

#ifndef	__MIDAS_H

#define	__MIDAS_H

#if 	defined(_GC87C520A0) || defined(_GC81C520A0) || defined(_GC80C520A0) || \
	defined(_GC87C510A0) || defined(_GC87C510A1) || defined(_GC81C510A0) || \
	defined(_GC81C510A1) || defined(_GC89C591A0) || defined(_GC81C591A0)
#define __ADC_VERSION
#endif

#if	defined(_GC87C520G0) || defined(_GC81C520G0) || defined(_GC80C520G0) || \
	defined(_GC87C520A0) || defined(_GC81C520A0) || defined(_GC80C520A0) || \
	defined(_GC89C591A0) || defined(_GC89C591G0) || defined(_GC81C591A0) || \
	defined(_GC81C591G0)
#define __TIMER2_DEVICE
#endif

#if	defined(_GC89C591A0) || defined(_GC89C591G0) || defined(_GC81C591A0) || \
	defined(_GC81C591G0)
#define __2UART_DEVICE
#define __PCA_DEVICE
#endif

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;
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 EXIF	@ 0x91;
#if defined(__PCA_DEVICE)
static volatile unsigned char C0CAP0L	@ 0x92;
static volatile unsigned char C0CAP1L	@ 0x93;
static volatile unsigned char C0CAP2L	@ 0x94;
static volatile unsigned char C0CAP3L	@ 0x95;
static volatile unsigned char C0CAP4L	@ 0x96;
static volatile unsigned char C0CAP5L	@ 0x97;
#endif
static volatile unsigned char SCON	@ 0x98;
static volatile unsigned char SBUF	@ 0x99;
#if defined(__PCA_DEVICE)
static volatile unsigned char C0CAP0H	@ 0x9A;
static volatile unsigned char C0CAP1H	@ 0x9B;
static volatile unsigned char C0CAP2H	@ 0x9C;
static volatile unsigned char C0CAP3H	@ 0x9D;
static volatile unsigned char C0CAP4H	@ 0x9E;
static volatile unsigned char C0CAP5H	@ 0x9F;
#endif
static volatile unsigned char P2	@ 0xA0;
#if defined(__2UART_DEVICE)
static volatile unsigned char SBUF1	@ 0xA1;
#endif
#if defined(__PCA_DEVICE)
static          unsigned char C0CAPM0	@ 0xA2;
static          unsigned char C0CAPM1	@ 0xA3;
static          unsigned char C0CAPM2	@ 0xA4;
static          unsigned char C0CAPM3	@ 0xA5;
static          unsigned char C0CAPM4	@ 0xA6;
static          unsigned char C0CAPM5	@ 0xA7;
#endif
static          unsigned char IE	@ 0xA8;
static          unsigned char SADDR	@ 0xA9;
static          unsigned char SADDR1	@ 0xAA;
static          unsigned char SADEN1	@ 0xAB;
#if defined(__PCA_DEVICE)
static volatile unsigned char C0CON	@ 0xAC;
static          unsigned char C0MOD	@ 0xAD;
static volatile unsigned char C0L	@ 0xAE;
static volatile unsigned char C0H	@ 0xAF;
#endif
static volatile unsigned char P3	@ 0xB0;
#if defined(__2UART_DEVICE)
static volatile unsigned char SCON1	@ 0xB1;
#endif
static volatile unsigned char P5	@ 0xB2;
static volatile unsigned char P6	@ 0xB3;
static volatile unsigned char P7	@ 0xB4;
static volatile unsigned char P8	@ 0xB5;
static volatile unsigned char P9	@ 0xB6;
static          unsigned char IPH	@ 0xB7;
static          unsigned char IP	@ 0xB8;
static          unsigned char SADEN	@ 0xB9;
static          unsigned char P5DIR	@ 0xBA;
static          unsigned char P6DIR	@ 0xBB;
static          unsigned char P7DIR	@ 0xBC;
static          unsigned char P8DIR	@ 0xBD;
static          unsigned char P9DIR	@ 0xBE;
static          unsigned char AUXAD	@ 0xBF;
static volatile unsigned char P4	@ 0xC0;
static          unsigned char P5PUP	@ 0xC2;
static          unsigned char P6PUP	@ 0xC3;
static          unsigned char PMR	@ 0xC4;
static volatile unsigned char STATUS	@ 0xC5;
static volatile unsigned char OSCICN	@ 0xC6;
static          unsigned char IOCFG	@ 0xC7;
#if defined(__TIMER2_DEVICE)
static volatile unsigned char T2CON	@ 0xC8;
static          unsigned char T2MOD	@ 0xC9;
static volatile unsigned char RCAP2L	@ 0xCA;
static volatile unsigned char RCAP2H	@ 0xCB;
static volatile unsigned char TL2	@ 0xCC;
static volatile unsigned char TH2	@ 0xCD;
#endif
#if defined(__PCA_DEVICE)
static volatile unsigned char C1CON	@ 0xCE;
static          unsigned char C1MOD	@ 0xCF;
#endif
static volatile unsigned char PSW	@ 0xD0;
#if defined(__PCA_DEVICE)
static volatile unsigned char C1CAP0L	@ 0xD2;
static volatile unsigned char C1CAP1L	@ 0xD3;
static volatile unsigned char C1CAP2L	@ 0xD4;
static volatile unsigned char C1CAP3L	@ 0xD5;
static volatile unsigned char C1CAP4L	@ 0xD6;
static volatile unsigned char C1CAP5L	@ 0xD7;
#endif
static volatile unsigned char WDCON	@ 0xD8;
static          unsigned char P7PUP	@ 0xD9;
#if defined(__PCA_DEVICE)
static volatile unsigned char C1CAP0H	@ 0xDA;
static volatile unsigned char C1CAP1H	@ 0xDB;
static volatile unsigned char C1CAP2H	@ 0xDC;
static volatile unsigned char C1CAP3H	@ 0xDD;
static volatile unsigned char C1CAP4H	@ 0xDE;
static volatile unsigned char C1CAP5H	@ 0xDF;
#endif
static volatile unsigned char ACC	@ 0xE0;
static          unsigned char P8PUP	@ 0xE1;
#if defined(__PCA_DEVICE)
static          unsigned char C1CAPM0	@ 0xE2;
static          unsigned char C1CAPM1	@ 0xE3;
static          unsigned char C1CAPM2	@ 0xE4;
static          unsigned char C1CAPM3	@ 0xE5;
static          unsigned char C1CAPM4	@ 0xE6;
static          unsigned char C1CAPM5	@ 0xE7;
#endif
static          unsigned char EIE	@ 0xE8;
static          unsigned char P9PUP	@ 0xE9;
#if defined(__PCA_DEVICE)
static volatile unsigned char C1L	@ 0xEA;
static volatile unsigned char C1H	@ 0xEB;
#endif
#if defined(__ADC_VERSION)
static          unsigned char ADCHEN	@ 0xEC;
static          unsigned char ADCSEL	@ 0xED;
static volatile unsigned char ADCR	@ 0xEE;
static volatile unsigned char ADCON	@ 0xEF;
#endif
static volatile unsigned char B		@ 0xF0;
static          unsigned char FAEN	@ 0xF7;
static          unsigned char EIP	@ 0xF8;

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 volatile SFR_BITS	 P1_BITS	@ 0x90;
static volatile SFR_BITS	 EXIF_BITS	@ 0x91;
static volatile SFR_BITS	 SCON_BITS	@ 0x98;
static volatile SFR_BITS	 P2_BITS	@ 0xA0;
#if defined(__PCA_DEVICE)
static          SFR_BITS	 C0CAPM0_BITS	@ 0xA2;
static          SFR_BITS	 C0CAPM1_BITS	@ 0xA3;
static          SFR_BITS	 C0CAPM2_BITS	@ 0xA4;
static          SFR_BITS	 C0CAPM3_BITS	@ 0xA5;
static          SFR_BITS	 C0CAPM4_BITS	@ 0xA6;
static          SFR_BITS	 C0CAPM5_BITS	@ 0xA7;
#endif
static          SFR_BITS	 IE_BITS	@ 0xA8;
static          SFR_BITS	 SADDR_BITS	@ 0xA9;
#if defined(__PCA_DEVICE)
static volatile SFR_BITS	 C0CON_BITS	@ 0xAC;
static          SFR_BITS	 C0MOD_BITS	@ 0xAD;
#endif
static volatile SFR_BITS	 P3_BITS	@ 0xB0;
#if defined(__2UART_DEVICE)
static volatile SFR_BITS	 SCON1_BITS	@ 0xB1;
#endif
static volatile SFR_BITS	 P5_BITS	@ 0xB2;
static volatile SFR_BITS	 P6_BITS	@ 0xB3;
static volatile SFR_BITS	 P7_BITS	@ 0xB4;
static volatile SFR_BITS	 P8_BITS	@ 0xB5;
static volatile SFR_BITS	 P9_BITS	@ 0xB6;
static          SFR_BITS	 IPH_BITS	@ 0xB7;
static          SFR_BITS	 IP_BITS	@ 0xB8;
static          SFR_BITS	 SADEN_BITS	@ 0xB9;
static          SFR_BITS	 P5DIR_BITS	@ 0xBA;
static          SFR_BITS	 P6DIR_BITS	@ 0xBB;
static          SFR_BITS	 P7DIR_BITS	@ 0xBC;
static          SFR_BITS	 P8DIR_BITS	@ 0xBD;
static          SFR_BITS	 P9DIR_BITS	@ 0xBE;
static volatile SFR_BITS	 P4_BITS	@ 0xC0;
static          SFR_BITS	 P5PUP_BITS	@ 0xC2;
static          SFR_BITS	 P6PUP_BITS	@ 0xC3;
static          SFR_BITS	 PMR_BITS	@ 0xC4;
static volatile SFR_BITS	 STATUS_BITS	@ 0xC5;
static volatile SFR_BITS	 OSCICN_BITS	@ 0xC6;
static          SFR_BITS	 IOCFG_BITS	@ 0xC7;
#if defined(__TIMER2_DEVICE)
static volatile SFR_BITS	 T2CON_BITS	@ 0xC8;
static          SFR_BITS	 T2MOD_BITS	@ 0xC9;
#endif
#if defined(__PCA_DEVICE)
static volatile SFR_BITS	 C1CON_BITS	@ 0xCE;
static          SFR_BITS	 C1MOD_BITS	@ 0xCF;
#endif
static volatile SFR_BITS	 PSW_BITS	@ 0xD0;
static volatile SFR_BITS	 WDCON_BITS	@ 0xD8;
static          SFR_BITS	 P7PUP_BITS	@ 0xD9;
static volatile SFR_BITS	 ACC_BITS	@ 0xE0;
static          SFR_BITS	 P8PUP_BITS	@ 0xE1;
#if defined(__PCA_DEVICE)
static          SFR_BITS	 C1CAPM0_BITS	@ 0xE2;
static          SFR_BITS	 C1CAPM1_BITS	@ 0xE3;
static          SFR_BITS	 C1CAPM2_BITS	@ 0xE4;
static          SFR_BITS	 C1CAPM3_BITS	@ 0xE5;
static          SFR_BITS	 C1CAPM4_BITS	@ 0xE6;
static          SFR_BITS	 C1CAPM5_BITS	@ 0xE7;
#endif
static          SFR_BITS	 EIE_BITS	@ 0xE8;
static          SFR_BITS	 P9PUP_BITS	@ 0xE9;
#if defined(__ADC_VERSION)
static          SFR_BITS	 ADCHEN_BITS	@ 0xEC;
static          SFR_BITS	 ADCSEL_BITS	@ 0xED;
static volatile SFR_BITS	 ADCON_BITS	@ 0xEF;
#endif
static volatile SFR_BITS	 B_BITS		@ 0xF0;
static          SFR_BITS	 FAEN_BITS	@ 0xF7;
static          SFR_BITS	 EIP_BITS	@ 0xF8;


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

// 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	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	ES	@ 0xAC;
#if defined(__TIMER2_DEVICE)
static		bit	ET2	@ 0xAD;
#endif
#if defined(__ADC_VERSION)
static		bit	EADC	@ 0xAE;
#endif
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	PS	@ 0xBC;
#if defined(__TIMER2_DEVICE)
static 		bit	PT2	@ 0xBD;
#endif
#if defined(__ADC_VERSION)
static 		bit	PADC	@ 0xBE;
#endif

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

#if defined(__TIMER2_DEVICE)
// 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;
#endif

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

// Watchdog Control WDCON
static volatile bit	RWT	@ 0xD8;
static		bit	EWT	@ 0xD9;
static volatile bit	WTRF	@ 0xDA;
static volatile bit	WDIF	@ 0xDB;
static volatile bit	PFI	@ 0xDC;
static		bit	EPFI	@ 0xDD;
static volatile bit	POR	@ 0xDE;

// 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	EWDT	@ 0xEC;
#if defined(__2UART_DEVICE)
static		bit	ES1	@ 0xED;
#endif
#if defined(__PCA_DEVICE)
static		bit	EPCA0	@ 0xEE;
static		bit	EPCA1	@ 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;

// Extended Interrupt Priority EIP
static		bit	PX2	@ 0xF8;
static		bit	PX3	@ 0xF9;
static		bit	PX4	@ 0xFA;
static		bit	PX5	@ 0xFB;
static		bit	PWDT	@ 0xFC;
#if defined(__2UART_DEVICE)
static		bit	PS1	@ 0xFD;
#endif
#if defined(__PCA_DEVICE)
static		bit	PPCA0	@ 0xFE;
static		bit	PPCA1	@ 0xFF;
#endif


// Interrupt Vectors
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	SERIAL	0x23
#if defined(__TIMER2_DEVICE)
#define	TIMER2	0x2B
#endif
#define	LVD	0x33
#if defined(__ADC_VERSION)
#define	ADC	0x3B
#endif
#define	EXTINT2	0x43
#define	EXTINT3	0x4B
#define	EXTINT4	0x53
#define	EXTINT5	0x5B
#define	WDT	0x63
#if defined(__2UART_DEVICE)
#define	SERIAL1	0x6B
#endif
#if defined(__PCA_DEVICE)
#define	PCA0	0x73
#define	PCA1	0x7B
#endif

#endif
