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

/* 
 *	Header file for the Microchip :
 * 	PIC 14000 chip
 *	Midrange Microcontroller
 */

static volatile unsigned char	TMR0	@ 0x01;
static volatile unsigned char	PCL	@ 0x02;
static volatile unsigned char	STATUS	@ 0x03;
static 		unsigned char	FSR	@ 0x04;
static volatile unsigned char	PORTA	@ 0x05;
static volatile unsigned char	PORTC	@ 0x07;
static volatile unsigned char	PORTD	@ 0x08;
static 		unsigned char	PCLATH	@ 0x0A;
static volatile unsigned char	INTCON	@ 0x0B;
static volatile unsigned char	PIR1	@ 0x0C;
static volatile unsigned char	ADTMRL	@ 0x0E;
static volatile unsigned char	ADTMRH	@ 0x0F;
static volatile unsigned char	I2CBUF	@ 0x13;
static volatile unsigned char	I2CCON	@ 0x14;
static volatile unsigned short	ADCAP	@ 0x15;
static volatile unsigned char	ADCAPL	@ 0x15;
static volatile unsigned char	ADCAPH	@ 0x16;
static volatile unsigned char	ADCON0	@ 0x1F;

static 		unsigned char bank1	OPTION	@ 0x81;
static volatile	unsigned char bank1	TRISA	@ 0x85;
static volatile	unsigned char bank1	TRISC	@ 0x87;
static volatile	unsigned char bank1	TRISD	@ 0x88;
static volatile unsigned char bank1	PIE1	@ 0x8C;
static volatile unsigned char bank1	PCON	@ 0x8E;
static volatile unsigned char bank1	SLPCON	@ 0x8F;
static volatile unsigned char bank1	I2CADD	@ 0x93;
static volatile unsigned char bank1	I2CSTAT	@ 0x94;
static volatile unsigned char bank1	PREFA	@ 0x9B;
static volatile unsigned char bank1	PREFB	@ 0x9C;
static volatile unsigned char bank1	CMCON	@ 0x9D;
static volatile unsigned char bank1	MISC	@ 0x9E;
static volatile unsigned char bank1	ADCON1	@ 0x9F;

/*	STATUS bits	*/
static volatile bit	RP0	@ (unsigned)&STATUS*8+5;
static volatile bit	TO	@ (unsigned)&STATUS*8+4;
static volatile bit	PD	@ (unsigned)&STATUS*8+3;
static volatile bit	ZERO	@ (unsigned)&STATUS*8+2;
static volatile bit	DC	@ (unsigned)&STATUS*8+1;
static volatile bit	CARRY	@ (unsigned)&STATUS*8+0;

/*      PORTA bits      */
static volatile bit      RA7     @ (unsigned)&PORTA*8+7;
static volatile bit      RA6     @ (unsigned)&PORTA*8+6;
static volatile bit      RA5     @ (unsigned)&PORTA*8+5;
static volatile bit      RA4     @ (unsigned)&PORTA*8+4;
static volatile bit      RA3     @ (unsigned)&PORTA*8+3;
static volatile bit      RA2     @ (unsigned)&PORTA*8+2;
static volatile bit      RA1     @ (unsigned)&PORTA*8+1;
static volatile bit      RA0     @ (unsigned)&PORTA*8+0;

/*      PORTC bits      */
static volatile bit      RC7     @ (unsigned)&PORTC*8+7;
static volatile bit      RC6     @ (unsigned)&PORTC*8+6;
static volatile bit      RC5     @ (unsigned)&PORTC*8+5;
static volatile bit      RC4     @ (unsigned)&PORTC*8+4;
static volatile bit      RC3     @ (unsigned)&PORTC*8+3;
static volatile bit      RC2     @ (unsigned)&PORTC*8+2;
static volatile bit      RC1     @ (unsigned)&PORTC*8+1;
static volatile bit      RC0     @ (unsigned)&PORTC*8+0;

/*      PORTD bits      */
static volatile bit      RD7     @ (unsigned)&PORTD*8+7;
static volatile bit      RD6     @ (unsigned)&PORTD*8+6;
static volatile	bit      RD5     @ (unsigned)&PORTD*8+5;
static volatile bit      RD4     @ (unsigned)&PORTD*8+4;
static volatile bit      RD3     @ (unsigned)&PORTD*8+3;
static volatile bit      RD2     @ (unsigned)&PORTD*8+2;
static volatile bit      RD1     @ (unsigned)&PORTD*8+1;
static volatile bit      RD0     @ (unsigned)&PORTD*8+0;

/*	INTCON bits	*/
static volatile	bit	GIE	@ (unsigned)&INTCON*8+7;
static volatile	bit	PEIE	@ (unsigned)&INTCON*8+6;
static volatile bit	T0IE	@ (unsigned)&INTCON*8+5;
static volatile bit	T0IF	@ (unsigned)&INTCON*8+2;

/*	PIR1 bits	*/
static volatile bit	CMIF	@ (unsigned)&PIR1*8+7;
static volatile bit	PBIF	@ (unsigned)&PIR1*8+4;
static volatile bit	I2CIF	@ (unsigned)&PIR1*8+3;
static volatile bit	RCIF	@ (unsigned)&PIR1*8+2;
static volatile bit	ADCIF	@ (unsigned)&PIR1*8+1;
static volatile bit	OVFIF	@ (unsigned)&PIR1*8+0;

/*	I2CCON bits	*/
static volatile bit	WCOL	@ (unsigned)&I2CCON*8+7;
static volatile bit	I2COV	@ (unsigned)&I2CCON*8+6;
static volatile bit	I2CEN	@ (unsigned)&I2CCON*8+5;
static volatile bit	CKP	@ (unsigned)&I2CCON*8+4;
static volatile bit	I2CM3	@ (unsigned)&I2CCON*8+3;
static volatile bit	I2CM2	@ (unsigned)&I2CCON*8+2;
static volatile bit	I2CM1	@ (unsigned)&I2CCON*8+1;
static volatile bit	I2CM0	@ (unsigned)&I2CCON*8+0;

/*	ADCON0 bits	*/
static volatile bit	ADCS3	@ (unsigned)&ADCON0*8+7;
static volatile bit	ADCS2	@ (unsigned)&ADCON0*8+6;
static volatile bit	ADCS1	@ (unsigned)&ADCON0*8+5;
static volatile bit	ADCS0	@ (unsigned)&ADCON0*8+4;
static volatile bit	AMUXOE	@ (unsigned)&ADCON0*8+2;
static volatile bit	ADRST	@ (unsigned)&ADCON0*8+1;
static volatile bit	ADZERO	@ (unsigned)&ADCON0*8+0;

/*	OPTION bits	*/
static bank1 bit	RCPU	@ (unsigned)&OPTION*8+7;
static bank1 bit	T0CS	@ (unsigned)&OPTION*8+5;
static bank1 bit	T0SE	@ (unsigned)&OPTION*8+4;
static bank1 bit	PSA	@ (unsigned)&OPTION*8+3;
static bank1 bit	PS2	@ (unsigned)&OPTION*8+2;
static bank1 bit	PS1	@ (unsigned)&OPTION*8+1;
static bank1 bit	PS0	@ (unsigned)&OPTION*8+0;

/*      TRISA bits      */
static volatile bank1 bit        TRISA7  @ (unsigned)&TRISA*8+7;
static volatile bank1 bit        TRISA6  @ (unsigned)&TRISA*8+6;
static volatile bank1 bit        TRISA5  @ (unsigned)&TRISA*8+5;
static volatile bank1 bit        TRISA4  @ (unsigned)&TRISA*8+4;
static volatile bank1 bit        TRISA3  @ (unsigned)&TRISA*8+3;
static volatile bank1 bit        TRISA2  @ (unsigned)&TRISA*8+2;
static volatile bank1 bit        TRISA1  @ (unsigned)&TRISA*8+1;
static volatile bank1 bit        TRISA0  @ (unsigned)&TRISA*8+0;

/*      TRISC bits      */
static volatile bank1 bit        TRISC7  @ (unsigned)&TRISC*8+7;
static volatile bank1 bit        TRISC6  @ (unsigned)&TRISC*8+6;
static volatile bank1 bit        TRISC5  @ (unsigned)&TRISC*8+5;
static volatile bank1 bit        TRISC4  @ (unsigned)&TRISC*8+4;
static volatile bank1 bit        TRISC3  @ (unsigned)&TRISC*8+3;
static volatile bank1 bit        TRISC2  @ (unsigned)&TRISC*8+2;
static volatile bank1 bit        TRISC1  @ (unsigned)&TRISC*8+1;
static volatile bank1 bit        TRISC0  @ (unsigned)&TRISC*8+0;

/*      TRISD bits      */
static volatile bank1 bit        TRISD7  @ (unsigned)&TRISD*8+7;
static volatile bank1 bit        TRISD6  @ (unsigned)&TRISD*8+6;
static volatile bank1 bit        TRISD5  @ (unsigned)&TRISD*8+5;
static volatile bank1 bit        TRISD4  @ (unsigned)&TRISD*8+4;
static volatile bank1 bit        TRISD3  @ (unsigned)&TRISD*8+3;
static volatile bank1 bit        TRISD2  @ (unsigned)&TRISD*8+2;
static volatile bank1 bit        TRISD1  @ (unsigned)&TRISD*8+1;
static volatile bank1 bit        TRISD0  @ (unsigned)&TRISD*8+0;

/*	PIE1 bits	*/
static volatile bank1 bit	CMIE	@ (unsigned)&PIE1*8+7;
static volatile bank1 bit	PBIE	@ (unsigned)&PIE1*8+4;
static volatile bank1 bit	I2CIE	@ (unsigned)&PIE1*8+3;
static volatile bank1 bit	RCIE	@ (unsigned)&PIE1*8+2;
static volatile bank1 bit	ADCIE	@ (unsigned)&PIE1*8+1;
static volatile bank1 bit	OVFIE	@ (unsigned)&PIE1*8+0;

/*	PCON bits	*/
static volatile	bank1 bit	POR	@ (unsigned)&PCON*8+1;
static volatile bank1 bit	LVD	@ (unsigned)&PCON*8+0;

/*	SLPCON bits	*/
static volatile bank1 bit	HIBEN	@ (unsigned)&SLPCON*8+7;
static volatile bank1 bit	REFOFF	@ (unsigned)&SLPCON*8+5;
static volatile bank1 bit	LSOFF	@ (unsigned)&SLPCON*8+4;
static volatile bank1 bit	OSCOFF	@ (unsigned)&SLPCON*8+3;
static volatile bank1 bit	CMOFF	@ (unsigned)&SLPCON*8+2;
static volatile bank1 bit	TEMPOFF	@ (unsigned)&SLPCON*8+1;
static volatile bank1 bit	ADOFF	@ (unsigned)&SLPCON*8+0;

/*	I2CSTAT bits	*/
static volatile bank1 bit	DA	@ (unsigned)&I2CSTAT*8+5;
static volatile bank1 bit	STOP	@ (unsigned)&I2CSTAT*8+4;
static volatile bank1 bit	START	@ (unsigned)&I2CSTAT*8+3;
static volatile bank1 bit	RW	@ (unsigned)&I2CSTAT*8+2;
static volatile bank1 bit	UA	@ (unsigned)&I2CSTAT*8+1;
static volatile bank1 bit	BF	@ (unsigned)&I2CSTAT*8+0;
#ifdef __STAT_BACKWARD_COMPATIBILITY
#define STAT_DA	DA
#define STAT_P	STOP
#define STAT_S	START
#define STAT_RW	RW
#define STAT_UA	UA
#define STAT_BF	BF
#endif

/*	PREFA bits	*/
static volatile bank1 bit	PRA7	@ (unsigned)&PREFA*8+7;
static volatile bank1 bit	PRA6	@ (unsigned)&PREFA*8+6;
static volatile bank1 bit	PRA5	@ (unsigned)&PREFA*8+5;
static volatile bank1 bit	PRA4	@ (unsigned)&PREFA*8+4;
static volatile bank1 bit	PRA3	@ (unsigned)&PREFA*8+3;
static volatile bank1 bit	PRA2	@ (unsigned)&PREFA*8+2;
static volatile bank1 bit	PRA1	@ (unsigned)&PREFA*8+1;
static volatile bank1 bit	PRA0	@ (unsigned)&PREFA*8+0;

/*	PREFB bits	*/
static volatile bank1 bit	PRB7	@ (unsigned)&PREFB*8+7;
static volatile bank1 bit	PRB6	@ (unsigned)&PREFB*8+6;
static volatile bank1 bit	PRB5	@ (unsigned)&PREFB*8+5;
static volatile bank1 bit	PRB4	@ (unsigned)&PREFB*8+4;
static volatile bank1 bit	PRB3	@ (unsigned)&PREFB*8+3;
static volatile bank1 bit	PRB2	@ (unsigned)&PREFB*8+2;
static volatile bank1 bit	PRB1	@ (unsigned)&PREFB*8+1;
static volatile bank1 bit	PRB0	@ (unsigned)&PREFB*8+0;

/*	CMCON bits	*/
static volatile bank1 bit	CMBOUT	@ (unsigned)&CMCON*8+6;
static volatile bank1 bit	CMBOE	@ (unsigned)&CMCON*8+5;
static volatile bank1 bit	CPOLB	@ (unsigned)&CMCON*8+4;
static volatile bank1 bit	CMAOUT	@ (unsigned)&CMCON*8+2;
static volatile bank1 bit	CMAOE	@ (unsigned)&CMCON*8+1;
static volatile bank1 bit	CPOLA	@ (unsigned)&CMCON*8+0;

/*	MISC bits	*/
static volatile bank1 bit	SMHOG	@ (unsigned)&MISC*8+7;
static volatile bank1 bit	SPGNDB	@ (unsigned)&MISC*8+6;
static volatile bank1 bit	SPGNDA	@ (unsigned)&MISC*8+5;
static volatile bank1 bit	I2CSEL	@ (unsigned)&MISC*8+4;
static volatile bank1 bit	SMBUS	@ (unsigned)&MISC*8+3;
static volatile bank1 bit	INCLKEN	@ (unsigned)&MISC*8+2;
static volatile bank1 bit	OSC2	@ (unsigned)&MISC*8+1;
static volatile bank1 bit	OSC1	@ (unsigned)&MISC*8+0;

/*	ADCON1 bits	*/
static volatile bank1 bit	ADDAC3	@ (unsigned)&ADCON1*8+7;
static volatile bank1 bit	ADDAC2	@ (unsigned)&ADCON1*8+6;
static volatile bank1 bit	ADDAC1	@ (unsigned)&ADCON1*8+5;
static volatile bank1 bit	ADDAC0	@ (unsigned)&ADCON1*8+4;
static volatile bank1 bit	PCFG3	@ (unsigned)&ADCON1*8+3;
static volatile bank1 bit	PCFG2	@ (unsigned)&ADCON1*8+2;
static volatile bank1 bit	PCFG1	@ (unsigned)&ADCON1*8+1;
static volatile bank1 bit	PCFG0	@ (unsigned)&ADCON1*8+0;

#define CONFIG_ADDR	0x2007
/*osc configuration*/
#define INT		0x3FFF	// internal 4MHz oscillator
#define HS		0x3FFE	// high speed crystal/resonator

/*watchdog*/
#define WTDTEN		0x3FFF	//use alternate definition
#define WDTEDIS		0x3FFB	//use alternate definition
// alternate definitions
#define WDTEN		0x3FFF	// enable watchdog timer
#define WDTDIS		0x3FFB	// disable watchdog timer

/*power up timer*/
#define PWRTEN		0x3FFB	// enable power up timer
#define PWRTDIS		0x3FFF	// disable power up timer

/*Calibration Space Code Protection*/
#define CPROTECT	0x3F7F	// protect the calibration space
#define CUNPROTECT	0x3FFF	// do not protect the calibration space

/*code protection*/
#define UNPROTECT	0x3FFF	// do not protect the code
#define PROTECT		0x3FCF	// protect the code

/*      ADC calibration data etc. Access with get_cal_data, e.g.
 *
 *      x = get_cal_data(KREF);
 *
 */

extern double get_cal_data(const unsigned char *);

static const unsigned char      KREF[4]    @ 0xFC0;     /* Slope reference ratio */
static const unsigned char      KBG[4]     @ 0xFC4;     /* Bandgap reference voltage */
static const unsigned char      VTHERM[4]  @ 0xFC8;     /* Temperature sensor voltage */
static const unsigned char      KTC[4]     @ 0xFCC;     /* Temperature sensor coefficient */
static const unsigned char      OSCM       @ 0xFD0;     /* Oscillator freq. multiplier */
static const unsigned char      TWDT       @ 0xFD2;     /* WDT time-out */

