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

/*
 *	Header file for the Microchip 
 *	PIC 12C671 chip
 *	PIC 12C672 chip
 *	PIC 12CE673 chip
 *	PIC 12CE674 chip
 *	Midrange Microcontrollers
 */

static volatile unsigned char	RTCC	@ 0x01;
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	GPIO	@ 0x05;
static 		unsigned char	PCLATH	@ 0x0A;
static volatile unsigned char	INTCON	@ 0x0B;
static volatile unsigned char	PIR1	@ 0x0C;
static volatile unsigned char	ADRES	@ 0x1E;
static volatile unsigned char	ADCON0	@ 0x1F;

static 		unsigned char bank1	OPTION	@ 0x81;
static volatile	unsigned char bank1	TRIS	@ 0x85;
static volatile unsigned char bank1	PIE1	@ 0x8C;
static volatile unsigned char bank1	PCON	@ 0x8E;
static volatile unsigned char bank1	OSCCAL	@ 0x8F;
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;

/*	GPIO bits	*/
#if defined(_12CE673) || defined(_12CE674)
static volatile bit	SCL	@ (unsigned)&GPIO*8+7;
static volatile bit	SDA	@ (unsigned)&GPIO*8+6;
#endif
static volatile bit	GP5	@ (unsigned)&GPIO*8+5;
static volatile bit	GP4	@ (unsigned)&GPIO*8+4;
static volatile bit	GP3	@ (unsigned)&GPIO*8+3;
static volatile bit	GP2	@ (unsigned)&GPIO*8+2;
static volatile bit	GP1	@ (unsigned)&GPIO*8+1;
static volatile bit	GP0	@ (unsigned)&GPIO*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	INTE	@ (unsigned)&INTCON*8+4;
static volatile bit	GPIE	@ (unsigned)&INTCON*8+3;
static volatile bit	T0IF	@ (unsigned)&INTCON*8+2;
static volatile bit	INTF	@ (unsigned)&INTCON*8+1;
static volatile bit	GPIF	@ (unsigned)&INTCON*8+0;

/*	PIR1 bits */
static volatile bit	ADIF	@ (unsigned)&PIR1*8+6;

/*	ADCON0 bits	*/
static volatile	bit	ADCS1	@ (unsigned)&ADCON0*8+7;
static volatile	bit	ADCS0	@ (unsigned)&ADCON0*8+6;
static volatile	bit	CHS1	@ (unsigned)&ADCON0*8+4;
static volatile	bit	CHS0	@ (unsigned)&ADCON0*8+3;
static volatile bit	GODONE	@ (unsigned)&ADCON0*8+2;
static volatile	bit	ADON	@ (unsigned)&ADCON0*8+0;

/*	OPTION bits	*/
static bank1 bit	GPPU	@ (unsigned)&OPTION*8+7;
static bank1 bit	INTEDG	@ (unsigned)&OPTION*8+6;
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;

/*      TRIS bits      */
static volatile bank1 bit        TRIS5  @ (unsigned)&TRIS*8+5;
static volatile bank1 bit        TRIS4  @ (unsigned)&TRIS*8+4;
static volatile bank1 bit        TRIS3  @ (unsigned)&TRIS*8+3;
static volatile bank1 bit        TRIS2  @ (unsigned)&TRIS*8+2;
static volatile bank1 bit        TRIS1  @ (unsigned)&TRIS*8+1;
static volatile bank1 bit        TRIS0  @ (unsigned)&TRIS*8+0;

/*	PIE1 bits	*/
static volatile bank1 bit	ADIE	@ (unsigned)&PIE1*8+6;

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

/*	OSCCAL bits */
#if defined(_12C671) || defined(_12C672)
static volatile bank1 bit	CAL3	@ (unsigned)&OSCCAL*8+7;
static volatile bank1 bit	CAL2	@ (unsigned)&OSCCAL*8+6;
static volatile bank1 bit	CAL1	@ (unsigned)&OSCCAL*8+5;
static volatile bank1 bit	CAL0	@ (unsigned)&OSCCAL*8+4;
static volatile bank1 bit	CALFST	@ (unsigned)&OSCCAL*8+3;
static volatile bank1 bit	CALSLW	@ (unsigned)&OSCCAL*8+2;
#elif defined(_12CE673) || defined(_12CE674)
static volatile bank1 bit	CAL5	@ (unsigned)&OSCCAL*8+7;
static volatile bank1 bit	CAL4	@ (unsigned)&OSCCAL*8+6;
static volatile bank1 bit	CAL3	@ (unsigned)&OSCCAL*8+5;
static volatile bank1 bit	CAL2	@ (unsigned)&OSCCAL*8+4;
static volatile bank1 bit	CAL1	@ (unsigned)&OSCCAL*8+3;
static volatile bank1 bit	CAL0	@ (unsigned)&OSCCAL*8+2;
#endif

/*	ADCON1 bits */
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;

/*	Calibration constant in ROM */

#if defined(_12C671) || defined(_12CE673)
#define	_READ_OSCCAL_DATA()	(*(unsigned char(*)())0x3FF)()
#endif

#if defined(_12C672) || defined(_12CE674)
#define	_READ_OSCCAL_DATA()	(*(unsigned char(*)())0x7FF)()
#endif

#define CONFIG_ADDR	0x2007

/*osc configurations*/
#define EXTRC		0x3FFF	// external resistor/capacitor with clockout on OSC2
#define EXTRCIO		0x3FFE	// external resistor/capacitor with OSC2 as I/O
#define INTRC		0x3FFD	// internal 4MHz oscillator, clockout on OSC2 
#define INTRCIO		0x3FFC	// internal 4MHz oscillator, OSC2 as I/O
#define HS		0x3FFA	// high speed crystal/resonator
#define XT		0x3FF9	// crystal resonator
#define LP		0x3FF8	// low power crystal

/*watchdog*/
#define WDTEN		0x3FFF	// enable watchdog timer
#define WDTDIS		0x3FF7	// disable watchdog timer

/*code protection*/
#define PROTECT		0x009F	// protect all code blocks
#define PROTECT75	0x15BF	// protect 200h - 7FEh
#if !defined(_12C671) && !defined(_12CE673)
#define PROTECT50	0x2ADF	// protect 400h - 7FEh
#endif
#define UNPROTECT	0x3FFF	// no code protection

/*MCLRE*/
#define MCLRN		0x3FFF	// use alternative definition
//alternatively
#define MCLREN		0x3FFF	// enable master clear
#define MCLRDIS		0x3F7F	// disable master clear

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