1、寻迹小车realh equ 30h reall equ 31h wanth equ 32h wantl equ 33h bufferh equ 34h bufferl equ 35h bit_count equ 36h timer equ 37h timer1 equ 38dh data_in equ 020h data_out equ 021h s0 equ 022h num equ 3ch buffer equ 3dh s equ 3eh spre equ 3fh spre1 equ 40h cs bit p3.5 clk bit p3.4 dat bit p3.3 upret bit p
2、2.0 upkep bit p2.1 hangret bit p2.2 hangkep bit p2.3 hangled bit p2.4 lieled bit p2.5 led1 bit p1.0 led2 bit p1.1 led3 bit p1.2 led4 bit p1.3 org 0000 jmp main org 0003h jmp input org 0bh ljmp timer0 org 0030h table1: db 1 db 2 db 3 db 4 org 38h db 5 db 6 db 7 db 8 org 40h db 9 db 0 db 10 db 11 org
3、48h db 12 db 13 db 14 db 15 table2: db 0 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 1
4、3 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 db -1 db 25 db -2 db 25 db -3 db 25 db -4 db 24 db -5 db 24 db -6 db 24 db -7 db 24 db -8 db 23 db -9 db 23 db -10 db 22 db -11 db 22 db -12 db 21
5、 db -13 db 21 db -14 db 20 db -15 db 20 db -16 db 18 db -17 db 17 db -18 db 16 db -20 db 15 db -20 db 14 db -21 db 13 db -21 db 12 db -22 db 11 db -22 db 10 db -23 db 9 db -23 db 8 db -24 db 7 db -24 db 6 db -24 db 5 db -24 db 4 db -25 db 3 db -25 db 2 db -25 db 1 db -25 db 0 db -25 db -1 db -25 db
6、-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
7、-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 db 1 db -25 db 2 db -25 db 3 db -25 db 4 db -24 db 5 db -24 db 6 db -24 db 7 db -24 db 8 db -23 db 9 db -23 db 10 db -22 db 11 db -22 db 1
8、2 db -21 db 13 db -21 db 14 db -20 db 15 db -20 db 16 db -18 db 17 db -17 db 18 db -16 db 20 db -15 db 20 db -14 db 21 db -13 db 21 db -12 db 22 db -11 db 22 db -10 db 23 db -9 db 23 db -8 db 24 db -7 db 24 db -6 db 24 db -5 db 24 db -4 db 25 db -3 db 25 db -2 db 25 db -1 db 25 db 0 db 25 org 400h m
9、ain: clr upkep ;端口初始化 clr hangkep mov num,#0 ;变量初始化 mov sp,#4fh mov timer,#50 ;7279初始化 start_delay: mov timer1,#255 start_delay1: djnz timer1,start_delay1 djnz timer,start_delay mov data_out,#10100100b call send ;mov data_out,#0bfh ;call send setb cs setb upret setb upkep setb hangret setb hangkep ;
10、坐标初始化 acall delay herec:jnb hangled,herec clr hangkep clr upkep mov reall,#00 clr upret setb upkep acall delay hered:jnb lieled,hered clr upkep mov realh,#0 acall write mov tcon,#01h ;中断初始化 mov ie,#81h hered1: sjmp hered1 input: push acc push b acall read mov a,data_in cjne a,#10,next10 mov num,#0 a
11、call move ;直走 jmp exitin next10: cjne a,#11,next11 mov num,#0 mov dptr,#table2 mov r0,#141 ;? nextcir: movx a,dptr add a,wanth mov wanth,a inc dptr movx a,dptr add a,wantl mov wantl,a inc dptr acall move djnz r0,nextcir ;划圆 jmp exitin next11: cjne a,#12,next12 acall xunji ;寻迹 jmp exitin next12: cjne
12、 A,#13,NEXT13 mov num,#0 ;发挥 jmp exitin next13: ;输入数据 mov r0,num cjne r0,#0,nexth1 mov buffer,data_in mov data_out,data_in mov data_out,#86h call send mov data_out,data_in call send setb cs jmp outin nexth1: cjne r0,#1,nexth2 mov b,#10 mov a,buffer mul ab clr c add a,data_in mov buffer,a mov data_ou
13、t,data_in mov data_out,#85h call send mov data_out,data_in call send setb cs jmp outin nexth2: cjne r0,#2,nexth3 mov b,#10 mov a,buffer mul ab add a,data_in mov data_out,data_in mov data_out,#84h call send mov data_out,data_in call send setb cs mov wantl,a jmp outin nexth3: cjne r0,#3,nextl1 mov buf
14、fer,data_in mov data_out,data_in mov data_out,#82h call send mov data_out,data_in call send setb cs jmp outin nextl1: cjne r0,#4,nextl2 mov b,#10 mov a,buffer mul ab clr c add a,data_in mov buffer,a mov data_out,data_in mov data_out,#81h call send mov data_out,data_in call send setb cs jmp outin nex
15、tl2: cjne r0,#5,nextl3 mov b,#10 mov a,buffer mul ab clr c add a,data_in mov data_out,data_in mov data_out,#80h call send mov data_out,data_in call send setb cs mov wanth,a jmp outin nextL3: mov num,#0 mov data_out,#10100100b call send SETB CS jmp NEXT13 outin: inc num exitin: pop b pop acc reti mov
16、e: ;运动程序 PUSH ACC begin1: MOV A,reall CJNE A,wantl,NEXTM1 clr hangkep clr upkep ;停止运动 JMP begin2 ;转到行调整 NEXTM1: CLR C SUBB A,wantl JC NEXTMX clr hangret clr upret ;向左 SETB hangkep setb upkep ;开始运动 ACALL DELAY HEREM1:jnb hangled,herem1 dec reall acall write sjmp begin1 nextmx: setb hangret setb upret
17、 ;向右 setb hangkep setb upkep ;开始运动 acall delay herem2:jnb hangled,herem2 inc reall acall write jmp begin1 begin2: mov a,realh CJNE A,wanth,nextm3 clr upkep JMP outmov NEXTM3: CLR C SUBB A,wanth JC NEXTMX2 SETB upret ;向下 SETB upkep ;开始运动 ACALL DELAY HEREM3:jnb lieled,herem3 dec realh acall write jmp
18、begin2 nextmx2: clr upret ;向上 setb upkep ;开始运动 acall delay herem4:jnb lieled,herem4 inc realh acall write jmp begin2 outmov: pop acc ret write: ;显示运动中实际位置 push acc push b mov a,realh mov b,#10 div ab mov data_out,#84h call send mov data_out,b call send mov b,#10 div ab mov data_out,#85h call send mo
19、v data_out,b call send mov data_out,#86h call send mov data_out,A call send mov a,reall mov b,#10 div ab mov data_out,#80h call send mov data_out,b call send mov b,#10 div ab mov data_out,#81h call send mov data_out,b call send mov data_out,#82h call send mov data_out,A call send pop b pop acc ret s
20、end: ;7279显示 PUSH ACC mov bit_count,#8 clr cs call long_delay send_loop: mov c,data_out.7 mov dat,c setb clk mov a,data_out rl a mov data_out,a call short_delay clr clk djnz bit_count,send_loop clr dat POP ACC ret read: ;读键盘 push acc push psw push dpl push dph mov data_out,#00010101b call send mov b
21、it_count,#8 setb dat call long_delay receive_loop: setb clk call short_delay mov a,data_in rl a mov data_in,a mov c,dat mov data_in.0,c clr clk call short_delay djnz bit_count,receive_loop clr dat mov a,data_in mov dptr,#table1 movc a,a+dptr mov data_in,a setb cs pop dph pop dpl pop psw pop acc ret
22、delay: ;光电扫描延时 mov r2,#2; timeD: mov r1,#255; loop2: mov r0,#255; loop1: djnz r0,loop1; djnz r1,loop2; djnz r2,timeD; ret long_delay: ;7279长延时 mov timer,#25 delay_loop:djnz timer,delay_loop ret short_delay: ;7279短延时 mov timer,#4 short_lp: djnz timer,short_lp ret timer0: mov spre1,s clr tr0 reti xunj
23、i: mov num,#0 mov s,#00 mov spre,#02h mov spre1,#02h lcall fuzhi nextxun: mov a,p1 anl a,#0fh cjne a,#0h ,nextxun0 sjmp nextxun nextxun0: cjne a,#01h,nextx1 mov r0,s cjne r0,#00h,nextx11 mov r0,spre1 cjne r0,#02,nextx111 jmp search nextx111: mov s,#03h lcall fuzhi mov spre,#00 mov spre1,spre mov tl0
24、,#0 mov th0,#03 setb tr0 nextx11: mov r0,spre1 cjne r0,#00,nextx112 jmp search nextx112: mov s,#01h lcall fuzhi mov spre ,#02 mov spre1,spre mov tl0,#0 mov th0,#3 setb tr0 jmp nextxun nextx1: cjne a,#02h,nextx2 mov r0,s cjne r0,#00h,nextx21 mov r0,spre1 cjne r0,#03,nextx211 jmp search nextx211: mov
25、s,#02h lcall fuzhi mov spre,#00 mov spre1,spre mov tl0,#0 mov th0,#3 setb tr0 nextx21: mov r0,spre1 cjne r0,#00,nextx212 jmp search nextx212: mov s,#01h lcall fuzhi mov spre ,#03 mov spre1,spre mov tl0,#0 mov th0,#3 setb tr0 jmp nextxun nextx2: cjne a,#04h,nextx3 mov r0,s cjne r0,#01h,nextx31 mov r0
26、,spre1 cjne r0,#02,nextx311 jmp search nextx311: mov s,#03h lcall fuzhi mov spre,#01 mov spre1,spre mov tl0,#0 mov th0,#3 setb tr0 nextx31: mov r0,spre1 cjne r0,#01,nextx312 jmp search nextx312: mov s,#00h lcall fuzhi mov spre ,#02 mov spre1,spre mov tl0,#0 mov th0,#3 setb tr0 jmp nextxun nextx3: cjne a,#08h,search mov r0,s cjne r0,#01h,nextx41 mov r0,spre1 cjne r0,#03,nextx411 jm
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1