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

📄 app.s

📁 易于atmage128和ucos的手动机器人控制程序。
💻 S
📖 第 1 页 / 共 5 页
字号:
	clr R17
	xcall _OSMboxCreate
	sts _time_Box+1,R17
	sts _time_Box,R16
; 	motor_l_Box		  =OSMboxCreate((void*)0);		  //建立左电机消息邮箱
	clr R16
	clr R17
	xcall _OSMboxCreate
	sts _motor_l_Box+1,R17
	sts _motor_l_Box,R16
; 	motor_r_Box		  =OSMboxCreate((void*)0);		  //建立右电机消息邮箱
	clr R16
	clr R17
	xcall _OSMboxCreate
	sts _motor_r_Box+1,R17
	sts _motor_r_Box,R16
; 	motor_m_Box		  =OSMboxCreate((void*)0);		  //建立中电机消息邮箱
	clr R16
	clr R17
	xcall _OSMboxCreate
	sts _motor_m_Box+1,R17
	sts _motor_m_Box,R16
; 	motor_t_Box		  =OSMboxCreate((void*)0);		  //建立中电机消息邮箱
	clr R16
	clr R17
	xcall _OSMboxCreate
	sts _motor_t_Box+1,R17
	sts _motor_t_Box,R16
; 	
; 	OSTaskCreate(Task_Start, (void *)0, (OS_STK *)&TaskStartStk[OS_TASK_STK_SIZE - 1], 0);
	clr R2
	std y+2,R2
	ldi R24,<_TaskStartStk+255
	ldi R25,>_TaskStartStk+255
	std y+0,R24
	std y+1,R25
	clr R18
	clr R19
	ldi R16,<PL_Task_Start
	ldi R17,>PL_Task_Start
	xcall _OSTaskCreate
; 	OSStart();                                  	  //Start multitasking (i.e. give control to uC/OS-II) 
	xcall _OSStart
; }
L1:
	adiw R28,3
	.dbline 0 ; func end
	ret
;   cpu_usage_10 -> R20,R21
;    cpu_usage_1 -> R20,R21
;          p_arg -> R22,R23
	.even
_Task_Start:
	xcall push_gset2
	movw R22,R16
	sbiw R28,3
; 
; /*
; *********************************************************************************************************
; *                                          STARTUP TASK
; 起始任务,主任务
; 手柄的扫描,模式切换,键值改变判别并给Task_action发送消息
; *********************************************************************************************************
; */
; 
; static void  Task_Start (void *p_arg)
; {
;     INT16S cpu_usage_1=0x0000,cpu_usage_10=0x0000;	  //cpu使用百分率 个位和十位
	clr R20
	clr R21
;     p_arg = p_arg;                                    //Prevent compiler warnings                         
; 	Init_TC();									 	  //定时计数器初始化           
	xcall _Init_TC
;     IO_Init();                                 	 	  // Initialize the I/Os                            
	xcall _IO_Init
;     intit_LED();								 	  //数码管初始化
	xcall _intit_LED
; 	OSStatInit();									  //任务统计初始化	
	xcall _OSStatInit
; 	OSTaskCreate(Task_time_show, (void *)0, (OS_STK *)&Task_time_show_Stk[OS_TASK_STK_SIZE - 1], 2); //创建时间显示任务 优先级2
	ldi R24,2
	std y+2,R24
	ldi R24,<_Task_time_show_Stk+255
	ldi R25,>_Task_time_show_Stk+255
	std y+0,R24
	std y+1,R25
	clr R18
	clr R19
	ldi R16,<PL_Task_time_show
	ldi R17,>PL_Task_time_show
	xcall _OSTaskCreate
; 	OSTaskCreate(motor_move_l, (void *)0, (OS_STK *)&motor_move_l_Stk[OS_TASK_STK_SIZE - 1], 3); //左电机行进任务 优先级3
	ldi R24,3
	std y+2,R24
	ldi R24,<_motor_move_l_Stk+255
	ldi R25,>_motor_move_l_Stk+255
	std y+0,R24
	std y+1,R25
	clr R18
	clr R19
	ldi R16,<PL_motor_move_l
	ldi R17,>PL_motor_move_l
	xcall _OSTaskCreate
; 	OSTaskCreate(motor_move_r, (void *)0, (OS_STK *)&motor_move_r_Stk[OS_TASK_STK_SIZE - 1], 4); //左电机行进任务 优先级3
	ldi R24,4
	std y+2,R24
	ldi R24,<_motor_move_r_Stk+255
	ldi R25,>_motor_move_r_Stk+255
	std y+0,R24
	std y+1,R25
	clr R18
	clr R19
	ldi R16,<PL_motor_move_r
	ldi R17,>PL_motor_move_r
	xcall _OSTaskCreate
; 	OSTaskCreate(motor_move_m, (void *)0, (OS_STK *)&motor_move_m_Stk[OS_TASK_STK_SIZE - 1], 5); //左电机行进任务 优先级3
	ldi R24,5
	std y+2,R24
	ldi R24,<_motor_move_m_Stk+255
	ldi R25,>_motor_move_m_Stk+255
	std y+0,R24
	std y+1,R25
	clr R18
	clr R19
	ldi R16,<PL_motor_move_m
	ldi R17,>PL_motor_move_m
	xcall _OSTaskCreate
; 	OSTaskCreate(motor_move_t, (void *)0, (OS_STK *)&motor_move_t_Stk[OS_TASK_STK_SIZE - 1], 6); //左电机行进任务 优先级3
	ldi R24,6
	std y+2,R24
	ldi R24,<_motor_move_t_Stk+255
	ldi R25,>_motor_move_t_Stk+255
	std y+0,R24
	std y+1,R25
	clr R18
	clr R19
	ldi R16,<PL_motor_move_t
	ldi R17,>PL_motor_move_t
	xcall _OSTaskCreate
; 	//开电后手抓全开-----------
; 	hand_cy[0]=hand_st_1[0];
	lds R2,_hand_st_1
	lds R3,_hand_st_1+1
	sts _hand_cy+1,R3
	sts _hand_cy,R2
; 	hand_cy[1]=hand_st_1[1];
	lds R2,_hand_st_1+2
	lds R3,_hand_st_1+2+1
	sts _hand_cy+2+1,R3
	sts _hand_cy+2,R2
; 	hand_cy[2]=hand_st_1[2];
	lds R2,_hand_st_1+4
	lds R3,_hand_st_1+4+1
	sts _hand_cy+4+1,R3
	sts _hand_cy+4,R2
; 	hand_cy[3]=hand_st_1[3];
	lds R2,_hand_st_1+6
	lds R3,_hand_st_1+6+1
	sts _hand_cy+6+1,R3
	sts _hand_cy+6,R2
	xjmp L16
L15:
; 	while (TRUE) 
; 	{ 
;         scan();	 								 	  //手柄信号扫描
	xcall _scan
; 
; //系统复位---------------------------------------------------------------------------
; 	if(rx_chr[1][0][1]&((~rx_chr[2][4][0])&rx_chr[2][4][1]))	 	  //复位键按下(防颤)
	lds R2,_rx_chr+32+8+1
	lds R3,_rx_chr+32+8
	com R3
	and R3,R2
	lds R2,_rx_chr+16+1
	and R2,R3
	breq L18
; 		{
; 			robot_model_key=1;	   				  //复位打开
	ldi R24,1
	sts _robot_model_key,R24
; 			OSTaskDel(2);							  //删除时间任务
	ldi R16,2
	xcall _OSTaskDel
; 			//LED_send_16b(0x054e);	   			  //显示刷新
; 		}
L18:
; 	
; 	if(robot_model_key!=0)reset_action();	      //如果复位模式
	lds R2,_robot_model_key
	tst R2
	breq L27
	xcall _reset_action
	xjmp L28
L27:
; 	else Task_action();  				 	   	  //否则正常运行
	xcall _Task_action
L28:
; 
; 
; //手柄信号改变检查开始计时------------------------------------------------------------------------
; 
; 		 if(((rx_chr_b[1][1]&0xd0)!=(rx_chr_b[1][0]&0xd0))||(rx_chr_b[2][1]!=rx_chr_b[2][0]))
	lds R24,_rx_chr_b+2
	andi R24,208
	lds R25,_rx_chr_b+2+1
	andi R25,208
	cp R25,R24
	brne L37
	lds R2,_rx_chr_b+4
	lds R3,_rx_chr_b+4+1
	cp R3,R2
	breq L29
L37:
; 		  {
; 		     *time_key_ptr=time_key_msg;					  
	lds R2,_time_key_msg
	lds R3,_time_key_msg+1
	lds R30,_time_key_ptr
	lds R31,_time_key_ptr+1
	std z+0,R2
	std z+1,R3
; 		   	 OSMboxPost(time_Box,time_key_ptr);		  //发送时间函数邮件
	movw R18,R30
	lds R16,_time_Box
	lds R17,_time_Box+1
	xcall _OSMboxPost
; 		  }
L29:
	ldi R16,5
	ldi R17,0
	xcall _OSTimeDly
L16:
	xjmp L15
X0:
; 		  
; 		  	
; //cpu百分率显示----------------------------------------------------------------------------------
;    /*
;         cpu_usage_1   =(OSCPUUsage%10)|0x0800;		  //个位 			
; 		cpu_usage_10  =(OSCPUUsage/10)|0x0700;		  //十位
; 		LED_send_16b(cpu_usage_1);
; 		LED_send_16b(cpu_usage_10);
; 		OCR1B=0x03ff;
; 		*/
; //延时0.1s--------------------------------------------------------------------------	
; 
;      OSTimeDly(OS_TICKS_PER_SEC/10);				  // 0.1s
; 	 }
; 	 
;     }
L3:
	adiw R28,3
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.even
_Task_action:
	xcall push_gset2
	sbiw R28,3
; /*
; *********************************************************************************************************
; *                                              action 
; 										控制机器人对于手柄响应的任务
; *********************************************************************************************************
; */
; 
; static void  Task_action(void)
; {
; 
; //时间复位--------------
;  		 if((~rx_chr[1][0][0])&rx_chr[1][0][1])
	lds R2,_rx_chr+16+1
	lds R3,_rx_chr+16
	com R3
	and R3,R2
	breq L39
; 		 {
; 		     OSTaskDel(2);	
	ldi R16,2
	xcall _OSTaskDel
; 			 OSTaskCreate(Task_time_show, (void *)0, (OS_STK *)&Task_time_show_Stk[OS_TASK_STK_SIZE - 1], 2); //创建时间显示任务 优先级2
	ldi R24,2
	std y+2,R24
	ldi R24,<_Task_time_show_Stk+255
	ldi R25,>_Task_time_show_Stk+255
	std y+0,R24
	std y+1,R25
	clr R18
	clr R19
	ldi R16,<PL_Task_time_show
	ldi R17,>PL_Task_time_show
	xcall _OSTaskCreate
; 		 }
L39:
; 
; 
; //速度切换部分--------------------------------------------------------
; 
; 		  if((~rx_chr[1][7][0])&rx_chr[1][7][1])     // 切换到正常速度
	lds R2,_rx_chr+16+14+1
	lds R3,_rx_chr+16+14
	com R3
	and R3,R2
	breq L45
; 		  {
; 		     if(speed_model==1)  speed_model=0;      //如果是低速档
	lds R24,_speed_model
	cpi R24,1
	brne L52
	clr R2
	sts _speed_model,R2
	xjmp L53
L52:
; 			 else if(speed_model==0) speed_model=1;	 //如果是高速速档 
	lds R2,_speed_model
	tst R2
	brne L54
	ldi R24,1
	sts _speed_model,R24
L54:
L53:
; 		  }
L45:
; 		  
; 		  if(speed_model==0) 
	lds R2,_speed_model
	tst R2
	brne L56
; 		  {
; 		      LED_send_16b(0x0500);	 //速度模式0  显示
	ldi R16,1280
	ldi R17,5
	xcall _LED_send_16b
; 		  	  LED_send_16b(0x0600);
	ldi R16,1536
	ldi R17,6
	xcall _LED_send_16b
; 			  LED_send_16b(0x0700);
	ldi R16,1792
	ldi R17,7
	xcall _LED_send_16b
; 			  LED_send_16b(0x0800);
	ldi R16,2048
	ldi R17,8
	xcall _LED_send_16b
; 		 }
	xjmp L57
L56:
; 		  else if(speed_model==1)
	lds R24,_speed_model
	cpi R24,1
	brne L58
; 		  {
; 		      LED_send_16b(0x0501);//速度模式1  显示
	ldi R16,1281
	ldi R17,5
	xcall _LED_send_16b
; 			  LED_send_16b(0x0601);
	ldi R16,1537
	ldi R17,6
	xcall _LED_send_16b
; 			  LED_send_16b(0x0701);
	ldi R16,1793
	ldi R17,7
	xcall _LED_send_16b
; 			  LED_send_16b(0x0801);
	ldi R16,2049
	ldi R17,8
	xcall _LED_send_16b
; 		  }
L58:
L57:
; //行走部分(按2个轮子)------------------------------------------------------------------
; 
; 		  
; 		  if(rx_chr[1][4][1]&rx_chr[2][4][1])		  // up 3
	lds R2,_rx_chr+32+8+1
	lds R3,_rx_chr+16+8+1
	and R3,R2
	breq L60
; 		  	{
; 				motor_l_msg=0;					  //1 正 0 反 2 停
	clr R2
	clr R3
	sts _motor_l_msg+1,R3
	sts _motor_l_msg,R2
; 				motor_r_msg=0;
	sts _motor_r_msg+1,R3
	sts _motor_r_msg,R2
; 				motor_m_msg=0;
	sts _motor_m_msg+1,R3
	sts _motor_m_msg,R2
; 
; 			}
	xjmp L61
L60:
; 		  else if(rx_chr[1][6][1]&rx_chr[2][6][1])	  //dawn x
	lds R2,_rx_chr+32+12+1
	lds R3,_rx_chr+16+12+1
	and R3,R2
	breq L68
; 		  	{
; 			    motor_l_msg=1;
	ldi R24,1
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				motor_r_msg=1;
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				motor_m_msg=1;
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 
; 			}
	xjmp L69
L68:
; 		  else if(rx_chr[1][4][1]&rx_chr[2][6][1])	  //up x
	lds R2,_rx_chr+32+12+1
	lds R3,_rx_chr+16+8+1
	and R3,R2
	breq L76
; 		  	{
; 			     motor_l_msg=2;
	ldi R24,2
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				 motor_r_msg=2;
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				 motor_m_msg=2;				  
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 			}
	xjmp L77
L76:
; 		  else if(rx_chr[1][6][1]&rx_chr[2][4][1])	  //dawn 3
	lds R2,_rx_chr+32+8+1
	lds R3,_rx_chr+16+12+1
	and R3,R2
	breq L84
; 		  	{
; 			     motor_l_msg=3;
	ldi R24,3
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				 motor_r_msg=3;
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				 motor_m_msg=3;	
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 			}
	xjmp L85
L84:
; 			
; 			
; //单轮--------------------------------------------------
; 		  else if(rx_chr[1][4][1]&(~rx_chr[2][4][0])&(~rx_chr[2][4][1])&(~rx_chr[2][5][1]))	  //探测本次和上次对方键值,保持直线 				  //up
	lds R2,_rx_chr+32+8
	com R2
	lds R3,_rx_chr+16+8+1
	and R3,R2
	lds R2,_rx_chr+32+8+1
	com R2
	and R3,R2
	lds R2,_rx_chr+32+10+1
	com R2
	and R3,R2
	breq L92
; 		  	{
; 			    motor_l_msg=4;
	ldi R24,4
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				motor_r_msg=4;
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				motor_m_msg=4;		
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 			}
	xjmp L93
L92:
; 		  else if(rx_chr[1][6][1]&(~rx_chr[2][7][0])&(~rx_chr[2][7][1])&(~rx_chr[2][5][1]))	   				  //dawn //探测本次和上次对方键值,保持直线
	lds R2,_rx_chr+32+14
	com R2
	lds R3,_rx_chr+16+12+1
	and R3,R2
	lds R2,_rx_chr+32+14+1
	com R2
	and R3,R2
	lds R2,_rx_chr+32+10+1
	com R2
	and R3,R2
	breq L105
; 		  	{
; 		        motor_l_msg=5;
	ldi R24,5
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				motor_r_msg=5;
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				motor_m_msg=5;			
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 			}
	xjmp L106
L105:
; 		  else if(rx_chr[2][4][1]&(~rx_chr[1][4][0])&(~rx_chr[1][4][1]))	   				  //3  //探测本次和上次对方键值,保持直线
	lds R2,_rx_chr+16+8
	com R2
	lds R3,_rx_chr+32+8+1
	and R3,R2
	lds R2,_rx_chr+16+8+1
	com R2
	and R3,R2
	breq L118
; 		  	{
; 			      motor_l_msg=6;
	ldi R24,6
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				  motor_r_msg=6;
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				  motor_m_msg=6;				  
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 			}
	xjmp L119
L118:
; 		  else if(rx_chr[2][6][1]&(~rx_chr[1][6][0])&(~rx_chr[1][6][1]))	  			  	  // x  //探测本次和上次对方键值,保持直线
	lds R2,_rx_chr+16+12
	com R2
	lds R3,_rx_chr+32+12+1
	and R3,R2
	lds R2,_rx_chr+16+12+1
	com R2
	and R3,R2
	breq L128
; 		  	{
; 			      motor_l_msg=7;
	ldi R24,7
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				  motor_r_msg=7;	
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				  motor_m_msg=7;	
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 			}
	xjmp L129
L128:
; 			/*
; 			 else if(rx_chr[1][7][1])	  			  	  // 左平移
; 		  	{
; 			      motor_l_msg=8;
; 				  motor_r_msg=8;
; 				  motor_m_msg=8;
; 			}		
; 			 else if(rx_chr[2][5][1])	  			  	  // 右平移
; 		  	{
; 			      motor_l_msg=9;
; 				  motor_r_msg=9;	
; 				  motor_m_msg=9;	
; 			}
; 			*/
; 			else  					   				  //stop
; 		  	{
; 			    motor_l_msg=10;
	ldi R24,10
	ldi R25,0
	sts _motor_l_msg+1,R25
	sts _motor_l_msg,R24
; 				motor_r_msg=10;
	sts _motor_r_msg+1,R25
	sts _motor_r_msg,R24
; 				motor_m_msg=10;				  
	sts _motor_m_msg+1,R25
	sts _motor_m_msg,R24
; 			}
L129:
L119:
L106:
L93:
L85:
L77:
L69:
L61:
; 				OSMboxPost(motor_l_Box,&motor_l_msg);  //发送左电机驱动邮件				  
	ldi R18,<_motor_l_msg
	ldi R19,>_motor_l_msg
	lds R16,_motor_l_Box
	lds R17,_motor_l_Box+1
	xcall _OSMboxPost
; 		   	    OSMboxPost(motor_r_Box,&motor_r_msg);  //发送右电机驱动邮件				  
	ldi R18,<_motor_r_msg
	ldi R19,>_motor_r_msg
	lds R16,_motor_r_Box
	lds R17,_motor_r_Box+1
	xcall _OSMboxPost
; 		   	    OSMboxPost(motor_m_Box,&motor_m_msg);  //发送中电机驱动邮件
	ldi R18,<_motor_m_msg
	ldi R19,>_motor_m_msg
	lds R16,_motor_m_Box
	lds R17,_motor_m_Box+1
	xcall _OSMboxPost
; 					
; //提升部分--------------------------------------------------
; 			
; 			
; 			///自动上升下降次数累加
; 			if(rx_chr[1][5][1])
	lds R2,_rx_chr+16+10+1
	tst R2
	breq L138

⌨️ 快捷键说明

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