【Start_DSC28034PNT湖人开发板免费体验】(开源)控制机械臂小游戏 - RISC-V MCU技术社区 - 电子技术论坛 - 广受欢迎的专业电子论坛
分享 收藏 返回

[文章]

【Start_DSC28034PNT湖人开发板免费体验】(开源)控制机械臂小游戏

控制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;

	/*初始化PIE 向量表*/
	InitPieVectTable();

	/*调用官方库函数,初始化CPU定时器*/
	InitCpuTimers();

GpioDataRegs.GPBSET.bit.GPIO32 = 1; 
int v;

	while(1)
	{
		for ( v = 80; v > 40 ; v-- )//32 1
		{

			/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
			ConfigCpuTimer(&CpuTimer1, 120, 2000);

			/*To start or restart the CPU-timer, set TSS to 0*/
			CpuTimer1Regs.TCR.bit.TSS = 0;

			/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
			ConfigCpuTimer(&CpuTimer2, 120, 18000);

			/*To start or restart the CPU-timer, set TSS to 0*/
			CpuTimer2Regs.TCR.bit.TSS = 0;

		CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
		GpioDataRegs.GPBSET.bit.GPIO32 = 1;
		while(CpuTimer1Regs.TCR.bit.TIF != 1)
			{

			}

		CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1; /*,GPIO32置低*/

//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1; /* GPIO32电平翻转,D400交互闪烁*/

while(CpuTimer2Regs.TCR.bit.TIF != 1)
		{
		}
		}

for ( v = 80; v > 40 ; v-- ) //33 1
		{

			/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
			ConfigCpuTimer(&CpuTimer1, 120, 2000);

			/*To start or restart the CPU-timer, set TSS to 0*/
			CpuTimer1Regs.TCR.bit.TSS = 0;

			/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
			ConfigCpuTimer(&CpuTimer2, 120, 18000);

			/*To start or restart the CPU-timer, set TSS to 0*/
			CpuTimer2Regs.TCR.bit.TSS = 0;

		CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
		GpioDataRegs.GPBSET.bit.GPIO33 = 1;
		while(CpuTimer1Regs.TCR.bit.TIF != 1)
			{

			}

		CpuTimer2Regs.TCR.bit.TIF = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO33 = 1; /*,GPIO33置低*/

//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1; /* GPIO电平翻转,D400交互闪烁*/

while(CpuTimer2Regs.TCR.bit.TIF != 1)
		{
		}
		}



		for ( v = 80; v > 40 ; v-- ) //32 2
			{

				/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
				ConfigCpuTimer(&CpuTimer1, 120, 1000);

				/*To start or restart the CPU-timer, set TSS to 0*/
				CpuTimer1Regs.TCR.bit.TSS = 0;

				/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
				ConfigCpuTimer(&CpuTimer2, 120, 19000);

				/*To start or restart the CPU-timer, set TSS to 0*/
				CpuTimer2Regs.TCR.bit.TSS = 0;

			CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
			GpioDataRegs.GPBSET.bit.GPIO32 = 1;
			while(CpuTimer1Regs.TCR.bit.TIF != 1)
				{

				}

			CpuTimer2Regs.TCR.bit.TIF = 1;
	GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1; /*,GPIO43置低*/

	//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1; /* GPIO41电平翻转,D400交互闪烁*/

	while(CpuTimer2Regs.TCR.bit.TIF != 1)
			{
			}
			}




		for ( v = 80; v > 40 ; v-- )//33 2
			{

				/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
				ConfigCpuTimer(&CpuTimer1, 120, 1000);

				/*To start or restart the CPU-timer, set TSS to 0*/
				CpuTimer1Regs.TCR.bit.TSS = 0;

				/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
				ConfigCpuTimer(&CpuTimer2, 120, 19000);

				/*To start or restart the CPU-timer, set TSS to 0*/
				CpuTimer2Regs.TCR.bit.TSS = 0;

			CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
			GpioDataRegs.GPBSET.bit.GPIO33 = 1;
			while(CpuTimer1Regs.TCR.bit.TIF != 1)
				{

				}

			CpuTimer2Regs.TCR.bit.TIF = 1;
	GpioDataRegs.GPBCLEAR.bit.GPIO33 = 1; /*,GPIO33置低*/

	//GpioDataRegs.GPBTOGGLE.bit.GPIO41 = 1; /* GPIO41电平翻转,D400交互闪烁*/

	while(CpuTimer2Regs.TCR.bit.TIF != 1)
			{
			}
			}


//////////////////////////////////////////////////////////////////////////////
		for ( v = 80; v > 40 ; v-- )//40 1
				{

					/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
					ConfigCpuTimer(&CpuTimer1, 120, 2000);

					/*To start or restart the CPU-timer, set TSS to 0*/
					CpuTimer1Regs.TCR.bit.TSS = 0;

					/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
					ConfigCpuTimer(&CpuTimer2, 120, 18000);

					/*To start or restart the CPU-timer, set TSS to 0*/
					CpuTimer2Regs.TCR.bit.TSS = 0;

				CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
				GpioDataRegs.GPBSET.bit.GPIO40 = 1;
				while(CpuTimer1Regs.TCR.bit.TIF != 1)
					{

					}

				CpuTimer2Regs.TCR.bit.TIF = 1;
		GpioDataRegs.GPBCLEAR.bit.GPIO40 = 1; /*,GPIO32置低*/

		//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1; /* GPIO32电平翻转,D400交互闪烁*/

		while(CpuTimer2Regs.TCR.bit.TIF != 1)
				{
				}
				}

		for ( v = 80; v > 40 ; v-- ) //44 1
				{

					/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
					ConfigCpuTimer(&CpuTimer1, 120, 2000);

					/*To start or restart the CPU-timer, set TSS to 0*/
					CpuTimer1Regs.TCR.bit.TSS = 0;

					/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
					ConfigCpuTimer(&CpuTimer2, 120, 18000);

					/*To start or restart the CPU-timer, set TSS to 0*/
					CpuTimer2Regs.TCR.bit.TSS = 0;

				CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
				GpioDataRegs.GPBSET.bit.GPIO44 = 1;
				while(CpuTimer1Regs.TCR.bit.TIF != 1)
					{

					}

				CpuTimer2Regs.TCR.bit.TIF = 1;
		GpioDataRegs.GPBCLEAR.bit.GPIO44 = 1; /*,GPIO33置低*/

		//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1; /* GPIO电平翻转,D400交互闪烁*/

		while(CpuTimer2Regs.TCR.bit.TIF != 1)
				{
				}
				}



				for ( v = 80; v > 40 ; v-- ) //40 2
					{

						/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
						ConfigCpuTimer(&CpuTimer1, 120, 1000);

						/*To start or restart the CPU-timer, set TSS to 0*/
						CpuTimer1Regs.TCR.bit.TSS = 0;

						/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
						ConfigCpuTimer(&CpuTimer2, 120, 19000);

						/*To start or restart the CPU-timer, set TSS to 0*/
						CpuTimer2Regs.TCR.bit.TSS = 0;

					CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
					GpioDataRegs.GPBSET.bit.GPIO40 = 1;
					while(CpuTimer1Regs.TCR.bit.TIF != 1)
						{

						}

					CpuTimer2Regs.TCR.bit.TIF = 1;
			GpioDataRegs.GPBCLEAR.bit.GPIO40 = 1; /*,GPIO43置低*/

			//GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1; /* GPIO41电平翻转,D400交互闪烁*/

			while(CpuTimer2Regs.TCR.bit.TIF != 1)
					{
					}
					}




				for ( v = 80; v > 40 ; v-- )//44 2
					{

						/*定时器1初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
						ConfigCpuTimer(&CpuTimer1, 120, 1000);

						/*To start or restart the CPU-timer, set TSS to 0*/
						CpuTimer1Regs.TCR.bit.TSS = 0;

						/*定时器2初始化,第二个参数为CPU SYSCLK = 120M, 第三个参数为设定的周期,us单位*/
						ConfigCpuTimer(&CpuTimer2, 120, 19000);

						/*To start or restart the CPU-timer, set TSS to 0*/
						CpuTimer2Regs.TCR.bit.TSS = 0;

					CpuTimer1Regs.TCR.bit.TIF = 1; /*clear flag*/
					GpioDataRegs.GPBSET.bit.GPIO44 = 1;
					while(CpuTimer1Regs.TCR.bit.TIF != 1)
						{

						}

					CpuTimer2Regs.TCR.bit.TIF = 1;
			GpioDataRegs.GPBCLEAR.bit.GPIO44 = 1; /*,GPIO33置低*/

			//GpioDataRegs.GPBTOGGLE.bit.GPIO41 = 1; /* GPIO41电平翻转,D400交互闪烁*/

			while(CpuTimer2Regs.TCR.bit.TIF != 1)
					{
					}
					}





	}

	return 0;
}

4.jpg

屏幕截图 2023-07-20 223418.jpg

屏幕截图 2023-07-20 223502.jpg

非常棒的DSP开发板!!!
谢谢!

更多回帖

×
发帖