⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c_function.c

📁 在凌阳科技教育推广中心的兴趣产品智能机器人的基础上
💻 C
📖 第 1 页 / 共 2 页
字号:
//******************************************
void go(int n)
{
	int i;
	for(i=0;i<n;i++)
	{
   Set_IOB_Bit(9,1,1,1,1);
//   Set_IOB_Bit(10,1,1,1,1);
//PlayRespond(0);
PlayRespond(15);
    Set_IOB_Bit(9,1,1,0,0);
//    Set_IOB_Bit(10,1,1,0,0);
//   Set_IOB_Bit(8,1,1,1,1);
   Set_IOB_Bit(11,1,1,1,1); 
   	Delay(2000);    
	ClearWatchDog();
//PlayRespond(1);
PlayRespond(15);
   Set_IOB_Bit(9,1,1,1,1);
//    Set_IOB_Bit(10,1,1,1,1);
//   Set_IOB_Bit(8,1,1,0,0);
   Set_IOB_Bit(11,1,1,0,0);  
   	Delay(2000); 
   	ClearWatchDog();
//PlayRespond(0);	
PlayRespond(15);
    Set_IOB_Bit(9,1,1,0,0);
//    Set_IOB_Bit(10,1,1,0,0);
//   Set_IOB_Bit(8,1,1,1,1);
   Set_IOB_Bit(11,1,1,1,1);  
   	Delay(2000); 
   	ClearWatchDog();  
PlayRespond(15);
   Set_IOB_Bit(9,1,1,1,1);
//    Set_IOB_Bit(10,1,1,1,1);
 //  Set_IOB_Bit(8,1,1,0,0);
   Set_IOB_Bit(11,1,1,0,0); 
   	Delay(2000); 
   	ClearWatchDog(); 
PlayRespond(15);	
    Set_IOB_Bit(9,1,1,0,0);
//    Set_IOB_Bit(10,1,1,0,0);
//   Set_IOB_Bit(8,1,1,1,1);
   Set_IOB_Bit(11,1,1,1,1); 
   	Delay(2000); 
   	ClearWatchDog();   
PlayRespond(15);
   Set_IOB_Bit(9,1,1,1,1);
//    Set_IOB_Bit(10,1,1,1,1);
//   Set_IOB_Bit(8,1,1,0,0);
   Set_IOB_Bit(11,1,1,0,0);  
   	Delay(2000); 
   	ClearWatchDog();
PlayRespond(15);	
    Set_IOB_Bit(9,1,1,0,0);
 //   Set_IOB_Bit(10,1,1,0,0);
//   Set_IOB_Bit(8,1,1,1,1);
   Set_IOB_Bit(11,1,1,1,1); 
   	Delay(2000); 
   	ClearWatchDog();
   	 SystemInitial();
   } 	
   SystemInitial();
}

void go1(int n)
{
	int i;
	for(i=0;i<n;i++)
	{
   Set_IOB_Bit(9,1,1,1,1);
   Set_IOB_Bit(11,1,1,1,1);
//PlayRespond(0);
PlayRespond(15);
 Delay(2000);
   	 SystemInitial();
   } 	
   SystemInitial();
}
void backup(int n)
{
  	int i;
  	for(i=0;i<n;i++)
  	{
    Set_IOB_Bit(8,1,1,1,1);     
    PlayRespond(15);
    Set_IOB_Bit(8,1,1,0,0);
    Set_IOB_Bit(10,1,1,1,1);
    	Delay(2000); 
    PlayRespond(15);
    Set_IOB_Bit(8,1,1,1,1);
    Set_IOB_Bit(10,1,1,0,0);  
    	Delay(2000);   
    PlayRespond(15);
    Set_IOB_Bit(8,1,1,0,0);
    Set_IOB_Bit(10,1,1,1,1);
    	Delay(2000);  
   
     SystemInitial();  
	}
}
void turnleft(int n)
{
  	int i;
  	for(i=0;i<n;i++)
  	{
   
    Set_IOB_Bit(9,1,1,1,1);
    Set_IOB_Bit(10,1,1,1,1); 
    Delay(2000); 
    PlayRespond(15);
    SystemInitial();       
	}
}
void turnright(int n)
{
  	int i;
  	for(i=0;i<n;i++)
  	{
 
    
    Set_IOB_Bit(8,1,1,1,1);
    Set_IOB_Bit(11,1,1,1,1); 
    PlayRespond(15);
    Delay(2000); 

    SystemInitial();       

	}
}
void headturnleft(int n)
{
  	int i;
  	for(i=0;i<n;i++)
  	{
    Set_IOB_Bit(13,1,1,1,1);
    PlayRespond(20);
//     PlayRespond(5);
    Delay(200); 
    SystemInitial();       
	}
}
void headturnright(int n)
{
  	int i;
  	for(i=0;i<n;i++)
  	{
    Set_IOB_Bit(14,1,1,1,1);
    PlayRespond(20);
//     PlayRespond(5);
    Delay(200); 
    SystemInitial();       
	}
}
void shootpre(int n)
{
  	int i;
    Set_IOB_Bit(7,1,1,1,1);
  	for(i=0;i<n;i++)
  	{
 //   Set_IOB_Bit(14,1,1,1,1);
    PlayRespond(16);
//     PlayRespond(5);
    Delay(200); 
//    SystemInitial();       
	}
}
void shoot(int n)
{
  	int i;
  	for(i=0;i<n;i++)
{
    Set_IOB_Bit(15,1,1,1,1);

 //   Set_IOB_Bit(14,1,1,1,1);
    PlayRespond(17);
//     PlayRespond(5);
    Delay(200); 
           
	}
	SystemInitial();
}
void shootfive(int n)
{
  	int i,j;
  	for(i=0;i<n;i++)
{
   for(j=0;j<5;j++)
    {Set_IOB_Bit(15,1,1,1,1);

 //   Set_IOB_Bit(14,1,1,1,1);
    PlayRespond(18);
//     PlayRespond(5);
    Delay(200); 
      }     
	}
	SystemInitial();
}
//*************************************BS*****************************
void PlayRespond2(int Result)
{
	int i=0;
	BSR_StopRecognizer();
	SACM_A2000_Initial(1);
	SACM_A2000_Play(Result, 3, 3);
	while((SACM_A2000_Status()&0x0001) != 0)
	{
		SACM_A2000_ServiceLoop();
		ClearWatchDog();
		i++;
	}
	SACM_A2000_Stop();
	BSR_InitRecognizer(BSR_MIC);
	BSR_EnableCPUIndicator();	
}

void PlayRespond(int Result)
{
	int i;
	BSR_StopRecognizer();
	SACM_S480_Initial(1);
	SACM_S480_Play(Result, 3, 3);
	Set_IOB_Bit(12,1,1,1,1);
	while((SACM_S480_Status()&0x0001) != 0)
	{
		SACM_S480_ServiceLoop();
		ClearWatchDog();
	}
	SACM_S480_Stop();
	BSR_InitRecognizer(BSR_MIC);
	BSR_EnableCPUIndicator();	
	Set_IOB_Bit(12,1,1,0,0);
}

int TrainWord(int WordID, int RespondID)
{
	int res;
	PlayRespond(RespondID);
	while(1)
	{
		res = BSR_Train(WordID,BSR_TRAIN_TWICE);
		
		if(res == 0) break;
		switch(res)
		{
		case -1: 									//没有检测出声音
			PlayRespond(11);
			return -1;
		case -2: 									//需要重新训练一遍
			PlayRespond(12);
			break;
		case -3: 									//环境太吵
			PlayRespond(13);
			return -1;		
		case -4: 									//数据库满
		 	return -1;
		case -5: 									//检测出声音不同
			if(WordID == NAME_ID)	PlayRespond(14);//两次输入名称不同
			else					PlayRespond(14);//两次输入命令不同
			return -1;
		case -6: 									//序号错误
			return -1;
		}
	}
	return 0;
}

void F_FiveCommandSave(int ulAddr)
{
    int i;
	PlayRespond(0);				    		//播放开始训练的提示音
	//..........训练名称..............................
	while(TrainWord(NAME_ID,0) != 0) ;
	//..........训练第一条命令.......................
	while(TrainWord(COMMAND_ONE_ID,1) != 0) ;
	//..........训练第二条命令.......................
	while(TrainWord(COMMAND_TWO_ID,21) != 0) ;
	//..........训练第三条命令.......................
	while(TrainWord(COMMAND_THREE_ID,22) != 0) ;
	//..........训练第四条命令.......................
	while(TrainWord(COMMAND_FORE_ID,23) != 0) ;


	for(commandID=0x100;commandID<0x105;commandID++)
	{
		g_Ret=BSR_ExportSDWord(commandID);
		while(g_Ret!=0)
		g_Ret=BSR_ExportSDWord(commandID);//		
		for(i=0;i<100;i++)
		{
		    F_FlashWrite1Word(ulAddr,BSR_SDModel[i]);
	        ClearWatchDog();
			ulAddr+=1;												
		}
		}	//***********************
	}

void F_FiveCommandImport(int addr)	
{
    int jk,k,Ret,*p;
    BSR_DeleteSDGroup(0);
    p=addr;    
	for(jk=0;jk<5;jk++)
	{
		for(k=0;k<100;k++)
		{
			Ret=*p;							
			BSR_SDModel[k]=Ret;				
			p+=1;	
			ClearWatchDog();												
		}					
		g_Ret=BSR_ImportSDWord();
		while(g_Ret!=0)
		
		g_Ret=BSR_ImportSDWord();	
		ClearWatchDog();						
	}
}
void F_BSFlashTurn(int addr)
{
    int i=addr;
    BSR_DeleteSDGroup(0);							// 初始化存储器RAM
//	   F_FlashErase(addr);
//       F_FlashErase(addr+100);
//       F_FlashErase(addr+200);
//       F_FlashErase(addr+300);
//       F_FlashErase(addr+400);
	F_FiveCommandSave(addr);

//	F_FiveCommandImport(i);
	}
	
void FlashTurn()
{
   F_FlashErase(0xF700);
   F_FlashErase(0xF700+100);
   F_FlashErase(0xF700+200);
   F_FlashErase(0xF700+300);
   F_FlashErase(0xF700+400);
   F_FlashErase(0xF900);
   F_FlashErase(0xF900+100);
   F_FlashErase(0xF900+200);
   F_FlashErase(0xF900+300);
   F_FlashErase(0xF900+400);
   F_FlashErase(0xFb00);
   F_FlashErase(0xFb00+100);
   F_FlashErase(0xFb00+200);
   F_FlashErase(0xFb00+300);
   F_FlashErase(0xFb00+400);
   
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -