Photoelectric automatic track tracking vehicle

Publisher:sokakuLatest update time:2018-01-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;***************************************************************************
; Photoelectric automatic track tracking vehicle.dt
;***************************************************************************

 PORT5 == 0x05 ; define port 5, 6, 7
 PORT6 == 0x06
 PORT7 == 0x07
;-----------------------------------------------------------------------
 IOCE == 0x0E ; define WDT control register IOCE
;-----------------------------------------------------------------------
 STATUS == 3 ; define status register STATUS and zero flag Z_FLAG
 Z_FLAG == 2
;---------------------------------------------------------------
 DLY1 == 13 ; define delay setting unit DLY1, DLY2, DLY3
 DLY2 == 14
 DLY3 == 15 
 TEMP == 16 ; define temporary register unit TEMP to store photoelectric read data       
;-----------------------------------------------------------------------
          ORG 0x00
 
 INIT: MOV A,@0x0FF ; set P7 port all as input
          IOW PORT7
          IOW PORT5             
          MOV A,@0x00 ; set P6 port all as output
          IOW PORT6
          MOV A,@0X11             
          IOW IOCE ;Turn off the watchdog function
          MOV A,@0x00 ;Stop the motor
          MOV PORT6,A
;-----------------------------------------------------------------------
 MAIN: MOV A,PORT7 ;Read photoelectric input
          AND A,@0B00000111 ;Shield the upper 5 bits
          XOR A,@0B00000111
          MOV TEMP,A
          BC STATUS,Z_FLAG ;Clear the zero flag
 CHECK0: MOV A,TEMP   
          XOR A,@0B00000000 ;Is the photoelectric input 000?
          JBS STATUS,Z_FLAG
          JMP CHECK1
          JMP ACT000
 CHECK1: MOV A,TEMP
          XOR A,@0B00000001 ; Is the photoelectric input 001?
          JBS STATUS,Z_FLAG
          JMP CHECK2
          JMP ACT001
 CHECK2: MOV A,TEMP
          XOR A,@0B00000010 ; Is the photoelectric input 010? JBS STATUS,Z_FLAG           JMP CHECK3           JMP ACT010  CHECK3: MOV A,TEMP           XOR A,@0B00000011 ; Is the photoelectric input 011?           JBS STATUS,Z_FLAG
          JMP           CHECK4           JMP ACT011  CHECK4: MOV A,TEMP           XOR A,@0B00000100 ; Is the photoelectric input 100?           JBS STATUS,Z_FLAG           JMP CHECK5           JMP ACT100  CHECK5: MOV A,TEMP           XOR A,@0B00000101 ; Is the photoelectric input 101?














          JBS STATUS,Z_FLAG
          JMP CHECK6
          JMP ACT101
 CHECK6: MOV A,TEMP
          XOR A,@0B00000110 ;Is the photoelectric input 110?
          JBS STATUS,Z_FLAG
          JMP CHECK7
          JMP ACT110
 CHECK7: MOV A,TEMP
          XOR A,@0B00000111 ;Is the photoelectric input 111?
          JBS STATUS,Z_FLAG
          JMP MAIN
          JMP ACT111
;-----------------------------------------------------------------------
 ACT000: NOP ;Keep the status quo, no action, return to    
          JMP MAIN
 ACT001: MOV A,@0B00000100 ;Slightly to the right, M1 stops, M2 rotates forward                  
          MOV PORT6,A
          CALL TURNDELAY
          JMP ACT101
 ACT010: ​​NOP ;No action, return to
          JMP MAIN
 ACT011: MOV A,@0B00000100 ;Lean to the right, M1 stops, M2 rotates forward                  
          MOV PORT6,A
          CALL TURNDELAY
          JMP ACT101
 ACT100: MOV A,@0B00000001 ;Slightly to the left, M1 rotates forward, M2 stops 
          MOV PORT6,A
          CALL TURNDELAY
          JMP ACT101
 ACT101: MOV A,@0B00000101 ;Move along the center of the black tape, M1 rotates forward, M2 rotates forward 
          MOV PORT6,A
          JMP MAIN
 ACT110: MOV A,@0B00000001 ;Lean to the left, M1 rotates forward, M2 stops 
          MOV PORT6,A
          CALL TURNDELAY
          JMP ACT101
 ACT111: MOV A,@0B00001001 ;The black tape is not pressed, M1 rotates forward and M2 rotates reversely
          MOV PORT6,A
          CALL TURNDELAY
          CALL TURNDELAY
          JMP ACT101
;-----------------------------------------------------------------------
 TURNDELAY:MOV A,@50 ;The turning delay is about 100 milliseconds, which needs to be adjusted
          MOV DLY3,A
          CALL DELAY
          RET
;-----------------------------------------------------------------------
                                        ;Delay time = 2mS * DLY3
 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 ;Delay return
          to EOP


Reference address:Photoelectric automatic track tracking vehicle

Previous article:EM78P447 infrared remote control motor
Next article:EM78 series single chip microcomputer programming

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号