寻迹小车.docx
《寻迹小车.docx》由会员分享,可在线阅读,更多相关《寻迹小车.docx(31页珍藏版)》请在冰豆网上搜索。
寻迹小车
realhequ30h
reallequ31h
wanthequ32h
wantlequ33h
bufferhequ34h
bufferlequ35h
bit_countequ36h
timerequ37h
timer1equ38dh
data_inequ020h
data_outequ021h
s0equ022h
numequ3ch
bufferequ3dh
sequ3eh
spreequ3fh
spre1equ40h
csbitp3.5
clkbitp3.4
datbitp3.3
upretbitp2.0
upkepbitp2.1
hangretbitp2.2
hangkepbitp2.3
hangledbitp2.4
lieledbitp2.5
led1bitp1.0
led2bitp1.1
led3bitp1.2
led4bitp1.3
org0000
jmpmain
org0003h
jmpinput
org0bh
ljmptimer0
org0030h
table1:
db1
db2
db3
db4
org38h
db5
db6
db7
db8
org40h
db9
db0
db10
db11
org48h
db12
db13
db14
db15
table2:
db0
db25
db1
db25
db2
db25
db3
db25
db4
db25
db5
db24
db6
db24
db7
db24
db8
db24
db9
db23
db10
db23
db11
db22
db12
db22
db13
db21
db14
db21
db15
db20
db16
db20
db17
db18
db18
db17
db20
db16
db20
db15
db21
db14
db21
db13
db22
db12
db22
db11
db23
db10
db23
db9
db24
db8
db24
db7
db24
db6
db24
db5
db25
db4
db25
db3
db25
db2
db25
db1
db25
db0
db25
db-1
db25
db-2
db25
db-3
db25
db-4
db24
db-5
db24
db-6
db24
db-7
db24
db-8
db23
db-9
db23
db-10
db22
db-11
db22
db-12
db21
db-13
db21
db-14
db20
db-15
db20
db-16
db18
db-17
db17
db-18
db16
db-20
db15
db-20
db14
db-21
db13
db-21
db12
db-22
db11
db-22
db10
db-23
db9
db-23
db8
db-24
db7
db-24
db6
db-24
db5
db-24
db4
db-25
db3
db-25
db2
db-25
db1
db-25
db0
db-25
db-1
db-25
db-2
db-25
db-3
db-25
db-4
db-25
db-5
db-24
db-6
db-24
db-7
db-24
db-8
db-24
db-9
db-23
db-10
db-23
db-11
db-22
db-12
db-22
db-13
db-21
db-14
db-21
db-15
db-20
db-16
db-20
db-17
db-18
db-18
db-17
db-20
db-16
db-20
db-15
db-21
db-14
db-21
db-13
db-22
db-12
db-22
db-11
db-23
db-10
db-23
db-9
db-24
db-8
db-24
db-7
db-24
db-6
db-24
db-5
db-25
db-4
db-25
db-3
db-25
db-2
db-25
db-1
db-25
db-0
db-25
db1
db-25
db2
db-25
db3
db-25
db4
db-24
db5
db-24
db6
db-24
db7
db-24
db8
db-23
db9
db-23
db10
db-22
db11
db-22
db12
db-21
db13
db-21
db14
db-20
db15
db-20
db16
db-18
db17
db-17
db18
db-16
db20
db-15
db20
db-14
db21
db-13
db21
db-12
db22
db-11
db22
db-10
db23
db-9
db23
db-8
db24
db-7
db24
db-6
db24
db-5
db24
db-4
db25
db-3
db25
db-2
db25
db-1
db25
db0
db25
org400h
main:
clrupkep;端口初始化
clrhangkep
movnum,#0
;变量初始化
movsp,#4fh
movtimer,#50;7279初始化
start_delay:
movtimer1,#255
start_delay1:
djnztimer1,start_delay1
djnztimer,start_delay
movdata_out,#10100100b
callsend
;movdata_out,#0bfh
;callsend
setbcs
setbupret
setbupkep
setbhangret
setbhangkep;坐标初始化
acalldelay
herec:
jnbhangled,herec
clrhangkep
clrupkep
movreall,#00
clrupret
setbupkep
acalldelay
hered:
jnblieled,hered
clrupkep
movrealh,#0
acallwrite
movtcon,#01h;中断初始化
movie,#81h
hered1:
sjmphered1
input:
pushacc
pushb
acallread
mova,data_in
cjnea,#10,next10
movnum,#0
acallmove;直走
jmpexitin
next10:
cjnea,#11,next11
movnum,#0
movdptr,#table2
movr0,#141;?
?
?
?
?
?
?
?
?
?
?
?
?
?
nextcir:
movxa,@dptr
adda,wanth
movwanth,a
incdptr
movxa,@dptr
adda,wantl
movwantl,a
incdptr
acallmove
djnzr0,nextcir;划圆
jmpexitin
next11:
cjnea,#12,next12
acallxunji
;寻迹
jmpexitin
next12:
cjneA,#13,NEXT13
movnum,#0
;发挥
jmpexitin
next13:
;输入数据
movr0,num
cjner0,#0,nexth1
movbuffer,data_in
movdata_out,data_in
movdata_out,#86h
callsend
movdata_out,data_in
callsend
setbcs
jmpoutin
nexth1:
cjner0,#1,nexth2
movb,#10
mova,buffer
mulab
clrc
adda,data_in
movbuffer,a
movdata_out,data_in
movdata_out,#85h
callsend
movdata_out,data_in
callsend
setbcs
jmpoutin
nexth2:
cjner0,#2,nexth3
movb,#10
mova,buffer
mulab
adda,data_in
movdata_out,data_in
movdata_out,#84h
callsend
movdata_out,data_in
callsend
setbcs
movwantl,a
jmpoutin
nexth3:
cjner0,#3,nextl1
movbuffer,data_in
movdata_out,data_in
movdata_out,#82h
callsend
movdata_out,data_in
callsend
setbcs
jmpoutin
nextl1:
cjner0,#4,nextl2
movb,#10
mova,buffer
mulab
clrc
adda,data_in
movbuffer,a
movdata_out,data_in
movdata_out,#81h
callsend
movdata_out,data_in
callsend
setbcs
jmpoutin
nextl2:
cjner0,#5,nextl3
movb,#10
mova,buffer
mulab
clrc
adda,data_in
movdata_out,data_in
movdata_out,#80h
callsend
movdata_out,data_in
callsend
setbcs
movwanth,a
jmpoutin
nextL3:
movnum,#0
movdata_out,#10100100b
callsend
SETBCS
jmpNEXT13
outin:
incnum
exitin:
popb
popacc
reti
move:
;运动程序
PUSHACC
begin1:
MOVA,reall
CJNEA,wantl,NEXTM1
clrhangkep
clrupkep;停止运动
JMPbegin2;转到行调整
NEXTM1:
CLRC
SUBBA,wantl
JCNEXTMX
clrhangret
clrupret;向左
SETBhangkep
setbupkep;开始运动
ACALLDELAY
HEREM1:
jnbhangled,herem1
decreall
acallwrite
sjmpbegin1
nextmx:
setbhangret
setbupret;向右
setbhangkep
setbupkep;开始运动
acalldelay
herem2:
jnbhangled,herem2
increall
acallwrite
jmpbegin1
begin2:
mova,realh
CJNEA,wanth,nextm3
clrupkep
JMPoutmov
NEXTM3:
CLRC
SUBBA,wanth
JCNEXTMX2
SETBupret;向下
SETBupkep;开始运动
ACALLDELAY
HEREM3:
jnblieled,herem3
decrealh
acallwrite
jmpbegin2
nextmx2:
clrupret;向上
setbupkep;开始运动
acalldelay
herem4:
jnblieled,herem4
increalh
acallwrite
jmpbegin2
outmov:
popacc
ret
write:
;显示运动中实际位置
pushacc
pushb
mova,realh
movb,#10
divab
movdata_out,#84h
callsend
movdata_out,b
callsend
movb,#10
divab
movdata_out,#85h
callsend
movdata_out,b
callsend
movdata_out,#86h
callsend
movdata_out,A
callsend
mova,reall
movb,#10
divab
movdata_out,#80h
callsend
movdata_out,b
callsend
movb,#10
divab
movdata_out,#81h
callsend
movdata_out,b
callsend
movdata_out,#82h
callsend
movdata_out,A
callsend
popb
popacc
ret
send:
;7279显示
PUSHACC
movbit_count,#8
clrcs
calllong_delay
send_loop:
movc,data_out.7
movdat,c
setbclk
mova,data_out
rla
movdata_out,a
callshort_delay
clrclk
djnzbit_count,send_loop
clrdat
POPACC
ret
read:
;读键盘
pushacc
pushpsw
pushdpl
pushdph
movdata_out,#00010101b
callsend
movbit_count,#8
setbdat
calllong_delay
receive_loop:
setbclk
callshort_delay
mova,data_in
rla
movdata_in,a
movc,dat
movdata_in.0,c
clrclk
callshort_delay
djnzbit_count,receive_loop
clrdat
mova,data_in
movdptr,#table1
movca,@a+dptr
movdata_in,a
setbcs
popdph
popdpl
poppsw
popacc
ret
delay:
;光电扫描延时
movr2,#2;
timeD:
movr1,#255;
loop2:
movr0,#255;
loop1:
djnzr0,loop1;
djnzr1,loop2;
djnzr2,timeD;
ret
long_delay:
;7279长延时
movtimer,#25
delay_loop:
djnztimer,delay_loop
ret
short_delay:
;7279短延时
movtimer,#4
short_lp:
djnztimer,short_lp
ret
timer0:
movspre1,s
clrtr0
reti
xunji:
movnum,#0
movs,#00
movspre,#02h
movspre1,#02h
lcallfuzhi
nextxun:
mova,p1
anla,#0fh
cjnea,#0h,nextxun0
sjmpnextxun
nextxun0:
cjnea,#01h,nextx1
movr0,s
cjner0,#00h,nextx11
movr0,spre1
cjner0,#02,nextx111
jmpsearch
nextx111:
movs,#03h
lcallfuzhi
movspre,#00
movspre1,spre
movtl0,#0
movth0,#03
setbtr0
nextx11:
movr0,spre1
cjner0,#00,nextx112
jmpsearch
nextx112:
movs,#01h
lcallfuzhi
movspre,#02
movspre1,spre
movtl0,#0
movth0,#3
setbtr0
jmpnextxun
nextx1:
cjnea,#02h,nextx2
movr0,s
cjner0,#00h,nextx21
movr0,spre1
cjner0,#03,nextx211
jmpsearch
nextx211:
movs,#02h
lcallfuzhi
movspre,#00
movspre1,spre
movtl0,#0
movth0,#3
setbtr0
nextx21:
movr0,spre1
cjner0,#00,nextx212
jmpsearch
nextx212:
movs,#01h
lcallfuzhi
movspre,#03
movspre1,spre
movtl0,#0
movth0,#3
setbtr0
jmpnextxun
nextx2:
cjnea,#04h,nextx3
movr0,s
cjner0,#01h,nextx31
movr0,spre1
cjner0,#02,nextx311
jmpsearch
nextx311:
movs,#03h
lcallfuzhi
movspre,#01
movspre1,spre
movtl0,#0
movth0,#3
setbtr0
nextx31:
movr0,spre1
cjner0,#01,nextx312
jmpsearch
nextx312:
movs,#00h
lcallfuzhi
movspre,#02
movspre1,spre
movtl0,#0
movth0,#3
setbtr0
jmpnextxun
nextx3:
cjnea,#08h,search
movr0,s
cjner0,#01h,nextx41
movr0,spre1
cjner0,#03,nextx411
jm