光电自动轨迹跟踪车
扫描二维码
随时随地手机看文章
;***********************************************************************
; 光电自动轨迹跟踪车.dt
;***********************************************************************
PORT5 == 0x05 ;定义端口5,6,7
PORT6 == 0x06
PORT7 == 0x07
;-----------------------------------------------------------------------
IOCE == 0x0E ;定义WDT控制寄存器IOCE
;-----------------------------------------------------------------------
STATUS == 3 ;定义状态寄存器STATUS和零标志位Z_FLAG
Z_FLAG == 2
;---------------------------------------------------------------
DLY1 == 13 ;定义延时置数单元DLY1,DLY2,DLY3
DLY2 == 14
DLY3 == 15
TEMP == 16 ;定义暂存器单元TEMP,存放光电读入数据
;-----------------------------------------------------------------------
ORG 0x00
INIT: MOV A,@0x0FF ;设定P7口全部为输入
IOW PORT7
IOW PORT5
MOV A,@0x00 ;设定P6口全部为输出
IOW PORT6
MOV A,@0X11
IOW IOCE ;关闭看门狗功能
MOV A,@0x00 ;停止电机运行
MOV PORT6,A
;-----------------------------------------------------------------------
MAIN: MOV A,PORT7 ;读光电输入
AND A,@0B00000111 ;屏蔽高5位
XOR A,@0B00000111
MOV TEMP,A
BC STATUS,Z_FLAG ;清除零标志位
CHECK0: MOV A,TEMP
XOR A,@0B00000000 ;光电输入是000?
JBS STATUS,Z_FLAG
JMP CHECK1
JMP ACT000
CHECK1: MOV A,TEMP
XOR A,@0B00000001 ;光电输入是001?
JBS STATUS,Z_FLAG
JMP CHECK2
JMP ACT001
CHECK2: MOV A,TEMP
XOR A,@0B00000010 ;光电输入是010?
JBS STATUS,Z_FLAG
JMP CHECK3
JMP ACT010
CHECK3: MOV A,TEMP
XOR A,@0B00000011 ;光电输入是011?
JBS STATUS,Z_FLAG
JMP CHECK4
JMP ACT011
CHECK4: MOV A,TEMP
XOR A,@0B00000100 ;光电输入是100?
JBS STATUS,Z_FLAG
JMP CHECK5
JMP ACT100
CHECK5: MOV A,TEMP
XOR A,@0B00000101 ;光电输入是101?
JBS STATUS,Z_FLAG
JMP CHECK6
JMP ACT101
CHECK6: MOV A,TEMP
XOR A,@0B00000110 ;光电输入是110?
JBS STATUS,Z_FLAG
JMP CHECK7
JMP ACT110
CHECK7: MOV A,TEMP
XOR A,@0B00000111 ;光电输入是111?
JBS STATUS,Z_FLAG
JMP MAIN
JMP ACT111
;-----------------------------------------------------------------------
ACT000: NOP ;保持原状,无动作,返回
JMP MAIN
ACT001: MOV A,@0B00000100 ;稍偏右,M1仃转,M2正转
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT010: NOP ;无动作,返回
JMP MAIN
ACT011: MOV A,@0B00000100 ;偏右,M1仃转,M2正转
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT100: MOV A,@0B00000001 ;稍偏左,M1正转,M2仃转
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT101: MOV A,@0B00000101 ;沿黑色胶带正中前进,M1正转,M2正转
MOV PORT6,A
JMP MAIN
ACT110: MOV A,@0B00000001 ;偏左,M1正转,M2仃转
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT111: MOV A,@0B00001001 ;没有压到黑色胶带,M1正转、M2反转
MOV PORT6,A
CALL TURNDELAY
CALL TURNDELAY
JMP ACT101
;-----------------------------------------------------------------------
TURNDELAY:MOV A,@50 ;转弯延时约100毫秒,需调整
MOV DLY3,A
CALL DELAY
RET
;-----------------------------------------------------------------------
;延时时间 = 2mS * DLY3
DELAY: MOV A,@25 ;1*(DLY3)
MOV DLY2,A ;1*(DLY3)
INNER2: MOV A,@133 ;1*(DLY3)*(250)
MOV DLY1,A ;1*(DLY3)*(250)
INNER1: DJZ DLY1 ;1*(DLY3)*(250)*(133)
JMP INNER1 ;2*(DLY3)*(250)*(133)
DJZ DLY2 ;1*(DLY3)*(250)
JMP INNER2 ;2*(DLY3)*(250)
DJZ DLY3 ;1*(DLY3)
JMP DELAY ;2*(DLY3)
RET ;延时返回
EOP