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

📄 car_init.s

📁 本次设计的自动往返电动小汽车
💻 S
字号:
	.module car_init.c
	.area data(ram, con, rel)
_tenms::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\Car&Lcd\car_init.c
	.dbsym e tenms _tenms I
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\Car&Lcd\car_init.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 26
; // car_init.c
; // 8/1/2005 written by MrLiu
; //
; 
; #include <io8515v.h>
; #include <macros.h>
; 
; #include "1602LCD.h"
; #include "car_init.h"
; 
; // globals
; int tenms=0;
; 
; // extern varables
; extern int lcnt;
; extern int qcnt;
; extern int juli[3];
; extern unsigned int time[3];
; 
; ////////////////////////////////////////////
; // Function : port_init()
; // Purpose :端口初始化
; // Comments : A口输出/B口输出/C口输入/D口输入
; //
; void port_init(void)
; {
	.dbline 27
;     PORTA = 0xFF;
	ldi R24,255
	out 0x1b,R24
	.dbline 28
;  	DDRA  = 0xFF;
	out 0x1a,R24
	.dbline 29
;  	PORTB = 0xFF;
	out 0x18,R24
	.dbline 30
;  	DDRB  = 0xFF;
	out 0x17,R24
	.dbline 31
;  	PORTC = 0xFF;
	out 0x15,R24
	.dbline 32
;  	DDRC  = 0x00;
	clr R2
	out 0x14,R2
	.dbline 33
;  	PORTD = 0xFF;
	out 0x12,R24
	.dbline 34
;  	DDRD  = 0x00;
	out 0x11,R2
	.dbline -2
	.dbline 35
; }
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 44
; 
; //////////////////////////////////////////
; // Function : timer0_init()
; // Purpose : T/C0初始化
; // Commnets :产生10ms中断
; //
; 
; void timer0_init(void)
; {
	.dbline 45
;  TCCR0 = 0x00; //stop timer
	clr R2
	out 0x33,R2
	.dbline 46
;  TCNT0 = 0xB2; //set count value
	ldi R24,178
	out 0x32,R24
	.dbline 47
;  TCCR0 = 0x05; //start timer
	ldi R24,5
	out 0x33,R24
	.dbline -2
	.dbline 48
; }
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 14
	rjmp _timer0_ovf_isr
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\Car&Lcd\car_init.c
	.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
	.even
_timer0_ovf_isr::
	rcall push_lset
	sbiw R28,2
	.dbline -1
	.dbline 55
; 
; // Function : timer0_ovf_isr()
; // Purpose : T/C0中断服务
; //
; #pragma interrupt_handler timer0_ovf_isr:8
; void timer0_ovf_isr(void)
; {
	.dbline 56
;     TCNT0 = 0xB2; //reload counter value
	ldi R24,178
	out 0x32,R24
	.dbline 57
;  	tenms++;
	lds R24,_tenms
	lds R25,_tenms+1
	adiw R24,1
	sts _tenms+1,R25
	sts _tenms,R24
	.dbline 58
;  	if (tenms==10)
	cpi R24,10
	ldi R30,0
	cpc R25,R30
	breq X0
	rjmp L4
X0:
	.dbline 59
;  	{
	.dbline 60
; 	    tenms=0;
	clr R2
	clr R3
	sts _tenms+1,R3
	sts _tenms,R2
	.dbline 61
; 		time[2]++;
	lds R24,_time+4
	lds R25,_time+4+1
	adiw R24,1
	sts _time+4+1,R25
	sts _time+4,R24
	.dbline 62
; 		if(time[2]<10)
	cpi R24,10
	ldi R30,0
	cpc R25,R30
	brsh L7
	.dbline 63
; 		    LCD_write(8,0,'0'+time[2]);
	adiw R24,48
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,8
	rcall _LCD_write
L7:
	.dbline 64
; 		if(time[2]==10)
	lds R24,_time+4
	lds R25,_time+4+1
	cpi R24,10
	ldi R30,0
	cpc R25,R30
	breq X1
	rjmp L11
X1:
	.dbline 65
;  		{
	.dbline 66
; 		    time[2]=0;
	clr R2
	clr R3
	sts _time+4+1,R3
	sts _time+4,R2
	.dbline 67
; 	        LCD_write(8,0,'0'+time[2]);
	mov R24,R2
	mov R25,R3
	adiw R24,48
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,8
	rcall _LCD_write
	.dbline 68
; 			time[1]++;
	lds R24,_time+2
	lds R25,_time+2+1
	adiw R24,1
	sts _time+2+1,R25
	sts _time+2,R24
	.dbline 69
; 		    if(time[1]<10)
	cpi R24,10
	ldi R30,0
	cpc R25,R30
	brsh L17
	.dbline 70
; 		    LCD_write(6,0,'0'+time[1]);
	adiw R24,48
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,6
	rcall _LCD_write
L17:
	.dbline 71
; 		    if(time[1]==10)
	lds R24,_time+2
	lds R25,_time+2+1
	cpi R24,10
	ldi R30,0
	cpc R25,R30
	brne L21
	.dbline 72
; 			{
	.dbline 73
; 		        time[1]=0;
	clr R2
	clr R3
	sts _time+2+1,R3
	sts _time+2,R2
	.dbline 74
; 				LCD_write(6,0,'0'+time[1]);
	mov R24,R2
	mov R25,R3
	adiw R24,48
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,6
	rcall _LCD_write
	.dbline 75
; 				time[0]++;
	lds R24,_time
	lds R25,_time+1
	adiw R24,1
	sts _time+1,R25
	sts _time,R24
	.dbline 76
; 		        LCD_write(5,0,'0'+time[0]);
	adiw R24,48
	std y+1,R25
	std y+0,R24
	clr R18
	ldi R16,5
	rcall _LCD_write
	.dbline 77
; 			} 
L21:
	.dbline 78
; 	    }
L11:
	.dbline 79
L4:
	.dbline -2
	.dbline 80
;     }
; }
L3:
	adiw R28,2
	rcall pop_lset
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e timer1_init _timer1_init fV
	.even
_timer1_init::
	.dbline -1
	.dbline 88
; 
; ////////////////////////////////////////
; // Function : timer1_init()
; // Purpose : T/C1 PWM模式初始化
; //
; 
; void timer1_init(void)
; {
	.dbline 89
;     TCCR1B = 0x00; //stop
	clr R2
	out 0x2e,R2
	.dbline 90
;  	TCNT1H = 0xE0; //setup
	ldi R24,224
	out 0x2d,R24
	.dbline 91
;  	TCNT1L = 0xC0;
	ldi R24,192
	out 0x2c,R24
	.dbline 92
;  	OCR1AH = 0x1F;
	ldi R24,31
	out 0x2b,R24
	.dbline 93
;  	OCR1AL = 0x40;
	ldi R24,64
	out 0x2a,R24
	.dbline 94
;  	OCR1BH = 0xFF;
	ldi R24,255
	out 0x29,R24
	.dbline 95
;  	OCR1BL = 0xFF;
	out 0x28,R24
	.dbline 96
;  	TCCR1A = 0x63;
	ldi R24,99
	out 0x2f,R24
	.dbline 97
;  	TCCR1B = 0x01; //start Timer
	ldi R24,1
	out 0x2e,R24
	.dbline -2
	.dbline 98
; }
L26:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 2
	rjmp _int0_isr
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\Car&Lcd\car_init.c
	.dbfunc e int0_isr _int0_isr fV
	.even
_int0_isr::
	st -y,R24
	st -y,R25
	in R24,0x3f
	st -y,R24
	.dbline -1
	.dbline 107
; 
; ////////////////////////////////////////
; // Function : int0_isr()
; // Purpose : INT0中断服务
; //
; 
; #pragma interrupt_handler int0_isr:2
; void int0_isr(void)
; {
	.dbline 108
;    lcnt++;//检测的线条数目
	lds R24,_lcnt
	lds R25,_lcnt+1
	adiw R24,1
	sts _lcnt+1,R25
	sts _lcnt,R24
	.dbline -2
	.dbline 109
; }
L27:
	ld R24,y+
	out 0x3f,R24
	ld R25,y+
	ld R24,y+
	.dbline 0 ; func end
	reti
	.dbend
	.area vector(rom, abs)
	.org 4
	rjmp _int1_isr
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\Car&Lcd\car_init.c
	.dbfunc e int1_isr _int1_isr fV
	.even
_int1_isr::
	rcall push_lset
	sbiw R28,2
	.dbline -1
	.dbline 117
; ///////////////////////////////////////
; // Function : int1_1sr()
; // Purpose : INT1中断服务
; //
; 
; #pragma interrupt_handler int1_isr:3
; void int1_isr(void)
; {
	.dbline 118
;     qcnt++;	
	lds R24,_qcnt
	lds R25,_qcnt+1
	adiw R24,1
	sts _qcnt+1,R25
	sts _qcnt,R24
	.dbline 119
;  	juli[0]=JULI/100;                          //距离换算
	ldi R16,<L29
	ldi R17,>L29
	rcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	lds R16,_qcnt
	lds R17,_qcnt+1
	rcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall mpy32fs
	ldi R16,<L30
	ldi R17,>L30
	rcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall div32f
	rcall fp2int
	sts _juli+1,R17
	sts _juli,R16
	.dbline 120
;  	juli[1]=(JULI-juli[0]*100)/10;
	ldi R16,<L29
	ldi R17,>L29
	rcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	lds R16,_qcnt
	lds R17,_qcnt+1
	rcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall mpy32fs
	lds R18,_juli
	lds R19,_juli+1
	ldi R16,100
	ldi R17,0
	rcall mpy16s
	rcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall sub32fs
	ldi R16,<L32
	ldi R17,>L32
	rcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall div32f
	rcall fp2int
	sts _juli+2+1,R17
	sts _juli+2,R16
	.dbline 121
;  	juli[2]=JULI-juli[1]*10-juli[0]*100;	   	
	ldi R16,<L29
	ldi R17,>L29
	rcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	lds R16,_qcnt
	lds R17,_qcnt+1
	rcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall mpy32fs
	lds R18,_juli+2
	lds R19,_juli+2+1
	ldi R16,10
	ldi R17,0
	rcall mpy16s
	rcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall sub32fs
	lds R18,_juli
	lds R19,_juli+1
	ldi R16,100
	ldi R17,0
	rcall mpy16s
	rcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	rcall sub32f
	rcall fp2int
	sts _juli+4+1,R17
	sts _juli+4,R16
	.dbline 122
;  	LCD_write(5,1,'0'+juli[0]);
	lds R24,_juli
	lds R25,_juli+1
	adiw R24,48
	std y+1,R25
	std y+0,R24
	ldi R18,1
	ldi R16,5
	rcall _LCD_write
	.dbline 123
;  	LCD_write(6,1,'0'+juli[1]);
	lds R24,_juli+2
	lds R25,_juli+2+1
	adiw R24,48
	std y+1,R25
	std y+0,R24
	ldi R18,1
	ldi R16,6
	rcall _LCD_write
	.dbline 124
;  	LCD_write(8,1,'0'+juli[2]);
	lds R24,_juli+4
	lds R25,_juli+4+1
	adiw R24,48
	std y+1,R25
	std y+0,R24
	ldi R18,1
	ldi R16,8
	rcall _LCD_write
	.dbline -2
	.dbline 125
; }
L28:
	adiw R28,2
	rcall pop_lset
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 133
; 
; ////////////////////////////////
; // Function : init_devices()
; // Purpose : 硬件初始化
; //
; 
; void init_devices(void)
; {
	.dbline 134
;     CLI(); 
	cli
	.dbline 135
;  	port_init();
	rcall _port_init
	.dbline 136
;  	timer0_init();
	rcall _timer0_init
	.dbline 137
;  	timer1_init();
	rcall _timer1_init
	.dbline 138
;  	PORTA&=0xC0;
	in R24,0x1b
	andi R24,192
	out 0x1b,R24
	.dbline 139
;  	PORTB=0xFF;                                      
	ldi R24,255
	out 0x18,R24
	.dbline 140
;  	MCUCR = 0x0F;
	ldi R24,15
	out 0x35,R24
	.dbline 141
;  	GIMSK = 0xC0;
	ldi R24,192
	out 0x3b,R24
	.dbline 142
;  	TIMSK = 0x02;
	ldi R24,2
	out 0x39,R24
	.dbline 143
;  	SEI(); 
	sei
	.dbline -2
	.dbline 144
; }
L37:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e shifth _shifth fV
	.even
_shifth::
	.dbline -1
	.dbline 150
; 
; ///////////////////////////////
; // 控制车速函数
; //
; void shifth(void)			   				  //控制高速
; {
	.dbline 151
;     OCR1BH = 0xFF; 	   					 
	ldi R24,255
	out 0x29,R24
	.dbline 152
;  	OCR1BL = 0xFF;
	out 0x28,R24
	.dbline -2
	.dbline 153
; }
L38:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e stop _stop fV
	.even
_stop::
	.dbline -1
	.dbline 156
; 
; void stop(void)								  //制动
; {
	.dbline 157
;     OCR1BH = 0x00; 	   					 
	clr R2
	out 0x29,R2
	.dbline 158
;  	OCR1BL = 0x00;
	out 0x28,R2
	.dbline -2
	.dbline 159
; }
L39:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e shiftl _shiftl fV
	.even
_shiftl::
	.dbline -1
	.dbline 162
; 
; void shiftl(void)							  //控制低速
; {
	.dbline 163
;     OCR1BH = 0x01; 	   					 
	ldi R24,1
	out 0x29,R24
	.dbline 164
;  	OCR1BL = 0x7F;
	ldi R24,127
	out 0x28,R24
	.dbline -2
	.dbline 165
; }
L40:
	.dbline 0 ; func end
	ret
	.dbend
	.area lit(rom, con, rel)
L32:
	.word 0x0,0x4120
L30:
	.word 0x0,0x42c8
L29:
	.word 0x9168,0x3fad

⌨️ 快捷键说明

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