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

📄 jidong.s

📁 基于m16的寻迹寻光小车程序
💻 S
📖 第 1 页 / 共 3 页
字号:
	.dbline 131
	sbi 0x1b,2
	.dbline 131
	.dbline 131
	.dbline 132
; 	ADC3_in;
	.dbline 132
	in R24,0x1a
	andi R24,247
	out 0x1a,R24
	.dbline 132
	sbi 0x1b,3
	.dbline 132
	.dbline 132
	.dbline 133
; 	ADC4_in;
	.dbline 133
	in R24,0x1a
	andi R24,239
	out 0x1a,R24
	.dbline 133
	sbi 0x1b,4
	.dbline 133
	.dbline 133
	.dbline -2
L42:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e ADC_REG_init _ADC_REG_init fV
	.even
_ADC_REG_init::
	.dbline -1
	.dbline 138
; }
; 
; //ADC寄存器初始化
; void ADC_REG_init( void )
; {
	.dbline 139
;     ADCSRA = 0X00;         //ADC控制器清零,不启动ADC转换
	clr R2
	out 0x6,R2
	.dbline 140
; 	AD_mux( ad_m );        //选择内部电压,初始时使用ADC0通道做为单通道输入
	.dbline 140
	lds R24,_ad_m
	ori R24,192
	out 0x7,R24
	.dbline 140
	.dbline 140
	.dbline 141
;     SFIOR = 0X00;          //定义为连续自由转换
	out 0x30,R2
	.dbline 142
;     ADCSRA = 0B11101101;   //启动ADC转换1110 1101, 开启ADC中断允许, 32分频(比较合适)
	ldi R24,237
	out 0x6,R24
	.dbline -2
L43:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e ADC_convert _ADC_convert fD
	.even
_ADC_convert::
	.dbline -1
	.dbline 147
; }
; 
; //ADC采样, 不利用中断完成的采样
; float ADC_convert( void )
; {
L45:
	.dbline 148
;     while( !ADIF );        					 //等待ADC转换完成 ,ADC转换完成后,ADIF = 1
L46:
	.dbline 148
	.dbline 149
;     adcl = ( uint )ADCL;   					 //定义的为右对齐, 取ADCL的值
	in R2,0x4
	clr R3
	sts _adcl+1,R3
	sts _adcl,R2
	.dbline 150
;     adch = ( uint )ADCH;   					 //取ADCH的值
	in R2,0x5
	clr R3
	sts _adch+1,R3
	sts _adch,R2
	.dbline 151
;     adcvalue = adcl + ( adch << 8 );         //取10位ADC的值
	mov R3,R2
	clr R2
	lds R4,_adcl
	lds R5,_adcl+1
	add R4,R2
	adc R5,R3
	sts _adcvalue+1,R5
	sts _adcvalue,R4
	.dbline 152
;     return adcvalue * Vref / 1024;           //将ADC的值比较Vref转化为浮点数
	ldi R16,<L48
	ldi R17,>L48
	xcall lpm32
	movw R2,R16
	movw R4,R18
	lds R16,_adcvalue
	lds R17,_adcvalue+1
	xcall uint2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpmule2
	movw R2,R16
	movw R4,R18
	ldi R16,<L49
	ldi R17,>L49
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpdiv2
	.dbline -2
L44:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 56
	jmp _adc_isr
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbfunc e adc_isr _adc_isr fV
	.even
_adc_isr::
	st -y,R0
	st -y,R1
	st -y,R2
	st -y,R3
	st -y,R4
	st -y,R5
	st -y,R6
	st -y,R7
	st -y,R8
	st -y,R9
	st -y,R16
	st -y,R17
	st -y,R18
	st -y,R19
	st -y,R24
	st -y,R25
	st -y,R26
	st -y,R27
	st -y,R30
	st -y,R31
	in R0,0x3f
	st -y,R0
	xcall push_xgset300C
	sbiw R28,16
	.dbline -1
	.dbline 158
; }
; 
; //ADC值转换完成初始化
; #pragma interrupt_handler adc_isr:iv_ADC
; void adc_isr(void)
; {
	.dbline 162
;  //conversion complete, read value (int) using...
;  // value=ADCL;            //Read 8 low bits first (important)
;  // value|=(int)ADCH << 8; //read 2 high bits and shift into top byte
;  	 ADCSRA &=~ ( 1 << ADIE ) | ( 1 << ADIF );       //禁止转换中断
	cbi 0x6,3
	.dbline 164
; 	 
; 	 switch( ad_m )
	lds R20,_ad_m
	clr R21
	cpi R20,0
	cpc R20,R21
	breq L54
X16:
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	breq L55
X17:
	cpi R20,2
	ldi R30,0
	cpc R21,R30
	breq L56
X18:
	cpi R20,3
	ldi R30,0
	cpc R21,R30
	breq L57
X19:
	cpi R20,4
	ldi R30,0
	cpc R21,R30
	breq L58
X20:
	xjmp L51
L54:
	.dbline 167
;  	 {
;   	  	  case 0:
; 	      {
	.dbline 168
; 			   ad0_tmp = ADC_convert();
	xcall _ADC_convert
	sts _ad0_tmp+1,R17
	sts _ad0_tmp,R16
	sts _ad0_tmp+2+1,R19
	sts _ad0_tmp+2,R18
	.dbline 169
; 			   ad_m = 1;		//转换通道	
	ldi R24,1
	sts _ad_m,R24
	.dbline 170
; 		  }break;
	.dbline 170
	xjmp L52
L55:
	.dbline 173
; 
; 		  case 1:
; 	 	  {
	.dbline 174
; 			  ad1_tmp = ADC_convert();
	xcall _ADC_convert
	sts _ad1_tmp+1,R17
	sts _ad1_tmp,R16
	sts _ad1_tmp+2+1,R19
	sts _ad1_tmp+2,R18
	.dbline 175
; 			  ad_m = 2;         //转换通道
	ldi R24,2
	sts _ad_m,R24
	.dbline 176
; 		  }break;
	.dbline 176
	xjmp L52
L56:
	.dbline 179
; 		
; 		  case 2:
; 	 	  {
	.dbline 180
; 			  ad2_tmp = ADC_convert();
	xcall _ADC_convert
	sts _ad2_tmp+1,R17
	sts _ad2_tmp,R16
	sts _ad2_tmp+2+1,R19
	sts _ad2_tmp+2,R18
	.dbline 181
; 			  ad_m = 3;         //转换通道			  			
	ldi R24,3
	sts _ad_m,R24
	.dbline 182
; 		  }break;
	.dbline 182
	xjmp L52
L57:
	.dbline 185
; 		  
; 		  case 3:
; 	      {
	.dbline 186
; 			   ad3_tmp = ADC_convert();
	xcall _ADC_convert
	sts _ad3_tmp+1,R17
	sts _ad3_tmp,R16
	sts _ad3_tmp+2+1,R19
	sts _ad3_tmp+2,R18
	.dbline 187
; 			   ad_m = 4;		//转换通道	
	ldi R24,4
	sts _ad_m,R24
	.dbline 188
; 		  }break;
	.dbline 188
	xjmp L52
L58:
	.dbline 191
; 
; 		  case 4:
; 	 	  {
	.dbline 192
; 			  ad4_tmp = ADC_convert();
	xcall _ADC_convert
	sts _ad4_tmp+1,R17
	sts _ad4_tmp,R16
	sts _ad4_tmp+2+1,R19
	sts _ad4_tmp+2,R18
	.dbline 193
; 			  ad_m = 0;         //转换通道
	clr R2
	sts _ad_m,R2
	.dbline 200
; 			  
; 			  			
; 	          //显示三个AD光度采样的值		
; 			  //LCD_write_datafloat( 2, 1, ad0_tmp, 100, 2);
; 			  //LCD_write_datafloat( 2, 6, ad1_tmp, 100, 2);
; 			  //LCD_write_datafloat( 2, 11, ad2_tmp, 100, 2);
; 			 small_flag = get_5small( ad0_tmp, ad1_tmp, ad2_tmp, ad3_tmp, ad4_tmp );   //获取三点中最亮的一点
	movw R2,R16
	movw R4,R18
	std y+12,R2
	std y+13,R3
	std y+14,R4
	std y+15,R5
	lds R4,_ad3_tmp+2
	lds R5,_ad3_tmp+2+1
	lds R2,_ad3_tmp
	lds R3,_ad3_tmp+1
	std y+8,R2
	std y+9,R3
	std y+10,R4
	std y+11,R5
	lds R4,_ad2_tmp+2
	lds R5,_ad2_tmp+2+1
	lds R2,_ad2_tmp
	lds R3,_ad2_tmp+1
	std y+4,R2
	std y+5,R3
	std y+6,R4
	std y+7,R5
	lds R4,_ad1_tmp+2
	lds R5,_ad1_tmp+2+1
	lds R2,_ad1_tmp
	lds R3,_ad1_tmp+1
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	lds R18,_ad0_tmp+2
	lds R19,_ad0_tmp+2+1
	lds R16,_ad0_tmp
	lds R17,_ad0_tmp+1
	xcall _get_5small
	mov R2,R16
	clr R3
	sts _small_flag+1,R3
	sts _small_flag,R2
	.dbline 201
;          	 car_xunguang( small_flag );
	xcall _car_xunguang
	.dbline 203
; 			 	
; 		  }break;
	.dbline 203
L51:
L52:
	.dbline 207
; 		
;      }
; 
; 	 AD_mux( ad_m );                          //重新启动ADC, 重新选择基准电压和输入通道.此算法适用于多通道.
	.dbline 207
	lds R24,_ad_m
	ori R24,192
	out 0x7,R24
	.dbline 207
	.dbline 207
	.dbline 208
; 	 ADCSRA |= ( 1 << ADSC ) | ( 1 << ADIE ); //开中断, 重新启动
	in R24,0x6
	ori R24,72
	out 0x6,R24
	.dbline 209
; 	 delay_nms( 1 );                          //一定要这个延时, 否则转换通道会出错
	ldi R16,1
	ldi R17,0
	xcall _delay_nms
	.dbline 211
; 	 
; 	 if( ad_m == 0 ) ADC_stop();
	lds R2,_ad_m
	tst R2
	brne L59
X21:
	.dbline 211
	xcall _ADC_stop
L59:
	.dbline 212
; 	 delay_nms( 2 );
	ldi R16,2
	ldi R17,0
	xcall _delay_nms
	.dbline -2
L50:
	.dbline 0 ; func end
	adiw R28,16
	xcall pop_xgset300C
	ld R0,y+
	out 0x3f,R0
	ld R31,y+
	ld R30,y+
	ld R27,y+
	ld R26,y+
	ld R25,y+
	ld R24,y+
	ld R19,y+
	ld R18,y+
	ld R17,y+
	ld R16,y+
	ld R9,y+
	ld R8,y+
	ld R7,y+
	ld R6,y+
	ld R5,y+
	ld R4,y+
	ld R3,y+
	ld R2,y+
	ld R1,y+
	ld R0,y+
	reti
	.dbend
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
_model::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbsym e model _model c
_model_a::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbsym e model_a _model_a c
_count_1::
	.blkb 4
	.area idata
	.word 0,0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbsym e count_1 _count_1 L
_count_2::
	.blkb 4
	.area idata
	.word 0,0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbsym e count_2 _count_2 L
_count_3::
	.blkb 4
	.area idata
	.word 0,0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbsym e count_3 _count_3 L
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbfunc e time_off _time_off fV
	.even
_time_off::
	.dbline -1
	.dbline 228
; }
; //////////////////////////////寻光部分结束///////////////////////////////
; 
; 
; ///////////////////////////////避障部分///////////////////////////////
; //定义全局变量
; uchar model = 0;
; uchar model_a = 0;
; uchar flag_zhangai;
; long int count_1 = 0;
; long int count_2 = 0;
; long int count_3 = 0;
; 
; //time0 allow
; void time_off( void )
; {
	.dbline 229
;  	 TCCR0 &=~ ( 1 << OCIE0 );
	in R24,0x33
	andi R24,253
	out 0x33,R24
	.dbline -2
L61:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e time_on _time_on fV
	.even
_time_on::
	.dbline -1
	.dbline 234
; }
; 
; //time0 ON
; void time_on( void )
; {
	.dbline 235
;  	 TCCR0 |= ( 1 << OCIE0 );
	in R24,0x33
	ori R24,2
	out 0x33,R24
	.dbline -2
L62:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 243
; }
; 
; //TIMER0 initialize - prescale:256
; // WGM: CTC
; // desired value: 4mSec
; // actual value:  4.032mSec (-0.8%)
; void timer0_init(void)
; {
	.dbline 244
;  TCCR0 = 0x00; //stop
	clr R2
	out 0x33,R2
	.dbline 245
;  TCNT0 = 0x83; //set count
	ldi R24,131
	out 0x32,R24
	.dbline 246
;  OCR0  = 0x7D;  //set compare
	ldi R24,125
	out 0x3c,R24
	.dbline 247
;  TCCR0 = 0x0C; //start timer
	ldi R24,12
	out 0x33,R24
	.dbline -2
L63:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e hw_port_init _hw_port_init fV
	.even
_hw_port_init::
	.dbline -1
	.dbline 252
; }
; 
; //扫描端口初始化
; void hw_port_init( void )
; {
	.dbline 253
;     DDRC &=~ ( 1 << PC0 ) | ( 1 << PC1 );     //定义PC0, PC1口为上拉
	cbi 0x14,0
	.dbline 254
;     PORTC |= ( 1 << PC0 ) | ( 1 << PC1 );
	in R24,0x15
	ori R24,3
	out 0x15,R24
	.dbline -2
L64:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e int_scan _int_scan fc
	.even
_int_scan::
	.dbline -1
	.dbline 259
; }
; 
; //红外返回值
; uchar int_scan( void )   //判断障碍,并执行相应动作
; {
	.dbline 260
;     switch( PINC & 0b00000011 )
	in R16,0x13
	clr R17
	andi R16,3
	andi R17,0
	cpi R16,0
	cpc R16,R17
	breq L69
X22:
	cpi R16,1
	ldi R30,0
	cpc R17,R30
	breq L71
X23:
	cpi R16,2
	ldi R30,0
	cpc R17,R30
	breq L70
X24:
	xjmp L66
L69:
	.dbline 262
;     {
;         case 0b00000000: model = 1; return 1; break;     //左右同时遇到障碍
	ldi R24,1
	sts _model,R24
	.dbline 262
	ldi R16,1
	xjmp L65
L70:
	.dbline 263
;         case 0b00000010: model = 2; return 2; break;     //左遇到障碍
	ldi R24,2
	sts _model,R24
	.dbline 263
	ldi R16,2
	xjmp L65
L71:
	.dbline 264
;         case 0b00000001: model = 3; return 3; break;     //右遇到障碍
	ldi R24,3
	sts _model,R24
	.dbline 264
	ldi R16,3
	xjmp L65
L66:
	.dbline 265
;         default : model = 0; return 0; break;            //没有遇到障碍
	clr R2
	sts _model,R2
	.dbline 265
	clr R16
	.dbline 265
	.dbline -2
L65:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 76
	jmp _timer0_comp_isr
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\复件自~1\自动充电小车\298\jidong.c
	.dbfunc e timer0_comp_isr _timer0_comp_isr fV
	.even
_timer0_comp_isr::
	st -y,R0
	st -y,R1
	st -y,R2
	st -y,R3
	st -y,R4
	st -y,R5
	st -y,R6
	st -y,R7
	st -y,R8
	st -y,R9
	st -y,R16
	st -y,R17
	st -y,R18
	st -y,R19
	st -y,R24
	st -y,R25
	st -y,R26
	st -y,R27
	st -y,R30
	st -y,R31
	in R0,0x3f
	st -y,R0
	st -y,R10
	st -y,R11
	sbiw R28,12
	.dbline -1
	.dbline 272
;     }
; }
; 
; 
; #pragma interrupt_handler timer0_comp_isr:iv_TIM0_COMP
; void timer0_comp_isr(void)        // CTC模式, 比较匹配中断服务程序
; {	
	.dbline 276
; 	//CLI();
; 	//time_off();			  
; 	
; 	if( model == 0 )              //如果没有障碍返回值,刚继续前一动作
	lds R2,_model
	tst R2
	brne L73
X25:
	.dbline 277
; 	{
	.dbline 278
; 	    if( flag_zhangai == 1 ) model = model_a;
	lds R24,_flag_zhangai
	cpi R24,1
	brne L75
X26:
	.dbline 278
	lds R2,_model_a
	sts _model,R2
	xjmp L76
L75:
	.dbline 279
; 	    else ADC_start();
	xcall _ADC_start
L76:
	.dbline 280
; 	}
L73:
	.dbline 282
; 	
; 	if( model == 1 )         //左方右方有障碍, 即是前方有障碍
	lds R24,_model
	cpi R24,1
	breq X42
	xjmp L77
X42:
X27:
	.dbline 283
; 	{
	.dbline 284
; 	    model_a = model;
	mov R2,R24
	sts _model_a,R2
	.dbline 285
; 	    flag_zhangai = 1;
	ldi R24,1
	sts _flag_zhangai,R24
	.dbline 286
; 	    turn_r();
	xcall _turn_r
	.dbline 287
; 	    if( int_scan() == 0 )
	xcall _int_scan
	tst R16
	breq X43
	xjmp L79
X43:
X28:
	.dbline 288
; 	    {
	.dbline 289
;             if( ++count_1 >= 100 )
	ldi R24,1
	ldi R25,0
	ldi R26,0
	ldi R27,0
	lds R4,_count_1+2

⌨️ 快捷键说明

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