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

/* This is a header file for the Phillips Microcontrollers
	P83C751
	P87C751

*** Please note that due to duplicate variable names, ***
*** the following changes have been made to I2CON (write mode) ***
*** I2CON.0	XSTP	->	STOP	***
*** I2CON.1	XSTR	->	START	***
*** I2CON.6	IDLE	->	IDL	***

 */

#ifndef __P8XC751_H
#define __P8XC751_H


typedef struct {
	unsigned B7:1; //This is the most signifigant 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
static volatile unsigned char P0	@ 0x80;
static volatile unsigned char SP	@ 0x81;
static volatile unsigned char DPL	@ 0x82;
static volatile unsigned char DPH	@ 0x83;
// 16 bit definition
static volatile unsigned char PCON	@ 0x87;
static volatile unsigned char TCON	@ 0x88;
static volatile unsigned char TL	@ 0x8A;
static		unsigned char RTL	@ 0x8B;
static volatile unsigned char TH	@ 0x8C;
static		unsigned char RTH	@ 0x8D;
static volatile unsigned char P1	@ 0x90;
static volatile unsigned char I2CON	@ 0x98;
static volatile unsigned char I2DAT	@ 0x99;
static		unsigned char IE	@ 0xA8;
static volatile unsigned char P3	@ 0xB0;
static volatile unsigned char PSW	@ 0xD0;
static volatile unsigned char I2CFG	@ 0xD8;
static volatile unsigned char ACC	@ 0xE0;
static volatile unsigned char B		@ 0xF0;
static volatile unsigned char I2STA	@ 0xF8;

static volatile SFR_BITS P0_BITS		@ 0x80;
static volatile SFR_BITS PCON_BITS		@ 0x87;
static volatile SFR_BITS TCON_BITS		@ 0x88;
static volatile SFR_BITS P1_BITS		@ 0x90;
static volatile SFR_BITS I2CON_BITS		@ 0x98;
static		SFR_BITS IE_BITS		@ 0xA8;
static volatile SFR_BITS P3_BITS		@ 0xB0;
static volatile SFR_BITS PSW_BITS		@ 0xD0;
static volatile SFR_BITS I2CFG_BITS		@ 0xD8;
static volatile SFR_BITS ACC_BITS		@ 0xE0;
static volatile SFR_BITS B_BITS			@ 0xF0;
static volatile SFR_BITS I2STA_BITS		@ 0xF8;

//Bit Addressable Locations
//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;
// Alternate definitions
static volatile bit 	SCL	@ 0x80;
static volatile bit 	SDA	@ 0x81;

//Timer Control TCON
static 		bit 	IT1	@ 0x88;
static volatile bit 	IE1	@ 0x89;
static 		bit 	IT0	@ 0x8A;
static volatile bit 	IE0	@ 0x8B;
static 		bit 	TR	@ 0x8C;
static volatile bit 	TF	@ 0x8D;
static 		bit 	CT	@ 0x8E;
static		bit 	GATE	@ 0x8F;

//Port 1 P1
static volatile bit 	P10	@ 0x90;
static volatile bit 	P11	@ 0x91;
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 definitions
static volatile bit 	INT0	@ 0x95;
static volatile bit 	INT1	@ 0x96;
static volatile bit 	T0	@ 0x97;

//I2C Control Register I2CON
//This Register operates in a READ and WRITE mode
//WRITE
static volatile	bit 	STOP	@ 0x98;
static volatile	bit 	START 	@ 0x99;
static volatile	bit 	CSTP 	@ 0x9A;
static volatile	bit 	CSTR 	@ 0x9B;
static volatile	bit 	CARL 	@ 0x9C;
static volatile	bit 	CDR 	@ 0x9D;
static volatile	bit 	IDL 	@ 0x9E;
static volatile	bit 	CXA 	@ 0x9F;
//READ
static volatile	bit 	MASTER 	@ 0x99;
static volatile bit 	STP 	@ 0x9A;
static volatile bit 	STR 	@ 0x9B;
static volatile bit 	ARL 	@ 0x9C;
static volatile bit 	DRDY 	@ 0x9D;
static volatile	bit 	ATN	@ 0x9E;
static volatile	bit 	RDAT 	@ 0x9F;

// Interrupt enable register
static		bit	EX0	@ 0xA8;
static		bit	ET0	@ 0xA9;
static		bit	EX1	@ 0xAA;
static		bit	ET1	@ 0xAB;
static		bit	EI2	@ 0xAC;
static		bit	EA	@ 0xAF;

//Port 3 P3
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;

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

//I2C Configuration Register I2CFG
static 		bit 	CT0	@ 0xD8;
static		bit 	CT1	@ 0xD9;
static 		bit 	TIRUN	@ 0xDC;
static volatile bit 	CLRTI	@ 0xDD;
static volatile bit 	MASTRQ	@ 0xDE;
static volatile bit 	SLAVEN	@ 0xDF;

//Accumulator ACC
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 volatile bit 	B0	@ 0xF0;
static volatile bit 	B1	@ 0xF1;
static volatile bit 	B2	@ 0xF2;
static volatile bit 	B3	@ 0xF3;
static volatile bit 	B4	@ 0xF4;
static volatile bit 	B5	@ 0xF5;
static volatile bit 	B6	@ 0xF6;
static volatile bit 	B7	@ 0xF7;

//I2C Status I2CSTA
static volatile bit 	XSTP	@ 0xF8;
static volatile bit 	XSTR	@ 0xF9;
static volatile bit 	MAKSTP	@ 0xFA;
static volatile bit 	MAKSTR	@ 0xFB;
static volatile bit 	XACTV	@ 0xFC;
static volatile bit 	XDATA	@ 0xFD;
static volatile bit 	IDLE	@ 0xFE;


//Interrupt Vectors
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	I2C	0x23

#endif
