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

/*
 *	Header file for the Microchip 
 *	PIC 16F627 chip
 *	PIC 16F628 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	PORTB	@ 0x06;
static          unsigned char	PCLATH	@ 0x0A;
static volatile unsigned char	INTCON	@ 0x0B;
static volatile unsigned char	PIR1	@ 0x0C;
static volatile unsigned char	TMR1L	@ 0x0E;
static volatile unsigned char	TMR1H	@ 0x0F;
static volatile unsigned char	T1CON	@ 0x10;
static volatile unsigned char	TMR2	@ 0x11;
static volatile unsigned char	T2CON	@ 0x12;
static volatile unsigned char	CCPR1L	@ 0x15;
static volatile unsigned char	CCPR1H	@ 0x16;
static volatile unsigned char	CCP1CON	@ 0x17;
static volatile unsigned char	RCSTA	@ 0x18;
static volatile unsigned char	TXREG	@ 0x19;
static volatile unsigned char	RCREG	@ 0x1A;
static volatile unsigned char	CMCON	@ 0x1F;

/*	bank 1 registers */
static          unsigned char bank1	OPTION	@ 0x81;
static volatile	unsigned char bank1	TRISA	@ 0x85;
static volatile	unsigned char bank1	TRISB	@ 0x86;
static volatile unsigned char bank1	PIE1	@ 0x8C;
static volatile unsigned char bank1	PCON	@ 0x8E;
static volatile unsigned char bank1	PR2	@ 0x92;
static volatile unsigned char bank1	TXSTA	@ 0x98;
static volatile unsigned char bank1	SPBRG	@ 0x99;
static volatile unsigned char bank1	EEDATA	@ 0x9A;
static volatile unsigned char bank1	EEADR	@ 0x9B;
static volatile unsigned char bank1	EECON1	@ 0x9C;
static volatile unsigned char bank1	EECON2	@ 0x9D;
static volatile unsigned char bank1	VRCON	@ 0x9F;

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

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

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

/*	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	*/
static volatile bit	EEIF	@ (unsigned)&PIR1*8+7;
static volatile bit	CMIF	@ (unsigned)&PIR1*8+6;
static volatile bit	RCIF	@ (unsigned)&PIR1*8+5;
static volatile bit	TXIF	@ (unsigned)&PIR1*8+4;
static volatile bit	CCP1IF	@ (unsigned)&PIR1*8+2;
static volatile bit	TMR2IF	@ (unsigned)&PIR1*8+1;
static volatile bit	TMR1IF	@ (unsigned)&PIR1*8+0;

/*	T1CON bits	*/
static volatile bit	T1CKPS1	@ (unsigned)&T1CON*8+5;
static volatile bit	T1CKPS0	@ (unsigned)&T1CON*8+4;
static volatile bit	T1OSCEN	@ (unsigned)&T1CON*8+3;
static volatile bit	T1SYNC 	@ (unsigned)&T1CON*8+2;
static volatile bit	TMR1CS 	@ (unsigned)&T1CON*8+1;
static volatile bit	TMR1ON 	@ (unsigned)&T1CON*8+0;

/*	T2CON bits	*/
static volatile bit	TOUTPS3	@ (unsigned)&T2CON*8+6;
static volatile bit	TOUTPS2	@ (unsigned)&T2CON*8+5;
static volatile bit	TOUTPS1	@ (unsigned)&T2CON*8+4;
static volatile bit	TOUTPS0	@ (unsigned)&T2CON*8+3;
static volatile bit	TMR2ON 	@ (unsigned)&T2CON*8+2;
static volatile bit	T2CKPS1	@ (unsigned)&T2CON*8+1;
static volatile bit	T2CKPS0	@ (unsigned)&T2CON*8+0;

/*	CCP1CON bits	*/
static volatile bit	CCP1X	@ (unsigned)&CCP1CON*8+5;
static volatile bit	CCP1Y	@ (unsigned)&CCP1CON*8+4;
static volatile bit	CCP1M3	@ (unsigned)&CCP1CON*8+3;
static volatile bit	CCP1M2	@ (unsigned)&CCP1CON*8+2;
static volatile bit	CCP1M1	@ (unsigned)&CCP1CON*8+1;
static volatile bit	CCP1M0	@ (unsigned)&CCP1CON*8+0;

/*	RCSTA bits	*/
static volatile bit	SPEN	@ (unsigned)&RCSTA*8+7;
static volatile bit	RX9 	@ (unsigned)&RCSTA*8+6;
static volatile bit	SREN	@ (unsigned)&RCSTA*8+5;
static volatile bit	CREN	@ (unsigned)&RCSTA*8+4;
static volatile bit	ADEN	@ (unsigned)&RCSTA*8+3;
static volatile bit	FERR	@ (unsigned)&RCSTA*8+2;
static volatile bit	OERR	@ (unsigned)&RCSTA*8+1;
static volatile bit	RX9D	@ (unsigned)&RCSTA*8+0;

/*	 CMCON bits	*/
static volatile bit	C2OUT	@ (unsigned)&CMCON*8+7;
static volatile bit	C1OUT 	@ (unsigned)&CMCON*8+6;
static volatile bit	C2INV	@ (unsigned)&CMCON*8+5;
static volatile bit	C1INV	@ (unsigned)&CMCON*8+4;
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;

/* 	OPTION bits	*/
static bank1 bit	RBPU	@ (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;

/*      TRISA bits      */
static volatile bank1 bit	TRISA7	@ (unsigned)&TRISA*8+7;
static volatile bank1 bit	TRISA6	@ (unsigned)&TRISA*8+6;
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;

/*      TRISB bits      */
static volatile bank1 bit	TRISB7	@ (unsigned)&TRISB*8+7;
static volatile bank1 bit	TRISB6	@ (unsigned)&TRISB*8+6;
static volatile bank1 bit	TRISB5	@ (unsigned)&TRISB*8+5;
static volatile bank1 bit	TRISB4	@ (unsigned)&TRISB*8+4;
static volatile bank1 bit	TRISB3	@ (unsigned)&TRISB*8+3;
static volatile bank1 bit	TRISB2	@ (unsigned)&TRISB*8+2;
static volatile bank1 bit	TRISB1	@ (unsigned)&TRISB*8+1;
static volatile bank1 bit	TRISB0	@ (unsigned)&TRISB*8+0;

/*	PIE1 bits	*/
static volatile bank1 bit	EEIE	@ (unsigned)&PIE1*8+7;
static volatile bank1 bit	CMIE	@ (unsigned)&PIE1*8+6;
static volatile bank1 bit	RCIE	@ (unsigned)&PIE1*8+5;
static volatile bank1 bit	TXIE	@ (unsigned)&PIE1*8+4;
static volatile bank1 bit	CCP1IE	@ (unsigned)&PIE1*8+2;
static volatile bank1 bit	TMR2IE	@ (unsigned)&PIE1*8+1;
static volatile bank1 bit	TMR1IE	@ (unsigned)&PIE1*8+0;

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

/*	TXSTA bits	*/
static volatile bank1 bit	CSRC	@ (unsigned)&TXSTA*8+7;
static volatile bank1 bit	TX9	@ (unsigned)&TXSTA*8+6;
static volatile bank1 bit	TXEN	@ (unsigned)&TXSTA*8+5;
static volatile bank1 bit	SYNC	@ (unsigned)&TXSTA*8+4;
static volatile bank1 bit	BRGH	@ (unsigned)&TXSTA*8+2;
static volatile bank1 bit	TRMT	@ (unsigned)&TXSTA*8+1;
static volatile bank1 bit	TX9D	@ (unsigned)&TXSTA*8+0;

/*	EECON1 bits	*/
static volatile bank1 bit	WRERR	@ (unsigned)&EECON1*8+3;
static volatile bank1 bit	WREN	@ (unsigned)&EECON1*8+2;
static volatile bank1 bit	WR	@ (unsigned)&EECON1*8+1;
static volatile bank1 bit	RD	@ (unsigned)&EECON1*8+0;

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

					
#define CONFIG_ADDR	0x2007

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

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

/* MCLR pin function */
#define MCLREN		0x3FFF	// master clear reset enable
#define MCLRDIS		0x3FDF	// master clear reset disable
//alternately
#define MCLRIO		0x3FDF // use MCLRDIS

/*brown out reset*/
#define BOREN		0x3FFF	// enable brown out reset
#define BORDIS		0x3FBF	// disable brown out reset

/*low voltage programming*/
#define LVPEN		0x3FFF	// low voltage programming enable
#define LVPDIS		0x3F7F	// low voltage programming disabled

/*data code protection*/
#define DP		0x3EFF	// protect the data code
// alternative definitions
#define DATPROT		0x3EFF	// use DP
#define DATUNPROT	0x3FFF	// use UNPROTECT

/*code protection*/
#define UNPROTECT	0x3FFF	// do not protect the code
#define PROTECT		0x03FF	// protect the program code
	/* Code protection for 2K program memory	*/
#ifdef _16F628		
#define PROTECT75	0x17FF	/* Protects from 0200h-07ffh	*/
#define PROTECT50	0x2BFF	/* Protects from 0400h-07ffh	*/
#else	/* Code protection for 1K program memory	*/
#define PROTECT50	0x17FF	/* Protects from 0200h-03ffh	*/
#endif 

/*osc configurations*/
#define ER		0x3FFF	/* external resistor, CLKOUT on CLKOUT pin, R on CLKIN */
#define ERIO		0x3FFE	/* external resistor, IO fn on CLKOUT pin, R on CLKIN */
#define INT		0x3FFD	/* internal resistor/capacitor, CLKOUT on CLKOUT pin, IO on CLKIN */
#define INTIO		0x3FFC	/* internal resistor/capacitor, IO fn on CLKOUT pin, IO on CLKIN */
#define EC		0x3FEF	/* external clock in, IO fn on CLKOUT pin, CLKIN on CLKIN */
#define HS		0x3FEE	/* high speed crystal */
#define XT		0x3FED	/* crystal/resonator */
#define LP		0x3FEC	/* low power crystal */
