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


 /* header file for the CML Microsystems microcontroller
	CMX850

*** not that bits PWM1 & 2 (P3 alternate function) have been renamed PWM1OUT & 2OUT ***
  */

#ifndef	__CMX850_H

#define	__CMX850_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
// 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 volatile unsigned char P1	@ 0x90;
static          unsigned char P1DIR	@ 0x91;
static		unsigned char P1OD	@ 0x92;
static		unsigned char P1RES	@ 0x93;
static          unsigned char P0DIR	@ 0x94;
static volatile unsigned char SCON	@ 0x98;
static volatile unsigned char SBUF	@ 0x99;
static		unsigned char OSCCON	@ 0x9C;
static volatile unsigned char SPDCON	@ 0x9D;
static		unsigned char SPXMASK	@ 0x9E;
static		unsigned char PDXMASK	@ 0x9F;
static volatile unsigned char P2	@ 0xA0;
static          unsigned char IE	@ 0xA8;
static		unsigned char IE_1	@ 0xA9;
static volatile unsigned char ICON1A	@ 0xAA;
static volatile unsigned char ICON1B	@ 0xAB;
static volatile unsigned char P3	@ 0xB0;
static          unsigned char P3DIR	@ 0xB1;
static		unsigned char P3OD	@ 0xB2;
static		unsigned char P3RES	@ 0xB3;
static          unsigned char IP	@ 0xB8;
static		unsigned char IP_1	@ 0xB9;
static volatile unsigned char P4	@ 0xC0;
static          unsigned char P4DIR	@ 0xC1;
static		unsigned char P4OD	@ 0xC2;
static		unsigned char P4RES	@ 0xC3;
static volatile unsigned char PSW	@ 0xD0;
static volatile unsigned char P5	@ 0xD8;
static          unsigned char P5DIR	@ 0xD9;
static		unsigned char P5OD	@ 0xDA;
static		unsigned char P5RES	@ 0xDB;
static		unsigned char PWMCON	@ 0xDD;
static          unsigned char PWM1	@ 0xDE;
static          unsigned char PWM2	@ 0xDF;
static volatile unsigned char ACC	@ 0xE0;
static volatile unsigned char ADCCON1	@ 0xE2;
static		unsigned char ADCCON2	@ 0xE3;
static volatile unsigned char ADCBUFL	@ 0xE4;
static volatile unsigned char ADCBUFH	@ 0xE5;
static		unsigned char ADCTHRL	@ 0xE6;
static		unsigned char ADCTHRH	@ 0xE7;
static volatile unsigned char CASDET	@ 0xE9;
static volatile unsigned char CBUSCON	@ 0xEA;
static volatile unsigned char CBUSBUF	@ 0xEB;
static		unsigned char KBCON	@ 0xEC;
static volatile unsigned char KBSTAT	@ 0xED;
static volatile unsigned char KBBUF	@ 0xEE;
static volatile unsigned char B		@ 0xF0;
static volatile unsigned char WDTCON	@ 0xF2;
static		unsigned char WDTLD	@ 0xF3;
static		unsigned char ALM0	@ 0xF4;
static		unsigned char ALM1	@ 0xF5;
static		unsigned char ALM2	@ 0xF6;
static		unsigned char ALM3	@ 0xF7;
static		unsigned char MEMCON	@ 0xFA;
static volatile unsigned char RTCCON	@ 0xFB;
static volatile unsigned char TIME0	@ 0xFC;
static volatile unsigned char TIME1	@ 0xFD;
static volatile unsigned char TIME2	@ 0xFE;
static volatile unsigned char TIME3	@ 0xFF;

static volatile SFR_BITS	 P0_BITS	@ 0x80;
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 volatile SFR_BITS	 P1_BITS	@ 0x90;
static          SFR_BITS	 P1DIR_BITS	@ 0x91;
static		SFR_BITS	 P1OD_BITS	@ 0x92;
static		SFR_BITS	 P1RES_BITS	@ 0x93;
static          SFR_BITS	 P0DIR_BITS	@ 0x94;
static volatile SFR_BITS	 SCON_BITS	@ 0x98;
static		SFR_BITS	 OSCCON_BITS	@ 0x9C;
static volatile SFR_BITS	 SPDCON_BITS	@ 0x9D;
static		SFR_BITS	 SPXMASK_BITS	@ 0x9E;
static		SFR_BITS	 PDXMASK_BITS	@ 0x9F;
static volatile SFR_BITS	 P2_BITS	@ 0xA0;
static          SFR_BITS	 IE_BITS	@ 0xA8;
static		SFR_BITS	 IE_1_BITS	@ 0xA9;
static volatile SFR_BITS	 ICON1A_BITS	@ 0xAA;
static volatile SFR_BITS	 ICON1B_BITS	@ 0xAB;
static volatile SFR_BITS	 P3_BITS	@ 0xB0;
static          SFR_BITS	 P3DIR_BITS	@ 0xB1;
static		SFR_BITS	 P3OD_BITS	@ 0xB2;
static		SFR_BITS	 P3RES_BITS	@ 0xB3;
static          SFR_BITS	 IP_BITS	@ 0xB8;
static		SFR_BITS	 IP_1_BITS	@ 0xB9;
static volatile SFR_BITS	 P4_BITS	@ 0xC0;
static          SFR_BITS	 P4DIR_BITS	@ 0xC1;
static		SFR_BITS	 P4OD_BITS	@ 0xC2;
static		SFR_BITS	 P4RES_BITS	@ 0xC3;
static volatile SFR_BITS	 PSW_BITS	@ 0xD0;
static volatile SFR_BITS	 P5_BITS	@ 0xD8;
static          SFR_BITS	 P5DIR_BITS	@ 0xD9;
static		SFR_BITS	 P5OD_BITS	@ 0xDA;
static		SFR_BITS	 P5RES_BITS	@ 0xDB;
static		SFR_BITS	 PWMCON_BITS	@ 0xDD;
static volatile SFR_BITS	 ACC_BITS	@ 0xE0;
static volatile SFR_BITS	 ADCCON1_BITS	@ 0xE2;
static		SFR_BITS	 ADCCON2_BITS	@ 0xE3;
static volatile SFR_BITS	 CASDET_BITS	@ 0xE9;
static volatile SFR_BITS	 CBUSCON_BITS	@ 0xEA;
static		SFR_BITS	 KBCON_BITS	@ 0xEC;
static volatile SFR_BITS	 KBSTAT_BITS	@ 0xED;
static volatile SFR_BITS	 KBBUF_BITS	@ 0xEE;
static volatile SFR_BITS	 B_BITS		@ 0xF0;
static volatile SFR_BITS	 WDTCON_BITS	@ 0xF2;
static		SFR_BITS	 MEMCON_BITS	@ 0xFA;
static volatile SFR_BITS	 RTCCON_BITS	@ 0xFB;


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

//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;
// alternate functions
static volatile bit	KBR0	@ 0x90;
static volatile bit	KBR1	@ 0x91;
static volatile bit	KBR2	@ 0x92;
static volatile bit	KBR3	@ 0x93;
static volatile bit	KBR4	@ 0x94;
static volatile bit	KBR5	@ 0x95;
static volatile bit	KBR6	@ 0x96;
static volatile bit	KBR7	@ 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 volatile 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;

//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	PWM1OUT	@ 0xB6;
static volatile bit	PWM2OUT	@ 0xB7;

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

//Port 4
static volatile bit	P40	@ 0xC0;
static volatile bit	P41	@ 0xC1;
static volatile bit	P42	@ 0xC2;
static volatile bit	P43	@ 0xC3;
static volatile bit	P44	@ 0xC4;
static volatile bit	P45	@ 0xC5;
static volatile bit	P46	@ 0xC6;
static volatile bit	P47	@ 0xC7;
// alternate functions
static volatile bit	KBC0	@ 0xC0;
static volatile bit	KBC1	@ 0xC1;
static volatile bit	KBC2	@ 0xC2;
static volatile bit	KBC3	@ 0xC3;
static volatile bit	KBC4	@ 0xC4;
static volatile bit	KBC5	@ 0xC5;
static volatile bit	KBC6	@ 0xC6;
static volatile bit	KBC7	@ 0xC7;

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

//Port 5 P5
static volatile bit	P50	@ 0xD8;
static volatile bit	P51	@ 0xD9;
static volatile bit	P52	@ 0xDA;
static volatile bit	P53	@ 0xDB;
static volatile bit	P54	@ 0xDC;
static volatile bit	P55	@ 0xDD;
static volatile bit	P56	@ 0xDE;
static volatile bit	P57	@ 0xDF;
// alternate functions
static volatile bit	KBC8	@ 0xD8;
static volatile bit	KBC9	@ 0xD9;
static volatile bit	KBC10	@ 0xDA;
static volatile bit	KBC11	@ 0xDB;
static volatile bit	KBC12	@ 0xDC;
static volatile bit	KBC13	@ 0xDD;
static volatile bit	KBC14	@ 0xDE;
static volatile bit	KBC15	@ 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;

// C-BUS registers and addresses
#define GENRESET	0x01
#define GENCONTROL	0xE0
#define TXMODE		0xE1
#define RXMODE		0xE2
#define TXDATA		0xE3
#define TXDATA2		0xE4
#define RXDATA		0xE5
#define STATUS1		0xE6
#define STATUS2		0xE7
#define PROGRAM		0xE8
#define ANALOGUE	0xEC
// alternate definition
#define TXDATA1		0xE3

//Interrupt Vectors
#define	RESET	0
#define	EXTINT0	0x03
#define TIMER0	0x0B
#define	EXTINT1	0x13
#define	TIMER1	0x1B
#define	SERIAL	0x23
#define	CAS	0x33
#define	DSP	0x3B
#define	KBE	0x43
#define	ADC	0x4B
#define	RTC	0x53
#define	ALARM	0x5B
#define	WDT	0x63
#define	EXTINT9	0x6B

#endif
