;***********************************************************************
; 光電自動(dòng)軌跡跟蹤車.dt
;***********************************************************************
PORT5 == 0x05 ;定義端口5,6,7
PORT6 == 0x06
PORT7 == 0x07
;-----------------------------------------------------------------------
IOCE == 0x0E ;定義WDT控制寄存器IOCE
;-----------------------------------------------------------------------
STATUS == 3 ;定義狀態(tài)寄存器STATUS和零標(biāo)志位Z_FLAG
Z_FLAG == 2
;---------------------------------------------------------------
DLY1 == 13 ;定義延時(shí)置數(shù)單元DLY1,DLY2,DLY3
DLY2 == 14
DLY3 == 15
TEMP == 16 ;定義暫存器單元TEMP,存放光電讀入數(shù)據(jù)
;-----------------------------------------------------------------------
ORG 0x00
INIT: MOV A,@0x0FF ;設(shè)定P7口全部為輸入
IOW PORT7
IOW PORT5
MOV A,@0x00 ;設(shè)定P6口全部為輸出
IOW PORT6
MOV A,@0X11
IOW IOCE ;關(guān)閉看門狗功能
MOV A,@0x00 ;停止電機(jī)運(yùn)行
MOV PORT6,A
;-----------------------------------------------------------------------
MAIN: MOV A,PORT7 ;讀光電輸入
AND A,@0B00000111 ;屏蔽高5位
XOR A,@0B00000111
MOV TEMP,A
BC STATUS,Z_FLAG ;清除零標(biāo)志位
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 ;保持原狀,無動(dòng)作,返回
JMP MAIN
ACT001: MOV A,@0B00000100 ;稍偏右,M1仃轉(zhuǎn),M2正轉(zhuǎn)
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT010: NOP ;無動(dòng)作,返回
JMP MAIN
ACT011: MOV A,@0B00000100 ;偏右,M1仃轉(zhuǎn),M2正轉(zhuǎn)
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT100: MOV A,@0B00000001 ;稍偏左,M1正轉(zhuǎn),M2仃轉(zhuǎn)
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT101: MOV A,@0B00000101 ;沿黑色膠帶正中前進(jìn),M1正轉(zhuǎn),M2正轉(zhuǎn)
MOV PORT6,A
JMP MAIN
ACT110: MOV A,@0B00000001 ;偏左,M1正轉(zhuǎn),M2仃轉(zhuǎn)
MOV PORT6,A
CALL TURNDELAY
JMP ACT101
ACT111: MOV A,@0B00001001 ;沒有壓到黑色膠帶,M1正轉(zhuǎn)、M2反轉(zhuǎn)
MOV PORT6,A
CALL TURNDELAY
CALL TURNDELAY
JMP ACT101
;-----------------------------------------------------------------------
TURNDELAY:MOV A,@50 ;轉(zhuǎn)彎延時(shí)約100毫秒,需調(diào)整
MOV DLY3,A
CALL DELAY
RET
;-----------------------------------------------------------------------
;延時(shí)時(shí)間 = 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 ;延時(shí)返回
EOP