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

/*header file for the SIEMENS C541U Microcontrollers
	C541U_1E	
	C541U_L	
 */

#ifndef	__C541U_H

#define	__C541U_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;

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		WDTREL	@ 0x86;
static 		unsigned char		PCON	@ 0x87;
static volatile	unsigned char		TCON	@ 0x88;
//to access PCON1, RMAP SYSCON.4 must be set
static volatile	unsigned char		PCON1	@ 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 volatile	unsigned char		SSCON	@ 0x93;
static		unsigned char		STB	@ 0x94;
static volatile unsigned char		SRB	@ 0x95;
static volatile	unsigned char		SSCMOD	@ 0x96;
static volatile	unsigned char		ITCON	@ 0x9A;
static volatile unsigned char		P2	@ 0xA0;
static 		unsigned char		IEN0	@ 0xA8;
static 		unsigned char		IEN1	@ 0xA9;
static volatile	unsigned char		SCF	@ 0xAB;
static		unsigned char		SCIEN	@ 0xAC;
static volatile unsigned char		P3	@ 0xB0;
static volatile unsigned char		SYSCON	@ 0xB1;
static		unsigned char		IP0	@ 0xB8;
static 		unsigned char		IP1	@ 0xB9;
static volatile	unsigned char		WDCON	@ 0xC0;
//C1 to C7 = USB Device and Endpint Register
//EPSEL = 1XXX XXXXb
static volatile unsigned char		DCR	@ 0xC1;
static volatile unsigned char		DPWDR	@ 0xC2;
static		unsigned char		DIER	@ 0xC3;
static volatile unsigned char		DIRR	@ 0xC4;
static volatile unsigned char		FNRL	@ 0xC6;
static volatile unsigned char		FNRH	@ 0xC7;
//EPSEL = 0XXX X000b
static volatile unsigned char		EPBC0	@ 0xC1;
static volatile unsigned char		EPBS0	@ 0xC2;
static		unsigned char		EPIE0	@ 0xC3;
static volatile unsigned char		EPIR0	@ 0xC4;
static volatile unsigned char		EPBA0	@ 0xC5;
static volatile	unsigned char		EPLEN0	@ 0xC6;
//EPSEL = 0XXX X001b
static volatile unsigned char		EPBC1	@ 0xC1;
static volatile unsigned char		EPBS1	@ 0xC2;
static		unsigned char		EPIE1	@ 0xC3;
static volatile unsigned char		EPIR1	@ 0xC4;
static volatile unsigned char		EPBA1	@ 0xC5;
static volatile	unsigned char		EPLEN1	@ 0xC6;
//EPSEL = 0XXX X010b
static volatile unsigned char		EPBC2	@ 0xC1;
static volatile unsigned char		EPBS2	@ 0xC2;
static		unsigned char		EPIE2	@ 0xC3;
static volatile unsigned char		EPIR2	@ 0xC4;
static volatile unsigned char		EPBA2	@ 0xC5;
static volatile	unsigned char		EPLEN2	@ 0xC6;
//EPSEL = 0XXX X011b
static volatile unsigned char		EPBC3	@ 0xC1;
static volatile unsigned char		EPBS3	@ 0xC2;
static		unsigned char		EPIE3	@ 0xC3;
static volatile unsigned char		EPIR3	@ 0xC4;
static volatile unsigned char		EPBA3	@ 0xC5;
static volatile	unsigned char		EPLEN3	@ 0xC6;
//EPSEL = 0XXX X100b
static volatile unsigned char		EPBC4	@ 0xC1;
static volatile unsigned char		EPBS4	@ 0xC2;
static		unsigned char		EPIE4	@ 0xC3;
static volatile unsigned char		EPIR4	@ 0xC4;
static volatile unsigned char		EPBA4	@ 0xC5;
static volatile	unsigned char		EPLEN4	@ 0xC6;

static volatile unsigned char		PSW	@ 0xD0;
static		unsigned char		EPSEL	@ 0xD2;
static volatile unsigned char		USBVAL	@ 0xD3;
static		unsigned char		ADROFF	@ 0xD4;
static volatile unsigned char		GEPIR	@ 0xD6;
static volatile unsigned char		ACC	@ 0xE0;
//Registers E6 to EF are used in USB low speed operation
static volatile unsigned char		USBPWD	@ 0xE6;
static volatile unsigned char		USBDCR	@ 0xE7;
static volatile unsigned char		USBDR0	@ 0xE8;
static volatile unsigned char		USBDR1	@ 0xE9;
static volatile unsigned char		USBDR2	@ 0xEA;
static volatile unsigned char		USBDR3	@ 0xEB;
static volatile unsigned char		USBDR4	@ 0xEC;
static volatile unsigned char		USBDR5	@ 0xED;
static volatile unsigned char		USBDR6	@ 0xEE;
static volatile unsigned char		USBDR7	@ 0xEF;
static volatile unsigned char		B	@ 0xF0;
static		unsigned char		VR0	@ 0xFC;
static		unsigned char		VR1	@ 0xFD;
static		unsigned char		VR2	@ 0xFE;

static volatile SFR_BITS	P0_BITS		@ 0x80;
static 		SFR_BITS	PCON_BITS	@ 0x87;
static volatile	SFR_BITS	TCON_BITS	@ 0x88;
//to access PCON1, RMAP SYSCON.4 must be set
static volatile	SFR_BITS	PCON1_BITS	@ 0x88;
static 		SFR_BITS	TMOD_BITS	@ 0x89;
static volatile SFR_BITS	P1_BITS		@ 0x90;
static volatile	SFR_BITS	SSCON_BITS	@ 0x93;
static volatile	SFR_BITS	SSCMOD_BITS	@ 0x96;
static volatile	SFR_BITS	ITCON_BITS	@ 0x9A;
static volatile SFR_BITS	P2_BITS		@ 0xA0;
static 		SFR_BITS	IEN0_BITS	@ 0xA8;
static 		SFR_BITS	IEN1_BITS	@ 0xA9;
static volatile	SFR_BITS	SCF_BITS	@ 0xAB;
static		SFR_BITS	SCIEN_BITS	@ 0xAC;
static volatile SFR_BITS	P3_BITS		@ 0xB0;
static volatile SFR_BITS	SYSCON_BITS	@ 0xB1;
static		SFR_BITS	IP0_BITS	@ 0xB8;
static 		SFR_BITS	IP1_BITS	@ 0xB9;
static volatile	SFR_BITS	WDCON_BITS	@ 0xC0;
//C1 to C7 = USB Device and Endpint Register
//EPSEL = 1XXX XXXXb
static volatile SFR_BITS	DCR_BITS	@ 0xC1;
static volatile SFR_BITS	DPWDR_BITS	@ 0xC2;
static		SFR_BITS	DIER_BITS	@ 0xC3;
static volatile SFR_BITS	DIRR_BITS	@ 0xC4;
static volatile SFR_BITS	FNRL_BITS	@ 0xC6;
static volatile SFR_BITS	FNRH_BITS	@ 0xC7;
//EPSEL = 0XXX X000b
static volatile SFR_BITS	EPBC0_BITS	@ 0xC1;
static volatile SFR_BITS	EPBS0_BITS	@ 0xC2;
static		SFR_BITS	EPIE0_BITS	@ 0xC3;
static volatile SFR_BITS	EPIR0_BITS	@ 0xC4;
static volatile SFR_BITS	EPBA0_BITS	@ 0xC5;
static volatile	SFR_BITS	EPLEN0_BITS	@ 0xC6;
//EPSEL = 0XXX X001b
static volatile SFR_BITS	EPBC1_BITS	@ 0xC1;
static volatile SFR_BITS	EPBS1_BITS	@ 0xC2;
static		SFR_BITS	EPIE1_BITS	@ 0xC3;
static volatile SFR_BITS	EPIR1_BITS	@ 0xC4;
static volatile SFR_BITS	EPBA1_BITS	@ 0xC5;
static volatile	SFR_BITS	EPLEN1_BITS	@ 0xC6;
//EPSEL = 0XXX X010b
static volatile SFR_BITS	EPBC2_BITS	@ 0xC1;
static volatile SFR_BITS	EPBS2_BITS	@ 0xC2;
static		SFR_BITS	EPIE2_BITS	@ 0xC3;
static volatile SFR_BITS	EPIR2_BITS	@ 0xC4;
static volatile SFR_BITS	EPBA2_BITS	@ 0xC5;
static volatile	SFR_BITS	EPLEN2_BITS	@ 0xC6;
//EPSEL = 0XXX X011b
static volatile SFR_BITS	EPBC3_BITS	@ 0xC1;
static volatile SFR_BITS	EPBS3_BITS	@ 0xC2;
static		SFR_BITS	EPIE3_BITS	@ 0xC3;
static volatile SFR_BITS	EPIR3_BITS	@ 0xC4;
static volatile SFR_BITS	EPBA3_BITS	@ 0xC5;
static volatile	SFR_BITS	EPLEN3_BITS	@ 0xC6;
//EPSEL = 0XXX X100b
static volatile SFR_BITS	EPBC4_BITS	@ 0xC1;
static volatile SFR_BITS	EPBS4_BITS	@ 0xC2;
static		SFR_BITS	EPIE4_BITS	@ 0xC3;
static volatile SFR_BITS	EPIR4_BITS	@ 0xC4;
static volatile SFR_BITS	EPBA4_BITS	@ 0xC5;
static volatile	SFR_BITS	EPLEN4_BITS	@ 0xC6;

static volatile SFR_BITS	PSW_BITS	@ 0xD0;
static		SFR_BITS	EPSEL_BITS	@ 0xD2;
static volatile SFR_BITS	GEPIR_BITS	@ 0xD6;
static volatile SFR_BITS	ACC_BITS	@ 0xE0;
//Registers E6 to EF are used in USB low speed operation
static volatile SFR_BITS	USBPWD_BITS	@ 0xE6;
static volatile SFR_BITS	USBDCR_BITS	@ 0xE7;
static volatile SFR_BITS	B_BITS		@ 0xF0;


/*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;
//to access PCON1, RMAP SYSCON.4 must be set
//Power Control 1 PCON1
static 		bit	WS	@ 0x8C;
static volatile bit	EWPD	@ 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 Functions
static volatile bit	LED0	@ 0x90;
static volatile bit	LED1	@ 0x91;
static volatile bit	SCLK	@ 0x92;
static volatile bit	SRI	@ 0x93;
static volatile bit	STO	@ 0x94;
static volatile bit	SLS	@ 0x95;

//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 IEN0
static		bit	EX0	@ 0xA8;
static		bit	ET0	@ 0xA9;
static		bit	EX1	@ 0xAA;
static		bit	ET1	@ 0xAB;
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	LED2	@ 0xB0;
static volatile bit	DADD	@ 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 0 IP0
static 		bit	PX0	@ 0xB8;
static 		bit	PT0	@ 0xB9;
static 		bit	PX1	@ 0xBA;
static 		bit	PT1	@ 0xBB;

//Watchdog Control WDCON
static volatile	bit	SWDT	@ 0xC0;
static volatile	bit	WDT	@ 0xC1;
static volatile	bit	WDTS	@ 0xC2;
static volatile	bit	OWDS	@ 0xC3;

//Timer 2 Control T2CON
static volatile	bit	T2I0	@ 0xC8;
static volatile	bit	T2I1	@ 0xC9;
static volatile	bit	T2CM	@ 0xCA;
static volatile	bit	T2R0	@ 0xCB;
static volatile	bit	T2R1	@ 0xCC;
static volatile	bit	I2FR	@ 0xCD;
static volatile	bit	I3FR	@ 0xCE;
static volatile	bit	T2PS	@ 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;

//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	SSC	0x43
#define	USBEPT	0x4B
#define	USBDEV	0x53
#define	WUPD	0x7B

#endif
