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

📄 car_main.s

📁 基于m16的寻迹小车(包含小车题目
💻 S
📖 第 1 页 / 共 3 页
字号:
	clr R21
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	breq L67
X22:
	cpi R20,3
	ldi R30,0
	cpc R21,R30
	breq L67
X23:
	xjmp L65
L67:
	.dbline 310
; 			case 1:
; 			case 3:
; 				modle_last = modle_now;
	lds R2,_modle_now
	sts _modle_last,R2
	.dbline 311
; 				break;
	.dbline 314
; 
; 			default :
; 				break;
L65:
	.dbline 316
; 		}
; 	}
L62:
L56:
L49:
	.dbline -2
L47:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 322
; }
; /*-------------------------------end---------------------------------------------*/
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 324
;  	//stop errant interrupts until set up
; 	closeJTAG();
	xcall _closeJTAG
	.dbline 325
;  	CLI(); //disable all interrupts
	cli
	.dbline 328
; 
; 	//时间使用
; 	timer2_init();
	xcall _timer2_init
	.dbline 329
; 	Time2OnOff(OFF);
	clr R16
	xcall _Time2OnOff
	.dbline 332
; 
; 	//计圈数使用
; 	timer0_init();
	xcall _timer0_init
	.dbline 333
; 	Time0OnOff(OFF);
	clr R16
	xcall _Time0OnOff
	.dbline 336
; 
; 	//lcd
;  	LCD_init();
	xcall _LCD_init
	.dbline 339
; 
; 	//pwm
; 	PwmInit();
	xcall _PwmInit
	.dbline 340
; 	PwmASet(PWMA_MIN_VAL);
	clr R16
	clr R17
	xcall _PwmASet
	.dbline 341
; 	PwmBSet(PWMB_MIN_VAL);
	clr R16
	clr R17
	xcall _PwmBSet
	.dbline 344
;  
;  	//INT1:0
; 	DDRD &=~ (1 << PD0) | (1 << PD1) | (1 << PD2) | (1 << PD3) | (1 << PD6); //PD口的0,1,6做扩展中断, 2,3做中断
	cbi 0x11,0
	.dbline 345
; 	PORTD |= (1 << PD0) | (1 << PD1) | (1 << PD2) | (1 << PD3) | (1 << PD6);
	in R24,0x12
	ori R24,79
	out 0x12,R24
	.dbline 347
; 
; 	DDRA &=~ (1 << PA0);  //小车按钮开关, 上拉
	cbi 0x1a,0
	.dbline 348
; 	PORTA |= (1 << PA0);
	sbi 0x1b,0
	.dbline 350
; 
; 	DDRC  |=  0b11110000;
	in R24,0x14
	ori R24,240
	out 0x14,R24
	.dbline 351
; 	PORTC &=~ 0b01010000;
	in R24,0x15
	andi R24,175
	out 0x15,R24
	.dbline 352
; 	PORTC |=  0b10100000; //PC口4,5,6,7输出, 电机停
	in R24,0x15
	ori R24,160
	out 0x15,R24
	.dbline 354
; 
; 	DDRB &=~ (1 << PB0);  //T0做外部计数
	cbi 0x17,0
	.dbline 355
; 	PORTB |= (1 << PB0);
	sbi 0x18,0
	.dbline 357
; 	
;  	MCUCR = 0x0A;  //中断方式, 都是下降沿	
	ldi R24,10
	out 0x35,R24
	.dbline 358
; 	GICR |= (1 << INT1) | (1 << INT0); 	
	in R24,0x3b
	ori R24,192
	out 0x3b,R24
	.dbline -2
L68:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	sbiw R28,8
	.dbline -1
	.dbline 368
;  
; 	//TIMSK = 0x80; //定时器中断使能
;  	//SEI();
; }
; 
; #define debug
; //主函数
; void main(void)
; 
; {		
	.dbline 369
; 	init_devices();
	xcall _init_devices
	.dbline 371
; 
; 	LCD_write_string(1, 4, "Good luck");
	ldi R24,<L70
	ldi R25,>L70
	std y+1,R25
	std y+0,R24
	ldi R18,4
	ldi R16,1
	xcall _LCD_write_string
	.dbline 372
; 	LCD_write_string(2, 0, "made on 09-05-01");
	ldi R24,<L71
	ldi R25,>L71
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,2
	xcall _LCD_write_string
	.dbline 375
; 		
; 	#ifdef debug
; 	LightOnOff(ON);
	ldi R16,1
	xcall _LightOnOff
	.dbline 376
; 	delay_nms(200);
	ldi R16,200
	ldi R17,0
	xcall _delay_nms
	.dbline 377
; 	LightOnOff(OFF);
	clr R16
	xcall _LightOnOff
	.dbline 378
; 	delay_nms(200);
	ldi R16,200
	ldi R17,0
	xcall _delay_nms
	xjmp L73
L72:
	.dbline 383
; 	#endif
; 	
; 	//while(1) {;}  
; 	
;     while(1){		
	.dbline 384
; 		if ((PINA & (1 << PA0)) == 0 ) {  //等待按下开始键	
	sbic 0x19,0
	rjmp L75
X24:
	.dbline 384
	.dbline 385
; 			SEI(); //打开全局中断
	sei
	.dbline 387
; 			
; 			CarGoAheadMidSpeed();  //小车向前		
	xcall _CarGoAheadMidSpeed
	xjmp L78
L77:
	.dbline 388
; 			while (1) {
	.dbline 389
; 				CarFindLine();     //小车寻线
	xcall _CarFindLine
	.dbline 391
; 				
; 				if (getlinestart == 1) { //如果遇到起跑线
	lds R24,_getlinestart
	cpi R24,1
	breq X32
	xjmp L80
X32:
X25:
	.dbline 391
	.dbline 392
; 					LCD_write_string(1, 0, "                   ");
	ldi R24,<L82
	ldi R25,>L82
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,1
	xcall _LCD_write_string
	.dbline 393
; 					LCD_write_string(2, 0, "                   ");
	ldi R24,<L82
	ldi R25,>L82
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,2
	xcall _LCD_write_string
	.dbline 394
; 					LCD_write_string(1, 0, "circle:      cm ");
	ldi R24,<L83
	ldi R25,>L83
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,1
	xcall _LCD_write_string
	.dbline 395
; 					LCD_write_string(2, 0, "time  : 0    s ");
	ldi R24,<L84
	ldi R25,>L84
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,2
	xcall _LCD_write_string
	.dbline 397
; 					
; 					Time0OnOff(ON); //开始计算路程
	ldi R16,1
	xcall _Time0OnOff
	.dbline 398
; 					Time2OnOff(ON); //开始计时
	ldi R16,1
	xcall _Time2OnOff
	xjmp L86
L85:
	.dbline 400
; 					
; 					while (1) {
	.dbline 401
; 						CarFindLine(); //寻线
	xcall _CarFindLine
	.dbline 403
; 
; 						if (T2_1s_set == 1) { //显示时间
	lds R24,_T2_1s_set
	cpi R24,1
	brne L88
X26:
	.dbline 403
	.dbline 404
; 							LCD_write_datalongint(2, 8, T2_1s_set_n);
	lds R4,_T2_1s_set_n+2
	lds R5,_T2_1s_set_n+2+1
	lds R2,_T2_1s_set_n
	lds R3,_T2_1s_set_n+1
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	ldi R18,8
	ldi R16,2
	xcall _LCD_write_datalongint
	.dbline 405
; 							T2_1s_set = 0;
	clr R2
	sts _T2_1s_set,R2
	.dbline 406
; 						}
L88:
	.dbline 408
; 
; 						if (T0_10_set == 1) {  //显示路程
	lds R24,_T0_10_set
	cpi R24,1
	breq X33
	xjmp L90
X33:
X27:
	.dbline 408
	.dbline 409
; 							circle = (((10 * T0_10_n) + TCNT0) / 5) * LENGHT_PER_CIRCLE;
	lds R4,_T0_10_n+2
	lds R5,_T0_10_n+2+1
	lds R2,_T0_10_n
	lds R3,_T0_10_n+1
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	movw R16,R20
	movw R18,R22
	xcall empy32u
	movw R2,R16
	movw R4,R18
	in R6,0x32
	clr R7
	clr R8
	clr R9
	add R2,R6
	adc R3,R7
	adc R4,R8
	adc R5,R9
	ldi R20,5
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall div32u
	ldi R20,18
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R20
	movw R18,R22
	xcall empy32u
	sts _circle+1,R17
	sts _circle,R16
	sts _circle+2+1,R19
	sts _circle+2,R18
	.dbline 410
; 							LCD_write_datalongint(1, 8, circle);
	movw R2,R16
	movw R4,R18
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	ldi R18,8
	ldi R16,1
	xcall _LCD_write_datalongint
	.dbline 411
; 							T0_10_set = 0;
	clr R2
	sts _T0_10_set,R2
	.dbline 412
; 						}
L90:
	.dbline 414
; 						
; 						if (circle_n_new != circle_n_old) {
	lds R2,_circle_n_old
	lds R3,_circle_n_new
	cp R3,R2
	breq L92
X28:
	.dbline 414
	.dbline 415
; 						   LCD_write_datalongint(1, 15, circle_n_new);
	mov R2,R3
	clr R3
	clr R4
	clr R5
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	ldi R18,15
	ldi R16,1
	xcall _LCD_write_datalongint
	.dbline 416
; 						   circle_n_old = circle_n_new;
	lds R2,_circle_n_new
	sts _circle_n_old,R2
	.dbline 418
; 
; 						   LightOnOff(ON);
	ldi R16,1
	xcall _LightOnOff
	.dbline 419
; 						   light_set_flag = 1;
	ldi R24,1
	sts _light_set_flag,R24
	.dbline 420
; 						   Light_time = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sts _Light_time+1,R21
	sts _Light_time,R20
	sts _Light_time+2+1,R23
	sts _Light_time+2,R22
	.dbline 421
; 						}
L92:
	.dbline 423
; 
; 						if ((light_set_flag == 1) && (Light_time++) >= 5000) {
	lds R24,_light_set_flag
	cpi R24,1
	brne L94
X29:
	lds R4,_Light_time+2
	lds R5,_Light_time+2+1
	lds R2,_Light_time
	lds R3,_Light_time+1
	std y+4,R2
	std y+5,R3
	std y+6,R4
	std y+7,R5
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+4
	ldd R3,y+5
	ldd R4,y+6
	ldd R5,y+7
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	sts _Light_time+1,R3
	sts _Light_time,R2
	sts _Light_time+2+1,R5
	sts _Light_time+2,R4
	ldi R20,136
	ldi R21,19
	ldi R22,0
	ldi R23,0
	ldd R2,y+4
	ldd R3,y+5
	ldd R4,y+6
	ldd R5,y+7
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L94
X30:
	.dbline 423
	.dbline 424
; 							light_set_flag = 0;
	clr R2
	sts _light_set_flag,R2
	.dbline 425
; 							LightOnOff(OFF);
	clr R16
	xcall _LightOnOff
	.dbline 426
; 						}								
L94:
	.dbline 427
; 					}
L86:
	.dbline 400
	xjmp L85
L80:
	.dbline 429
; 				}			
; 			}
L78:
	.dbline 388
	xjmp L77
L75:
	.dbline 431
; 		}
;     }
L73:
	.dbline 383
	xjmp L72
X31:
	.dbline -2
L69:
	.dbline 0 ; func end
	adiw R28,8
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
_lcd_k::
	.blkb 2
	.dbsym e lcd_k _lcd_k i
_lcd_j::
	.blkb 2
	.dbsym e lcd_j _lcd_j i
_lcd_i::
	.blkb 2
	.dbsym e lcd_i _lcd_i i
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
L84:
	.blkb 16
	.area idata
	.byte 't,'i,'m,'e,32,32,58,32,48,32,32,32,32,'s,32,0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
L83:
	.blkb 17
	.area idata
	.byte 'c,'i,'r,'c,'l,'e,58,32,32,32,32,32,32,'c,'m,32
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
L82:
	.blkb 20
	.area idata
	.byte 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32
	.byte 32,32,32,0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
L71:
	.blkb 17
	.area idata
	.byte 'm,'a,'d,'e,32,'o,'n,32,48,57,45,48,53,45,48,49
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
L70:
	.blkb 10
	.area idata
	.byte 'G,'o,'o,'d,32,'l,'u,'c,'k,0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
; }
; 

⌨️ 快捷键说明

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