基于单片机的脉冲宽度测量
利用单片机测量mc6c遥控器各通道输出信号的脉宽
;P3.2->INTURRUPT0 0亮1灭 TH0->R0,TL0->R1, R7延时 R2,R3,R4,R5
ORG 0000H
LJMP 0030H
ORG 0003H
INTURRUPT0:
MOV R0,TH0
MOV R1,TL0
MOV TH0,#00H
MOV TL0,#00H
RETI
ORG 000BH
TIMER0:
MOV TH0,#00H
MOV TL0,#00H
RETI
ORG 0030H
INIT_T0:
MOV TMOD,#09H
MOV TH0,#00H
MOV TL0,#00H
SETB ET0
SETB TR0
INIT_INT0:
SETB IT0
SETB EX0
SETB EA
MOV R0,#00H
MOV R1,#00H
MAIN:
LCALL TRANSFER
SETB P2.7
MOV P0,#00111101B
CLR P2.7
SETB P2.6
MOV P0,R2
ACALL DELAY
SETB P2.7
MOV P0,#00111011B
CLR P2.7
SETB P2.6
MOV P0,R3
ACALL DELAY
SETB P2.7
MOV P0,#00110111B
CLR P2.7
SETB P2.6
MOV P0,R4
ACALL DELAY
SETB P2.7
MOV P0,#00101111B
CLR P2.7
SETB P2.6
MOV P0,R5
ACALL DELAY
LJMP MAIN
TRANSFER:
MOV A,#0FH
ANL A,R0
MOV DPL,A
MOV DPH,#00H
MOV A,#TABLE
MOVC A,@A+DPTR
MOV R3,A
MOV A,#0F0H
ANL A,R0
SWAP A
MOV DPL,A
MOV DPH,#00H
MOV A,#TABLE
MOVC A,@A+DPTR
MOV R2,A
MOV A,#0FH
ANL A,R1
MOV DPL,A
MOV DPH,#00H
MOV A,#TABLE
MOVC A,@A+DPTR
MOV R5,A
MOV A,#0F0H
ANL A,R1
SWAP A
MOV DPL,A
MOV DPH,#00H
MOV A,#TABLE
MOVC A,@A+DPTR
MOV R4,A
RETI
DELAY:
MOV R7,#0FFH
DJNZ R7,$ ;若为0程序向下执行,若不为0程序跳转到
MOV R7,#0FFH
DJNZ R7,$
RET
TABLE:
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH, 77H, 7CH, 39H, 5EH, 79H, 71H
END
|