EM78P447紅外遙控電動(dòng)機(jī)
;***********************************************************************
; 紅外遙控電動(dòng)機(jī).dt
;***********************************************************************
PORT5 == 0x05 ;定義端口5,6
PORT6 == 0x06
;-----------------------------------------------------------------------
IOCE == 0x0E ;定義WDT控制寄存器IOCE
;-----------------------------------------------------------------------
BUFFER == 12 ;定義暫存器BUFFER,存放當(dāng)前輸出
DLY1 == 13 ;定義延時(shí)置數(shù)單元DLY1,DLY2,DLY3
DLY2 == 14
DLY3 == 15
;-----------------------------------------------------------------------
ORG 0x00
INIT: MOV A,@0x0FF ;設(shè)定P5口全部為輸入
IOW PORT5
MOV A,@0x00 ;設(shè)定P6口全部為輸出
IOW PORT6
MOV A,@0X11
IOW IOCE ;關(guān)閉看門狗功能
MOV A,@00000000B
MOV BUFFER,A ;停止電機(jī)運(yùn)行
MOV PORT6,A
;-----------------------------------------------------------------------
MAIN: NOP
IRTEST0: JBC PORT5,0 ;檢查紅外按鍵0(前進(jìn),保持)
JMP IRTEST1
JMP IR0
IRTEST1: JBC PORT5,1 ;檢查紅外按鍵1(后退,保持)
JMP IRTEST2
JMP IR1
IRTEST2: JBC PORT5,2 ;檢查紅外按鍵2(自轉(zhuǎn),保持)
JMP IRTEST3
JMP IR2
IRTEST3: JBC PORT5,3 ;檢查紅外按鍵3(右轉(zhuǎn),點(diǎn)動(dòng))
JMP IRTEST4
JMP IR3
IRTEST4: JBC PORT5,4 ;檢查紅外按鍵4(左轉(zhuǎn),點(diǎn)動(dòng))
JMP IRTEST5
JMP IR4
IRTEST5: JBC PORT5,5 ;檢查紅外按鍵5(停止)
JMP KEEPRUN ;無(wú)鍵按入,保持原運(yùn)行狀態(tài)
JMP IR5
;-----------------------------------------------------------------------
IR0: CALL KEYDELAY ;電機(jī)M1正轉(zhuǎn),M2正轉(zhuǎn),保持
IR00: MOV A,@0B00000101 ;輸出編碼
MOV BUFFER,A ;送暫存器保存
MOV PORT6,A ;Port6口輸出
IR000: JBS PORT5,0 ;檢查按鍵是否已釋放
JMP IR000 ;未釋放,等待
JMP IRTEST0 ;已釋放,跳轉(zhuǎn)去檢查按鍵是否有按下
IR1: CALL KEYDELAY ;電機(jī)M1仃轉(zhuǎn),M2正轉(zhuǎn),點(diǎn)動(dòng)
IR01: MOV A,@0B00000100
MOV PORT6,A
CALL TURNDELAY
MOV A,BUFFER
MOV PORT6,A
IR010: JBS PORT5,1
JMP IR010
JMP IRTEST0
IR2: CALL KEYDELAY ;電機(jī)M1正轉(zhuǎn),M2反轉(zhuǎn),保持
IR02: MOV A,@0B00001001
MOV BUFFER,A
MOV PORT6,A
IR020: JBS PORT5,2
JMP IR020
JMP IRTEST0
IR3: CALL KEYDELAY ;電機(jī)M1正轉(zhuǎn),M2仃轉(zhuǎn),點(diǎn)動(dòng)
IR03: MOV A,@0B00000001
MOV PORT6,A
CALL TURNDELAY
MOV A,BUFFER
MOV PORT6,A
IR030: JBS PORT5,3
JMP IR030
JMP IRTEST0
IR4: CALL KEYDELAY ;電機(jī)M1反轉(zhuǎn),M2反轉(zhuǎn),保持
IR04: MOV A,@0B00001010
MOV BUFFER,A
MOV PORT6,A
IR040: JBS PORT5,4
JMP IR040
JMP IRTEST0
IR5: CALL KEYDELAY ;電機(jī)M1,電機(jī)M2停轉(zhuǎn),保持
IR05: MOV A,@0B00000000
MOV BUFFER,A
MOV PORT6,A
IR050: JBS PORT5,4
JMP IR050
JMP IRTEST0
;-----------------------------------------------------------------------
KEEPRUN: MOV A,BUFFER ;保持原運(yùn)行狀態(tài)
MOV PORT6,A
JMP IRTEST0 ;繼續(xù)檢測(cè)紅外按鍵
;-----------------------------------------------------------------------
KEYDELAY:MOV A,@1 ;按鍵去抖動(dòng)延時(shí)10ms左右,需調(diào)整
MOV DLY3,A
CALL DELAY
RET
TURNDELAY:MOV A,@100 ;轉(zhuǎn)彎延時(shí)500毫秒左右,需調(diào)整
MOV DLY3,A
CALL DELAY
RET
;-----------------------------------------------------------------------
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