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

/*
 * 	Header file for the Microchip
 * 	PIC 16C432 chip
 * 	PIC 16C433 chip
 * 	Midrange Microcontrollers
 */

static volatile	unsigned char	TMR0	@ 0x01;
static volatile	unsigned char 	PCL	@ 0x02;
static volatile unsigned char	STATUS	@ 0x03;
static 		unsigned char	FSR	@ 0x04;
#if	defined(_16C432)
static volatile unsigned char	PORTA	@ 0x05;
static volatile	unsigned char	PORTB	@ 0x06;
#endif
#if 	defined(_16C433)
static volatile	unsigned char	GPIO	@ 0x05;
#endif
static 		unsigned char	PCLATH	@ 0x0A;
static volatile	unsigned char	INTCON	@ 0x0B;
static volatile	unsigned char	PIR1	@ 0x0C;
#if	defined(_16C433)
static volatile	unsigned char	ADRES	@ 0x1E;
static volatile	unsigned char	ADCON0	@ 0x1F;
#endif
#if	defined(_16C432)
static volatile	unsigned char	CMCON	@ 0x1F;
#endif

static 		unsigned char bank1	OPTION	@ 0x81;
#if 	defined(_16C432)
static		unsigned char bank1	TRISA	@ 0x85;
static 		unsigned char bank1	TRISB	@ 0x86;
#endif
#if	defined(_16C433)
static		unsigned char bank1	TRIS	@ 0x85;
#endif
static volatile unsigned char bank1	PIE1	@ 0x8C;
static volatile	unsigned char bank1	PCON	@ 0x8E;
#if	defined(_16C433)
static 		unsigned char bank1 	OSCCAL	@ 0x8F;
static volatile	unsigned char bank1	ADCON1	@ 0x9F;
#endif
#if	defined(_16C432)
static volatile unsigned char bank1	LININTF	@ 0x90;
static volatile unsigned char bank1	VRCON	@ 0x9F;
#endif


/*	TMR0 bits	*/
static 		bit	TMR07	@ (unsigned)&TMR0*8+7;
static 		bit	TMR06	@ (unsigned)&TMR0*8+6;
static 		bit	TMR05	@ (unsigned)&TMR0*8+5;
static 		bit	TMR04	@ (unsigned)&TMR0*8+4;
static 		bit	TMR03	@ (unsigned)&TMR0*8+3;
static 		bit	TMR02	@ (unsigned)&TMR0*8+2;
static 		bit	TMR01	@ (unsigned)&TMR0*8+1;
static 		bit	TMR00	@ (unsigned)&TMR0*8+0;

/* 	PCL bits	*/
static 		bit	PCL7	@ (unsigned)&PCL*8+7;
static 		bit	PCL6	@ (unsigned)&PCL*8+6;
static 		bit	PCL5	@ (unsigned)&PCL*8+5;
static 		bit	PCL4	@ (unsigned)&PCL*8+4;
static 		bit	PCL3	@ (unsigned)&PCL*8+3;
static 		bit	PCL2	@ (unsigned)&PCL*8+2;
static 		bit	PCL1	@ (unsigned)&PCL*8+1;
static 		bit	PCL0	@ (unsigned)&PCL*8+0;

/*	STATUS bits	*/
static volatile bit	IRP	@ (unsigned)&STATUS*8+7;
static volatile bit	RP1	@ (unsigned)&STATUS*8+6;
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;

#if	defined(_16C432)
/*	PORTA bits	*/
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;

/*	PORTB bits	*/
static volatile bit	RB7	@ (unsigned)&PORTB*8+7;
static volatile bit	RB6	@ (unsigned)&PORTB*8+6;
static volatile bit	RB5	@ (unsigned)&PORTB*8+5;
static volatile bit	RB4	@ (unsigned)&PORTB*8+4;
static volatile bit	RB3	@ (unsigned)&PORTB*8+3;
static volatile bit	RB2	@ (unsigned)&PORTB*8+2;
static volatile bit	RB1	@ (unsigned)&PORTB*8+1;
static volatile bit	RB0	@ (unsigned)&PORTB*8+0;
#endif

#if	defined(_16C433)
/*	GPIO bits	*/
static volatile bit	LINTX	@ (unsigned)&GPIO*8+7;
static volatile bit	LINRX	@ (unsigned)&GPIO*8+6;
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;
#endif

/*	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	RBIE	@ (unsigned)&INTCON*8+3;
static volatile bit	T0IF	@ (unsigned)&INTCON*8+2;
static volatile bit	INTF	@ (unsigned)&INTCON*8+1;
static volatile bit	RBIF	@ (unsigned)&INTCON*8+0;

/*	PIR1 bits	*/
#if 	defined(_16C432)
static volatile bit	CMIF	@ (unsigned)&PIR1*8+6;
#endif
#if	defined(_16C433)
static volatile bit	ADIF	@ (unsigned)&PIR1*8+6;
#endif

#if	defined(_16C433)
/*	ADRES bits	*/
static volatile bit	ADRES7	@ (unsigned)&ADRES*8+7;
static volatile bit	ADRES6	@ (unsigned)&ADRES*8+6;
static volatile bit	ADRES5	@ (unsigned)&ADRES*8+5;
static volatile bit	ADRES4	@ (unsigned)&ADRES*8+4;
static volatile bit	ADRES3	@ (unsigned)&ADRES*8+3;
static volatile bit	ADRES2	@ (unsigned)&ADRES*8+2;
static volatile bit	ADRES1	@ (unsigned)&ADRES*8+1;
static volatile bit	ADRES0	@ (unsigned)&ADRES*8+0;

/*	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	GO_DONE	@ (unsigned)&ADCON0*8+2;
static volatile bit	ADON	@ (unsigned)&ADCON0*8+0;
#endif

/*	CMCON bits	*/
#if	defined(_16C432)
static volatile bit	C2OUT	@ (unsigned)&CMCON*8+7;
static volatile bit 	C1OUT	@ (unsigned)&CMCON*8+6;
static volatile bit	CIS	@ (unsigned)&CMCON*8+3;
static volatile bit	CM2	@ (unsigned)&CMCON*8+2;
static volatile bit	CM1	@ (unsigned)&CMCON*8+1;
static volatile bit	CM0	@ (unsigned)&CMCON*8+0;
#endif

/*	OPTION bits	*/
#if	defined(_16C432)
static volatile bit bank1	RBPU	@ (unsigned)&OPTION*8+7;
#endif
#if	defined(_16C433)
static volatile bit bank1	GPPU	@ (unsigned)&OPTION*8+7;
#endif
static volatile bit bank1	INTEDG	@ (unsigned)&OPTION*8+6;
static volatile bit bank1	T0CS	@ (unsigned)&OPTION*8+5;
static volatile bit bank1	T0SE	@ (unsigned)&OPTION*8+4;
static volatile bit bank1	PSA	@ (unsigned)&OPTION*8+3;
static volatile bit bank1	PS2	@ (unsigned)&OPTION*8+2;
static volatile bit bank1	PS1	@ (unsigned)&OPTION*8+1;
static volatile bit bank1	PS0	@ (unsigned)&OPTION*8+0;

#if	defined(_16C432)
/*	TRISA	bits	*/
static volatile bit bank1	TRISA4	@ (unsigned)&TRISA*8+4;
static volatile bit bank1	TRISA3	@ (unsigned)&TRISA*8+3;
static volatile bit bank1	TRISA2	@ (unsigned)&TRISA*8+2;
static volatile bit bank1	TLINRX	@ (unsigned)&TRISA*8+1;
static volatile bit bank1	TRISA0	@ (unsigned)&TRISA*8+0;

/*	TRISB bits 	*/
static volatile bit bank1	TRISB7	@ (unsigned)&TRISB*8+4;
static volatile bit bank1	TRISB6	@ (unsigned)&TRISB*8+4;
static volatile bit bank1	TRISB5	@ (unsigned)&TRISB*8+4;
static volatile bit bank1	TRISB4	@ (unsigned)&TRISB*8+4;
static volatile bit bank1	TRISB3	@ (unsigned)&TRISB*8+4;
static volatile bit bank1	TRISB2	@ (unsigned)&TRISB*8+4;
static volatile bit bank1	TRISB1	@ (unsigned)&TRISB*8+4;
static volatile bit bank1	TRISB0	@ (unsigned)&TRISB*8+4;
#endif

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

/*	PIE1 bits	*/
#if	defined(_16C432)
static volatile bit bank1	CMIE	@ (unsigned)&PIE1*8+6;
#endif
#if	defined(_16C433)
static volatile bit bank1	ADIE	@ (unsigned)&PIE1*8+6;
#endif
	
/*	PCON bits	*/
static volatile bit bank1	POR	@ (unsigned)&PCON*8+1;
#if	defined(_16C432)
static volatile bit bank1	BOD	@ (unsigned)&PCON*8+0;
#endif

#if	defined(_16C432)
/*	LININTF bits	*/
static volatile bit bank1	LINTX	@ (unsigned)&LININTF*8+1;
static volatile bit bank1	LINV 	@ (unsigned)&LININTF*8+0;

/*	VRCON bits	*/
static volatile bit bank1	VREN	@ (unsigned)&VRCON*8+7;
static volatile bit bank1	VROE	@ (unsigned)&VRCON*8+6;
static volatile bit bank1	VRR	@ (unsigned)&VRCON*8+5;
static volatile bit bank1	VR3	@ (unsigned)&VRCON*8+3;
static volatile bit bank1	VR2	@ (unsigned)&VRCON*8+2;
static volatile bit bank1	VR1	@ (unsigned)&VRCON*8+1;
static volatile bit bank1	VR0	@ (unsigned)&VRCON*8+0;
#endif

#if 	defined(_16C433)
/*	OSCCAL bits	*/
static 		bit bank1	CAL3	@ (unsigned)&OSCCAL*8+7;
static 		bit bank1	CAL2	@ (unsigned)&OSCCAL*8+6;
static 		bit bank1	CAL1	@ (unsigned)&OSCCAL*8+5;
static 		bit bank1	CAL0	@ (unsigned)&OSCCAL*8+4;
static 		bit bank1	CALFST	@ (unsigned)&OSCCAL*8+3;
static 		bit bank1	CALSLW	@ (unsigned)&OSCCAL*8+2;

/*	ADCON1 bits	*/
static volatile bit bank1	PCFG2	@ (unsigned)&ADCON1*8+2;
static volatile bit bank1	PCFG1	@ (unsigned)&ADCON1*8+1;
static volatile bit bank1	PCFG0	@ (unsigned)&ADCON1*8+0;
#endif

#define CONFIG_ADDR	0x2007

#define PWRTDIS		0x3FFF	// disable power up timer

#define WDTEN		0x3FFF	// enable watchdog timer

#if	defined(_16C432)
#define BOREN		0x3FFF	// enable brown out reset
#define BORDIS		0x3FBF	// disable brown out reset
#define	PWRTEN	 	0x3FF7	// enable power up timer
#define WDTDIS		0x3FFB	// disable watchdog timer
#endif

#if 	defined(_16C433)
#define	MCLREN		0x3F7F	// enable master clear
#define	MCLRDIS		0x3FFF	// disable master clear
#define PWRTEN		0x3FEF	// enable power up timer
#define WDTDIS		0x3FF7	// disable watchdog timer
#endif

/*osc configurations*/
#if	defined(_16C433)
#define EXTRC		0x3FFF	// external resistor/capacitor, clock out on OSC2
#define EXTRCIO		0x3FFE	// external resistor/capacitor, OSC2 is I/O
#define INTRC		0x3FFD	// internal 4Mhz oscillator, clock out on OSC2
#define INTRCIO		0x3FFC	// internal 4Mhz oscillator, OSC2 is I/O
#define HS		0x3FFA	// high speed crystal/resonator
#define XT		0x3FF9	// crystal/resonator
#define LP		0x3FF8	// low power crystal/resonator
#endif
#if	defined(_16C432)
#define RC		0x3FFF	// external resistor/capacitor
#define HS		0x3FFE	// high speed crystal/resonator
#define XT		0x3FFD	// crystal/resonator
#define LP		0x3FFC	// low power crystal/resonator
#endif

/*code protection*/
#define UNPROTECT	0x3FFF	/* do not protect the code */
#if	defined(_16C432)
#define PROTECT50	0x2AEF;	// protect 50% of code
#define PROTECT75	0x15DF;	// protect 75% of code
#define	PROTECT		0x00CF;	// protect all code
#endif
#if	defined(_16C433)
#define PROTECT50	0x2ADF;	// protect 50% of code
#define PROTECT75	0x15BF;	// protect 75% of code
#define	PROTECT		0x009F;	// protect all code
#endif


