我自己写了一个us级的延时函数,不知道对不对?请大家帮我看看。
void delay(int N)
{
int i;
//MCGFLLCLK as clock
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1);
//open TPM0 clock gate control
SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK;
//set count value
i=48*N;//48 about 1us
TPM0_MOD = i;
//TPM counter increments on every TPM counter clock
TPM0_SC = TPM_SC_TOIE_MASK | TPM_SC_CMOD(1) ;
while(!(TPM0_SC&TPM_SC_TOF_MASK));
TPM0_SC |= TPM_SC_TOF_MASK;
TPM0_SC &= ~TPM_SC_TOIE_MASK;
} |