控制4自由度机械臂
源代码:
#include "dsc_config.h"
#include <syscalls.h>
#include "IQmathLib.h"
#include "gpio.h"
int main(void)
{
InitSysCtrl();
LEDInit();
BeepInit();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitCpuTimers();
GpioDataRegs.GPBSET.bit.GPIO32 = 1;
int v;
while(1)
{
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 2000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 18000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO32 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 2000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 18000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO33 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO33 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 1000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 19000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO32 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 1000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 19000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO33 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO33 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO41 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
//////////////////////////////////////////////////////////////////////////////
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 2000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 18000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO40 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO40 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 2000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 18000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO44 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO44 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 1000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 19000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO40 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO40 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
for ( v = 80; v > 40 ; v
{
ConfigCpuTimer(&CpuTimer1, 120, 1000);
CpuTimer1Regs.TCR.bit.TSS = 0;
ConfigCpuTimer(&CpuTimer2, 120, 19000);
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer1Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBSET.bit.GPIO44 = 1;
while(CpuTimer1Regs.TCR.bit.TIF != 1)
{
}
CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO44 = 1;
//GpioDataRegs.GPBTOGGLE.bit.GPIO41 = 1;
while(CpuTimer2Regs.TCR.bit.TIF != 1)
{
}
}
}
return 0;
}
非常棒的DSP开发板!!!
谢谢!
|