;***********************************************************************
; 自收發(fā)光電檢測(cè).dt
;***********************************************************************
PORT5 == 0x05 ;定義端口5,6,7
PORT6 == 0x06
PORT7 == 0x07
;-----------------------------------------------------------------------
IOCE == 0x0E ;定義WDT控制寄存器IOCE
;-----------------------------------------------------------------------
DLY1 == 12 ;定義延時(shí)置數(shù)單元DLY1,DLY2,DLY3,DLY4
DLY2 == 13
DLY3 == 14
DLY4 == 15
BUFFER == 16 ;定義暫存器BUFFER,存放當(dāng)前輸出
;-----------------------------------------------------------------------
ORG 0X00
INIT: MOV A,@0X11 ;關(guān)閉看門狗功能
IOW IOCE
MOV A,@0XFF ;設(shè)定PORT5全部為輸入
IOW PORT5
MOV A,@0X00 ;設(shè)定PORT6、PORT7全部為輸出
IOW PORT6
IOW PORT7
MOV A,@0XFF ;設(shè)置暫存器BUFFER初值,
MOV BUFFER,A
MOV PORT7,A ;PORT7輸出指示LED全暗
MOV A,@0X00
MOV PORT6,A ;PORT6輸出低電平,熄滅光電發(fā)射管
GDCHECK: MOV A,@0XFF ;PORT6輸出高電平,點(diǎn)亮光電發(fā)射管
MOV PORT6,A
CALL DL10 ;發(fā)射時(shí)間維持5ms左右
MOV A,PORT5 ;從PORT5讀入光電接收管狀態(tài)
AND A,@0B00000111 ;屏蔽高5位,只保留3位
XOR A,@0XFF ;光電接收管狀態(tài)值反向
MOV BUFFER,A ;送暫存器BUFFER保存
MOV A,@0X00 ;PORT6輸出低電平,熄滅光電發(fā)射管
MOV PORT6,A
DISPLAY: MOV A,BUFFER ;發(fā)光二極管顯示光電接收狀態(tài)值
MOV PORT7,A
CALL DELAY ;采樣延時(shí)
JMP GDCHECK ;繼續(xù)進(jìn)行自收發(fā)光電信號(hào)檢測(cè)
;-----------------------------------------------------------------------
DELAY: MOV A,@1 ;延時(shí),需要調(diào)整
MOV DLY3,A ;1
DEL: MOV A,@10 ;1*(DLY3)
MOV DLY2,A ;1*(DLY3)
INNER2 MOV A,@250 ;1*(DLY3)*(DLY2)
MOV DLY1,A ;1*(DLY3)*(DLY2)
INNER1: DJZ DLY1 ;1*(DLY3)*(DLY2)*(DLY1)
JMP INNER1 ;1*(DLY3)*(DLY2)*(DLY1)
DJZ DLY2 ;1*(DLY3)*(DLY2)
JMP INNER2 ;1*(DLY3)*(DLY2)
DJZ DLY3 ;1*(DLY3)
JMP DEL ;1*(DLY3)
RET ;延時(shí)返回
;-----------------------------------------------------------------------
DL10: MOV A,2 ;延時(shí)5ms左右,需要調(diào)整
MOV DLY4,A
INNER3: DJZ DLY4
JMP INNER3
RET
EOP
-
EM78P447S
+關(guān)注
關(guān)注
0文章
4瀏覽量
1370
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論