/* header file for the MICROCHIP PIC microcontroller
 *  16F685
 */


#ifndef __HS23F2211D_H
#define __HS23F2211D_H

//
// Special function register definitions
//
volatile union {
    struct {
        unsigned	C                   : 1;
        unsigned	DC                  : 1;
        unsigned	Z                   : 1;
        unsigned	nPD                 : 1;
        unsigned	nTO                 : 1;
        unsigned	RP                  : 2;
        unsigned	IRP                 : 1;
    };
    struct {
        unsigned	                    : 5;
        unsigned	RP0                 : 1;
        unsigned	RP1                 : 1;
    };
} STATUSbits @ 0x003;

// Register: INDF
volatile unsigned char           INDF                @ 0x000;
// bit and bitfield definitions

// Register: TMR0
volatile unsigned char           TMR0                @ 0x001;
// bit and bitfield definitions

// Register: PCL
volatile unsigned char           PCL                 @ 0x002;
// bit and bitfield definitions

// Register: STATUS
volatile unsigned char           STATUS              @ 0x003;
// bit and bitfield definitions
volatile bit CARRY               @ ((unsigned)&STATUS*8)+0;
volatile bit DC                  @ ((unsigned)&STATUS*8)+1;
volatile bit ZERO                @ ((unsigned)&STATUS*8)+2;
volatile bit nPD                 @ ((unsigned)&STATUS*8)+3;
volatile bit nTO                 @ ((unsigned)&STATUS*8)+4;
volatile bit RP0                 @ ((unsigned)&STATUS*8)+5;
volatile bit RP1                 @ ((unsigned)&STATUS*8)+6;
volatile bit RST                 @ ((unsigned)&STATUS*8)+7;

volatile bit C                   @ ((unsigned)&STATUS*8)+0;
volatile bit HC                  @ ((unsigned)&STATUS*8)+1;
volatile bit Z                	 @ ((unsigned)&STATUS*8)+2;
volatile bit nPF                 @ ((unsigned)&STATUS*8)+3;
volatile bit nTF                 @ ((unsigned)&STATUS*8)+4;
volatile bit PAGE                @ ((unsigned)&STATUS*8)+5;


volatile unsigned char           FSR                 @ 0x004;
volatile unsigned char           PORTA               @ 0x005;
volatile bit RA0                 @ ((unsigned)&PORTA*8)+0;
volatile bit RA1                 @ ((unsigned)&PORTA*8)+1;
volatile bit RA2                 @ ((unsigned)&PORTA*8)+2;
volatile bit RA3                 @ ((unsigned)&PORTA*8)+3;
volatile bit RA4                 @ ((unsigned)&PORTA*8)+4;
volatile bit RA5                 @ ((unsigned)&PORTA*8)+5;
volatile bit RA6                 @ ((unsigned)&PORTA*8)+6;
volatile bit RA7                 @ ((unsigned)&PORTA*8)+7;

volatile bit PA0                 @ ((unsigned)&PORTA*8)+0;
volatile bit PA1                 @ ((unsigned)&PORTA*8)+1;
volatile bit PA2                 @ ((unsigned)&PORTA*8)+2;
volatile bit PA3                 @ ((unsigned)&PORTA*8)+3;
volatile bit PA4                 @ ((unsigned)&PORTA*8)+4;
volatile bit PA5                 @ ((unsigned)&PORTA*8)+5;
volatile bit PA6                 @ ((unsigned)&PORTA*8)+6;
volatile bit PA7                 @ ((unsigned)&PORTA*8)+7;

volatile unsigned char           PORTB               @ 0x006;
volatile bit RB0                 @ ((unsigned)&PORTB*8)+0;
volatile bit RB1                 @ ((unsigned)&PORTB*8)+1;
volatile bit RB2                 @ ((unsigned)&PORTB*8)+2;
volatile bit RB3                 @ ((unsigned)&PORTB*8)+3;
volatile bit RB4                 @ ((unsigned)&PORTB*8)+4;
volatile bit RB5                 @ ((unsigned)&PORTB*8)+5;
volatile bit RB6                 @ ((unsigned)&PORTB*8)+6;
volatile bit RB7                 @ ((unsigned)&PORTB*8)+7;

volatile bit PB0                 @ ((unsigned)&PORTB*8)+0;
volatile bit PB1                 @ ((unsigned)&PORTB*8)+1;
volatile bit PB2                 @ ((unsigned)&PORTB*8)+2;
volatile bit PB3                 @ ((unsigned)&PORTB*8)+3;
volatile bit PB4                 @ ((unsigned)&PORTB*8)+4;
volatile bit PB5                 @ ((unsigned)&PORTB*8)+5;
volatile bit PB6                 @ ((unsigned)&PORTB*8)+6;
volatile bit PB7                 @ ((unsigned)&PORTB*8)+7;


volatile unsigned char           PCON                @ 0x008;
volatile unsigned char           WUCON               @ 0x009;
// bit and bitfield definitions
volatile bit WUB0               @ ((unsigned)&WUCON*8)+0;
volatile bit WUB1               @ ((unsigned)&WUCON*8)+1;
volatile bit WUB2               @ ((unsigned)&WUCON*8)+2;
volatile bit WUB3               @ ((unsigned)&WUCON*8)+3;
volatile bit WUB4               @ ((unsigned)&WUCON*8)+4;
volatile bit WUB5               @ ((unsigned)&WUCON*8)+5;
volatile bit WUB6               @ ((unsigned)&WUCON*8)+6;
volatile bit WUB7               @ ((unsigned)&WUCON*8)+7;

volatile unsigned char           PCLATH              @ 0x00A;


volatile unsigned char           PDCON              @ 0x00B;
volatile bit PDB0                @ ((unsigned)&PDCON*8)+0;
volatile bit PDB1                @ ((unsigned)&PDCON*8)+1;
volatile bit PDB2                @ ((unsigned)&PDCON*8)+2;
volatile bit PDB3                @ ((unsigned)&PDCON*8)+3;
volatile bit PDB4                @ ((unsigned)&PDCON*8)+4;
volatile bit PDB5                @ ((unsigned)&PDCON*8)+5;
volatile bit PDB6                @ ((unsigned)&PDCON*8)+6;
volatile bit PDB7                @ ((unsigned)&PDCON*8)+7;

volatile unsigned char           ODCON              @ 0x00C;
volatile bit ODB0                @ ((unsigned)&ODCON*8)+0;
volatile bit ODB1                @ ((unsigned)&ODCON*8)+1;
volatile bit ODB2                @ ((unsigned)&ODCON*8)+2;
volatile bit ODB3                @ ((unsigned)&ODCON*8)+3;
volatile bit ODB4                @ ((unsigned)&ODCON*8)+4;
volatile bit ODB5                @ ((unsigned)&ODCON*8)+5;
volatile bit ODB6                @ ((unsigned)&ODCON*8)+6;
volatile bit ODB7                @ ((unsigned)&ODCON*8)+7;

volatile unsigned char           PHCON              @ 0x00D;
volatile bit PHB0                @ ((unsigned)&PHCON*8)+0;
volatile bit PHB1                @ ((unsigned)&PHCON*8)+1;
volatile bit PHB2                @ ((unsigned)&PHCON*8)+2;
volatile bit PHB3                @ ((unsigned)&PHCON*8)+3;
volatile bit PHB4                @ ((unsigned)&PHCON*8)+4;
volatile bit PHB5                @ ((unsigned)&PHCON*8)+5;
volatile bit PHB6                @ ((unsigned)&PHCON*8)+6;
volatile bit PHB7                @ ((unsigned)&PHCON*8)+7;


#define WPUA PHCON
#define WPU  PHCON


volatile unsigned char           INTEN              @ 0x00E;
volatile bit T0IE                @ ((unsigned)&INTEN*8)+0;
volatile bit PBIE                @ ((unsigned)&INTEN*8)+1;
volatile bit INTIE               @ ((unsigned)&INTEN*8)+2;
volatile bit TC0IE               @ ((unsigned)&INTEN*8)+3;
volatile bit TP0IE               @ ((unsigned)&INTEN*8)+4;
volatile bit INT1IE              @ ((unsigned)&INTEN*8)+5;
volatile bit GIE                 @ ((unsigned)&INTEN*8)+7;

volatile unsigned char           INTFLAG              @ 0x00F;
volatile bit T0IF                @ ((unsigned)&INTFLAG*8)+0;
volatile bit PBIF                @ ((unsigned)&INTFLAG*8)+1;
volatile bit INTIF               @ ((unsigned)&INTFLAG*8)+2;
volatile bit TC0IF               @ ((unsigned)&INTFLAG*8)+3;
volatile bit TP0IF               @ ((unsigned)&INTFLAG*8)+4;
volatile bit INT1IF              @ ((unsigned)&INTFLAG*8)+5;

#define  INTCON INTEN
#define  INTE	INTIE
#define  PAIE   PBIE
#define  INTF	INTIF
#define  PAIF   PBIF   


volatile unsigned char           PWM0EN_R              @ 0x050;
volatile bit PWM0EN              @ ((unsigned)&PWM0EN_R*8)+0;
volatile bit PWM0OEN             @ ((unsigned)&PWM0EN_R*8)+1;
volatile bit PWM01OEN            @ ((unsigned)&PWM0EN_R*8)+2;
volatile bit PWM0M               @ ((unsigned)&PWM0EN_R*8)+3;
volatile bit PWM1OEN             @ ((unsigned)&PWM0EN_R*8)+4;
volatile bit TPSEL8              @ ((unsigned)&PWM0EN_R*8)+5;
volatile bit TPEN                @ ((unsigned)&PWM0EN_R*8)+7;


volatile unsigned char           PWM0C               @ 0x051;
volatile unsigned char           PWM0TL              @ 0x052;
volatile unsigned char           PWM0TH              @ 0x053;
volatile unsigned char           PWM0PL              @ 0x054;
volatile unsigned char           PWM0PH              @ 0x055;
volatile unsigned char           PWM0DL              @ 0x056;
volatile unsigned char           PWM0DH              @ 0x057;
volatile unsigned char           PWM0DTL             @ 0x058;
volatile unsigned char           PWM0DTH             @ 0x059;
volatile unsigned char           PWMPSCON            @ 0x05B;
volatile unsigned char           PWM1DL              @ 0x060;
volatile unsigned char           PWM1DH              @ 0x061;
volatile unsigned char           PBIC1               @ 0x06C;
volatile unsigned char           PBIC0               @ 0x06D;
volatile unsigned char           PAHCON              @ 0x06E;
volatile unsigned char           PAIC1               @ 0x06F;
volatile unsigned char           PAIC0               @ 0x070;
volatile unsigned char           TC0L                @ 0x071;
volatile unsigned char           TC0M                @ 0x072;
volatile unsigned char           TC0R                @ 0x073;
volatile unsigned char           TC0H                @ 0x074;
volatile unsigned char           TC0D1               @ 0x075;
volatile unsigned char           TC0D2               @ 0x076;

volatile unsigned char           PWMCON              @ 0x077;
volatile bit PWM1EN              @ ((unsigned)&PWMCON*8)+0;
volatile bit PWM2EN              @ ((unsigned)&PWMCON*8)+1;
volatile bit PWM1S               @ ((unsigned)&PWMCON*8)+2;
volatile bit PWM2S               @ ((unsigned)&PWMCON*8)+3;
volatile bit PWM1XR0             @ ((unsigned)&PWMCON*8)+4;
volatile bit PWM1XR1             @ ((unsigned)&PWMCON*8)+5;
volatile bit PWM2XR0             @ ((unsigned)&PWMCON*8)+6;
volatile bit PWM2XR1             @ ((unsigned)&PWMCON*8)+7;

volatile unsigned char           PADCON              @ 0x078;
volatile bit PADC4             @ ((unsigned)&PADCON*8)+4;
volatile bit PADC5             @ ((unsigned)&PADCON*8)+5;

volatile unsigned char           OSCM                @ 0x079;
volatile bit CLKMD               @ ((unsigned)&OSCM*8)+0;
volatile bit STPHX               @ ((unsigned)&OSCM*8)+1;
volatile bit XTSEL               @ ((unsigned)&OSCM*8)+2;
volatile bit SLCON               @ ((unsigned)&OSCM*8)+3;
volatile bit SLT0C               @ ((unsigned)&OSCM*8)+4;
volatile bit GREE_MODE           @ ((unsigned)&OSCM*8)+5;
volatile bit WAKE                @ ((unsigned)&OSCM*8)+6;

volatile unsigned char           EECON1               @ 0x07A;
volatile bit READEE               @ ((unsigned)&EECON1*8)+0;
volatile bit PROGEE               @ ((unsigned)&EECON1*8)+1;
volatile bit ERASE_EE             @ ((unsigned)&EECON1*8)+2;
volatile bit ERALL_EE             @ ((unsigned)&EECON1*8)+3;
volatile bit TIMEE                @ ((unsigned)&EECON1*8)+6;

volatile unsigned char           EEADRH               @ 0x07B;
volatile unsigned char           EEADRL               @ 0x07C;
volatile unsigned char           EEDATL               @ 0x07E;

//BANK 1

volatile unsigned char			OPTION			      @ 0x062;
volatile unsigned char  		TRISA 			      @ 0x063;
volatile unsigned char  		TRISB 				  @ 0x064;

volatile unsigned char           TKC0               @ 0x0D0;
volatile unsigned char           TK16DH             @ 0x0D1;
volatile unsigned char           TK16DL             @ 0x0D2;
volatile unsigned char           TKC1               @ 0x0D3;
volatile unsigned char           TKC2               @ 0x0D4;
volatile unsigned char           TKC3               @ 0x0D5;
volatile unsigned char           TKSTA              @ 0x0D6;
volatile unsigned char           TKPDH              @ 0x0D7;
volatile unsigned char           TKPDL              @ 0x0D8;

volatile unsigned char           CMPC               @ 0x0D9;
volatile bit COPOL                @ ((unsigned)&CMPC*8)+1;
volatile bit CVEN                 @ ((unsigned)&CMPC*8)+2;
volatile bit CPEN                 @ ((unsigned)&CMPC*8)+3;
volatile bit CODEB                @ ((unsigned)&CMPC*8)+4;
volatile bit FTCKS                @ ((unsigned)&CMPC*8)+5;
volatile bit CMPIF                @ ((unsigned)&CMPC*8)+6;
volatile bit CMPEN                @ ((unsigned)&CMPC*8)+7;

volatile unsigned char           CMPM               @ 0x0DA;
volatile bit VRS0                 @ ((unsigned)&CMPM*8)+0;
volatile bit VRS1                 @ ((unsigned)&CMPM*8)+1;
volatile bit VRS2                 @ ((unsigned)&CMPM*8)+2;
volatile bit VRS3                 @ ((unsigned)&CMPM*8)+3;
volatile bit XRVSEL               @ ((unsigned)&CMPM*8)+4;
volatile bit CPINS0               @ ((unsigned)&CMPM*8)+5;
volatile bit CPINS1               @ ((unsigned)&CMPM*8)+6;



volatile unsigned char           OPAM               @ 0x0DB;
volatile bit MULTS0                 @ ((unsigned)&OPAM*8)+0;
volatile bit MULTS1                 @ ((unsigned)&OPAM*8)+1;
volatile bit OPAMEN                 @ ((unsigned)&OPAM*8)+2;
volatile bit COMMS                  @ ((unsigned)&OPAM*8)+3;

volatile unsigned char           INTEN1               @ 0x0DE;
volatile bit COMINTEN                 @ ((unsigned)&INTEN1*8)+1;

volatile unsigned char           INTFLAG1             @ 0x0DF;
volatile bit COMINTF                 @ ((unsigned)&INTFLAG1*8)+1;

volatile unsigned char           FLCON1               @ 0x0F9;
volatile bit READL                   @ ((unsigned)&FLCON1*8)+0;
volatile bit PROGL                   @ ((unsigned)&FLCON1*8)+1;
volatile bit EARSEL                  @ ((unsigned)&FLCON1*8)+2;
volatile bit TIMEL                   @ ((unsigned)&FLCON1*8)+6;
volatile bit CEFL                    @ ((unsigned)&FLCON1*8)+7;


volatile unsigned char           FLCON2               @ 0x0FA;
volatile unsigned char           FLADRH               @ 0x0FB;
volatile unsigned char           FLADRL               @ 0x0FC;
volatile unsigned char           FLDATH               @ 0x0FD;
volatile unsigned char           FLDATL               @ 0x0FE;

volatile unsigned char           FLERRF               @ 0x0FF;
volatile bit FOV                   @ ((unsigned)&FLERRF*8)+0;




volatile unsigned char           SFR5A               @ 0x05A;
volatile unsigned char           SFR5C               @ 0x05C;
volatile unsigned char           SFR5D               @ 0x05D;
volatile unsigned char           SFR5E               @ 0x05E;
volatile unsigned char           SFR5F               @ 0x05F;

volatile unsigned char           SFR62               @ 0x062;
volatile unsigned char           SFR63               @ 0x063;
volatile unsigned char           SFR64               @ 0x064;
volatile unsigned char           SFR65               @ 0x065;
volatile unsigned char           SFR66               @ 0x066;
volatile unsigned char           SFR67               @ 0x067;
volatile unsigned char           SFR68               @ 0x068;
volatile unsigned char           SFR6A               @ 0x069;
volatile unsigned char           SFR6B               @ 0x06A;
volatile unsigned char           SFR6C               @ 0x06B;

volatile unsigned char           SFR7D               @ 0x07D;
volatile unsigned char           SFR7F               @ 0x07F;

volatile unsigned char           SFRDC               @ 0x0DC;
volatile unsigned char           SFRDD               @ 0x0DD;
volatile unsigned char           SFRE0               @ 0x0E0;
volatile unsigned char           SFRE1               @ 0x0E1;
volatile unsigned char           SFRE2               @ 0x0E2;
volatile unsigned char           SFRE3               @ 0x0E3;
volatile unsigned char           SFRE4               @ 0x0E4;
volatile unsigned char           SFRE5               @ 0x0E5;
volatile unsigned char           SFRE6               @ 0x0E6;
volatile unsigned char           SFRE7               @ 0x0E7;
volatile unsigned char           SFRE8               @ 0x0E8;
volatile unsigned char           SFRE9               @ 0x0E9;
volatile unsigned char           SFREA               @ 0x0EA;
volatile unsigned char           SFREB               @ 0x0EB;
volatile unsigned char           SFREC               @ 0x0EC;
volatile unsigned char           SFRED               @ 0x0ED;
volatile unsigned char           SFREE               @ 0x0EE;
volatile unsigned char           SFREF               @ 0x0EF;
volatile unsigned char           SFRF0               @ 0x0F0;
volatile unsigned char           SFRF1               @ 0x0F1;
volatile unsigned char           SFRF2               @ 0x0F2;
volatile unsigned char           SFRF3               @ 0x0F3;
volatile unsigned char           SFRF4               @ 0x0F4;
volatile unsigned char           SFRF5               @ 0x0F5;
volatile unsigned char           SFRF6               @ 0x0F6;
volatile unsigned char           SFRF7               @ 0x0F7;
volatile unsigned char           SFRF8               @ 0x0F8;


#define CLR_OPTION()	asm("movlw 0");\
						asm("movwf 62h");	

#define CLR_IOSTA()	asm("movlw 0");\
					asm("movwf 63h");
					
#define CLR_IOSTB()	asm("movlw 0");\
					asm("movwf 64h");

#endif
