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

/*
   Header file for the Atmel microcontrollers
   AT83C5111
   AT87C5111
   T80C5111
   T83C5111
   T87C5111
   AT80C5112
   AT83C5112
   AT87C5112
   T80C5112
   T83C5112
   T87C5112
 */

#ifndef	__T8XC511X_H

#define	__T8XC511X_H
	
#if defined (_T80C5112) ||	defined (_T83C5112)	|| defined (_T87C5112) 
#define _T8XC5112
#endif

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
#if defined(_T8XC5112)
static volatile	unsigned char	P0	@ 0x80;
#endif
static volatile	unsigned char	SP	@ 0x81;
static volatile	unsigned char	DPL	@ 0x82;
static volatile	unsigned char	DPH	@ 0x83;
// 16 bit definition
static		unsigned char	CKSEL	@ 0x85;
static		unsigned char	OSCCON	@ 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;
#if defined(_T8XC5112)
static 		unsigned char	AUXR	@ 0x8E;
#endif
static		unsigned char	CKCON0	@ 0x8F;
static volatile	unsigned char	P1	@ 0x90;
static		unsigned char	CKRL	@ 0x97;
static volatile	unsigned char	SCON	@ 0x98;
static volatile	unsigned char	SBUF	@ 0x99;
static		unsigned char	BRL	@ 0x9A;
static volatile	unsigned char	BDRCON	@ 0x9B;
#if defined(_T8XC5112)
static volatile	unsigned char	P2	@ 0xA0;
#endif
static		unsigned char	AUXR1	@ 0xA2;
static 		unsigned char	WDTRST	@ 0xA6;
static volatile	unsigned char	WDTPRG	@ 0xA7;
static 		unsigned char	IE0	@ 0xA8;
static 		unsigned char	SADDR	@ 0xA9;
static 		unsigned char	CKCON1	@ 0xAF;
static volatile	unsigned char	P3	@ 0xB0;
static 		unsigned char	IE1	@ 0xB1;
static 		unsigned char	IPL1	@ 0xB2;
static 		unsigned char	IPH1	@ 0xB3;
static 		unsigned char	IPH0	@ 0xB7;
static 		unsigned char	IPL0 	@ 0xB8;
static 		unsigned char	SADEN	@ 0xB9;
static volatile	unsigned char	P4	@ 0xC0;
static 		unsigned char	SPCON	@ 0xC3;
static volatile	unsigned char	SPSTA	@ 0xC4;
static volatile	unsigned char	SPDAT	@ 0xC5;
static volatile	unsigned char	PSW	@ 0xD0;
static		unsigned char	P1M1	@ 0xD4;
static		unsigned char	P3M1	@ 0xD5;
static		unsigned char	P4M1	@ 0xD6;
static volatile	unsigned char	CCON	@ 0xD8;
static		unsigned char	CMOD	@ 0xD9;
static		unsigned char	CCAPM0	@ 0xDA;
static		unsigned char	CCAPM1	@ 0xDB;
static		unsigned char	CCAPM2	@ 0xDC;
static		unsigned char	CCAPM3	@ 0xDD;
static		unsigned char	CCAPM4	@ 0xDE;
static volatile	unsigned char	ACC	@ 0xE0;
static		unsigned char	P1M2	@ 0xE2;
static		unsigned char	P3M2	@ 0xE4;
static		unsigned char	P4M2	@ 0xE5;
static volatile	unsigned char	CL	@ 0xE9;
static volatile	unsigned char	CCAP0L	@ 0xEA;
static volatile	unsigned char	CCAP1L	@ 0xEB;
static volatile	unsigned char	CCAP2L	@ 0xEC;
static volatile	unsigned char	CCAP3L	@ 0xED;
static volatile	unsigned char	CCAP4L	@ 0xEE;
static volatile	unsigned char	CONF	@ 0xEF;
static volatile	unsigned char	B	@ 0xF0;
static		unsigned char	ADCLK	@ 0xF2;
static volatile	unsigned char	ADCON	@ 0xF3;
static volatile	unsigned char	ADDL	@ 0xF4;
static volatile	unsigned char	ADDH	@ 0xF5;
static		unsigned char	ADCF	@ 0xF6;
static volatile	unsigned char	CH	@ 0xF9;
static volatile	unsigned char	CCAP0H	@ 0xFA;
static volatile	unsigned char	CCAP1H	@ 0xFB;
static volatile	unsigned char	CCAP2H	@ 0xFC;
static volatile	unsigned char	CCAP3H	@ 0xFD;
static volatile	unsigned char	CCAP4H	@ 0xFE;

#if defined(_T8XC5112)
static volatile	SFR_BITS	P0_BITS		@ 0x80;
#endif
static		SFR_BITS	CKSEL_BITS	@ 0x85;
static		SFR_BITS	OSCCON_BITS	@ 0x86;
static volatile	SFR_BITS	PCON_BITS	@ 0x87;
static volatile	SFR_BITS	TCON_BITS	@ 0x88;
static 		SFR_BITS	TMOD_BITS	@ 0x89;
#if defined(_T8XC5112)
static 		SFR_BITS	AUXR_BITS	@ 0x8E;
#endif
static		SFR_BITS	CKCON0_BITS	@ 0x8F;
static volatile	SFR_BITS	P1_BITS		@ 0x90;
static		SFR_BITS	CKRL_BITS	@ 0x97;
static volatile	SFR_BITS	SCON_BITS	@ 0x98;
static		SFR_BITS	BRL_BITS	@ 0x9A;
static volatile	SFR_BITS	BDRCON_BITS	@ 0x9B;
#if defined(_T8XC5112)
static volatile	SFR_BITS	P2_BITS		@ 0xA0;
#endif
static		SFR_BITS	AUXR1_BITS	@ 0xA2;
static volatile	SFR_BITS	WDTPRG_BITS	@ 0xA7;
static 		SFR_BITS	IE0_BITS	@ 0xA8;
static 		SFR_BITS	CKCON1_BITS	@ 0xAF;
static volatile	SFR_BITS	P3_BITS		@ 0xB0;
static 		SFR_BITS	IE1_BITS	@ 0xB1;
static 		SFR_BITS	IPL1_BITS	@ 0xB2;
static 		SFR_BITS	IPH1_BITS	@ 0xB3;
static 		SFR_BITS	IPH0_BITS	@ 0xB7;
static 		SFR_BITS	IPL0_BITS	@ 0xB8;
static 		SFR_BITS	SADEN_BITS	@ 0xB9;
static volatile	SFR_BITS	P4_BITS		@ 0xC0;
static 		SFR_BITS	SPCON_BITS	@ 0xC3;
static volatile	SFR_BITS	SPSTA_BITS	@ 0xC4;
static volatile	SFR_BITS	PSW_BITS	@ 0xD0;
static		SFR_BITS	P1M1_BITS	@ 0xD4;
static		SFR_BITS	P3M1_BITS	@ 0xD5;
static		SFR_BITS	P4M1_BITS	@ 0xD6;
static volatile	SFR_BITS	CCON_BITS	@ 0xD8;
static		SFR_BITS	CMOD_BITS	@ 0xD9;
static volatile	SFR_BITS	ACC_BITS	@ 0xE0;
static		SFR_BITS	P1M2_BITS	@ 0xE2;
static		SFR_BITS	P3M2_BITS	@ 0xE4;
static		SFR_BITS	P4M2_BITS	@ 0xE5;
static volatile	SFR_BITS	CONF_BITS	@ 0xEF;
static volatile	SFR_BITS	B_BITS		@ 0xF0;
static		SFR_BITS	ADCLK_BITS	@ 0xF2;
static volatile	SFR_BITS	ADCON_BITS	@ 0xF3;
static		SFR_BITS	ADCF_BITS	@ 0xF6;

//bit addressable locations
#if defined(_T8XC5112)
//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;
#endif

//Timer control TCON
static 		bit	IT0	@ 0x88;
static volatile bit	IEX0	@ 0x89;
static 		bit	IT1	@ 0x8A;
static volatile bit	IEX1	@ 0x8B;
static 		bit	TR0	@ 0x8C;
static volatile bit	TF0	@ 0x8D;
static 		bit	TR1	@ 0x8E;
static volatile bit	TF1	@ 0x8F;

//Port 1
#if defined(_T8XC5112)
static volatile bit P10		@ 0x90;
static volatile bit P11		@ 0x91;
//alternate definitions
static volatile bit WR		@ 0x90;
static volatile bit RD		@ 0x91;
#endif
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 ECI		@ 0x92;
static volatile bit CEX0	@ 0x93;
static volatile bit CEX1	@ 0x94;
static volatile bit CEX2	@ 0x95;
static volatile bit CEX3	@ 0x96;
static volatile bit CEX4	@ 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;
// Alternate Function
static volatile	bit FE 		@ 0x9F;

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

//Interrupt Enable 0 IE0
static bit EX0	 		@ 0xA8;
static bit ET0	 		@ 0xA9;
static bit EX1 			@ 0xAA;
static bit ET1 			@ 0xAB;
static bit ES	 		@ 0xAC;
static bit EC			@ 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 RXD		@ 0xB0;
static volatile bit TXD		@ 0xB1;
static volatile bit INT0	@ 0xB2;
static volatile bit T0		@ 0xB3;
#if defined(_T80C5111) || defined(_T83C5111) || defined(_T87C5111)
static volatile bit XTAL1	@ 0xB4;
static volatile bit XTAL2	@ 0xB5;
static volatile bit RST		@ 0xB6;
#endif

//Interrupt Priority IPL0
static 		bit PX0L 	@ 0xB8;
static 		bit PT0L	@ 0xB9;
static 		bit PX1L	@ 0xBA;
static 		bit PT1L	@ 0xBB;
static 		bit PSL		@ 0xBC;
static 		bit PPCL	@ 0xBE;
// alternate definition
static 		bit PX0 	@ 0xB8;
static 		bit PT0		@ 0xB9;
static 		bit PX1		@ 0xBA;
static 		bit PT1		@ 0xBB;
static 		bit PS		@ 0xBC;
static 		bit PPC		@ 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 T1		@ 0xC1;
static volatile bit SS		@ 0xC2;
static volatile bit INT1	@ 0xC3;
static volatile bit MISO	@ 0xC4;
static volatile bit MOSI	@ 0xC5;
static volatile bit SPSCK	@ 0xC6;
static volatile bit AIN0	@ 0xC0;
static volatile bit AIN1	@ 0xC1;
static volatile bit AIN2	@ 0xC2;
static volatile bit AIN3	@ 0xC3;
static volatile bit AIN4	@ 0xC4;
static volatile bit AIN5	@ 0xC5;
static volatile bit AIN6	@ 0xC6;
static volatile bit AIN7	@ 0xC7;

//Program Status Word PSW
static volatile bit P		@ 0xD0;
static volatile bit UD	 	@ 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;

//Counter Control CCON
static volatile bit CCF0 	@ 0xD8;
static volatile bit CCF1 	@ 0xD9;
static volatile bit CCF2 	@ 0xDA;
static volatile bit CCF3 	@ 0xDB;
static volatile bit CCF4 	@ 0xDC;
static		bit CR	 	@ 0xDE;
static volatile bit CF		@ 0xDF;

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

//B Register
static bit B0		@ 0xF0;
static bit B1		@ 0xF1;
static bit B2		@ 0xF2;
static bit B3		@ 0xF3;
static bit B4		@ 0xF4;
static bit B5		@ 0xF5;
static bit B6		@ 0xF6;
static bit B7		@ 0xF7;

/*	Interrupt vectors */
#define	RESET	0
#define EXTINT0	0x03
#define TIMER0 	0x0B
#define EXTINT1	0x13
#define TIMER1 	0x1B
#define SERIAL 	0x23
#define PCA 	0x33
#define ADC 	0x43
#define SPI 	0x4B

#endif	
