?? car.s
字號:
.module car.c
.area text(rom, con, rel)
.dbfile F:\car\car.c
.area data(ram, con, rel)
.dbfile F:\car\car.c
_T::
.blkb 2
.area idata
.word 1000
.area data(ram, con, rel)
.dbfile F:\car\car.c
.dbsym e T _T i
.area text(rom, con, rel)
.dbfile F:\car\car.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 9
; //ICC-AVR application builder : 2008-4-29 16:08:41
; // Target : M32
; // Crystal: 12.000Mhz
;
; #include <iom32v.h>
; #include <macros.h>
; unsigned int T=1000;
; void port_init(void)
; {
.dbline 10
; PORTA = 0XFF;
ldi R24,255
out 0x1b,R24
.dbline 11
; DDRA = 0x00;//PA 為輸入口
clr R2
out 0x1a,R2
.dbline 12
; PORTB = 0xff;
out 0x18,R24
.dbline 13
; DDRB = 0xff;//PB 為輸出口
out 0x17,R24
.dbline 14
; PORTC = 0Xff;
out 0x15,R24
.dbline 15
; DDRC = 0x00;//PC 為輸入口
out 0x14,R2
.dbline 16
; PORTD = 0xFF;
out 0x12,R24
.dbline 17
; DDRD = 0xff;//PD 為輸出口
out 0x11,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay _delay fV
; i -> R20,R21
; hh -> R16,R17
.even
_delay::
st -y,R20
st -y,R21
.dbline -1
.dbline 27
; }
; //============================================================================================
; //函數(shù): void delay(int hh)
; //語法:void delay(int hh)
; //描述:延時子程序
; //參數(shù):
; //返回:無
; //============================================================================================
; void delay(unsigned int hh )
; {
.dbline 29
; int i;
; for(i=0;i<hh;i++)
clr R20
clr R21
xjmp L6
L3:
.dbline 30
; {
.dbline 31
; ;
.dbline 32
; }
L4:
.dbline 29
subi R20,255 ; offset = 1
sbci R21,255
L6:
.dbline 29
cp R20,R16
cpc R21,R17
brlo L3
X0:
.dbline -2
L2:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r i 20 I
.dbsym r hh 16 i
.dbend
.dbfunc e stop _stop fV
.even
_stop::
.dbline -1
.dbline 96
; }
; //============================================================================================
; //函數(shù): void pwma(int hh)
; //語法:void pwma(int hh)
; //描述: 用于控制右輪
; //參數(shù):占空比
; //返回:無
; //============================================================================================
; /*void pwma( unsigned int hh)
; {
; unsigned int s=0;
; unsigned int T0=10000;
; unsigned int H;
; s=PORTA;
; switch(hh) //占空比
; {
; case 0: s=s&0xfc; delay(T0);break; //關(guān)占空比
; case 1: delay(1000);s=s&0xfc; delay(9000);break;
; case 2: delay(2000);s=s&0xfc; delay(8000);break;
; case 3: delay(3000);s=s&0xfc; delay(7000);break;
; case 4: delay(4000);s=s&0xfC; delay(6000);break;
; case 5: delay(5000);s=s&0xfc; delay(5000);break;
; case 6: delay(6000);s=s&0xfc; delay(4000);break;
; case 7: delay(7000);s=s&0xfc; delay(3000);break;
; case 8: delay(8000);s=s&0xfc; delay(2000);break;
; case 9: delay(9000);s=s&0xfc; delay(1000);break;
; case 10: delay(10000);s=s&0xfc;break;
; }
; }
; //============================================================================================
; //函數(shù): void pwmb(int hh)
; //語法:void pwmb(int hh)
; //描述: 用于控制左輪
; //參數(shù):占空比
; //返回:無
; //============================================================================================
; void pwmb( unsigned int hh) //設(shè)定TA_TIMEOUT/16=(time_cl)/0x1e00)/16=100Hz
; {
; unsigned int k=0;
; int T=10000;
; int H;
; k=PORTA;
; switch(hh) //占空比
; {
; case 0: k=k&0xf3; break; //關(guān)占空比
; case 1: delay(1000);k=k&0xf3; delay(9000);break;
; case 2: delay(2000);k=k&0xf3; delay(8000);break;
; case 3: delay(3000);k=k&0xf3; delay(7000);break;
; case 4: delay(4000);k=k&0xf3; delay(6000);break;
; case 5: delay(5000);k=k&0xf3; delay(5000);break;
; case 6: delay(6000);k=k&0xf3; delay(4000);break;
; case 7: delay(7000);k=k&0xf3; delay(3000);break;
; case 8: delay(8000);k=k&0xf3; delay(2000);break;
; case 9: delay(9000);k=k&0xf3; delay(1000);break;
; case 10: delay(10000);k=k&0xf3;break;
; }
; }*/
; //============================================================================================
; //描述:車子方向控制子程序
; //參數(shù) 無
; //返回:無
; //============================================================================================
; void stop() //停止
; {
.dbline 97
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 98
; delay(1000);
ldi R16,1000
ldi R17,3
xcall _delay
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbend
.dbfunc e GO _GO fV
; aa -> R10,R11
.even
_GO::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 103
; }
;
;
; void GO(unsigned int aa) //直線前進
; {
.dbline 104
; PORTB=0X06;
ldi R24,6
out 0x18,R24
.dbline 105
; delay(aa);
movw R16,R10
xcall _delay
.dbline 106
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 107
; delay(T-aa);
lds R16,_T
lds R17,_T+1
sub R16,R10
sbc R17,R11
xcall _delay
.dbline -2
L8:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r aa 10 i
.dbend
.dbfunc e BACK _BACK fV
; bb -> R10,R11
.even
_BACK::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 112
;
; }
;
; void BACK(unsigned int bb) // 直線后退
; {
.dbline 113
; PORTB=0X09;
ldi R24,9
out 0x18,R24
.dbline 114
; delay(bb);
movw R16,R10
xcall _delay
.dbline 115
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 116
; delay(T-bb);
lds R16,_T
lds R17,_T+1
sub R16,R10
sbc R17,R11
xcall _delay
.dbline -2
L9:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r bb 10 i
.dbend
.dbfunc e GTOL _GTOL fV
; cc -> R10,R11
.even
_GTOL::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 120
; }
;
; void GTOL(unsigned int cc) //前左轉(zhuǎn)
; {
.dbline 122
;
; PORTB=0X02;
ldi R24,2
out 0x18,R24
.dbline 123
; delay(cc);
movw R16,R10
xcall _delay
.dbline 124
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 125
; delay(T-cc);
lds R16,_T
lds R17,_T+1
sub R16,R10
sbc R17,R11
xcall _delay
.dbline -2
L10:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r cc 10 i
.dbend
.dbfunc e GTOR _GTOR fV
; dd -> R10,R11
.even
_GTOR::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 129
; }
;
; void GTOR(unsigned int dd) //前右轉(zhuǎn)
; {
.dbline 131
;
; PORTB=0X04;
ldi R24,4
out 0x18,R24
.dbline 132
; delay(dd);
movw R16,R10
xcall _delay
.dbline 133
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 134
; delay(T-dd);
lds R16,_T
lds R17,_T+1
sub R16,R10
sbc R17,R11
xcall _delay
.dbline -2
L11:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r dd 10 i
.dbend
.dbfunc e BTOR _BTOR fV
; cc -> R10,R11
.even
_BTOR::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 137
; }
; void BTOR(unsigned int cc) //后左轉(zhuǎn)
; {
.dbline 139
;
; PORTB=0X01;
ldi R24,1
out 0x18,R24
.dbline 140
; delay(cc);
movw R16,R10
xcall _delay
.dbline 141
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 142
; delay(T-cc);
lds R16,_T
lds R17,_T+1
sub R16,R10
sbc R17,R11
xcall _delay
.dbline -2
L12:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r cc 10 i
.dbend
.dbfunc e BTOL _BTOL fV
; dd -> R10,R11
.even
_BTOL::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 146
; }
;
; void BTOL(unsigned int dd) //后右轉(zhuǎn)
; {
.dbline 148
;
; PORTB=0X08;
ldi R24,8
out 0x18,R24
.dbline 149
; delay(dd);
movw R16,R10
xcall _delay
.dbline 150
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 151
; delay(T-dd);
lds R16,_T
lds R17,_T+1
sub R16,R10
sbc R17,R11
xcall _delay
.dbline -2
L13:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r dd 10 i
.dbend
.dbfunc e Linecheck_GO _Linecheck_GO fV
; temp -> R10
.even
_Linecheck_GO::
xcall push_xgset300C
.dbline -1
.dbline 161
; }
; //============================================================================================
; //函數(shù): void line_check_GO(void)
; //語法:void line_check_GO(void)
; //描述: 前進黑白尋跡檢測
; //參數(shù):無
; //返回:無
; //============================================================================================
; void Linecheck_GO(void)
; {
.dbline 163
; unsigned char temp;
; PORTA = 0XFF;
ldi R24,255
out 0x1b,R24
.dbline 164
; DDRA = 0x00;//PA 為輸入口
clr R2
out 0x1a,R2
.dbline 165
; NOP();
nop
.dbline 166
; temp=PINA;
in R10,0x19
.dbline 167
; switch(temp)
mov R20,R10
clr R21
cpi R20,240
ldi R30,0
cpc R21,R30
breq L18
X1:
ldi R24,240
ldi R25,0
cp R24,R20
cpc R25,R21
brlt L24
X2:
L23:
cpi R20,225
ldi R30,0
cpc R21,R30
breq L22
X3:
xjmp L15
L24:
cpi R20,247
ldi R30,0
cpc R21,R30
breq L19
X4:
cpi R20,247
ldi R30,0
cpc R21,R30
brlt L15
X5:
L25:
cpi R20,251
ldi R30,0
cpc R21,R30
breq L20
X6:
cpi R20,253
ldi R30,0
cpc R21,R30
breq L21
X7:
xjmp L15
L18:
.dbline 169
; {
; case 0xf0: GTOL(600); break;
ldi R16,600
ldi R17,2
xcall _GTOL
.dbline 169
xjmp L16
L19:
.dbline 170
; case 0xF7: GTOL(600); break;
ldi R16,600
ldi R17,2
xcall _GTOL
.dbline 170
xjmp L16
L20:
.dbline 171
; case 0xFB: GO(700); break;
ldi R16,700
ldi R17,2
xcall _GO
.dbline 171
xjmp L16
L21:
.dbline 172
; case 0XFD: GTOR(600); break;
ldi R16,600
ldi R17,2
xcall _GTOR
.dbline 172
xjmp L16
L22:
.dbline 173
; case 0xe1: GTOR(600); break;
ldi R16,600
ldi R17,2
xcall _GTOR
.dbline 173
xjmp L16
L15:
.dbline 174
; default : GO(700);
ldi R16,700
ldi R17,2
xcall _GO
.dbline 175
; }
L16:
.dbline -2
L14:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r temp 10 c
.dbend
.dbfunc e Linecheck_BACK _Linecheck_BACK fV
; temp -> R10
.even
_Linecheck_BACK::
xcall push_xgset300C
.dbline -1
.dbline 185
; }
; //============================================================================================
; //函數(shù): void line_check_BACK(void)
; //語法:void line_check_BACK(void)
; //描述: 前進黑白尋跡檢測
; //參數(shù):無
; //返回:無
; //============================================================================================
; void Linecheck_BACK(void)
; {
.dbline 187
; unsigned char temp;
; PORTA = 0XFF;
ldi R24,255
out 0x1b,R24
.dbline 188
; DDRA = 0x00;//PA 為輸入口
clr R2
out 0x1a,R2
.dbline 189
; _NOP();
nop
.dbline 190
; temp=PINA;
in R10,0x19
.dbline 191
; switch(temp)
mov R20,R10
clr R21
cpi R20,225
ldi R30,0
cpc R21,R30
breq L34
X8:
cpi R20,226
ldi R30,0
cpc R21,R30
breq L33
X9:
cpi R20,228
ldi R30,0
cpc R21,R30
breq L32
X10:
cpi R20,232
ldi R30,0
cpc R21,R30
breq L31
X11:
cpi R20,225
ldi R30,0
cpc R21,R30
brlt L27
X12:
L35:
cpi R20,240
ldi R30,0
cpc R21,R30
breq L30
X13:
xjmp L27
L30:
.dbline 193
; {
; case 0xf0: BTOR(600); break;
ldi R16,600
ldi R17,2
xcall _BTOR
.dbline 193
xjmp L28
L31:
.dbline 194
; case 0xe8: BTOR(600); break;
ldi R16,600
ldi R17,2
xcall _BTOR
.dbline 194
xjmp L28
L32:
.dbline 195
; case 0xe4: BACK(700); break;
ldi R16,700
ldi R17,2
xcall _BACK
.dbline 195
xjmp L28
L33:
.dbline 196
; case 0Xe2: BTOL(600); break;
ldi R16,600
ldi R17,2
xcall _BTOL
.dbline 196
xjmp L28
L34:
.dbline 197
; case 0xe1: BTOL(600); break;
ldi R16,600
ldi R17,2
xcall _BTOL
.dbline 197
xjmp L28
L27:
.dbline 198
; default : BACK(700);
ldi R16,700
ldi R17,2
xcall _BACK
.dbline 199
; }
L28:
.dbline -2
L26:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r temp 10 c
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 209
; }
; //============================================================================================
; //函數(shù): void main()
; //語法:void main()
; //描述:主函數(shù)
; //參數(shù) 無
; //返回:無
; //============================================================================================
; void main()
; {
.dbline 210
; port_init();
xcall _port_init
xjmp L38
L37:
.dbline 212
; while(1)
; {
.dbline 213
; Linecheck_GO();
xcall _Linecheck_GO
.dbline 219
; //Linecheck_BACK();
; //GO(800);
; // BACK(700);
; // TOR(700);
; //TOL(500);
; }
L38:
.dbline 211
xjmp L37
X14:
.dbline -2
L36:
.dbline 0 ; func end
ret
.dbend
; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -