想法是利用T0定时,T1计数,T1记得的脉冲数用来计算速度与里程。代码附在下面,求大神帮忙看一下!
- DATA1 EQU 60H
- DATA2 EQU 62H
- DATA3 EQU 64H
- KEY1 EQU P0.0
- ORG 0000H
- START: MOV DATA1,#00H
- MOV DATA2,#00H
- MOV DATA3,#00H
- MOV SP,#70H
- MOV 40H,#00H
- MOV TH0,#03CH
- MOV TL0,#0B0H
- MOV TH1,#00H
- MOV TL1,#00H
- MOV IE,#10001010B
- MOV TMOD,#01010001B
- MOV DPTR,#TABLE
- MAIN: SETB TR0
- SETB TR1
- MOV R0,40H
- CJNE R0,#0AH,$
- LCALL SPEED
- LCALL DIS1
- AJMP MAIN
- INT_TIMER:
- MOV TH0,#03CH
- MOV TL0,#0B0H
- CLR TR1
- MOV DATA1,TL1
- MOV A,DATA1
- ADD A,DATA2
- MOV DATA2,A
- INC 40H
- JNC R
- INC DATA3
- R:RETI
-
- DIS1: MOV A,80H
- MOVC A,@A+DPTR
- SETB P2.3
- MOV P0,A
- CLR P2.3
- LCALL DELAY
- MOV A,81H
- MOVC A,@A+DPTR
- SETB P2.4
- MOV P0,A
- CLR P2.4
- LCALL DELAY
- MOV A,82H
- MOVC A,@A+DPTR
- SETB P2.5
- MOV P0,A
- CLR P2.5
- LCALL DELAY
- RET
- DIS2: MOV A,83H
- MOVC A,@A+DPTR
- SETB P2.0
- MOV P0,A
- CLR P2.0
- LCALL DELAY
- MOV A,84H
- MOVC A,@A+DPTR
- SETB P2.1
- MOV P0,A
- CLR P2.1
- LCALL DELAY
- MOV A,85H
- MOVC A,@A+DPTR
- SETB P2.2
- MOV P0,A
- CLR P2.2
- LCALL DELAY
- SETB P2.3
- MOV P0,#80H
- CLR P2.3
- LCALL DELAY
- MOV A,86H
- MOVC A,@A+DPTR
- SETB P2.4
- MOV P0,A
- CLR P2.4
- LCALL DELAY
- MOV A,87H
- MOVC A,@A+DPTR
- SETB P2.5
- MOV P0,A
- CLR P2.5
- LCALL DELAY
- RET
-
- SPEED: MOV A,DATA1
- MOV B,#0EH
- MUL AB
- MOV B,#64H
- DIV AB
- MOV 80H,A
- MOV A,B
- MOV B,#0AH
- DIV AB
- MOV 81H,A
- MOV A,B
- MOV 82H,A
- MOV DATA1,#00H
- RET
- MILAGE: MOV A,DATA3
- MOV B,#0C8H
- DIV AB
- MOV 83H,A
- MOV A,B
- MOV B,#014H
- DIV AB
- MOV 84H,A
- MOV A,B
- MOV B,#02H
- DIV AB
- MOV 85H ,A
- MOV A,B
- MOV A,DATA2
- MOV B,#032H
- DIV AB
- MOV 86H, A
- MOV A,B
- MOV B,#05H
- DIV AB
- MOV 87H,A
- RET
-
- DELAY: MOV R7,#250
- DL0: MOV R6,#2
- DL1: MOV R5,#2
- DL2: DJNZ R5,DL2
- DJNZ R6,DL1
- DJNZ R7,DL0
- RET
-
- TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
- END
复制代码
|