103 lines
3.2 KiB
C
103 lines
3.2 KiB
C
|
#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; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>Bank0
|
|||
|
#define McuBank1Sel() INSCON = 0x40; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>Bank1
|
|||
|
|
|||
|
#define McuWDTClear() RSTSTAT &= 0xF8; //<2F>忴<EFBFBD>Ź<EFBFBD>
|
|||
|
|
|||
|
#define McuFlashEn() FLASHCON |= 0x01; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MCU<43><55>Flash
|
|||
|
#define McuFlashDis() FLASHCON &= ~0x01; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MCU<43><55>Flash
|
|||
|
|
|||
|
#define McuTwiEn() ENTWI = 1; //<2F><><EFBFBD><EFBFBD>MCU<43><55>Twiģ<69><C4A3>
|
|||
|
#define McuTwiDis() ENTWI = 0; //<2F>ر<EFBFBD>MCU<43><55>Twiģ<69><C4A3>
|
|||
|
|
|||
|
#define McuPWM0En() PWM0CON |= 0x01; //PWM<57><4D><EFBFBD><EFBFBD>
|
|||
|
#define McuPWM1En() PWM1CON |= 0x01; //PWM<57><4D><EFBFBD><EFBFBD>
|
|||
|
#define McuPWM2En() PWM2CON |= 0x01; //PWM<57><4D><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
#define McuPWM0Dis() PWM0CON &= ~0x81; //<2F>ر<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪIO
|
|||
|
#define McuPWM1Dis() PWM1CON &= ~0x81; //<2F>ر<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪIO
|
|||
|
#define McuPWM2Dis() PWM2CON &= ~0x81; //<2F>ر<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪIO
|
|||
|
|
|||
|
#define IrqEn() EA = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>ʹ<EFBFBD><CAB9>λ
|
|||
|
#define IrqDis() EA = 0; //<2F>ر<EFBFBD><D8B1>ж<EFBFBD><D0B6><EFBFBD>ʹ<EFBFBD><CAB9>λ
|
|||
|
|
|||
|
#define IrqINT0En() EX0 = 1; //<2F>ⲿ<EFBFBD>ж<EFBFBD>0<EFBFBD><30><EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD>
|
|||
|
#define IrqINT0Dis() EX0 = 0;
|
|||
|
#define IrqINT0FlgClr() IE0 = 0;
|
|||
|
#define IrqINT0TrigLow() IT0 = 0;
|
|||
|
#define IrqINT0TrigFalling() IT0 = 1;
|
|||
|
|
|||
|
#define IrqINT1En() EX1 = 1; //<2F>ⲿ<EFBFBD>ж<EFBFBD>1<EFBFBD><31><EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD>
|
|||
|
#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
|