#ifndef __MCU_LIB_H #define __MCU_LIB_H #define RAM_CHECK_DATA 0x5A #define TIM_CLK_24MHz 0x00 #define TIM_CLK_12MHz 0x11 #define TIM_CLK_6MHz 0x22 #define TIM_CLK_2MHz 0x33 #define TIM_CLK_128KHz 0x44 #define TIM_CLK_32KHz 0x55 #define MCU_CLK_24MHz 0x00 #define MCU_CLK_12MHz 0x20 #define MCU_CLK_6MHz 0x40 #define MCU_CLK_2MHz 0x60 #define MCU_CLK_128KHz 0x80 #define MCU_CLK_32KHz 0xA0 #define McuBank0Sel() INSCON = 0x00; //定义寄存器的Bank0 #define McuBank1Sel() INSCON = 0x40; //定义寄存器的Bank1 #define McuWDTClear() RSTSTAT &= 0xF8; //清看门狗 #define McuFlashEn() FLASHCON |= 0x01; //允许访问MCU的Flash #define McuFlashDis() FLASHCON &= ~0x01; //不允许访问MCU的Flash #define McuTwiEn() ENTWI = 1; //开启MCU的Twi模块 #define McuTwiDis() ENTWI = 0; //关闭MCU的Twi模块 #define McuPWM0En() PWM0CON |= 0x01; //PWM输出 #define McuPWM1En() PWM1CON |= 0x01; //PWM输出 #define McuPWM2En() PWM2CON |= 0x01; //PWM输出 #define McuPWM0Dis() PWM0CON &= ~0x81; //关闭PWM并配置为IO #define McuPWM1Dis() PWM1CON &= ~0x81; //关闭PWM并配置为IO #define McuPWM2Dis() PWM2CON &= ~0x81; //关闭PWM并配置为IO #define IrqEn() EA = 1; //开启中断总使能位 #define IrqDis() EA = 0; //关闭中断总使能位 #define IrqINT0En() EX0 = 1; //外部中断0相关控制 #define IrqINT0Dis() EX0 = 0; #define IrqINT0FlgClr() IE0 = 0; #define IrqINT0TrigLow() IT0 = 0; #define IrqINT0TrigFalling() IT0 = 1; #define IrqINT1En() EX1 = 1; //外部中断1相关控制 #define IrqINT1Dis() EX1 = 0; #define IrqINT1FlgClr() IE1 = 0; #define IrqINT1TrigLow() IT1 = 0; #define IrqINT1TrigFalling() IT1 = 1; #define INT4_EXS40 0x01 #define INT4_EXS41 0x02 #define INT4_EXS42 0x04 #define INT4_EXS43 0x08 #define INT4_EXS44 0x10 #define INT4_EXS45 0x20 #define INT4_EXS46 0x40 #define INT4_EXS47 0x80 #define IrqINT4En() IEN1 |= 0x08; #define IrqINT4Dis() IEN1 &= ~0x08; #define IrqINT4xChEn(INT4x) IENC |= INT4x; #define IrqINT4xChDis(INT4x) IENC &= ~INT4x; #define IrqINT4FlgClr() EXF1 = 0; #define INT4_TRIG_LOW 0x00 #define INT4_TRIG_FALLING 0x40 #define INT4_TRIG_RISING 0x80 #define INT4_TRIG_FALL_RISE 0xC0 #define IrqINT4Trig(INT4Trig) EXF0 |= INT4Trig; #define IrqTimer3En() ET3 = 1; #define IrqTimer3Dis() ET3 = 0; #define IrqTimer3FlgClr() _push_(INSCON);McuBank1Sel();TF3 = 0;_pop_(INSCON); #define IrqUart0En() ES0 = 1; #define IrqUart0Dis() ES0 = 0; #define IrqUart1En() IEN2 |= 0x01; #define IrqUart1Dis() IEN2 &= 0xFE; #define IrqUart2En() IEN2 |= 0x02; #define IrqUart2Dis() IEN2 &= 0xFD; extern void ClrRam(void); extern void MemorySet(U8 xdata *pt, U8 setval, U8 length); extern void MemoryCopy(U8 xdata *source, U8 xdata *target, U8 length); extern void McuTimer3Set(U8 ClkSource, U16 XmS); extern void McuClockSet(U8 SysClock); extern void McuPWM0Set(U16 PwmFreq, U8 DutyRatio); extern void McuPWM1Set(U16 PwmFreq, U8 DutyRatio); extern void McuPWM2Set(U16 PwmFreq, U8 DutyRatio); extern void Delay1ms(U8 delaycnt); extern void McuIntoIdle(void); extern void McuIntoPD(void); extern void SystemResetProcess(void); extern BOOL RamCheckProcess(void); #endif