是的,首先你不能使用 libpic30.h。编译器不应该让你轻易使用它。您将需要使用 xc.h 并按照相应的 PIC32 器件进行操作。我不确定延迟功能在哪里,但那里有一个接近你想要的地方。如果找不到。在 Tick.c 中查找 TCP/IP 遗留库,其中有 32 位设备的书面延迟。
void SSTDelay10us(U32 tenMicroSecondCounter)
{
volatile S32 cyclesRequiredForEntireDelay;
int clock;
clock = 80000000;
if (clock <= 500000) //for all FCY speeds under 500KHz (FOSC <= 1MHz)
{
//10 cycles burned through this path (includes return to caller).
//For FOSC == 1MHZ, it takes 5us.
//For FOSC == 4MHZ, it takes 0.5us
//For FOSC == 8MHZ, it takes 0.25us.
//For FOSC == 10MHZ, it takes 0.2us.
}
else
{
//7 cycles burned to this point.
//We want to pre-calculate number of cycles required to delay 10us *
// tenMicroSecondCounter using a 1 cycle granule.
cyclesRequiredForEntireDelay = (S32)(clock / 100000) * tenMicroSecondCounter;
//We subtract all the cycles used up until we reach the
//while loop below, where each loop cycle count is subtracted.
//Also we subtract the 5 cycle function return.
cyclesRequiredForEntireDelay -= 24; //(19 + 5)
if (cyclesRequiredForEntireDelay <= 0)
{
// If we have exceeded the cycle count already, bail!
}
else
{
while (cyclesRequiredForEntireDelay > 0) //19 cycles used to this point.
{
cyclesRequiredForEntireDelay -= 8; //Subtract cycles burned while doing each delay stage, 8 in this case.
}
}
}
}