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

/*
Header file for the Phillips microcontrollers
	P87LPC760
	P87LPC761
	P87LPC762
  	P87LPC764
 	P87LPC767
	P87LPC768
	P87LPC769
 */

#ifndef __87LPC76X_H

#define __87LPC76X_H
	
/*please not that the addressable bits, CMP1 and CMP2 (from Port 0 Register) are refferred to as CMP1OUT and CMP2OUT*/

typedef struct {
	unsigned B7:1;	/* this is the most significant 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 		unsigned char	P0M1	@ 0x84;
static 		unsigned char	P0M2	@ 0x85;
static 		unsigned char	KBI	@ 0x86;
static volatile	unsigned char	PCON	@ 0x87;
static volatile	unsigned char	TCON	@ 0x88;
static 		unsigned char	TMOD	@ 0x89;
static volatile	unsigned char	TL0	@ 0x8A;
static volatile	unsigned char	TL1	@ 0x8B;
static volatile	unsigned char	TH0	@ 0x8C;
static volatile	unsigned char	TH1	@ 0x8D;
static volatile	unsigned char	P1	@ 0x90;
static 		unsigned char	P1M1	@ 0x91;
static 		unsigned char	P1M2	@ 0x92;
static 		unsigned char	DIVM	@ 0x95;
static volatile	unsigned char	SCON	@ 0x98;
static volatile	unsigned char	SBUF	@ 0x99;
static volatile	unsigned char	P2	@ 0xA0;
static volatile	unsigned char	AUXR1	@ 0xA2;
static volatile	unsigned char	P2M1	@ 0xA4;
static volatile	unsigned char	P2M2	@ 0xA5;
static 		unsigned char	WDRST	@ 0xA6;
static volatile	unsigned char	WDCON	@ 0xA7;
static 		unsigned char	IEN0	@ 0xA8;
static 		unsigned char	CMP1	@ 0xAC;
#if !defined(_P87LPC760)
static 		unsigned char	CMP2	@ 0xAD;
#endif
static 		unsigned char	SADDR	@ 0xA9;
static volatile	unsigned char	IP0H	@ 0xB7;
static 		unsigned char	IP0 	@ 0xB8;
static 		unsigned char	SADEN	@ 0xB9;
#if defined(_P87LPC767) | defined(_P87LPC768) | defined(_P87LPC769) 
static volatile unsigned char	ADCON	@ 0xC0;
static volatile unsigned char	DAC0	@ 0xC5;
#endif
#if defined(_P87LPC769)
static volatile unsigned char	DAC1	@ 0xC6;
#endif
static volatile	unsigned char	I2CFG	@ 0xC8;
static volatile	unsigned char	PSW	@ 0xD0;
#if defined(_P87LPC768)
static volatile unsigned char CNSW0	@ 0xD1;
static volatile unsigned char CNSW1	@ 0xD2;
static volatile unsigned char CPSW0	@ 0xD3;
static volatile unsigned char CPSW1	@ 0xD4;
static volatile unsigned char CPSW2	@ 0xD5;
static volatile unsigned char CPSW3	@ 0xD6;
static volatile unsigned char CPSW4	@ 0xD7;
static volatile	unsigned char PWMCON0	@ 0xDA;
static 		unsigned char PWMCON1	@ 0xDB;
#endif
static volatile	unsigned char	I2CON	@ 0xD8;
static volatile	unsigned char	I2DAT	@ 0xD9;
static volatile	unsigned char	ACC	@ 0xE0;
static 		unsigned char	IEN1	@ 0xE8;
static volatile	unsigned char	B	@ 0xF0;
static 		unsigned char	PT0AD	@ 0xF6;
static 		unsigned char	IP1H	@ 0xF7;
static 		unsigned char	IP1	@ 0xF8;


static volatile SFR_BITS P0_BITS		@ 0x80;
static 		SFR_BITS P0M1_BITS		@ 0x84;
static 		SFR_BITS P0M2_BITS		@ 0x85;
static volatile	SFR_BITS PCON_BITS		@ 0x87;
static volatile SFR_BITS TCON_BITS		@ 0x88;
static 		SFR_BITS TMOD_BITS		@ 0x89;
static volatile SFR_BITS P1_BITS		@ 0x90;
static 		SFR_BITS P1M1_BITS		@ 0x91;
static 		SFR_BITS P1M2_BITS		@ 0x92;
static volatile SFR_BITS SCON_BITS		@ 0x98;
static volatile SFR_BITS P2_BITS		@ 0xA0;
static volatile SFR_BITS AUXR1_BITS		@ 0xA2;
static 		SFR_BITS P2M1_BITS		@ 0xA4;
static 		SFR_BITS P2M2_BITS		@ 0xA5;
static volatile SFR_BITS WDCON_BITS		@ 0xA7;
static 		SFR_BITS IEN0_BITS		@ 0xA8;
static volatile SFR_BITS CMP1_BITS		@ 0xAC;
#if !defined(_P87LPC760)
static volatile SFR_BITS CMP2_BITS		@ 0xAD;
#endif
static 		SFR_BITS IP0H_BITS		@ 0xB7;
static 		SFR_BITS IP0_BITS		@ 0xB8;
static 		SFR_BITS SADEN_BITS		@ 0xB9;
#if defined(_P87LPC767) | defined(_P87LPC768) | defined(_P87LPC769) 
static volatile SFR_BITS ADCON_BITS		@ 0xC0;
static volatile SFR_BITS DAC0_BITS		@ 0xC5;
#endif
#if defined(_P87LPC769)
static volatile SFR_BITS DAC1_BITS		@ 0xC6;
#endif
static volatile SFR_BITS I2CFG_BITS		@ 0xC8;
static volatile SFR_BITS PSW_BITS		@ 0xD0;
#if defined(_P87LPC768)
static volatile SFR_BITS CNSW0_BITS		@ 0xD1;
static volatile SFR_BITS CNSW1_BITS		@ 0xD2;
static volatile SFR_BITS CPSW0_BITS		@ 0xD3;
static volatile SFR_BITS CPSW1_BITS		@ 0xD4;
static volatile SFR_BITS CPSW2_BITS		@ 0xD5;
static volatile SFR_BITS CPSW3_BITS		@ 0xD6;
static volatile SFR_BITS CPSW4_BITS		@ 0xD7;
static volatile	SFR_BITS PWMCON0_BITS		@ 0xDA;
static 		SFR_BITS PWMCON1_BITS		@ 0xDB;
#endif
static volatile SFR_BITS I2CON_BITS		@ 0xD8;
static volatile	SFR_BITS I2DAT_BITS		@ 0xD9;
static volatile SFR_BITS ACC_BITS		@ 0xE0;
static 		SFR_BITS IEN1_BITS		@ 0xE8;
static volatile SFR_BITS B_BITS			@ 0xF0;
static 		SFR_BITS PT0AD_BITS		@ 0xF6;
static 		SFR_BITS IP1H_BITS		@ 0xF7;
static 		SFR_BITS IP1_BITS		@ 0xF8;

//bit addressable locations
//Port 0
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
#if !defined(_P87LPC760)
static volatile bit	CMP2OUT	@ 0x80;
static volatile bit	CIN2B	@ 0x81;
static volatile bit	CIN2A	@ 0x82;
#endif
static volatile bit	CIN1B	@ 0x83;
static volatile bit	CIN1A	@ 0x84;
static volatile bit	CMPREF	@ 0x85;
static volatile bit	CMP1OUT	@ 0x86;
#if !defined(_P87LPC760) & !defined(_P87LPC761)
static volatile bit	T1	@ 0x87;
#endif

//Timer 0 and 1 Control TCON
static 		bit	IT0	@ 0x88;
static volatile bit	IE0	@ 0x89;
#if !defined(_P87LPC760) & !defined(_P87LPC761)
static 		bit	IT1	@ 0x8A;
static volatile bit	IE1 	@ 0x8B;
#endif
static		bit	TR0 	@ 0x8C;
static volatile bit	TF0 	@ 0x8D;
static		bit	TR1 	@ 0x8E;
static volatile bit	TF1 	@ 0x8F;

//Port 1
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 functions
static volatile bit	TXD 	@ 0x90;
static volatile bit	RXD 	@ 0x91;
static volatile bit	T0	@ 0x92;
static volatile bit	INT0	@ 0x93;
#if !defined(_P87LPC760) & !defined(_P87LPC761)
static volatile bit	INT1	@ 0x94;
#endif
static volatile bit	RST 	@ 0x95;

//Serial Port Control SCON
static volatile bit	RI 	@ 0x98;
static volatile bit	TI	@ 0x99;
static volatile bit	RB8 	@ 0x9A;
static 		bit	TB8 	@ 0x9B;
static 		bit	REN 	@ 0x9C;
static 		bit	SM2 	@ 0x9D;
static 		bit	SM1 	@ 0x9E;
static volatile	bit	SM0 	@ 0x9F;
// Alternate definition
static volatile	bit	FE 	@ 0x9F;

//Port 2
static volatile	bit	P20 	@ 0xA0;
static volatile	bit	P21 	@ 0xA1;
static volatile	bit	P22 	@ 0xA2;
static volatile	bit	P23 	@ 0xA3;
static volatile	bit	P24 	@ 0xA4;
static volatile	bit	P25 	@ 0xA5;
static volatile	bit	P26 	@ 0xA6;
static volatile	bit	P27 	@ 0xA7;
// Alternate Functions
static volatile	bit	X2 	@ 0xA0;
static volatile	bit	X1 	@ 0xA1;

//Interrupt Enable 0 IEN0
static 		bit	EX0 	@ 0xA8;
static		bit	ET0	@ 0xA9;
#if !defined(_P87LPC760) & !defined(_P87LPC761)
static 		bit	EX1	@ 0xAA;
#endif
static 		bit	ET1	@ 0xAB;
static 		bit	ES 	@ 0xAC;
static 		bit	EBO	@ 0xAD;
static 		bit	EWD	@ 0xAE;
static 		bit	EA 	@ 0xAF;

//Interrupt Priority 1 IP1
static 		bit	PX0	@ 0xB8;
static 		bit	PT0	@ 0xB9;
#if !defined(_P87LPC760) & !defined(_P87LPC761)
static 		bit	PX1	@ 0xBA;
#endif
static 		bit	PT1	@ 0xBB;
static 		bit	PS 	@ 0xBC;
static 		bit	PBO	@ 0xBD;
static 		bit	PWD	@ 0xBE;

#if defined(_P87LPC767) | defined(_P87LPC768) | defined(_P87LPC769) 
//A/D Control ADCON
static volatile bit	AADR0	@ 0xC0;
static volatile bit	AADR1	@ 0xC1;
static volatile bit	RCCLK	@ 0xC2;
static volatile bit	ADCS	@ 0xC3;
static volatile bit	ADCI	@ 0xC4;
static volatile bit 	NADC	@ 0xC7;
#endif
#if defined(_P87LPC769) 
static volatile bit	ENADC0	@ 0xC5;
static volatile bit	ENADC1	@ 0xC6;
#endif

//I2C Configuration Register I2CFG
static 		bit	CT0	@ 0xC8;
static		bit	CT1	@ 0xC9;
static 		bit	TIRUN	@ 0xCC;
static volatile bit	CLRTI	@ 0xCD;
static volatile bit	MASTRQ	@ 0xCE;
static volatile bit	SLAVEN	@ 0xCF;

//Program Status Word PSW
static volatile bit	P 	@ 0xD0;
static volatile bit	F1 	@ 0xD1;
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 Control Register I2CON
//This Register operates in a READ and WRITE mode
//WRITE
static volatile	bit	XSTP 	@ 0xD8;
static volatile	bit	XSTR 	@ 0xD9;
static volatile	bit	CSTP 	@ 0xDA;
static volatile	bit	CSTR 	@ 0xDB;
static volatile	bit	CARL 	@ 0xDC;
static volatile	bit	CDR 	@ 0xDD;
static volatile	bit	IDLE 	@ 0xDE;
static volatile	bit	CXA 	@ 0xDF;
//READ
static volatile	bit	MASTER 	@ 0xD9;
static volatile bit	STP 	@ 0xDA;
static volatile bit	STR 	@ 0xDB;
static volatile bit	ARL 	@ 0xDC;
static volatile bit	DRDY 	@ 0xDD;
static volatile	bit	ATN	@ 0xDE;
static volatile	bit	RDAT 	@ 0xDF;

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

//Interrupt enable 1 IEN1
static 		bit	EI2	@ 0xE8;
static 		bit	EKB	@ 0xE9;
#if !defined(_P87LPC760)
static 		bit	EC2	@ 0xEA;
#endif
#if defined(_P87LPC767) | defined(_P87LPC768) | defined(_P87LPC769) 
static 		bit	EAD	@ 0xEC;
#endif
static 		bit	EC1	@ 0xED;
static 		bit	ETI	@ 0xEF;

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

//Interrupt Priority 1 IP1
static		bit	PI2	@ 0xF8;
static 		bit	PKB	@ 0xF9;
#if !defined(_P87LPC760)
static 		bit	PC2	@ 0xFA;
#endif
#if defined(_P87LPC767) | defined(_P87LPC768)
static 		bit	PAD	@ 0xFC;
#endif
static 		bit	PC1	@ 0xFD;
static 		bit	PTI	@ 0xFF;

/*	Interrupt vectors */
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0 	0x0B
#if !defined(_P87LPC760) & !defined(_P87LPC761)
#define	EXTINT1	0x13
#endif
#define TIMER1 	0x1B
#define	SERIAL	0x23
#define BO 	0x2B
#define I2CI 	0x33
#define KB 	0x3B
#if !defined(_P87LPC760)
#define CM2 	0x43
#endif
#define WD 	0x53
#if defined(_P87LPC767) | defined(_P87LPC768) | defined(_P87LPC769) 
#define AD	0x5B
#endif
#define CM1	0x63
#define TMI 	0x73

#endif	
