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

/* header file for the Myson Technologies microcontroller
	MTP800
 */

#ifndef	__MTP800_H

#define	__MTP800_H


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	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	SCON	@ 0x98;
static volatile unsigned char	SBUF	@ 0x99;
static volatile unsigned char	P2	@ 0xA0;
static 		unsigned char	IE	@ 0xA8;
static volatile unsigned char	P3	@ 0xB0;
static 		unsigned char	IP	@ 0xB8;
static volatile unsigned char	PSW	@ 0xD0;
static volatile unsigned char	ACC	@ 0xE0;
static volatile unsigned char	B	@ 0xF0;

static volatile SFR_BITS	P0_BITS		@ 0x80;
static 		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	SCON_BITS	@ 0x98;
static volatile SFR_BITS	P2_BITS		@ 0xA0;
static 		SFR_BITS	IE_BITS		@ 0xA8;
static volatile SFR_BITS	P3_BITS		@ 0xB0;
static 		SFR_BITS	IP_BITS		@ 0xB8;
static volatile SFR_BITS	PSW_BITS	@ 0xD0;
static volatile SFR_BITS	ACC_BITS	@ 0xE0;
static volatile SFR_BITS	B_BITS		@ 0xF0;

// external special function registers (XFRs)
static volatile xdata unsigned char	IICSTUS		@ 0x00;
static volatile xdata unsigned char	IIC_INTF	@ 0x01;
static		xdata unsigned char	IIC_INTEN	@ 0x02;
static volatile xdata unsigned char	IIC_RCBUF	@ 0x03;
// alternate function
static volatile xdata unsigned char	IIC_TXBUF	@ 0x03;
static volatile xdata unsigned char	IIC_ADR		@ 0x04;
static volatile xdata unsigned char	WDT_CTL		@ 0x05;
static volatile xdata unsigned char	WDT_CNT		@ 0x06;
static volatile xdata unsigned char	MIIC_STUS	@ 0x07;
static		xdata unsigned char	MIIC_CONF	@ 0x08;
static volatile xdata unsigned char	MIIC_RXBUF	@ 0x09;
// alternate function
static volatile xdata unsigned char	MIIC_TXBUF	@ 0x09;
static volatile xdata unsigned char	DMA_CTL		@ 0x0A;
static volatile xdata unsigned char	C51_PTR		@ 0x0B;
static volatile xdata unsigned char	CD_PTR		@ 0x0C;
static volatile xdata unsigned char	ADH_PTR		@ 0x0D;
static volatile xdata unsigned char	C51_DAT		@ 0x0E;
static		xdata unsigned char	SM_MID		@ 0x10;
static		xdata unsigned char	SM_DID		@ 0x11;
static volatile xdata unsigned char	SM_STA		@ 0x12;
static		xdata unsigned char	SM_CMD0		@ 0x13;
static		xdata unsigned char	SM_A0		@ 0x14;
static		xdata unsigned char	SM_A1		@ 0x15;
static		xdata unsigned char	SM_A2		@ 0x16;
static		xdata unsigned char	SM_A3		@ 0x17;
static volatile xdata unsigned char	SM_CTL		@ 0x18;
static volatile xdata unsigned char	SM_TRG		@ 0x19;
static volatile xdata unsigned char	SM_ECC		@ 0x1A;
static volatile xdata unsigned char	MUL_CTL		@ 0x1B;
static		xdata unsigned char	SM_CMD1		@ 0x1C;
static volatile xdata unsigned char	SM_IID		@ 0x1D;
static volatile xdata unsigned char	SM_RES		@ 0x1E;
static		xdata unsigned char	CF_FEA		@ 0x20;
static volatile xdata unsigned char	CF_ERR		@ 0x21;
static volatile xdata unsigned char	CF_SC		@ 0x22;
static volatile xdata unsigned char	CF_SN		@ 0x23;
static volatile xdata unsigned char	CF_CYL		@ 0x24;
static volatile xdata unsigned char	CF_CYH		@ 0x25;
static volatile xdata unsigned char	CF_DRH		@ 0x26;
static volatile xdata unsigned char	CF_CMD		@ 0x27;
static volatile xdata unsigned char	CF_STA		@ 0x28;
static		xdata unsigned char	CF_DVC		@ 0x29;
static volatile xdata unsigned char	CF_ALT		@ 0x2A;
static volatile xdata unsigned char	CF_CTL		@ 0x2B;
static		xdata unsigned char	CF_DAT		@ 0x2C;
static volatile xdata unsigned char	CF_TXS1		@ 0x2D;
static volatile xdata unsigned char	CF_TXS2		@ 0x2E;
static		xdata unsigned char	CHIP_CFG	@ 0x2F;
static volatile xdata unsigned char	PORT4		@ 0x30;
static volatile xdata unsigned char	PORT5		@ 0x31;
static volatile xdata unsigned char	PORT6		@ 0x32;
static volatile xdata unsigned char	PORT7		@ 0x33;
static volatile xdata unsigned char	PORT8		@ 0x34;
static volatile xdata unsigned char	MM_CTL		@ 0x3A;
static		xdata unsigned char	MM_TRG		@ 0x3B;
static volatile xdata unsigned char	MM_DAT		@ 0x3C;
static		xdata unsigned char	MM_CMD		@ 0x3D;
static		xdata unsigned char	USBADR		@ 0x60;
static volatile xdata unsigned char	USBCTR		@ 0x61;
static volatile xdata unsigned char	USBINTR		@ 0x62;
static		xdata unsigned char	USBINTE		@ 0x63;
static volatile xdata unsigned char	EP0STUS		@ 0x64;
static volatile xdata unsigned char	TX0CTR		@ 0x65;
static volatile xdata unsigned char	TX23CTR		@ 0x66;
static volatile xdata unsigned char	TX1CTR		@ 0x67;
static volatile xdata unsigned char	RC0FIFO0	@ 0x68;
static volatile xdata unsigned char	RC0FIFO1	@ 0x69;
static volatile xdata unsigned char	RC0FIFO2	@ 0x6A;
static volatile xdata unsigned char	RC0FIFO3	@ 0x6B;
static volatile xdata unsigned char	RC0FIFO4	@ 0x6C;
static volatile xdata unsigned char	RC0FIFO5	@ 0x6D;
static volatile xdata unsigned char	RC0FIFO6	@ 0x6E;
static volatile xdata unsigned char	RC0FIFO7	@ 0x6F;
static		xdata unsigned char	TX0FIFO0	@ 0x70;
static		xdata unsigned char	TX0FIFO1	@ 0x71;
static		xdata unsigned char	TX0FIFO2	@ 0x72;
static		xdata unsigned char	TX0FIFO3	@ 0x73;
static		xdata unsigned char	TX0FIFO4	@ 0x74;
static		xdata unsigned char	TX0FIFO5	@ 0x75;
static		xdata unsigned char	TX0FIFO6	@ 0x76;
static		xdata unsigned char	TX0FIFO7	@ 0x77;
static		xdata unsigned char	TX1FIFO0	@ 0x78;
static		xdata unsigned char	TX1FIFO1	@ 0x79;
static		xdata unsigned char	TX1FIFO2	@ 0x7A;
static		xdata unsigned char	TX1FIFO3	@ 0x7B;
static		xdata unsigned char	TX1FIFO4	@ 0x7C;
static		xdata unsigned char	TX1FIFO5	@ 0x7D;
static		xdata unsigned char	TX1FIFO6	@ 0x7E;
static		xdata unsigned char	TX1FIFO7	@ 0x7F;
static volatile xdata unsigned char	SM_ECC0		@ 0x96;
static volatile xdata unsigned char	SM_ECC1		@ 0x97;
static volatile xdata unsigned char	SM_ECC2		@ 0x98;
static volatile xdata unsigned char	SM_ECC3		@ 0x99;
static volatile xdata unsigned char	SM_ECC4		@ 0x9A;
static volatile xdata unsigned char	SM_ECC5		@ 0x9B;
static volatile xdata unsigned char	EP23MISC	@ 0x9C;
static volatile xdata unsigned char	DMA_MISC	@ 0x9D;
static volatile xdata unsigned char	SDRAM_CTL1	@ 0xA0;
static volatile xdata unsigned char	SDRAM_RAH	@ 0xA1;
static volatile xdata unsigned char	SDRAM_RAL	@ 0xA2;
static		xdata unsigned char	SDRAM_CTL2	@ 0xA3;

/*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 Functions
static volatile bit	AD0	@ 0x80;
static volatile bit	AD1	@ 0x81;
static volatile bit	AD2	@ 0x82;
static volatile bit	AD3	@ 0x83;
static volatile bit	AD4	@ 0x84;
static volatile bit	AD5	@ 0x85;
static volatile bit	AD6	@ 0x86;
static volatile bit	AD7	@ 0x87;

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

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

//Serial 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		bit	SM0	@ 0x9F;

//Port 2 P2
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	A8	@ 0xA0;
static volatile bit	A9	@ 0xA1;
static volatile bit	A10	@ 0xA2;
static volatile bit	A11	@ 0xA3;
static volatile bit	A12	@ 0xA4;
static volatile bit	A13	@ 0xA5;
static volatile bit	A14	@ 0xA6;
static volatile bit	A15	@ 0xA7;

//Interrupt Enable IE
static		bit	EX0	@ 0xA8;
static		bit	ET0	@ 0xA9;
static		bit	EX1	@ 0xAA;
static		bit	ET1	@ 0xAB;
static 		bit	ES	@ 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;
// Alternate Functions
static volatile bit	RXD	@ 0xB0;
static volatile bit	TXD	@ 0xB1;
static volatile bit	INT0	@ 0xB2;
static volatile bit	INT1	@ 0xB3;
static volatile bit	T0	@ 0xB4;
static volatile bit	T1	@ 0xB5;
static volatile bit	WR	@ 0xB6;
static volatile bit	RD	@ 0xB7;

//Interrupt Priority
static 		bit	PX0	@ 0xB8;
static 		bit	PT0	@ 0xB9;
static 		bit	PX1	@ 0xBA;
static 		bit	PT1	@ 0xBB;
static 		bit	PS	@ 0xBC;

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

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

/*	Interrupt vectors */
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	SERIAL	0x23

#endif	
