#ifndef _STC8xxxx_H
#define _STC8xxxx_H
#include
sfr P0 = 0x80;
sfr SP = 0x81;
sfr DPL = 0x82;
sfr DPH = 0x83;
sfr S4CON = 0x84;
sfr S4BUF = 0x85;
sfr PCON = 0x87;
sfr TCON = 0x88;
sfr TMOD = 0x89;
sfr TL0 = 0x8A;
sfr TL1 = 0x8B;
sfr TH0 = 0x8C;
sfr TH1 = 0x8D;
sfr AUXR = 0x8E;
sfr WAKE_CLKO = 0x8F;
sfr INT_CLKO = 0x8F;
sfr P1 = 0x90;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr PCON2 = 0x97;
sfr AUXR2 = 0x97;
sfr SCON = 0x98;
sfr SBUF = 0x99;
sfr S2CON = 0x9A;
sfr S2BUF = 0x9B;
sfr P2 = 0xA0;
sfr BUS_SPEED = 0xA1;
sfr AUXR1 = 0xA2;
sfr P_SW1 = 0xA2;
sfr IE = 0xA8;
sfr SADDR = 0xA9;
sfr WKTCL = 0xAA;
sfr WKTCH = 0xAB;
sfr S3CON = 0xAC;
sfr S3BUF = 0xAD;
sfr TA = 0xAE;
sfr IE2 = 0xAF;
sfr P3 = 0xB0;
sfr P3M1 = 0xB1;
sfr P3M0 = 0xB2;
sfr P4M1 = 0xB3;
sfr P4M0 = 0xB4;
sfr IP2 = 0xB5;
sfr IP2H = 0xB6;
sfr IPH = 0xB7;
sfr IP = 0xB8;
sfr SADEN = 0xB9;
sfr P_SW2 = 0xBA;
sfr VOCTRL = 0xBB;
sfr ADC_CONTR = 0xBC;
sfr ADC_RES = 0xBD;
sfr ADC_RESL = 0xBE;
sfr P4 = 0xC0;
sfr WDT_CONTR = 0xC1;
sfr IAP_DATA = 0xC2;
sfr IAP_ADDRH = 0xC3;
sfr IAP_ADDRL = 0xC4;
sfr IAP_CMD = 0xC5;
sfr IAP_TRIG = 0xC6;
sfr IAP_CONTR = 0xC7;
sfr ISP_DATA = 0xC2;
sfr ISP_ADDRH = 0xC3;
sfr ISP_ADDRL = 0xC4;
sfr ISP_CMD = 0xC5;
sfr ISP_TRIG = 0xC6;
sfr ISP_CONTR = 0xC7;
sfr P5 = 0xC8;
sfr P5M1 = 0xC9;
sfr P5M0 = 0xCA;
sfr P6M1 = 0xCB;
sfr P6M0 = 0xCC;
sfr SPSTAT = 0xCD;
sfr SPCTL = 0xCE;
sfr SPDAT = 0xCF;
sfr PSW = 0xD0;
sfr T4T3M = 0xD1;
sfr T4H = 0xD2;
sfr T4L = 0xD3;
sfr T3H = 0xD4;
sfr T3L = 0xD5;
sfr T2H = 0xD6;
sfr T2L = 0xD7;
sfr TH4 = 0xD2;
sfr TL4 = 0xD3;
sfr TH3 = 0xD4;
sfr TL3 = 0xD5;
sfr TH2 = 0xD6;
sfr TL2 = 0xD7;
sfr CCON = 0xD8;
sfr CMOD = 0xD9;
sfr CCAPM0 = 0xDA;
sfr CCAPM1 = 0xDB;
sfr CCAPM2 = 0xDC;
sfr CCAPM3 = 0xDD;
sfr ADCCFG = 0xDE;
sfr ACC = 0xE0;
sfr P7M1 = 0xE1;
sfr P7M0 = 0xE2;
sfr DPS = 0xE3;
sfr DPL1 = 0xE4;
sfr DPH1 = 0xE5;
sfr CMPCR1 = 0xE6;
sfr CMPCR2 = 0xE7;
sfr P6 = 0xE8;
sfr CL = 0xE9;
sfr CCAP0L = 0xEA;
sfr CCAP1L = 0xEB;
sfr CCAP2L = 0xEC;
sfr CCAP3L = 0xED;
sfr AUXINTIF = 0xEF;
sfr B = 0xF0;
sfr PWMCFG = 0xF1;
sfr PCA_PWM0 = 0xF2;
sfr PCA_PWM1 = 0xF3;
sfr PCA_PWM2 = 0xF4;
sfr PCA_PWM3 = 0xF5;
sfr PWMIF = 0xF6;
sfr PWMFDCR = 0xF7;
sfr P7 = 0xF8;
sfr CH = 0xF9;
sfr CCAP0H = 0xFA;
sfr CCAP1H = 0xFB;
sfr CCAP2H = 0xFC;
sfr CCAP3H = 0xFD;
sfr PWMCR = 0xFE;
sfr RSTCFG = 0xFF;
#define INT4_Enable() INT_CLKO |= (1 << 6)
#define INT3_Enable() INT_CLKO |= (1 << 5)
#define INT2_Enable() INT_CLKO |= (1 << 4)
#define INT1_Enable() EX1 = 1
#define INT0_Enable() EX0 = 1
#define INT4_Disable() INT_CLKO &= ~(1 << 6)
#define INT3_Disable() INT_CLKO &= ~(1 << 5)
#define INT2_Disable() INT_CLKO &= ~(1 << 4)
#define INT1_Disable() EX1 = 0
#define INT0_Disable() EX0 = 0
#define INT4IF 0x40
#define INT3IF 0x20
#define INT2IF 0x10
#define T4IF 0x04
#define T3IF 0x02
#define T2IF 0x01
#define INT4_Clear() AUXINTIF &= ~INT4IF
#define INT3_Clear() AUXINTIF &= ~INT3IF
#define INT2_Clear() AUXINTIF &= ~INT2IF
#define INT1_Clear() IE1 = 0
#define INT0_Clear() IE0 = 0
#define INT0_Fall() IT0 = 1
#define INT0_RiseFall() IT0 = 0
#define INT1_Fall() IT1 = 1
#define INT1_RiseFall() IT0 = 0
#define EAXSFR() P_SW2 |= 0x80
#define EAXRAM() P_SW2 &= ~0x80
#define CLKSEL (*(unsigned char volatile xdata *)0xfe00)
#define CKSEL (*(unsigned char volatile xdata *)0xfe00)
#define CLKDIV (*(unsigned char volatile xdata *)0xfe01)
#define IRC24MCR (*(unsigned char volatile xdata *)0xfe02)
#define XOSCCR (*(unsigned char volatile xdata *)0xfe03)
#define IRC32KCR (*(unsigned char volatile xdata *)0xfe04)
#define MainFosc_IRC24M() CKSEL = (CKSEL & ~0x03)
#define MainFosc_XTAL() CKSEL = (CKSEL & ~0x03) | 0x01
#define EXT_CLOCK() XOSCCR = 0x80
#define EXT_CRYSTAL() XOSCCR = 0xC0
#define MainFosc_IRC32K() CKSEL = CKSEL | 0x03
#define MainFosc_OutP54() CKSEL = (CKSEL & ~0x08)
#define MainFosc_OutP16() CKSEL = (CKSEL | 0x08)
#define MCLKO_None() CKSEL = (CKSEL & 0x0f)
#define MCLKO_DIV1() CKSEL = (CKSEL & 0x0f) | 0x10
#define MCLKO_DIV2() CKSEL = (CKSEL & 0x0f) | 0x20
#define MCLKO_DIV4() CKSEL = (CKSEL & 0x0f) | 0x40
#define MCLKO_DIV8() CKSEL = (CKSEL & 0x0f) | 0x60
#define MCLKO_DIV16() CKSEL = (CKSEL & 0x0f) | 0x80
#define MCLKO_DIV32() CKSEL = (CKSEL & 0x0f) | 0xa0
#define MCLKO_DIV64() CKSEL = (CKSEL & 0x0f) | 0xc0
#define MCLKO_DIV128() CKSEL = (CKSEL & 0x0f) | 0xe0
#define MCLKO_P54 0x00
#define MCLKO_P16 0x08
#define MCLKO_0 0x00
#define MCLKO_1 0x10
#define MCLKO_2 0x20
#define MCLKO_4 0x40
#define MCLKO_8 0x60
#define MCLKO_16 0x80
#define MCLKO_32 0xa0
#define MCLKO_64 0xc0
#define MCLKO_128 0xe0
#define P0PU (*(unsigned char volatile xdata *)0xfe10)
#define P1PU (*(unsigned char volatile xdata *)0xfe11)
#define P2PU (*(unsigned char volatile xdata *)0xfe12)
#define P3PU (*(unsigned char volatile xdata *)0xfe13)
#define P4PU (*(unsigned char volatile xdata *)0xfe14)
#define P5PU (*(unsigned char volatile xdata *)0xfe15)
#define P6PU (*(unsigned char volatile xdata *)0xfe16)
#define P7PU (*(unsigned char volatile xdata *)0xfe17)
#define P0NCS (*(unsigned char volatile xdata *)0xfe18)
#define P1NCS (*(unsigned char volatile xdata *)0xfe19)
#define P2NCS (*(unsigned char volatile xdata *)0xfe1a)
#define P3NCS (*(unsigned char volatile xdata *)0xfe1b)
#define P4NCS (*(unsigned char volatile xdata *)0xfe1c)
#define P5NCS (*(unsigned char volatile xdata *)0xfe1d)
#define P6NCS (*(unsigned char volatile xdata *)0xfe1e)
#define P7NCS (*(unsigned char volatile xdata *)0xfe1f)
#define I2CCFG (*(unsigned char volatile xdata *)0xfe80)
#define I2CMSCR (*(unsigned char volatile xdata *)0xfe81)
#define I2CMSST (*(unsigned char volatile xdata *)0xfe82)
#define I2CSLCR (*(unsigned char volatile xdata *)0xfe83)
#define I2CSLST (*(unsigned char volatile xdata *)0xfe84)
#define I2CSLADR (*(unsigned char volatile xdata *)0xfe85)
#define I2CTXD (*(unsigned char volatile xdata *)0xfe86)
#define I2CRXD (*(unsigned char volatile xdata *)0xfe87)
#define PWM0T1 (*(unsigned int volatile xdata *)0xff00)
#define PWM0T2 (*(unsigned int volatile xdata *)0xff02)
#define PWM1T1 (*(unsigned int volatile xdata *)0xff10)
#define PWM1T2 (*(unsigned int volatile xdata *)0xff12)
#define PWM2T1 (*(unsigned int volatile xdata *)0xff20)
#define PWM2T2 (*(unsigned int volatile xdata *)0xff22)
#define PWM3T1 (*(unsigned int volatile xdata *)0xff30)
#define PWM3T2 (*(unsigned int volatile xdata *)0xff32)
#define PWM4T1 (*(unsigned int volatile xdata *)0xff40)
#define PWM4T2 (*(unsigned int volatile xdata *)0xff42)
#define PWM5T1 (*(unsigned int volatile xdata *)0xff50)
#define PWM5T2 (*(unsigned int volatile xdata *)0xff52)
#define PWM6T1 (*(unsigned int volatile xdata *)0xff60)
#define PWM6T2 (*(unsigned int volatile xdata *)0xff62)
#define PWM7T1 (*(unsigned int volatile xdata *)0xff70)
#define PWM7T2 (*(unsigned int volatile xdata *)0xff72)
#define PWMC (*(unsigned int volatile xdata *)0xfff0)
#define TADCP (*(unsigned int volatile xdata *)0xfff3)
#define PWM0T1H (*(unsigned char volatile xdata *)0xff00)
#define PWM0T1L (*(unsigned char volatile xdata *)0xff01)
#define PWM0T2H (*(unsigned char volatile xdata *)0xff02)
#define PWM0T2L (*(unsigned char volatile xdata *)0xff03)
#define PWM0CR (*(unsigned char volatile xdata *)0xff04)
#define PWM0HLD (*(unsigned char volatile xdata *)0xff05)
#define PWM1T1H (*(unsigned char volatile xdata *)0xff10)
#define PWM1T1L (*(unsigned char volatile xdata *)0xff11)
#define PWM1T2H (*(unsigned char volatile xdata *)0xff12)
#define PWM1T2L (*(unsigned char volatile xdata *)0xff13)
#define PWM1CR (*(unsigned char volatile xdata *)0xff14)
#define PWM1HLD (*(unsigned char volatile xdata *)0xff15)
#define PWM2T1H (*(unsigned char volatile xdata *)0xff20)
#define PWM2T1L (*(unsigned char volatile xdata *)0xff21)
#define PWM2T2H (*(unsigned char volatile xdata *)0xff22)
#define PWM2T2L (*(unsigned char volatile xdata *)0xff23)
#define PWM2CR (*(unsigned char volatile xdata *)0xff24)
#define PWM2HLD (*(unsigned char volatile xdata *)0xff25)
#define PWM3T1H (*(unsigned char volatile xdata *)0xff30)
#define PWM3T1L (*(unsigned char volatile xdata *)0xff31)
#define PWM3T2H (*(unsigned char volatile xdata *)0xff32)
#define PWM3T2L (*(unsigned char volatile xdata *)0xff33)
#define PWM3CR (*(unsigned char volatile xdata *)0xff34)
#define PWM3HLD (*(unsigned char volatile xdata *)0xff35)
#define PWM4T1H (*(unsigned char volatile xdata *)0xff40)
#define PWM4T1L (*(unsigned char volatile xdata *)0xff41)
#define PWM4T2H (*(unsigned char volatile xdata *)0xff42)
#define PWM4T2L (*(unsigned char volatile xdata *)0xff43)
#define PWM4CR (*(unsigned char volatile xdata *)0xff44)
#define PWM4HLD (*(unsigned char volatile xdata *)0xff45)
#define PWM5T1H (*(unsigned char volatile xdata *)0xff50)
#define PWM5T1L (*(unsigned char volatile xdata *)0xff51)
#define PWM5T2H (*(unsigned char volatile xdata *)0xff52)
#define PWM5T2L (*(unsigned char volatile xdata *)0xff53)
#define PWM5CR (*(unsigned char volatile xdata *)0xff54)
#define PWM5HLD (*(unsigned char volatile xdata *)0xff15)
#define PWM6T1H (*(unsigned char volatile xdata *)0xff60)
#define PWM6T1L (*(unsigned char volatile xdata *)0xff61)
#define PWM6T2H (*(unsigned char volatile xdata *)0xff62)
#define PWM6T2L (*(unsigned char volatile xdata *)0xff63)
#define PWM6CR (*(unsigned char volatile xdata *)0xff64)
#define PWM6HLD (*(unsigned char volatile xdata *)0xff65)
#define PWM7T1H (*(unsigned char volatile xdata *)0xff70)
#define PWM7T1L (*(unsigned char volatile xdata *)0xff71)
#define PWM7T2H (*(unsigned char volatile xdata *)0xff72)
#define PWM7T2L (*(unsigned char volatile xdata *)0xff73)
#define PWM7CR (*(unsigned char volatile xdata *)0xff74)
#define PWM7HLD (*(unsigned char volatile xdata *)0xff75)
#define PWMCH (*(unsigned char volatile xdata *)0xfff0)
#define PWMCL (*(unsigned char volatile xdata *)0xfff1)
#define PWMCKS (*(unsigned char volatile xdata *)0xfff2)
#define TADCPH (*(unsigned char volatile xdata *)0xfff3)
#define TADCPL (*(unsigned char volatile xdata *)0xfff4)
#define PWM0_ID 0
#define PWM1_ID 1
#define PWM2_ID 2
#define PWM3_ID 3
#define PWM4_ID 4
#define PWM5_ID 5
#define PWM6_ID 6
#define PWM7_ID 7
#define PwmClk_T2 0
#define PWM_ENCnO 0x80
#define PWM_CnINI 0x40
#define PWMn_PS_0 0x00
#define PWMn_PS_1 0x08
#define PWMn_PS_2 0x10
#define PWM_ECnI 0x04
#define PWM_ECnT2SI 0x02
#define PWM_ECnT1SI 0x01
#define PWM0_P20 0x00
#define PWM0_P10 0x08
#define PWM0_P60 0x10
#define PWM1_P21 0x00
#define PWM1_P11 0x08
#define PWM1_P61 0x10
#define PWM2_P22 0x00
#define PWM2_P12 0x08
#define PWM2_P62 0x10
#define PWM3_P23 0x00
#define PWM3_P13 0x08
#define PWM3_P63 0x10
#define PWM4_P24 0x00
#define PWM4_P14 0x08
#define PWM4_P64 0x10
#define PWM5_P25 0x00
#define PWM5_P15 0x08
#define PWM5_P65 0x10
#define PWM6_P26 0x00
#define PWM6_P16 0x08
#define PWM6_P66 0x10
#define PWM7_P27 0x00
#define PWM7_P17 0x08
#define PWM7_P67 0x10
#define CBIF 0x80
#define ETADC 0x40
#define C7IF 0x80
#define C6IF 0x40
#define C5IF 0x20
#define C4IF 0x10
#define C3IF 0x08
#define C2IF 0x04
#define C1IF 0x02
#define C0IF 0x01
#define INVCMP 0x80
#define INVIO 0x40
#define INVP35 0x40
#define ENFD 0x20
#define FLTFLIO 0x10
#define EFDI 0x08
#define FDCMP 0x04
#define FDIO 0x02
#define FDIF 0x01
#define PWM_FaultDetect_Enable() PWMFDCR |= 0x20
#define PWM_FaultDetect_Disable() PWMFDCR &= ~0x20
#define ENPWM 0x80
#define ECBI 0x40
#define PWM_Enable() PWMCR |= 0x80
#define PWM_Disable() PWMCR &= ~0x80
sbit CY = PSW^7;
sbit AC = PSW^6;
sbit F0 = PSW^5;
sbit RS1 = PSW^4;
sbit RS0 = PSW^3;
sbit OV = PSW^2;
sbit F1 = PSW^1;
sbit P = PSW^0;
sbit TF1 = TCON^7;
sbit TR1 = TCON^6;
sbit TF0 = TCON^5;
sbit TR0 = TCON^4;
sbit IE1 = TCON^3;
sbit IT1 = TCON^2;
sbit IE0 = TCON^1;
sbit IT0 = TCON^0;
sbit P00 = P0^0;
sbit P01 = P0^1;
sbit P02 = P0^2;
sbit P03 = P0^3;
sbit P04 = P0^4;
sbit P05 = P0^5;
sbit P06 = P0^6;
sbit P07 = P0^7;
sbit P10 = P1^0;
sbit P11 = P1^1;
sbit P12 = P1^2;
sbit P13 = P1^3;
sbit P14 = P1^4;
sbit P15 = P1^5;
sbit P16 = P1^6;
sbit P17 = P1^7;
sbit RXD2 = P1^0;
sbit TXD2 = P1^1;
sbit CCP1 = P1^0;
sbit CCP0 = P1^1;
sbit SPI_SS = P1^2;
sbit SPI_MOSI = P1^3;
sbit SPI_MISO = P1^4;
sbit SPI_SCLK = P1^5;
sbit SPI_SS_2 = P2^4;
sbit SPI_MOSI_2 = P2^3;
sbit SPI_MISO_2 = P2^2;
sbit SPI_SCLK_2 = P2^1;
sbit SPI_SS_3 = P5^4;
sbit SPI_MOSI_3 = P4^0;
sbit SPI_MISO_3 = P4^1;
sbit SPI_SCLK_3 = P4^3;
sbit P20 = P2^0;
sbit P21 = P2^1;
sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;
sbit P25 = P2^5;
sbit P26 = P2^6;
sbit P27 = P2^7;
sbit P30 = P3^0;
sbit P31 = P3^1;
sbit P32 = P3^2;
sbit P33 = P3^3;
sbit P34 = P3^4;
sbit P35 = P3^5;
sbit P36 = P3^6;
sbit P37 = P3^7;
sbit RXD = P3^0;
sbit TXD = P3^1;
sbit INT0 = P3^2;
sbit INT1 = P3^3;
sbit T0 = P3^4;
sbit T1 = P3^5;
sbit WR = P3^6;
sbit RD = P3^7;
sbit CCP2 = P3^7;
sbit CLKOUT0 = P3^5;
sbit CLKOUT1 = P3^4;
sbit P40 = P4^0;
sbit P41 = P4^1;
sbit P42 = P4^2;
sbit P43 = P4^3;
sbit P44 = P4^4;
sbit P45 = P4^5;
sbit P46 = P4^6;
sbit P47 = P4^7;
sbit P50 = P5^0;
sbit P51 = P5^1;
sbit P52 = P5^2;
sbit P53 = P5^3;
sbit P54 = P5^4;
sbit P55 = P5^5;
sbit P56 = P5^6;
sbit P57 = P5^7;
sbit P60 = P6^0;
sbit P61 = P6^1;
sbit P62 = P6^2;
sbit P63 = P6^3;
sbit P64 = P6^4;
sbit P65 = P6^5;
sbit P66 = P6^6;
sbit P67 = P6^7;
sbit P70 = P7^0;
sbit P71 = P7^1;
sbit P72 = P7^2;
sbit P73 = P7^3;
sbit P74 = P7^4;
sbit P75 = P7^5;
sbit P76 = P7^6;
sbit P77 = P7^7;
sbit SM0 = SCON^7;
sbit SM1 = SCON^6;
sbit SM2 = SCON^5;
sbit REN = SCON^4;
sbit TB8 = SCON^3;
sbit RB8 = SCON^2;
sbit TI = SCON^1;
sbit RI = SCON^0;
sbit EA = IE^7;
sbit ELVD = IE^6;
sbit EADC = IE^5;
sbit ES = IE^4;
sbit ET1 = IE^3;
sbit EX1 = IE^2;
sbit ET0 = IE^1;
sbit EX0 = IE^0;
sbit ACC0 = ACC^0;
sbit ACC1 = ACC^1;
sbit ACC2 = ACC^2;
sbit ACC3 = ACC^3;
sbit ACC4 = ACC^4;
sbit ACC5 = ACC^5;
sbit ACC6 = ACC^6;
sbit ACC7 = ACC^7;
sbit B0 = B^0;
sbit B1 = B^1;
sbit B2 = B^2;
sbit B3 = B^3;
sbit B4 = B^4;
sbit B5 = B^5;
sbit B6 = B^6;
sbit B7 = B^7;
#define SPI_INT_ENABLE() IE2 |= 2
#define SPI_INT_DISABLE() IE2 &= ~2
#define UART2_INT_ENABLE() IE2 |= 1
#define UART2_INT_DISABLE() IE2 &= ~1
sbit PPCA = IP^7;
sbit PLVD = IP^6;
sbit PADC = IP^5;
sbit PS = IP^4;
sbit PT1 = IP^3;
sbit PX1 = IP^2;
sbit PT0 = IP^1;
sbit PX0 = IP^0;
#define PPCAH 0x80
#define PLVDH 0x40
#define PADCH 0x20
#define PSH 0x10
#define PT1H 0x08
#define PX1H 0x04
#define PT0H 0x02
#define PX0H 0x01
#define PCA_InterruptFirst() PPCA = 1
#define LVD_InterruptFirst() PLVD = 1
#define ADC_InterruptFirst() PADC = 1
#define UART1_InterruptFirst() PS = 1
#define Timer1_InterruptFirst() PT1 = 1
#define INT1_InterruptFirst() PX1 = 1
#define Timer0_InterruptFirst() PT0 = 1
#define INT0_InterruptFirst() PX0 = 1
#define CMPEN 0x80
#define CMPIF 0x40
#define PIE 0x20
#define NIE 0x10
#define PIS 0x08
#define NIS 0x04
#define CMPOE 0x02
#define CMPRES 0x01
#define INVCMPO 0x80
#define DISFLT 0x40
#define LCDTY 0x00
#define S1_DoubleRate() PCON |= 0x80
#define S1_SHIFT() SCON &= 0x3f
#define S1_8bit() SCON = (SCON & 0x3f) | 0x40
#define S1_9bit() SCON = (SCON & 0x3f) | 0xc0
#define S1_RX_Enable() SCON |= 0x10
#define S1_RX_Disable() SCON &= ~0x10
#define TI1 TI
#define RI1 RI
#define SET_TI1() TI = 1
#define CLR_TI1() TI = 0
#define CLR_RI1() RI = 0
#define S1TB8_SET() TB8 = 1
#define S1TB8_CLR() TB8 = 0
#define S1_Int_Enable() ES = 1
#define S1_Int_Disable() ES = 0
#define S1_BRT_UseTimer1() AUXR &= ~1
#define S1_BRT_UseTimer2() AUXR |= 1
#define S1_USE_P30P31() P_SW1 &= ~0xc0
#define S1_USE_P36P37() P_SW1 = (P_SW1 & ~0xc0) | 0x40
#define S1_USE_P16P17() P_SW1 = (P_SW1 & ~0xc0) | 0x80
#define S1_TXD_RXD_SHORT() PCON2 |= (1<<4)
#define S1_TXD_RXD_OPEN() PCON2 &= ~(1<<4)
#define S2_MODE0() S2CON &= ~(1<<7)
#define S2_MODE1() S2CON |= (1<<7)
#define S2_8bit() S2CON &= ~(1<<7)
#define S2_9bit() S2CON |= (1<<7)
#define S2_RX_Enable() S2CON |= (1<<4)
#define S2_RX_Disable() S2CON &= ~(1<<4)
#define TI2 (S2CON & 2) != 0
#define RI2 (S2CON & 1) != 0
#define SET_TI2() S2CON |= (1<<1)
#define CLR_TI2() S2CON &= ~(1<<1)
#define CLR_RI2() S2CON &= ~1
#define S2TB8_SET() S2CON |= (1<<3)
#define S2TB8_CLR() S2CON &= ~(1<<3)
#define S2_Int_Enable() IE2 |= 1
#define S2_Int_Disable() IE2 &= ~1
#define S2_USE_P10P11() P_SW2 &= ~1
#define S2_USE_P46P47() P_SW2 |= 1
#define S3_MODE0() S3CON &= ~(1<<7)
#define S3_MODE1() S3CON |= (1<<7)
#define S3_8bit() S3CON &= ~(1<<7)
#define S3_9bit() S3CON |= (1<<7)
#define S3_RX_Enable() S3CON |= (1<<4)
#define S3_RX_Disable() S3CON &= ~(1<<4)
#define TI3 (S3CON & 2) != 0
#define RI3 (S3CON & 1) != 0
#define SET_TI3() S3CON |= (1<<1)
#define CLR_TI3() S3CON &= ~(1<<1)
#define CLR_RI3() S3CON &= ~1
#define S3TB8_SET() S3CON |= (1<<3)
#define S3TB8_CLR() S3CON &= ~(1<<3)
#define S3_Int_Enable() IE2 |= (1<<3)
#define S3_Int_Disable() IE2 &= ~(1<<3)
#define S3_BRT_UseTimer3() S3CON |= (1<<6)
#define S3_BRT_UseTimer2() S3CON &= ~(1<<6)
#define S3_USE_P00P01() P_SW2 &= ~2
#define S3_USE_P50P51() P_SW2 |= 2
#define S4_MODE0() S4CON &= ~(1<<7)
#define S4_MODE1() S4CON |= (1<<7)
#define S4_8bit() S4CON &= ~(1<<7)
#define S4_9bit() S4CON |= (1<<7)
#define S4_RX_Enable() S4CON |= (1<<4)
#define S4_RX_Disable() S4CON &= ~(1<<4)
#define TI4 (S4CON & 2) != 0
#define RI4 (S4CON & 1) != 0
#define SET_TI4() S4CON |= 2
#define CLR_TI4() S4CON &= ~2
#define CLR_RI4() S4CON &= ~1
#define S4TB8_SET() S4CON |= 8
#define S4TB8_CLR() S4CON &= ~8
#define S4_Int_Enable() IE2 |= (1<<4)
#define S4_Int_Disable() IE2 &= ~(1<<4)
#define S4_BRT_UseTimer4() S4CON |= (1<<6)
#define S4_BRT_UseTimer2() S4CON &= ~(1<<6)
#define S4_USE_P02P03() P_SW2 &= ~4
#define S4_USE_P52P53() P_SW2 |= 4
#define ExternalRAM_enable() AUXR |= 2
#define InternalRAM_enable() AUXR &= ~2
#define S1_M0x6() AUXR |= (1<<5)
#define S1_M0x1() AUXR &= ~(1<<5)
#define Timer0_16bitAutoReload() TMOD &= ~0x03
#define Timer0_16bit() TMOD = (TMOD & ~0x03) | 0x01
#define Timer0_8bitAutoReload() TMOD = (TMOD & ~0x03) | 0x02
#define Timer0_16bitAutoRL_NoMask() TMOD |= 0x03
#define Timer0_Run() TR0 = 1
#define Timer0_Stop() TR0 = 0
#define Timer0_Gate_INT0_P32() TMOD |= (1<<3)
#define Timer0_AsTimer() TMOD &= ~(1<<2)
#define Timer0_AsCounter() TMOD |= (1<<2)
#define Timer0_AsCounterP34() TMOD |= (1<<2)
#define Timer0_1T() AUXR |= (1<<7)
#define Timer0_12T() AUXR &= ~(1<<7)
#define Timer0_CLKO_Enable() INT_CLKO |= 1
#define Timer0_CLKO_Disable() INT_CLKO &= ~1
#define Timer0_CLKO_Enable_P34() INT_CLKO |= 1
#define Timer0_CLKO_Disable_P34() INT_CLKO &= ~1
#define Timer0_InterruptEnable() ET0 = 1
#define Timer0_InterruptDisable() ET0 = 0
#define T0_Load(n) TH0 = (n) / 256, TL0 = (n) % 256
#define T0_Load_us_1T(n) Timer0_AsTimer(),Timer0_1T(), Timer0_16bitAutoReload(),TH0=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)/256, TL0=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)%256
#define T0_Load_us_12T(n) Timer0_AsTimer(),Timer0_12T(),Timer0_16bitAutoReload(),TH0=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)/256,TL0=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)%256
#define T0_Frequency_1T_P35(n) ET0=0,Timer0_AsTimer(),Timer0_1T(),Timer0_16bitAutoReload(),TH0=(65536-(n/2+MAIN_Fosc/2)/(n))/256,TL0=(65536-(n/2+MAIN_Fosc/2)/(n))%256,INT_CLKO |= bit0,TR0=1
#define T0_Frequency_12T_P35(n) ET0=0,Timer0_AsTimer(),Timer0_12T(),Timer0_16bitAutoReload(),TH0=(65536-(n/2+MAIN_Fosc/24)/(n))/256,TL0=(65536-(n/2+MAIN_Fosc/24)/(n))%256,INT_CLKO |= bit0,TR0=1
#define Timer1_16bitAutoReload() TMOD &= ~0x30
#define Timer1_16bit() TMOD = (TMOD & ~0x30) | 0x10
#define Timer1_8bitAutoReload() TMOD = (TMOD & ~0x30) | 0x20
#define Timer1_Run() TR1 = 1
#define Timer1_Stop() TR1 = 0
#define Timer1_Gate_INT1_P33() TMOD |= (1<<7)
#define Timer1_AsTimer() TMOD &= ~(1<<6)
#define Timer1_AsCounter() TMOD |= (1<<6)
#define Timer1_AsCounterP35() TMOD |= (1<<6)
#define Timer1_1T() AUXR |= (1<<6)
#define Timer1_12T() AUXR &= ~(1<<6)
#define Timer1_CLKO_Enable() INT_CLKO |= 2
#define Timer1_CLKO_Disable() INT_CLKO &= ~2
#define Timer1_CLKO_Enable_P35() INT_CLKO |= 2
#define Timer1_CLKO_Disable_P35() INT_CLKO &= ~2
#define Timer1_InterruptEnable() ET1 = 1
#define Timer1_InterruptDisable() ET1 = 0
#define T1_Load(n) TH1 = (n) / 256, TL1 = (n) % 256
#define T1_Load_us_1T(n) Timer1_AsTimer(),Timer1_1T(), Timer1_16bitAutoReload(),TH1=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)/256, TL1=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)%256
#define T1_Load_us_12T(n) Timer1_AsTimer(),Timer1_12T(),Timer1_16bitAutoReload(),TH1=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)/256,TL1=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)%256
#define T1_Frequency_1T_P34(n) ET1=0,Timer1_AsTimer(),Timer1_1T(),Timer1_16bitAutoReload(),TH1=(65536-(n/2+MAIN_Fosc/2)/(n))/256,TL1=(65536-(n/2+MAIN_Fosc/2)/(n))%256,INT_CLKO |= bit1,TR1=1
#define T1_Frequency_12T_P34(n) ET1=0,Timer1_AsTimer(),Timer1_12T(),Timer1_16bitAutoReload(),TH1=(65536-(n/2+MAIN_Fosc/24)/(n))/256,TL1=(65536-(n/2+MAIN_Fosc/24)/(n))%256,INT_CLKO |= bit1,TR1=1
#define Timer2_Run() AUXR |= (1<<4)
#define Timer2_Stop() AUXR &= ~(1<<4)
#define Timer2_AsTimer() AUXR &= ~(1<<3)
#define Timer2_AsCounter() AUXR |= (1<<3)
#define Timer2_AsCounterP31() AUXR |= (1<<3)
#define Timer2_1T() AUXR |= (1<<2)
#define Timer2_12T() AUXR &= ~(1<<2)
#define Timer2_CLKO_Enable() INT_CLKO |= 4
#define Timer2_CLKO_Disable() INT_CLKO &= ~4
#define Timer2_CLKO_Enable_P30() INT_CLKO |= 4
#define Timer2_CLKO_Disable_P30() INT_CLKO &= ~4
#define Timer2_InterruptEnable() IE2 |= (1<<2)
#define Timer2_InterruptDisable() IE2 &= ~(1<<2)
#define T2_Load(n) TH2 = (n) / 256, TL2 = (n) % 256
#define T2_Load_us_1T(n) Timer2_AsTimer(),Timer2_1T(), TH2=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)/256, TL2=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)%256
#define T2_Load_us_12T(n) Timer2_AsTimer(),Timer2_12T(),TH2=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)/256,TL2=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)%256
#define T2_Frequency_1T_P30(n) Timer2_InterruptDisable(),Timer2_AsTimer(),Timer2_1T(), TH2=(65536-(n/2+MAIN_Fosc/2)/(n))/256, TL2=(65536-(n/2+MAIN_Fosc/2)/(n))%256, Timer2_CLKO_Enable_P30(),Timer2_Run()
#define T2_Frequency_12T_P30(n) Timer2_InterruptDisable(),Timer2_AsTimer(),Timer2_12T(),TH2=(65536-(n/2+MAIN_Fosc/24)/(n))/256,TL2=(65536-(n/2+MAIN_Fosc/24)/(n))%256,Timer2_CLKO_Enable_P30(),Timer2_Run()
#define Timer3_Run() T4T3M |= (1<<3)
#define Timer3_Stop() T4T3M &= ~(1<<3)
#define Timer3_AsTimer() T4T3M &= ~(1<<2)
#define Timer3_AsCounter() T4T3M |= (1<<2)
#define Timer3_AsCounterP05() T4T3M |= (1<<2)
#define Timer3_1T() T4T3M |= (1<<1)
#define Timer3_12T() T4T3M &= ~(1<<1)
#define Timer3_CLKO_Enable() T4T3M |= 1
#define Timer3_CLKO_Disable() T4T3M &= ~1
#define Timer3_CLKO_Enable_P04() T4T3M |= 1
#define Timer3_CLKO_Disable_P04() T4T3M &= ~1
#define Timer3_InterruptEnable() IE2 |= (1<<5)
#define Timer3_InterruptDisable() IE2 &= ~(1<<5)
#define T3_Load(n) TH3 = (n) / 256, TL3 = (n) % 256
#define T3_Load_us_1T(n) Timer3_AsTimer(),Timer3_1T(), TH3=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)/256, TL3=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)%256
#define T3_Load_us_12T(n) Timer3_AsTimer(),Timer3_12T(),TH3=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)/256,TL3=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)%256
#define T3_Frequency_1T_P04(n) Timer3_InterruptDisable(),Timer3_AsTimer(),Timer3_1T(), TH3=(65536-(n/2+MAIN_Fosc/2)/(n))/256, TL3=(65536-(n/2+MAIN_Fosc/2)/(n))%256, Timer3_CLKO_P04_Enable,Timer3_Run()
#define T3_Frequency_12T_P04(n) Timer3_InterruptDisable(),Timer3_AsTimer(),Timer3_12T(),TH3=(65536-(n/2+MAIN_Fosc/24)/(n))/256,TL3=(65536-(n/2+MAIN_Fosc/24)/(n))%256,Timer3_CLKO_P04_Enable,Timer3_Run()
#define Timer4_Run() T4T3M |= (1<<7)
#define Timer4_Stop() T4T3M &= ~(1<<7)
#define Timer4_AsTimer() T4T3M &= ~(1<<6)
#define Timer4_AsCounter() T4T3M |= (1<<6)
#define Timer4_AsCounterP07() T4T3M |= (1<<6)
#define Timer4_1T() T4T3M |= (1<<5)
#define Timer4_12T() T4T3M &= ~(1<<5)
#define Timer4_CLKO_Enable() T4T3M |= (1<<4)
#define Timer4_CLKO_Disable() T4T3M &= ~(1<<4)
#define Timer4_CLKO_Enable_P06() T4T3M |= (1<<4)
#define Timer4_CLKO_Disable_P06() T4T3M &= ~(1<<4)
#define Timer4_InterruptEnable() IE2 |= (1<<6)
#define Timer4_InterruptDisable() IE2 &= ~(1<<6)
#define T4_Load(n) TH4 = (n) / 256, TL4 = (n) % 256
#define T4_Load_us_1T(n) Timer4_AsTimer(),Timer4_1T(), TH4=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)/256, TL4=(65536-((MAIN_Fosc/1000)*(n)+500)/1000)%256
#define T4_Load_us_12T(n) Timer4_AsTimer(),Timer4_12T(),TH4=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)/256,TL4=(65536-((MAIN_Fosc/12000)*(n)+500)/1000)%256
#define T4_Frequency_1T_P06(n) Timer4_InterruptDisable(),Timer4_AsTimer(),Timer4_1T(), TH4=(65536-(n/2+MAIN_Fosc/2)/(n))/256, TL4=(65536-(n/2+MAIN_Fosc/2)/(n))%256, Timer4_CLKO_P06_Enable(),Timer4_Run()
#define T4_Frequency_12T_P06(n) Timer4_InterruptDisable(),Timer4_AsTimer(),Timer4_12T(),TH4=(65536-(n/2+MAIN_Fosc/24)/(n))/256,TL4=(65536-(n/2+MAIN_Fosc/24)/(n))%256,Timer4_CLKO_P06_Enable(),Timer4_Run()
#define D_WDT_FLAG (1<<7)
#define D_EN_WDT (1<<5)
#define D_CLR_WDT (1<<4)
#define D_IDLE_WDT (1<<3)
#define D_WDT_SCALE_2 0
#define D_WDT_SCALE_4 1
#define D_WDT_SCALE_8 2
#define D_WDT_SCALE_16 3
#define D_WDT_SCALE_32 4
#define D_WDT_SCALE_64 5
#define D_WDT_SCALE_128 6
#define D_WDT_SCALE_256 7
#define WDT_reset(n) WDT_CONTR = D_EN_WDT + D_CLR_WDT + D_IDLE_WDT + (n)
#define LVDF (1<<5)
#define MCU_IDLE() PCON |= 1
#define MCU_POWER_DOWN() PCON |= 2
#define ISP_STANDBY() ISP_CMD = 0
#define ISP_READ() ISP_CMD = 1
#define ISP_WRITE() ISP_CMD = 2
#define ISP_ERASE() ISP_CMD = 3
#define ISP_TRIG() ISP_TRIG = 0x5A, ISP_TRIG = 0xA5
#define ISP_EN (1<<7)
#define ISP_SWBS (1<<6)
#define ISP_SWRST (1<<5)
#define ISP_CMD_FAIL (1<<4)
#define ISP_WAIT_1MHZ 7
#define ISP_WAIT_2MHZ 6
#define ISP_WAIT_3MHZ 5
#define ISP_WAIT_6MHZ 4
#define ISP_WAIT_12MHZ 3
#define ISP_WAIT_20MHZ 2
#define ISP_WAIT_24MHZ 1
#define ISP_WAIT_30MHZ 0
#if (MAIN_Fosc >= 24000000L)
#define ISP_WAIT_FREQUENCY ISP_WAIT_30MHZ
#elif (MAIN_Fosc >= 20000000L)
#define ISP_WAIT_FREQUENCY ISP_WAIT_24MHZ
#elif (MAIN_Fosc >= 12000000L)
#define ISP_WAIT_FREQUENCY ISP_WAIT_20MHZ
#elif (MAIN_Fosc >= 6000000L)
#define ISP_WAIT_FREQUENCY ISP_WAIT_12MHZ
#elif (MAIN_Fosc >= 3000000L)
#define ISP_WAIT_FREQUENCY ISP_WAIT_6MHZ
#elif (MAIN_Fosc >= 2000000L)
#define ISP_WAIT_FREQUENCY ISP_WAIT_3MHZ
#elif (MAIN_Fosc >= 1000000L)
#define ISP_WAIT_FREQUENCY ISP_WAIT_2MHZ
#else
#define ISP_WAIT_FREQUENCY ISP_WAIT_1MHZ
#endif
#define SPI_SSIG_None() SPCTL |= (1<<7)
#define SPI_SSIG_Enable() SPCTL &= ~(1<<7)
#define SPI_Enable() SPCTL |= (1<<6)
#define SPI_Disable() SPCTL &= ~(1<<6)
#define SPI_LSB_First() SPCTL |= (1<<5)
#define SPI_MSB_First() SPCTL &= ~(1<<5)
#define SPI_Master() SPCTL |= (1<<4)
#define SPI_Slave() SPCTL &= ~(1<<4)
#define SPI_SCLK_NormalH() SPCTL |= (1<<3)
#define SPI_SCLK_NormalL() SPCTL &= ~(1<<3)
#define SPI_PhaseH() SPCTL |= (1<<2)
#define SPI_PhaseL() SPCTL &= ~(1<<2)
#define SPI_Speed(n) SPCTL = (SPCTL & ~3) | (n)
#define SPIF 0x80
#define WCOL 0x40
#define SPI_USE_P12P13P14P15() AUXR1 &= ~0x0c
#define SPI_USE_P24P23P22P21() AUXR1 = (AUXR1 & ~0x0c) | 0x04
#define SPI_USE_P54P40P41P43() AUXR1 = (AUXR1 & ~0x0c) | 0x08
#define PWM0_NORMAL() PCA_PWM0 &= ~2
#define PWM0_OUT_0() PCA_PWM0 |= 2, CCAP0H = 0xff
#define PWM0_OUT_1() PCA_PWM0 &= ~2, CCAP0H = 0
#define PWM1_NORMAL() PCA_PWM1 &= ~2
#define PWM1_OUT_0() PCA_PWM1 |= 2, CCAP1H = 0xff
#define PWM1_OUT_1() PCA_PWM1 &= ~2, CCAP1H = 0
#define PWM2_NORMAL() PCA_PWM2 &= ~2
#define PWM2_OUT_0() PCA_PWM2 |= 2, CCAP2H = 0xff
#define PWM2_OUT_1() PCA_PWM2 &= ~2, CCAP2H = 0
#define PWM3_NORMAL() PCA_PWM3 &= ~2
#define PWM3_OUT_0() PCA_PWM3 |= 2, CCAP3H = 0xff
#define PWM3_OUT_1() PCA_PWM3 &= ~2, CCAP3H = 0
sbit CCF0 = CCON^0;
sbit CCF1 = CCON^1;
sbit CCF2 = CCON^2;
sbit CCF3 = CCON^3;
sbit CR = CCON^6;
sbit CF = CCON^7;
#define PCA_IDLE_OFF() CMOD |= (1<<7)
#define PCA_IDLE_ON() CMOD &= ~(1<<7)
#define PCA_CLK_12T() CMOD &= ~0x0E
#define PCA_CLK_2T() CMOD = (CMOD & ~0x0E) + 2
#define PCA_CLK_T0() CMOD = (CMOD & ~0x0E) + 4
#define PCA_CLK_ECI() CMOD = (CMOD & ~0x0E) + 6
#define PCA_CLK_1T() CMOD = (CMOD & ~0x0E) + 8
#define PCA_CLK_4T() CMOD = (CMOD & ~0x0E) + 10
#define PCA_CLK_6T() CMOD = (CMOD & ~0x0E) + 12
#define PCA_CLK_8T() CMOD = (CMOD & ~0x0E) + 14
#define PCA_INT_ENABLE() CMOD |= 1
#define PCA_INT_DISABLE() CMOD &= ~1
#define PCA_USE_P12P17P16P15P14() AUXR1 &= ~0x30
#define PCA_USE_P22P23P24P25P26() AUXR1 = (AUXR1 & ~0x30) | 0x10
#define PCA_USE_P74P70P71P72P73() AUXR1 = (AUXR1 & ~0x30) | 0x20
#define PCA_USE_P35P33P32P31P30() AUXR1 = (AUXR1 & ~0x30) | 0x30
#define DPS_SEL1() AUXR1 |= 1
#define DPS_SEL0() AUXR1 &= ~1
#define PCA0_none() CCAPM0 = 0
#define PCA0_PWM(nbit) CCAPM0 = 0x42,PCA_PWM0 = (PCA_PWM0 & 0x0c) | ((8-nbit)<<6)
#define PCA0_PWM_rise_int(nbit) CCAPM0 = 0x63,PCA_PWM0 = (PCA_PWM0 & 0x0c) | ((8-nbit)<<6)
#define PCA0_PWM_fall_int(nbit) CCAPM0 = 0x53,PCA_PWM0 = (PCA_PWM0 & 0x0c) | ((8-nbit)<<6)
#define PCA0_PWM_edge_int(nbit) CCAPM0 = 0x73,PCA_PWM0 = (PCA_PWM0 & 0x0c) | ((8-nbit)<<6)
#define PCA0_capture_rise() CCAPM0 = (0x20 + 1)
#define PCA0_capture_fall() CCAPM0 = (0x10 + 1)
#define PCA0_capture_edge() CCAPM0 = (0x30 + 1)
#define PCA0_16bit_Timer() CCAPM0 = (0x48 + 1)
#define PCA0_High_Pulse() CCAPM0 = (0x4C + 1)
#define PCA1_none() CCAPM1 = 0
#define PCA1_PWM(nbit) CCAPM1 = 0x42,PCA_PWM1 = (PCA_PWM1 & 0x0c) | ((8-nbit)<<6)
#define PCA1_PWM_rise_int(nbit) CCAPM1 = 0x63,PCA_PWM1 = (PCA_PWM1 & 0x0c) | ((8-nbit)<<6)
#define PCA1_PWM_fall_int(nbit) CCAPM1 = 0x53,PCA_PWM1 = (PCA_PWM1 & 0x0c) | ((8-nbit)<<6)
#define PCA1_PWM_edge_int(nbit) CCAPM1 = 0x73,PCA_PWM1 = (PCA_PWM1 & 0x0c) | ((8-nbit)<<6)
#define PCA1_capture_rise() CCAPM1 = (0x20 + 1)
#define PCA1_capture_fall() CCAPM1 = (0x10 + 1)
#define PCA1_capture_edge() CCAPM1 = (0x30 + 1)
#define PCA1_16bit_Timer() CCAPM1 = (0x48 + 1)
#define PCA1_High_Pulse() CCAPM1 = (0x4C + 1)
#define PCA2_none() CCAPM2 = 0
#define PCA2_PWM(nbit) CCAPM2 = 0x42,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA2_PWM_rise_int(nbit) CCAPM2 = 0x63,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA2_PWM_fall_int(nbit) CCAPM2 = 0x53,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA2_PWM_edge_int(nbit) CCAPM2 = 0x73,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA2_capture_rise() CCAPM2 = (0x20 + 1)
#define PCA2_capture_fall() CCAPM2 = (0x10 + 1)
#define PCA2_capture_edge() CCAPM2 = (0x30 + 1)
#define PCA2_16bit_Timer() CCAPM2 = (0x48 + 1)
#define PCA2_High_Pulse() CCAPM2 = (0x4C + 1)
#define PCA3_none() CCAPM3 = 0
#define PCA3_PWM(nbit) CCAPM3 = 0x42,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA3_PWM_rise_int(nbit) CCAPM3 = 0x63,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA3_PWM_fall_int(nbit) CCAPM3 = 0x53,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA3_PWM_edge_int(nbit) CCAPM3 = 0x73,PCA_PWM2 = (PCA_PWM2 & 0x0c) | ((8-nbit)<<6)
#define PCA3_capture_rise() CCAPM3 = (0x20 + 1)
#define PCA3_capture_fall() CCAPM3 = (0x10 + 1)
#define PCA3_capture_edge() CCAPM3 = (0x30 + 1)
#define PCA3_16bit_Timer() CCAPM3 = (0x48 + 1)
#define PCA3_High_Pulse() CCAPM3 = (0x4C + 1)
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
#define NOP1() _nop_()
#define NOP2() NOP1(),NOP1()
#define NOP3() NOP2(),NOP1()
#define NOP4() NOP3(),NOP1()
#define NOP5() NOP4(),NOP1()
#define NOP6() NOP5(),NOP1()
#define NOP7() NOP6(),NOP1()
#define NOP8() NOP7(),NOP1()
#define NOP9() NOP8(),NOP1()
#define NOP10() NOP9(),NOP1()
#define NOP11() NOP10(),NOP1()
#define NOP12() NOP11(),NOP1()
#define NOP13() NOP12(),NOP1()
#define NOP14() NOP13(),NOP1()
#define NOP15() NOP14(),NOP1()
#define NOP16() NOP15(),NOP1()
#define NOP17() NOP16(),NOP1()
#define NOP18() NOP17(),NOP1()
#define NOP19() NOP18(),NOP1()
#define NOP20() NOP19(),NOP1()
#define NOP21() NOP20(),NOP1()
#define NOP22() NOP21(),NOP1()
#define NOP23() NOP22(),NOP1()
#define NOP24() NOP23(),NOP1()
#define NOP25() NOP24(),NOP1()
#define NOP26() NOP25(),NOP1()
#define NOP27() NOP26(),NOP1()
#define NOP28() NOP27(),NOP1()
#define NOP29() NOP28(),NOP1()
#define NOP30() NOP29(),NOP1()
#define NOP31() NOP30(),NOP1()
#define NOP32() NOP31(),NOP1()
#define NOP33() NOP32(),NOP1()
#define NOP34() NOP33(),NOP1()
#define NOP35() NOP34(),NOP1()
#define NOP36() NOP35(),NOP1()
#define NOP37() NOP36(),NOP1()
#define NOP38() NOP37(),NOP1()
#define NOP39() NOP38(),NOP1()
#define NOP40() NOP39(),NOP1()
#define NOP(N) NOP##N()
#define P0n_standard(bitn) P0M1 &= ~(bitn), P0M0 &= ~(bitn)
#define P0n_push_pull(bitn) P0M1 &= ~(bitn), P0M0 |= (bitn)
#define P0n_pure_input(bitn) P0M1 |= (bitn), P0M0 &= ~(bitn)
#define P0n_open_drain(bitn) P0M1 |= (bitn), P0M0 |= (bitn)
#define P1n_standard(bitn) P1M1 &= ~(bitn), P1M0 &= ~(bitn)
#define P1n_push_pull(bitn) P1M1 &= ~(bitn), P1M0 |= (bitn)
#define P1n_pure_input(bitn) P1M1 |= (bitn), P1M0 &= ~(bitn)
#define P1n_open_drain(bitn) P1M1 |= (bitn), P1M0 |= (bitn)
#define P2n_standard(bitn) P2M1 &= ~(bitn), P2M0 &= ~(bitn)
#define P2n_push_pull(bitn) P2M1 &= ~(bitn), P2M0 |= (bitn)
#define P2n_pure_input(bitn) P2M1 |= (bitn), P2M0 &= ~(bitn)
#define P2n_open_drain(bitn) P2M1 |= (bitn), P2M0 |= (bitn)
#define P3n_standard(bitn) P3M1 &= ~(bitn), P3M0 &= ~(bitn)
#define P3n_push_pull(bitn) P3M1 &= ~(bitn), P3M0 |= (bitn)
#define P3n_pure_input(bitn) P3M1 |= (bitn), P3M0 &= ~(bitn)
#define P3n_open_drain(bitn) P3M1 |= (bitn), P3M0 |= (bitn)
#define P4n_standard(bitn) P4M1 &= ~(bitn), P4M0 &= ~(bitn)
#define P4n_push_pull(bitn) P4M1 &= ~(bitn), P4M0 |= (bitn)
#define P4n_pure_input(bitn) P4M1 |= (bitn), P4M0 &= ~(bitn)
#define P4n_open_drain(bitn) P4M1 |= (bitn), P4M0 |= (bitn)
#define P5n_standard(bitn) P5M1 &= ~(bitn), P5M0 &= ~(bitn)
#define P5n_push_pull(bitn) P5M1 &= ~(bitn), P5M0 |= (bitn)
#define P5n_pure_input(bitn) P5M1 |= (bitn), P5M0 &= ~(bitn)
#define P5n_open_drain(bitn) P5M1 |= (bitn), P5M0 |= (bitn)
#define P6n_standard(bitn) P6M1 &= ~(bitn), P6M0 &= ~(bitn)
#define P6n_push_pull(bitn) P6M1 &= ~(bitn), P6M0 |= (bitn)
#define P6n_pure_input(bitn) P6M1 |= (bitn), P6M0 &= ~(bitn)
#define P6n_open_drain(bitn) P6M1 |= (bitn), P6M0 |= (bitn)
#define P7n_standard(bitn) P7M1 &= ~(bitn), P7M0 &= ~(bitn)
#define P7n_push_pull(bitn) P7M1 &= ~(bitn), P7M0 |= (bitn)
#define P7n_pure_input(bitn) P7M1 |= (bitn), P7M0 &= ~(bitn)
#define P7n_open_drain(bitn) P7M1 |= (bitn), P7M0 |= (bitn)
#define LVD_InterruptEnable() ELVD = 1
#define LVD_InterruptDisable() ELVD = 0
#define WakeTimerDisable() WKTCH &= 0x7f
#define WakeTimerSet(scale) WKTCL = (scale) % 256,WKTCH = (scale) / 256 | 0x80
#define BUS_SPEED_1T() BUS_SPEED = 0
#define BUS_SPEED_2T() BUS_SPEED = 1
#define BUS_SPEED_4T() BUS_SPEED = 2
#define BUS_SPEED_8T() BUS_SPEED = 3
#define INT0_VECTOR 0
#define TIMER0_VECTOR 1
#define INT1_VECTOR 2
#define TIMER1_VECTOR 3
#define UART1_VECTOR 4
#define ADC_VECTOR 5
#define LVD_VECTOR 6
#define PCA_VECTOR 7
#define UART2_VECTOR 8
#define SPI_VECTOR 9
#define INT2_VECTOR 10
#define INT3_VECTOR 11
#define TIMER2_VECTOR 12
#define INT4_VECTOR 16
#define UART3_VECTOR 17
#define UART4_VECTOR 18
#define TIMER3_VECTOR 19
#define TIMER4_VECTOR 20
#define CMP_VECTOR 21
#define PWM_VECTOR 22
#define PWMFD_VECTOR 23
#define I2C_VECTOR 24
#define TRUE 1
#define FALSE 0
#define PolityLow 0
#define PolityHigh 1
#define ENABLE 1
#define DISABLE 0
#define STC15F_L2K08S2 8
#define STC15F_L2K16S2 16
#define STC15F_L2K24S2 24
#define STC15F_L2K32S2 32
#define STC15F_L2K40S2 40
#define STC15F_L2K48S2 48
#define STC15F_L2K56S2 56
#define STC15F_L2K60S2 60
#define IAP15F_L2K61S2 61
#endif