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

📄 main.c

📁 在凌阳科技教育推广中心的兴趣产品智能机器人的基础上
💻 C
字号:
#include "bsrsd.h"
#include "hardware.h"
#define forever for(;;)
#define NAME_ID 		0x100
#define COMMAND_ONE_ID 	0x101
#define COMMAND_TWO_ID 	0x102
#define COMMAND_THREE_ID 	0x103
#define COMMAND_FORE_ID 	0x104
#define COMMAND_FIVE_ID 	0x105
#define	P_IOA_Data 				(volatile unsigned int *)0x7000   
#define P_IOA_Buffer 			(volatile unsigned int *)0x7001
#define P_IOA_Dir 				(volatile unsigned int *)0x7002
extern int gActivated;
extern int PlayFlag;

main()
{
    int random_no=0,res,timeCnt=0,BSTeam=0,i,FirstFlag=0,*p,danceflag=0;
	SystemInitial();
/* while(1)
 {
	PlayRespond(30);
	PlayRespond(31);
	PlayRespond(32);
	PlayRespond(33);
	PlayRespond(34);
	PlayRespond(35);
	PlayRespond(36);
	PlayRespond(37);
	PlayRespond(38);	 
 }*/
	p=0xfd00;
	FirstFlag=*p;
	if(FirstFlag==0xffff)
	{
	FlashTurn();
    F_BSFlashTurn(0xf700);
    PlayRespond(6);
    F_BSFlashTurn(0xf900);
    PlayRespond(4);
    PlayRespond(5);
    F_BSFlashTurn(0xfb00);
	PlayRespond(11);
	PlayRespond(12);
	PlayRespond(13);
	PlayRespond(14);
    FirstFlag=0xaaaa;
	F_FlashWrite1Word(0xfd00,0xaaaa);
    }
    F_FiveCommandImport(0xf700);
    BSTeam=0;
loop:
	BSR_InitRecognizer(BSR_MIC);		    		//辨识器初始化
	PlayRespond(11);
	PlayRespond(12);
	PlayRespond(13);
	PlayRespond(14);
	PlayRespond(4);
	PlayRespond(5);	
	while(1)
	{
	    ClearWatchDog();        
        random_no ++;
		if(random_no >= 3) random_no = 0;
		res = BSR_GetResult();		
		if(res > 0)							//识别出命令
		{
			  
			if(gActivated)
			{
				timeCnt = 0;
				switch(res)
				{
				case NAME_ID:
				   switch(BSTeam)
				  {
				  case 0:
				    PlayRespond(4);
                    PlayRespond(5);					    
				    PlayRespond(6);			
					ClearWatchDog();
					break;
				  case 1:
				    PlayRespond(4);
                    PlayRespond(5);	
				    break;
				  case 2: 
			        PlayRespond(2);
			        PlayRespond(3);
                	
				    break;
				   break;
				  }
					break;
				case COMMAND_ONE_ID:
				   switch(BSTeam)
				  {
				  case 0:
                   F_FiveCommandImport(0xf900);
                    BSTeam=1;
                    goto loop;		
					ClearWatchDog();
				  case 1:
					PlayRespond(19);				    
				    go(1);

	    
				    break;
				  case 2: 
         			headturnleft(1);
				    break;
				   break;
				  }
				    ClearWatchDog();
					gActivated = 0;
					break;
				case COMMAND_TWO_ID:
				   switch(BSTeam)
				  {
				  case 0:
					PlayRespond(11);
					PlayRespond(12);
					PlayRespond(13);
					PlayRespond(14);
				    F_FiveCommandImport(0xfb00);
                    BSTeam=2;
                    goto loop;		
					ClearWatchDog();
					break;
				  case 1:
					PlayRespond(19);
				    backup(1);
				    break;
				  case 2: 
					headturnright(1);
				   break;
				  }
				ClearWatchDog();
					gActivated = 0;
					break;
				case COMMAND_THREE_ID:
				   switch(BSTeam)
				  {
				  case 0:
				    F_Dance(2);	         		
					ClearWatchDog();
					break;
				  case 1:
                    turnleft(1);
				    break;
				  case 2: 
					shootpre(10);
					shoot(1);
				   break;
				  }
					ClearWatchDog();
				    gActivated = 0;
				    break;
				case COMMAND_FORE_ID:
				   switch(BSTeam)
				  {
				  case 0:
//					if(danceflag==1)
//					{
					F_Dance1(1);
					F_Dance2(1);
//					danceflag=0;
//					}	
//					else
//					{
//					F_Dance1(1);
//					F_Dance3(2);
//					danceflag=1;
//					}	
					ClearWatchDog();
					break;
				  case 1:
                    turnright(1);
				    F_FiveCommandImport(0xf700);
                    BSTeam=0;
                    goto loop;
                    break;	
				  case 2: 
					shootpre(20);
					shootfive(3);

				    F_FiveCommandImport(0xf700);
                    BSTeam=0;
                    goto loop;	
				   break;
				  }
				ClearWatchDog();
				    gActivated = 0;
				    break; 
			   }				
			}
			else		
			{
				if(res == NAME_ID)
				{
					ClearWatchDog(); 
					PlayRespond(4);				
					gActivated = 1;
					timeCnt = 0;
				}
		
			}	
		}
		else if (gActivated)
		{
		
			if (++timeCnt > 450)			//超出定时
			{
				ClearWatchDog(); 
								
				gActivated = 0;
				timeCnt = 0;
			}
		}
	 i=*P_IOA_Data;
	 i=i&0x0004;
	 if(i==0x0004)  F_FlashErase(0xfd00); 	
	}
	forever;
 
}

⌨️ 快捷键说明

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