CH552/projects/LCD/usr/Timer.h

94 lines
4.3 KiB
C
Raw Normal View History

2018-10-17 05:37:36 +02:00
// #define T0_INT 1 //T<>жϿ<D0B6><CFBF><EFBFBD>
//#define T1_INT 1
#define T2_INT 1
// #define T2_CAP 1
extern UINT8 Tim_3ms;
extern UINT8 FLAG;
extern UINT16 Cap[8];
//CH554 Timer0ʱ<30><CAB1>ѡ<EFBFBD><D1A1>
//bTMR_CLKͬʱӰ<CAB1><D3B0>Timer0&1&2,ʹ<><CAB9>ʱҪע<D2AA><D7A2> (<28><><EFBFBD><EFBFBD>ʱʹ<CAB1>ñ<EFBFBD>׼ʱ<D7BC><CAB1>)
#define mTimer0Clk12DivFsys( ) (T2MOD &= ~bT0_CLK) //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys/12 T0<54><30>׼ʱ<D7BC><CAB1>
#define mTimer0ClkFsys( ) (T2MOD |= bTMR_CLK | bT0_CLK) //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys
#define mTimer0Clk4DivFsys( ) (T2MOD &= ~bTMR_CLK;T2MOD |= bT0_CLK) //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys/4
#define mTimer0CountClk( ) (TMOD |= bT0_CT) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,T0<54><30><EFBFBD>ŵ<EFBFBD><C5B5>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD>Ч
//CH554 Timer0 <20><>ʼ(SS=1)/<2F><><EFBFBD><EFBFBD>(SS=0)
#define mTimer0RunCTL( SS ) (TR0 = SS ? START : STOP)
#define mTimer1Clk12DivFsys( ) (T2MOD &= ~bT1_CLK) //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys/12 T1<54><31>׼ʱ<D7BC><CAB1>
#define mTimer1ClkFsys( ) (T2MOD |= bTMR_CLK | bT1_CLK) //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys
#define mTimer1Clk4DivFsys( ) (T2MOD &= ~bTMR_CLK;T2MOD |= bT1_CLK) //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys/4
#define mTimer1CountClk( ) (TMOD |= bT1_CT) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,T0<54><30><EFBFBD>ŵ<EFBFBD><C5B5>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD>Ч
//CH554 Timer1 <20><>ʼ(SS=1)/<2F><><EFBFBD><EFBFBD>(SS=0)
#define mTimer1RunCTL( SS ) (TR1 = SS ? START : STOP)
#define mTimer2Clk12DivFsys( ) {T2MOD &= ~(bTMR_CLK | bT2_CLK);C_T2 = 0;} //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys/12 T2<54><32>׼ʱ<D7BC><CAB1>
#define mTimer2ClkFsys( ) {T2MOD |= (bTMR_CLK | bT2_CLK);C_T2=0;} //<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys
#define mTimer2Clk4DivFsys( ) {T2MOD &= ~bTMR_CLK;T2MOD |= bT2_CLK;C_T2 = 0;}//<2F><>ʱ<EFBFBD><CAB1><><CAB1>=Fsys/4
#define mTimer2CountClk( ) {C_T2 = 1;} //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,T2<54><32><EFBFBD>ŵ<EFBFBD><C5B5>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD>Ч
//CH554 Timer2 <20><>ʼ(SS=1)/<2F><><EFBFBD><EFBFBD>(SS=0)
#define mTimer2RunCTL( SS ) {TR2 = SS ? START : STOP;}
#define mTimer2OutCTL( ) (T2MOD |= T2OE) //T2<54><32><EFBFBD><EFBFBD> Ƶ<><C6B5>TF2/2
#define CAP1Alter( ) (PIN_FUNC |= bT2_PIN_X;) //CAP1<50><31>P10 ӳ<>䵽P14
#define CAP2Alter( ) (PIN_FUNC |= bT2EX_PIN_X;) //CAP2<50><32>P11 ӳ<><D3B3>RST
/*******************************************************************************
* Function Name : mTimer_x_ModInit(UINT8 x ,UINT8 mode)
* Description : CH554<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* Input : UINT8 mode,Timerģʽѡ<EFBFBD><EFBFBD>
0<EFBFBD><EFBFBD>ģʽ0<EFBFBD><EFBFBD>13λ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TLn<EFBFBD>ĸ<EFBFBD>3λ<EFBFBD><EFBFBD>Ч
1<EFBFBD><EFBFBD>ģʽ1<EFBFBD><EFBFBD>16λ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
2<EFBFBD><EFBFBD>ģʽ2<EFBFBD><EFBFBD>8λ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
3<EFBFBD><EFBFBD>ģʽ3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8λ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> Timer0
3<EFBFBD><EFBFBD>ģʽ3<EFBFBD><EFBFBD>Timer1ֹͣ
UINT8 x <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> 0 1 2
* Output : None
* Return : <EFBFBD>ɹ<EFBFBD> SUCCESS
ʧ<EFBFBD><EFBFBD> FAIL
*******************************************************************************/
UINT8 mTimer_x_ModInit(UINT8 x ,UINT8 mode);
/*******************************************************************************
* Function Name : mTimer_x_SetData(UINT8 x,UINT16 dat)
* Description : CH554Timer
* Input : UINT16 dat;<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
UINT8 x <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> 0 1 2
* Output : None
* Return : None
*******************************************************************************/
void mTimer_x_SetData(UINT8 x,UINT16 dat);
/*******************************************************************************
* Function Name : CAP2Init(UINT8 mode)
* Description : CH554<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2 T2EX<EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD>׽<EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><EFBFBD>
UINT8 mode,<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD>׽ģʽѡ<EFBFBD><EFBFBD>
0:T2ex<EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>
1:T2ex<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><EFBFBD>
3:T2ex<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CAP2Init(UINT8 mode);
/*******************************************************************************
* Function Name : CAP1Init(UINT8 mode)
* Description : CH554<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2 T2<EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD>׽<EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><EFBFBD>T2
UINT8 mode,<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD>׽ģʽѡ<EFBFBD><EFBFBD>
0:T2ex<EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>
1:T2ex<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><EFBFBD>
3:T2ex<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CAP1Init(UINT8 mode);