?? motor.s
字號:
.module motor.c
.area text(rom, con, rel)
.dbfile D:\桌面\avr程序設計\循跡小車\motor.c
.dbfunc e motor_left_forward _motor_left_forward fV
; speed -> R16
.even
_motor_left_forward::
.dbline -1
.dbline 9
; /****************************************************************
; ** 文件名:motor.c 電機驅(qū)動函數(shù)
; ****************************************************************/
; #include "config.h"
;
; /************************左電機動作*****************************/
; //左電機前進
; void motor_left_forward(uint8 speed)
; {
.dbline 10
; motol_uen1;
cbi 0x18,4
.dbline 11
; motol_en2;
sbi 0x18,5
.dbline 12
; if(speed!=0) //加入調(diào)速指令
tst R16
breq L2
.dbline 13
; {
.dbline 14
; OCR0=speed;
out 0x3c,R16
.dbline 15
; }
L2:
.dbline 16
; T0_EN;
in R24,0x39
ori R24,3
out 0x39,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r speed 16 c
.dbend
.dbfunc e motor_left_backward _motor_left_backward fV
; speed -> R16
.even
_motor_left_backward::
.dbline -1
.dbline 20
; }
; //左電機后退
; void motor_left_backward(uint8 speed)
; {
.dbline 21
; motol_en1;
sbi 0x18,4
.dbline 22
; motol_uen2;
cbi 0x18,5
.dbline 23
; if(speed!=0) //加入調(diào)速指令
tst R16
breq L5
.dbline 24
; {
.dbline 25
; OCR0=speed;
out 0x3c,R16
.dbline 26
; }
L5:
.dbline 27
; T0_EN;
in R24,0x39
ori R24,3
out 0x39,R24
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbsym r speed 16 c
.dbend
.dbfunc e motor_left_speed_set _motor_left_speed_set fV
; speed -> R16
.even
_motor_left_speed_set::
.dbline -1
.dbline 31
.dbline 32
tst R16
breq L8
.dbline 33
.dbline 34
out 0x3c,R16
.dbline 35
L8:
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbsym r speed 16 c
.dbend
.dbfunc e motor_left_stop _motor_left_stop fV
.even
_motor_left_stop::
.dbline -1
.dbline 39
; }
; //左電機速度設定
; void motor_left_speed_set(uint8 speed)
; {
; if(speed!=0)
; {
; OCR0=speed;
; }
; }
; //左電機滑行
; void motor_left_stop(void)
; {
.dbline 40
; motol_uen1;
cbi 0x18,4
.dbline 41
; motol_uen2;
cbi 0x18,5
.dbline 42
; T0_UEN;
in R24,0x39
andi R24,253
out 0x39,R24
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e motor_left_quick_stop _motor_left_quick_stop fV
.even
_motor_left_quick_stop::
.dbline -1
.dbline 46
; }
; //左電機急停
; void motor_left_quick_stop(void)
; {
.dbline 47
; motol_en1;
sbi 0x18,4
.dbline 48
; motol_en2;
sbi 0x18,5
.dbline 49
; T0_UEN;
in R24,0x39
andi R24,253
out 0x39,R24
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.dbfunc e motor_right_forward _motor_right_forward fV
; speed -> R16
.even
_motor_right_forward::
.dbline -1
.dbline 55
; }
;
; /*************************右電機動作*****************************/
; //右電機前進
; void motor_right_forward(uint8 speed)
; {
.dbline 56
; motor_en1;
sbi 0x18,1
.dbline 57
; motor_uen2;
cbi 0x18,2
.dbline 58
; if(speed!=0) //加入調(diào)速指令
tst R16
breq L13
.dbline 59
; {
.dbline 60
; OCR2=speed;
out 0x23,R16
L15:
.dbline 61
L16:
.dbline 61
; while(ASSR&(1<<TCR2UB)==1) ; //異步操作需要等待 OCR2寫入完畢
in R2,0x22
sbrc R2,0
rjmp L15
.dbline 62
; }
L13:
.dbline 63
; T2_EN;
in R24,0x39
ori R24,192
out 0x39,R24
.dbline -2
L12:
.dbline 0 ; func end
ret
.dbsym r speed 16 c
.dbend
.dbfunc e motor_right_backward _motor_right_backward fV
; speed -> R16
.even
_motor_right_backward::
.dbline -1
.dbline 67
; }
; //右電機后退
; void motor_right_backward(uint8 speed)
; {
.dbline 68
; motor_uen1;
cbi 0x18,1
.dbline 69
; motor_en2;
sbi 0x18,2
.dbline 70
; if(speed!=0) //加入調(diào)速指令
tst R16
breq L19
.dbline 71
; {
.dbline 72
; OCR2=speed;
out 0x23,R16
L21:
.dbline 73
L22:
.dbline 73
; while(ASSR&(1<<TCR2UB)==1) ; //異步操作需要等待 OCR2寫入完畢
in R2,0x22
sbrc R2,0
rjmp L21
.dbline 74
; }
L19:
.dbline 75
; T2_EN;
in R24,0x39
ori R24,192
out 0x39,R24
.dbline -2
L18:
.dbline 0 ; func end
ret
.dbsym r speed 16 c
.dbend
.dbfunc e motor_right_speed_set _motor_right_speed_set fV
; speed -> R16
.even
_motor_right_speed_set::
.dbline -1
.dbline 79
; }
; //右電機速度設定
; void motor_right_speed_set(uint8 speed)
; {
.dbline 80
; if(speed!=0)
tst R16
breq L25
.dbline 81
; {
.dbline 82
; OCR0=speed;
out 0x3c,R16
L27:
.dbline 83
L28:
.dbline 83
in R2,0x22
sbrc R2,0
rjmp L27
.dbline 84
L25:
.dbline -2
L24:
.dbline 0 ; func end
ret
.dbsym r speed 16 c
.dbend
.dbfunc e motor_right_stop _motor_right_stop fV
.even
_motor_right_stop::
.dbline -1
.dbline 88
; while(ASSR&(1<<TCR2UB)==1) ; //異步操作需要等待 OCR2寫入完畢
; }
; }
; //右電機滑行
; void motor_right_stop(void)
; {
.dbline 89
; motor_uen1;
cbi 0x18,1
.dbline 90
; motor_uen2;
cbi 0x18,2
.dbline 91
; T2_UEN;
in R24,0x39
andi R24,127
out 0x39,R24
.dbline -2
L30:
.dbline 0 ; func end
ret
.dbend
.dbfunc e motor_right_quick_stop _motor_right_quick_stop fV
.even
_motor_right_quick_stop::
.dbline -1
.dbline 96
; }
;
; //右電機急停
; void motor_right_quick_stop(void)
; {
.dbline 97
; motor_en1;
sbi 0x18,1
.dbline 98
; motor_en2;
sbi 0x18,2
.dbline 99
; T2_UEN;
in R24,0x39
andi R24,127
out 0x39,R24
.dbline -2
L31:
.dbline 0 ; func end
ret
.dbend
.dbfunc e straight _straight fV
.even
_straight::
.dbline -1
.dbline 105
; }
;
; /**********************小車動作*****************************/
;
; void straight(void) //直行
; {
.dbline 106
; motor_left_forward(0xfe);
ldi R16,254
xcall _motor_left_forward
.dbline 107
; motor_right_forward(0xfe);
ldi R16,254
xcall _motor_right_forward
.dbline -2
L32:
.dbline 0 ; func end
ret
.dbend
.dbfunc e turn_left _turn_left fV
.even
_turn_left::
.dbline -1
.dbline 111
; }
;
; void turn_left(void) //左轉(zhuǎn)
; {
.dbline 112
; motor_left_forward(0xfe);
ldi R16,254
xcall _motor_left_forward
.dbline 113
; motor_right_forward(0x50);
ldi R16,80
xcall _motor_right_forward
.dbline -2
L33:
.dbline 0 ; func end
ret
.dbend
.dbfunc e turn_right _turn_right fV
.even
_turn_right::
.dbline -1
.dbline 117
; }
;
; void turn_right(void) //右轉(zhuǎn)
; {
.dbline 118
; motor_left_forward(0x50);
ldi R16,80
xcall _motor_left_forward
.dbline 119
; motor_right_forward(0xfe);
ldi R16,254
xcall _motor_right_forward
.dbline -2
L34:
.dbline 0 ; func end
ret
.dbend
.dbfunc e straight_back _straight_back fV
.even
_straight_back::
.dbline -1
.dbline 123
; }
;
; void straight_back(void) //直回
; {
.dbline 124
; motor_left_backward(0xfe);
ldi R16,254
xcall _motor_left_backward
.dbline 125
; motor_right_backward(0xfe);
ldi R16,254
xcall _motor_right_backward
.dbline -2
L35:
.dbline 0 ; func end
ret
.dbend
.dbfunc e stop _stop fV
.even
_stop::
.dbline -1
.dbline 129
; }
;
; void stop(void) //急停
; {
.dbline 130
; motor_left_quick_stop();
xcall _motor_left_quick_stop
.dbline 131
; motor_right_quick_stop();
xcall _motor_right_quick_stop
.dbline -2
L36:
.dbline 0 ; func end
ret
.dbend
.dbfunc e mic_turn_right _mic_turn_right fV
.even
_mic_turn_right::
.dbline -1
.dbline 135
; }
;
; void mic_turn_right(void) //向右微調(diào)
; {
.dbline 136
; motor_left_forward(0xa0);
ldi R16,160
xcall _motor_left_forward
.dbline 137
; motor_right_forward(0xfe);
ldi R16,254
xcall _motor_right_forward
.dbline -2
L37:
.dbline 0 ; func end
ret
.dbend
.dbfunc e mic_turn_left _mic_turn_left fV
.even
_mic_turn_left::
.dbline -1
.dbline 141
; }
;
; void mic_turn_left(void) //向左微調(diào)
; {
.dbline 142
; motor_left_forward(0xFE);
ldi R16,254
xcall _motor_left_forward
.dbline 143
; motor_right_forward(0xa0);
ldi R16,160
xcall _motor_right_forward
.dbline -2
L38:
.dbline 0 ; func end
ret
.dbend
.dbfunc e flag_test _flag_test fV
.area func_lit(rom, con, rel)
L49:
.word `L48
.word `L44
.word `L45
.word `L47
.word `L45
.word `L45
.word `L44
.word `L44
.word `L44
.word `L45
.word `L44
.word `L45
.word `L46
.word `L45
.word `L44
.word `L43
.area text(rom, con, rel)
.dbfile D:\桌面\avr程序設計\循跡小車\motor.c
; temp -> R20
.even
_flag_test::
xcall push_gset1
.dbline -1
.dbline 147
; }
;
; void flag_test(void) //測試小車狀態(tài)
; {
.dbline 149
; uint8 temp;
; temp = PINA&0x0f; //PINA的低四位
in R20,0x19
andi R20,15
.dbline 150
; switch(temp)
clr R21
cpi R20,0
ldi R30,0
cpc R21,R30
brlt L41
ldi R24,15
ldi R25,0
cp R24,R20
cpc R25,R21
brlt L41
ldi R16,2
ldi R17,0
movw R18,R20
xcall empy16s
movw R30,R16
ldi R24,<L49
ldi R25,>L49
add R30,R24
adc R31,R25
lpm R0,Z+
lpm R1,Z
movw R30,R0
ijmp
X0:
.dbline 151
; {
L43:
.dbline 153
; case 0x0f:
; flag = 0; //未偏
clr R2
sts _flag,R2
.dbline 154
; break;
xjmp L41
L44:
.dbline 161
; case 0x01:
; case 0x06:
; case 0x07:
; case 0x08:
; case 0x0a:
; case 0x0e:
; flag = 1; //左偏
ldi R24,1
sts _flag,R24
.dbline 162
; break;
xjmp L41
L45:
.dbline 169
; case 0x02:
; case 0x04:
; case 0x05:
; case 0x09:
; case 0x0b:
; case 0x0d:
; flag = 2; //右偏
ldi R24,2
sts _flag,R24
.dbline 170
; break;
xjmp L41
L46:
.dbline 172
; case 0x0c:
; flag = 3; //前兩出線
ldi R24,3
sts _flag,R24
.dbline 173
; break;
xjmp L41
L47:
.dbline 175
; case 0x03:
; flag = 4; //后兩出線
ldi R24,4
sts _flag,R24
.dbline 176
; break;
xjmp L41
L48:
.dbline 178
ldi R24,5
sts _flag,R24
.dbline 179
.dbline 181
L41:
.dbline -2
L39:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -