;***********************************************************************
; 自收发光电检测.dt
;***********************************************************************
PORT5 == 0x05 ;定义端口5,6,7
PORT6 == 0x06
PORT7 == 0x07
;-----------------------------------------------------------------------
IOCE == 0x0E ;定义WDT控制寄存器IOCE
;-----------------------------------------------------------------------
DLY1 == 12 ;定义延时置数单元DLY1,DLY2,DLY3,DLY4
DLY2 == 13
DLY3 == 14
DLY4 == 15
BUFFER == 16 ;定义暂存器BUFFER,存放当前输出
;-----------------------------------------------------------------------
ORG 0X00
INIT: MOV A,@0X11 ;关闭看门狗功能
IOW IOCE
MOV A,@0XFF ;设定PORT5全部为输入
IOW PORT5
MOV A,@0X00 ;设定PORT6、PORT7全部为输出
IOW PORT6
IOW PORT7
MOV A,@0XFF ;设置暂存器BUFFER初值,
MOV BUFFER,A
MOV PORT7,A ;PORT7输出指示LED全暗
MOV A,@0X00
MOV PORT6,A ;PORT6输出低电平,熄灭光电发射管
GDCHECK: MOV A,@0XFF ;PORT6输出高电平,点亮光电发射管
MOV PORT6,A
CALL DL10 ;发射时间维持5ms左右
MOV A,PORT5 ;从PORT5读入光电接收管状态
AND A,@0B00000111 ;屏蔽高5位,只保留3位
XOR A,@0XFF ;光电接收管状态值反向
MOV BUFFER,A ;送暂存器BUFFER保存
MOV A,@0X00 ;PORT6输出低电平,熄灭光电发射管
MOV PORT6,A
DISPLAY: MOV A,BUFFER ;发光二极管显示光电接收状态值
MOV PORT7,A
CALL DELAY ;采样延时
JMP GDCHECK ;继续进行自收发光电信号检测
;-----------------------------------------------------------------------
DELAY: MOV A,@1 ;延时,需要调整
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 ;延时返回
;-----------------------------------------------------------------------
DL10: MOV A,2 ;延时5ms左右,需要调整
MOV DLY4,A
INNER3: DJZ DLY4
JMP INNER3
RET
EOP
全部0条评论
快来发表一下你的评论吧 !