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


 /* header file for the SMSC microcontroller
	USB97C201
 */

#ifndef	__USB97201_H

#define	__USB97201_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 SP	@ 0x81;
static volatile unsigned char DPL0	@ 0x82;
static volatile unsigned char DPH0	@ 0x83;
// 16 bit definition
// Alternate definition
static volatile unsigned char DPL1	@ 0x84;
static volatile unsigned char DPH1	@ 0x85;
// 16 bit definition
static          unsigned char DPS	@ 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          unsigned char CKCON	@ 0x8E;
static		unsigned char SPC_FNC	@ 0x8F;
static volatile unsigned char EXIF	@ 0x91;
static		unsigned char MPAGE	@ 0x92;
static volatile unsigned char SCON0	@ 0x98;
static volatile unsigned char SBUF0	@ 0x99;
static          unsigned char IE	@ 0xA8;
static          unsigned char IP	@ 0xB8;
static volatile unsigned char TL2	@ 0xCC;
static volatile unsigned char TH2	@ 0xCD;
static volatile unsigned char PSW	@ 0xD0;
static volatile unsigned char EICON	@ 0xD8;
static volatile unsigned char ACC	@ 0xE0;
static          unsigned char EIE	@ 0xE8;
static volatile unsigned char B		@ 0xF0;
static          unsigned char EIP	@ 0xF8;

static          SFR_BITS	 DPS_BITS	@ 0x86;
static volatile SFR_BITS	 PCON_BITS	@ 0x87;
static volatile SFR_BITS	 TCON_BITS	@ 0x88;
static          SFR_BITS	 TMOD_BITS	@ 0x89;
static          SFR_BITS	 CKCON_BITS	@ 0x8E;
static		SFR_BITS	 SPC_FNC_BITS	@ 0x8F;
static volatile SFR_BITS	 EXIF_BITS	@ 0x91;
static volatile SFR_BITS	 SCON0_BITS	@ 0x98;
static          SFR_BITS	 IE_BITS	@ 0xA8;
static          SFR_BITS	 IP_BITS	@ 0xB8;
static volatile SFR_BITS	 PSW_BITS	@ 0xD0;
static volatile SFR_BITS	 EICON_BITS	@ 0xD8;
static volatile SFR_BITS	 ACC_BITS	@ 0xE0;
static          SFR_BITS	 EIE_BITS	@ 0xE8;
static volatile SFR_BITS	 B_BITS		@ 0xF0;
static          SFR_BITS	 EIP_BITS	@ 0xF8;

// SFRs mapped into the external RAM area
static volatile xdata unsigned char ISR_0	@ 0x80;
static		xdata unsigned char IMR_0	@ 0x93;
static volatile xdata unsigned char ISR_1	@ 0x90;
static		xdata unsigned char IMR_1	@ 0x94;
static		xdata unsigned char DEV_REV	@ 0x95;
static		xdata unsigned char DEV_ID	@ 0x96;
static		xdata unsigned char GPIO_DIR	@ 0x97;
static volatile xdata unsigned char GPIO_OUT	@ 0x9A;
static volatile xdata unsigned char GPIO_IN	@ 0x9B;
static volatile xdata unsigned char GPIO_IRQ	@ 0xC0;
static		xdata unsigned char GPIO_MSK	@ 0x9C;
static volatile xdata unsigned char UTIL_CONFIG	@ 0x9D;
static volatile xdata unsigned char SRAM_DATA	@ 0x9F;
static volatile xdata unsigned char SRAM_ADD1	@ 0xA1;
static volatile xdata unsigned char SRAM_ADD2	@ 0xA2;
static		xdata unsigned char CLOCK_SEL	@ 0xA5;
static volatile xdata unsigned char WU_SRC_1	@ 0xA0;
static		xdata unsigned char WU_MSK_1	@ 0xA6;
static volatile xdata unsigned char USB_ADD	@ 0xA9;
static volatile xdata unsigned char SIE_CONF	@ 0xAA;
static volatile xdata unsigned char USB_STAT	@ 0xAB;
static		xdata unsigned char USB_MSK	@ 0xAC;
static volatile xdata unsigned char SIE_STAT	@ 0xB0;
static volatile xdata unsigned char USB_CONF	@ 0xAD;
static		xdata unsigned char SIE_MSK	@ 0xAE;
static volatile xdata unsigned char EP0RX_CTL	@ 0xAF;
static volatile xdata unsigned char EP0TX_CTL	@ 0xB1;
static volatile xdata unsigned char EP1RX_CTL	@ 0xB2;
static volatile xdata unsigned char EP1TX_CTL	@ 0xB3;
static volatile xdata unsigned char EP2_CTL	@ 0xB4;
static volatile xdata unsigned char EP0RX_BC	@ 0xB5;
static volatile xdata unsigned char EP0TX_BC	@ 0xB6;
static volatile xdata unsigned char EP1RX_BC	@ 0xB7;
static volatile xdata unsigned char EP1TX_BC	@ 0xC7;
static volatile xdata unsigned char RAMWRBC_A1	@ 0xCE;
static volatile xdata unsigned char RAMWRBC_A2	@ 0xCF;
static volatile xdata unsigned char RAMWRBC_B1	@ 0xD1;
static volatile xdata unsigned char RAMWRBC_B2	@ 0xD2;
static volatile xdata unsigned char RAMRDBC_A1	@ 0xD3;
static volatile xdata unsigned char RAMRDBC_A2	@ 0xD4;
static volatile xdata unsigned char RAMRDBC_B1	@ 0xD5;
static volatile xdata unsigned char RAMRDBC_B2	@ 0xD6;
static volatile xdata unsigned char NAK		@ 0xD7;
static		xdata unsigned char NAK_MSK	@ 0xD9;
static volatile xdata unsigned char USB_ERR	@ 0xDA;
static		xdata unsigned char MSB_ATA	@ 0xDB;
static		xdata unsigned char LSB_ATA	@ 0xDC;
static volatile xdata unsigned char ATA_CTL	@ 0xDD;
static		xdata unsigned char ATA_DMA	@ 0xDE;
static		xdata unsigned char IDE_TIM	@ 0xDF;
static volatile xdata unsigned char ATA_CNT0	@ 0xE1;
static volatile xdata unsigned char ATA_CNT1	@ 0xE2;
static volatile xdata unsigned char ATA_CNT2	@ 0xE3;
static volatile xdata unsigned char ATA_CNT3	@ 0xE4;
static		xdata unsigned char ATA_SRCA	@ 0xE5;
static		xdata unsigned char ATA_SRCB	@ 0xE6;

// Bit Addressable Locations
//Timer Control TCON
static 		bit	IT0	@ 0x88;
static volatile bit	IE0	@ 0x89;
static 		bit	IT1	@ 0x8A;
static volatile bit	IE1	@ 0x8B;
static 		bit	TR0	@ 0x8C;
static volatile bit	TF0	@ 0x8D;
static 		bit	TR1	@ 0x8E;
static volatile bit	TF1	@ 0x8F;

//Serial Control Register 0 SCON0
static volatile bit	RI_0	@ 0x98;
static volatile bit	TI_0	@ 0x99;
static volatile bit	RB8_0	@ 0x9A;
static 		bit	TB8_0	@ 0x9B;
static 		bit	REN_0	@ 0x9C;
static 		bit	SM2_0	@ 0x9D;
static 		bit	SM1_0	@ 0x9E;
static 		bit	SM0_0	@ 0x9F;
// more universal definitions
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 		bit	SM0	@ 0x9F;

//Interrupt Enable IE
static		bit	EX0	@ 0xA8;
static		bit	ET0	@ 0xA9;
static		bit	EX1	@ 0xAA;
static		bit	ET1	@ 0xAB;
static 		bit	ES0	@ 0xAC;
static 		bit	ET2	@ 0xAD;
static 		bit	ES1	@ 0xAE;
static 		bit	EA	@ 0xAF;

//Interrupt Priority
static 		bit	PX0	@ 0xB8;
static 		bit	PT0	@ 0xB9;
static 		bit	PX1	@ 0xBA;
static 		bit	PT1	@ 0xBB;
static 		bit	PS0	@ 0xBC;
static 		bit	PT2	@ 0xBD;
static 		bit	PS1	@ 0xBE;

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

// Extended Interrupt Control EICON
static volatile bit	WDTI	@ 0xDB;
static volatile bit	PFI	@ 0xDC;
static volatile bit	EPFI	@ 0xDD;
static		bit	SMOD1	@ 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;

//Extended Interrupt Enable EIE
static		bit	EX2	@ 0xE8;
static		bit	EX3	@ 0xE9;
static		bit	EX4	@ 0xEA;
static		bit	EX5	@ 0xEB;
static		bit	EWDI	@ 0xEC;

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

//Extended Interrupt Priority EIP
static		bit	PX2	@ 0xF8;
static		bit	PX3	@ 0xF9;
static		bit	PX4	@ 0xFA;
static		bit	PX5	@ 0xFB;
static		bit	PWDI	@ 0xFC;


//Interrupt Vectors
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	SERIAL	0x23
#define	TIMER2	0x2B
#define	S1	0x3B
#define	EXTINT2	0x43
#define	EXTINT3	0x4B
#define	EXTINT4	0x53
#define	EXTINT5	0x5B
#define	WDT	0x63

#endif
