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

📄 car_main.s

📁 基于m16的寻迹小车(包含小车题目
💻 S
📖 第 1 页 / 共 3 页
字号:
	.module car_main.c
	.area text(rom, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
_modle_now::
	.blkb 1
	.area idata
	.byte 4
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e modle_now _modle_now c
_modle_last::
	.blkb 1
	.area idata
	.byte 4
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e modle_last _modle_last c
_circle::
	.blkb 4
	.area idata
	.word 0,0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e circle _circle l
_circle_n_new::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e circle_n_new _circle_n_new c
_circle_n_old::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e circle_n_old _circle_n_old c
_getlinestart::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e getlinestart _getlinestart c
_nextint_time::
	.blkb 4
	.area idata
	.word 0,0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e nextint_time _nextint_time L
_Light_time::
	.blkb 4
	.area idata
	.word 0,0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e Light_time _Light_time l
_light_set_flag::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e light_set_flag _light_set_flag c
	.area text(rom, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbfunc e closeJTAG _closeJTAG fV
	.even
_closeJTAG::
	.dbline -1
	.dbline 45
; #include <iom16v.h>
; #include <macros.h>
; #include "delay.h"
; #include "lcd.h"
; 
; //调试使用
; uint lcd_i;
; uint lcd_j;
; uint lcd_k;
; 
; //寻线使用
; uchar modle_now = 4;
; uchar modle_last = 4;
; 
; //计圈数
; #define LENGHT_PER_CIRCLE  18 //单位cm , 每个轮子的圈数
; 
; unsigned long int circle = 0; //路程
; uchar circle_n_new = 0;       //圈数
; uchar circle_n_old = 0;
; uchar getlinestart = 0;       //碰到起跑线
; long int nextint_time = 0;    //下次起跑线取值的时间
; 
; unsigned long int Light_time = 0;     //遇到一圈时,响一下,由此计时
; uchar light_set_flag = 0;
; 
; 
; #define ON  1
; #define OFF 0
; 
; #define PWMA_HIG_VAL 110 //A电机高速时占空比, hight speed  注意,使用的是8位快速模式
; #define PWMB_HIG_VAL 110
; #define PWMA_LOW_VAL 1			   	 	//A电机低速时占空比  low   speed 
; #define PWMB_LOW_VAL 1
; 
; #define PWMA_MID_VAL 165//A电机中速时点空比  midlle speed 
; #define PWMB_MID_VAL 165
; 
; #define PWMB_MAX_VAL 1023  //最大占空比         max speed
; #define PWMB_MAX_VAL 1023
; #define PWMA_MIN_VAL 0    //最小占空比         min speed
; #define PWMB_MIN_VAL 0
; 
; void closeJTAG(void)//   1JTAG
; {MCUCSR|=0X80; MCUCSR|=0X80;}
	.dbline 45
	in R24,0x34
	ori R24,128
	out 0x34,R24
	.dbline 45
	in R24,0x34
	ori R24,128
	out 0x34,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e PwmInit _PwmInit fV
	.even
_PwmInit::
	.dbline -1
	.dbline 49
; 
; /*-------------------------------PWM----------------------------------*/	
; void PwmInit (void)
; {
	.dbline 51
; 	//T1 for PWM
;  	DDRD |= ( 1 << PD4 ) | ( 1 << PD5 );
	in R24,0x11
	ori R24,48
	out 0x11,R24
	.dbline 52
;  	TCCR1A = ( 1 << WGM11 ) | ( 1 << WGM10 ) | ( 1 << COM1A1 ) | ( 1 << COM1B1 ); //匹配清0,两路10位相位修正PWM
	ldi R24,163
	out 0x2f,R24
	.dbline 53
;  	TCCR1B = ( 0 << CS12 ) | ( 1 << CS11 ) | ( 1 << CS10 ); //预分频64	
	ldi R24,3
	out 0x2e,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e PwmASet _PwmASet fV
;              P -> R16,R17
	.even
_PwmASet::
	.dbline -1
	.dbline 58
; }
; 
; //设置pwm_A的占空比
; void PwmASet(uint P)
; {
	.dbline 59
; 	OCR1A = P;	
	out 0x2b,R17
	out 0x2a,R16
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbsym r P 16 i
	.dbend
	.dbfunc e PwmBSet _PwmBSet fV
;              P -> R16,R17
	.even
_PwmBSet::
	.dbline -1
	.dbline 64
; }
; 
; //设置pwm_B的占空比
; void PwmBSet(uint P)
; {
	.dbline 65
; 	OCR1B = P;	
	out 0x29,R17
	out 0x28,R16
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbsym r P 16 i
	.dbend
	.dbfunc e CarGoAheadFullSpeed _CarGoAheadFullSpeed fV
	.even
_CarGoAheadFullSpeed::
	.dbline -1
	.dbline 73
; }
; 
; /*------------------------------------PWM END----------------------------------------*/
; 
; /*------------------------------------car active----------------------------------------*/
; //全速向前
; void CarGoAheadFullSpeed (void)
; {
	.dbline 74
; 	PwmASet(PWMA_HIG_VAL);
	ldi R16,110
	ldi R17,0
	xcall _PwmASet
	.dbline 75
; 	PwmBSet(PWMB_HIG_VAL);
	ldi R16,110
	ldi R17,0
	xcall _PwmBSet
	.dbline -2
L5:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e CarGoAheadMidSpeed _CarGoAheadMidSpeed fV
	.even
_CarGoAheadMidSpeed::
	.dbline -1
	.dbline 80
; }
; 
; //中速向前
; void CarGoAheadMidSpeed(void)
; {
	.dbline 81
; 	PwmASet(PWMA_MID_VAL);
	ldi R16,165
	ldi R17,0
	xcall _PwmASet
	.dbline 82
; 	PwmBSet(PWMB_MID_VAL);	
	ldi R16,165
	ldi R17,0
	xcall _PwmBSet
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e CarTurnLeft _CarTurnLeft fV
	.even
_CarTurnLeft::
	.dbline -1
	.dbline 87
; }
; 
; //向左
; void CarTurnLeft (void)
; {
	.dbline 89
; 	//TCNT1 = 0x3fe;
; 	PwmASet(PWMA_LOW_VAL);
	ldi R16,1
	ldi R17,0
	xcall _PwmASet
	.dbline 90
; 	PwmBSet(PWMB_HIG_VAL);
	ldi R16,110
	ldi R17,0
	xcall _PwmBSet
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e CarTurnRight _CarTurnRight fV
	.even
_CarTurnRight::
	.dbline -1
	.dbline 95
; }
; 
; //向右
; void CarTurnRight (void)
; {
	.dbline 97
; 	//TCNT1 = 0x3fe;
; 	PwmASet(PWMA_HIG_VAL);
	ldi R16,110
	ldi R17,0
	xcall _PwmASet
	.dbline 98
; 	PwmBSet(PWMB_LOW_VAL);
	ldi R16,1
	ldi R17,0
	xcall _PwmBSet
	.dbline -2
L8:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e CarStop _CarStop fV
	.even
_CarStop::
	.dbline -1
	.dbline 103
; }
; 
; //停止
; void CarStop (void)
; {
	.dbline 105
; 	//TCNT1 = 0x3fe;
; 	PwmASet(PWMA_MIN_VAL);
	clr R16
	clr R17
	xcall _PwmASet
	.dbline 106
; 	PwmBSet(PWMB_MIN_VAL);
	clr R16
	clr R17
	xcall _PwmBSet
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LightOnOff _LightOnOff fV
;          onoff -> R16
	.even
_LightOnOff::
	.dbline -1
	.dbline 111
; }
; 
; //--------------------------------------------声光报警
; void LightOnOff (uchar onoff)
; {
	.dbline 112
; 	DDRC |= (1 << PC0);
	sbi 0x14,0
	.dbline 114
; 	
; 	if (onoff == OFF) {
	tst R16
	brne L11
X0:
	.dbline 114
	.dbline 115
; 		PORTC &=~ (1 << PC0);
	cbi 0x15,0
	.dbline 116
; 	}
	xjmp L12
L11:
	.dbline 118
; 
; 	else if (onoff == ON) {
	cpi R16,1
	brne L13
X1:
	.dbline 118
	.dbline 119
; 		PORTC |= (1 << PC0);
	sbi 0x15,0
	.dbline 120
; 	}		
L13:
L12:
	.dbline -2
L10:
	.dbline 0 ; func end
	ret
	.dbsym r onoff 16 c
	.dbend
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
_T2_int_n::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e T2_int_n _T2_int_n c
_T2_1s_set_n::
	.blkb 4
	.area idata
	.word 0,0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e T2_1s_set_n _T2_1s_set_n l
_T2_1s_set::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbsym e T2_1s_set _T2_1s_set c
	.area text(rom, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbfunc e timer2_init _timer2_init fV
	.even
_timer2_init::
	.dbline -1
	.dbline 136
; }
; 
; /*------------------------------------end car active ----------------------------------------*/
; 
; /*------------------------------------TIME ----------------------------------------*/
; uchar T2_int_n = 0;    //定时器25ms溢出次数
; unsigned long int T2_1s_set_n = 0; //1s次数
; uchar T2_1s_set = 0;
; 
; 
; //TIMER2 initialize - prescale:1024
; // WGM: CTC
; // desired value: 25mSec
; // actual value: 25.088mSec (0.4%)
; void timer2_init(void)
; {
	.dbline 137
;  TCCR2 = 0x00; //stop
	clr R2
	out 0x25,R2
	.dbline 138
;  ASSR  = 0x00; //set async mode
	out 0x22,R2
	.dbline 139
;  TCNT2 = 0x3D; //setup
	ldi R24,61
	out 0x24,R24
	.dbline 140
;  OCR2  = 0xC3;
	ldi R24,195
	out 0x23,R24
	.dbline 141
;  TCCR2 = 0x0F; //start
	ldi R24,15
	out 0x25,R24
	.dbline -2
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 12
	jmp _timer2_comp_isr
	.area text(rom, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c
	.dbfunc e timer2_comp_isr _timer2_comp_isr fV
	.even
_timer2_comp_isr::
	st -y,R0
	st -y,R1
	st -y,R2
	st -y,R3
	st -y,R4
	st -y,R5
	st -y,R24
	st -y,R25
	st -y,R26
	st -y,R27
	in R0,0x3f
	st -y,R0
	.dbline -1
	.dbline 146
; }
; 
; #pragma interrupt_handler timer2_comp_isr:iv_TIM2_COMP
; void timer2_comp_isr(void)
; {
	.dbline 149
;  //compare occured TCNT2=OCR2
;  //compare occured TCNT0=OCR0
; 	if((T2_int_n++) == 40) {  //25ms溢出, 40次则1s
	lds R2,_T2_int_n
	clr R3
	mov R24,R2
	subi R24,255    ; addi 1
	sts _T2_int_n,R24
	mov R24,R2
	cpi R24,40
	brne L17
X2:
	.dbline 149
	.dbline 150
; 		T2_1s_set = 1;
	ldi R24,1
	sts _T2_1s_set,R24
	.dbline 151
; 		T2_1s_set_n ++;  //置位1s
	ldi R24,1
	ldi R25,0
	ldi R26,0
	ldi R27,0
	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
	add R2,R24
	adc R3,R25
	adc R4,R26
	adc R5,R27
	sts _T2_1s_set_n+1,R3
	sts _T2_1s_set_n,R2
	sts _T2_1s_set_n+2+1,R5
	sts _T2_1s_set_n+2,R4
	.dbline 152
; 		T2_int_n = 0;  //溢出次数清0
	clr R2
	sts _T2_int_n,R2
	.dbline 153
; 	}
L17:
	.dbline -2
L16:
	.dbline 0 ; func end
	ld R0,y+
	out 0x3f,R0
	ld R27,y+
	ld R26,y+
	ld R25,y+
	ld R24,y+
	ld R5,y+
	ld R4,y+
	ld R3,y+
	ld R2,y+
	ld R1,y+
	ld R0,y+
	reti
	.dbend
	.dbfunc e Time2OnOff _Time2OnOff fV
;          onoff -> R16
	.even
_Time2OnOff::
	.dbline -1
	.dbline 159
; }
; 
; 
; //计时开始停止控制
; void Time2OnOff (uchar onoff)
; {
	.dbline 160
; 	if (onoff == ON) {
	cpi R16,1
	brne L20
X3:
	.dbline 160
	.dbline 161
; 		TIMSK |= (1 << OCIE2);  //开时间中断
	in R24,0x39
	ori R24,128
	out 0x39,R24
	.dbline 162
; 	}
	xjmp L21
L20:
	.dbline 164
; 
; 	else if (onoff == OFF) {
	tst R16
	brne L22
X4:
	.dbline 164
	.dbline 165
; 		TIMSK &=~ (1 << OCIE2);  //禁止时间中断
	in R24,0x39
	andi R24,127
	out 0x39,R24
	.dbline 166
; 	}		
L22:
L21:
	.dbline -2
L19:
	.dbline 0 ; func end
	ret
	.dbsym r onoff 16 c
	.dbend
	.area data(ram, con, rel)
	.dbfile d:\我的文档\桌面\小车\car1\car_main.c

⌨️ 快捷键说明

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