📄 carinit.s
字号:
.module CarInit.c
.area data(ram, con, rel)
_tenms::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\自动往返小汽车\源程序\自动往返小车lcd版\CarInit.c
.dbsym e tenms _tenms I
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\自动往返小汽车\源程序\自动往返小车lcd版\CarInit.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 25
; // car_init.c
; // 8/1/2005 written by MrLiu
; //
; #include <io8515v.h>
; #include <macros.h>
;
; #include "1602LCD.h"
; #include "CarInit.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 26
; PORTA = 0xFF;
ldi R24,255
out 0x1b,R24
.dbline 27
; DDRA = 0xFF;
out 0x1a,R24
.dbline 28
; PORTB = 0xFF;
out 0x18,R24
.dbline 29
; DDRB = 0xFF;
out 0x17,R24
.dbline 30
; PORTC = 0xFF;
out 0x15,R24
.dbline 31
; DDRC = 0x00;
clr R2
out 0x14,R2
.dbline 32
; PORTD = 0xFF;
out 0x12,R24
.dbline 33
; DDRD = 0x00;
out 0x11,R2
.dbline -2
.dbline 34
; }
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e timer0_init _timer0_init fV
.even
_timer0_init::
.dbline -1
.dbline 42
;
; //////////////////////////////////////////
; // Function : timer0_init()
; // Purpose : T/C0初始化
; // Commnets :产生10ms中断
; //
; void timer0_init(void)
; {
.dbline 43
; TCCR0 = 0x00; //stop timer
clr R2
out 0x33,R2
.dbline 44
; TCNT0 = 0xB2; //set count value
ldi R24,178
out 0x32,R24
.dbline 45
; TCCR0 = 0x05; //start timer
ldi R24,5
out 0x33,R24
.dbline -2
.dbline 46
; }
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\桌面\自动往返小汽车\源程序\自动往返小车lcd版\CarInit.c
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
rcall push_lset
sbiw R28,2
.dbline -1
.dbline 53
;
; // Function : timer0_ovf_isr()
; // Purpose : T/C0中断服务
; //
; #pragma interrupt_handler timer0_ovf_isr:8
; void timer0_ovf_isr(void)
; {
.dbline 54
; TCNT0 = 0xB2; //reload counter value
ldi R24,178
out 0x32,R24
.dbline 55
; tenms++;
lds R24,_tenms
lds R25,_tenms+1
adiw R24,1
sts _tenms+1,R25
sts _tenms,R24
.dbline 56
; if (tenms==10)
cpi R24,10
ldi R30,0
cpc R25,R30
breq X0
rjmp L4
X0:
.dbline 57
; {
.dbline 58
; tenms=0;
clr R2
clr R3
sts _tenms+1,R3
sts _tenms,R2
.dbline 59
; time[2]++;
lds R24,_time+4
lds R25,_time+4+1
adiw R24,1
sts _time+4+1,R25
sts _time+4,R24
.dbline 60
; if(time[2]<10)
cpi R24,10
ldi R30,0
cpc R25,R30
brsh L7
.dbline 61
; 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 62
; 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 63
; {
.dbline 64
; time[2]=0;
clr R2
clr R3
sts _time+4+1,R3
sts _time+4,R2
.dbline 65
; 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 66
; time[1]++;
lds R24,_time+2
lds R25,_time+2+1
adiw R24,1
sts _time+2+1,R25
sts _time+2,R24
.dbline 67
; if(time[1]<10)
cpi R24,10
ldi R30,0
cpc R25,R30
brsh L17
.dbline 68
; 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 69
; 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 70
; {
.dbline 71
; time[1]=0;
clr R2
clr R3
sts _time+2+1,R3
sts _time+2,R2
.dbline 72
; 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 73
; time[0]++;
lds R24,_time
lds R25,_time+1
adiw R24,1
sts _time+1,R25
sts _time,R24
.dbline 74
; if(time[0]==10)time[0]=0;
cpi R24,10
ldi R30,0
cpc R25,R30
brne L26
.dbline 74
clr R2
clr R3
sts _time+1,R3
sts _time,R2
L26:
.dbline 75
; LCD_write(5,0,'0'+time[0]);
lds R24,_time
lds R25,_time+1
adiw R24,48
std y+1,R25
std y+0,R24
clr R18
ldi R16,5
rcall _LCD_write
.dbline 76
; }
L21:
.dbline 77
; }
L11:
.dbline 78
L4:
.dbline -2
.dbline 79
; }
; }
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 86
;
; ////////////////////////////////////////
; // Function : timer1_init()
; // Purpose : T/C1 PWM模式初始化
; //
; void timer1_init(void)
; {
.dbline 87
; TCCR1B = 0x00; //stop
clr R2
out 0x2e,R2
.dbline 88
; TCNT1H = 0xE0; //setup
ldi R24,224
out 0x2d,R24
.dbline 89
; TCNT1L = 0xC0;
ldi R24,192
out 0x2c,R24
.dbline 90
; OCR1AH = 0x1F;
ldi R24,31
out 0x2b,R24
.dbline 91
; OCR1AL = 0x40;
ldi R24,64
out 0x2a,R24
.dbline 92
; OCR1BH = 0xFF;
ldi R24,255
out 0x29,R24
.dbline 93
; OCR1BL = 0xFF;
out 0x28,R24
.dbline 94
; TCCR1A = 0x63;
ldi R24,99
out 0x2f,R24
.dbline 95
; TCCR1B = 0x01; //start Timer
ldi R24,1
out 0x2e,R24
.dbline -2
.dbline 96
; }
L28:
.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\桌面\自动往返小汽车\源程序\自动往返小车lcd版\CarInit.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 104
;
; ////////////////////////////////////////
; // Function : int0_isr()
; // Purpose : INT0中断服务
; //
; #pragma interrupt_handler int0_isr:2
; void int0_isr(void)
; {
.dbline 105
; lcnt++;//检测的线条数目
lds R24,_lcnt
lds R25,_lcnt+1
adiw R24,1
sts _lcnt+1,R25
sts _lcnt,R24
.dbline -2
.dbline 106
; }
L29:
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\桌面\自动往返小汽车\源程序\自动往返小车lcd版\CarInit.c
.dbfunc e int1_isr _int1_isr fV
.even
_int1_isr::
rcall push_lset
sbiw R28,2
.dbline -1
.dbline 113
; ///////////////////////////////////////
; // Function : int1_1sr()
; // Purpose : INT1中断服务
; //
; #pragma interrupt_handler int1_isr:3
; void int1_isr(void)
; {
.dbline 114
; qcnt++;
lds R24,_qcnt
lds R25,_qcnt+1
adiw R24,1
sts _qcnt+1,R25
sts _qcnt,R24
.dbline 115
; if(juli[0]!=JULI/100)
lds R16,_juli
lds R17,_juli+1
rcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
ldi R16,<L33
ldi R17,>L33
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,<L34
ldi R17,>L34
rcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
rcall div32fs
rcall cmp32f
breq L31
.dbline 116
; {
.dbline 117
; juli[0]=JULI/100;
ldi R16,<L33
ldi R17,>L33
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,<L34
ldi R17,>L34
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 118
; LCD_write(5,1,'0'+juli[0]);
mov R24,R16
mov R25,R17
adiw R24,48
std y+1,R25
std y+0,R24
ldi R18,1
ldi R16,5
rcall _LCD_write
.dbline 119
; }
L31:
.dbline 120
; if(juli[1]!=(JULI-juli[0]*100)/10)
lds R16,_juli+2
lds R17,_juli+2+1
rcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
ldi R16,<L33
ldi R17,>L33
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,<L38
ldi R17,>L38
rcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
rcall div32fs
rcall cmp32f
breq L35
.dbline 121
; {
.dbline 122
; juli[1]=(JULI-juli[0]*100)/10;
ldi R16,<L33
ldi R17,>L33
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,<L38
ldi R17,>L38
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 123
; LCD_write(6,1,'0'+juli[1]);
mov R24,R16
mov R25,R17
adiw R24,48
std y+1,R25
std y+0,R24
ldi R18,1
ldi R16,6
rcall _LCD_write
.dbline 124
; }
L35:
.dbline 125
lds R16,_juli+4
lds R17,_juli+4+1
rcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
ldi R16,<L33
ldi R17,>L33
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 sub32fs
rcall cmp32f
brne X2
rjmp L41
X2:
.dbline 126
.dbline 127
ldi R16,<L33
ldi R17,>L33
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 128
mov R24,R16
mov R25,R17
adiw R24,48
std y+1,R25
std y+0,R24
ldi R18,1
ldi R16,8
rcall _LCD_write
.dbline 129
L41:
.dbline -2
.dbline 130
; if(juli[2]!=JULI-juli[1]*10-juli[0]*100)
; {
; juli[2]=JULI-juli[1]*10-juli[0]*100;
; LCD_write(8,1,'0'+juli[2]);
; }
; }
L30:
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 137
;
; ////////////////////////////////
; // Function : init_devices()
; // Purpose : 硬件初始化
; //
; void init_devices(void)
; {
.dbline 138
; CLI();
cli
.dbline 139
; port_init();
rcall _port_init
.dbline 140
; timer0_init();
rcall _timer0_init
.dbline 141
; timer1_init();
rcall _timer1_init
.dbline 142
; PORTA&=0xC0;
in R24,0x1b
andi R24,192
out 0x1b,R24
.dbline 143
; PORTB=0xFF;
ldi R24,255
out 0x18,R24
.dbline 144
; MCUCR = 0x0F;
ldi R24,15
out 0x35,R24
.dbline 145
; GIMSK = 0xC0;
ldi R24,192
out 0x3b,R24
.dbline 146
; TIMSK = 0x02;
ldi R24,2
out 0x39,R24
.dbline 147
; SEI();
sei
.dbline -2
.dbline 148
; }
L48:
.dbline 0 ; func end
ret
.dbend
.dbfunc e shifth _shifth fV
.even
_shifth::
.dbline -1
.dbline 154
;
; ///////////////////////////////
; // 控制车速函数
; //
; void shifth(void) //控制高速
; {
.dbline 155
; OCR1BH = 0xFF;
ldi R24,255
out 0x29,R24
.dbline 156
; OCR1BL = 0xFF;
out 0x28,R24
.dbline -2
.dbline 157
; }
L49:
.dbline 0 ; func end
ret
.dbend
.dbfunc e stop _stop fV
.even
_stop::
.dbline -1
.dbline 161
; //////////////////////////////
; //
; void stop(void) //制动
; {
.dbline 162
; OCR1BH = 0x00;
clr R2
out 0x29,R2
.dbline 163
; OCR1BL = 0x00;
out 0x28,R2
.dbline -2
.dbline 164
; }
L50:
.dbline 0 ; func end
ret
.dbend
.dbfunc e shiftl _shiftl fV
.even
_shiftl::
.dbline -1
.dbline 168
; //////////////////////////////
; //
; void shiftl(void) //控制低速
; {
.dbline 169
; OCR1BH = 0x01;
ldi R24,1
out 0x29,R24
.dbline 170
; OCR1BL = 0xFF;
ldi R24,255
out 0x28,R24
.dbline -2
.dbline 171
; }
L51:
.dbline 0 ; func end
ret
.dbend
.area lit(rom, con, rel)
L38:
.word 0x0,0x4120
L34:
.word 0x0,0x42c8
L33:
.word 0x9168,0x3fad
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -