将libpic30.h与PIC32一起使用

时间:2015-05-08 15:04:18

标签: pic microchip pic32

现在我正在开发自己的PIC32端口,我需要使用libpic30.h库。我一直在阅读它并寻找PIC32(入门套件III PIC32MX450 / 470 MCU)的相同库,我认为它不存在。那对吗?如果它存在美妙!

libpic30.h代码: https://code.google.com/p/uavfirmware/source/browse/UAVFirmware/include/libpic30.h?r=1db3ec8e9015efb837b0d684c98204317ea2efd5

在这种情况下,libpic30.h与PIC32不兼容吗? 我不知道,在这种情况下,如何做到这个端口的最好方法是什么?...我很失落!

谢谢你的知识! ;)

1 个答案:

答案 0 :(得分:1)

是的,首先你不能使用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.
            }
        }
    }

}