; Miniture RC car hack device PIC16F84,wdt_on,rc_osc,pwrt_on org 12 flag ds 1 temp ds 1 data ds 1 del0 ds 1 del1 ds 1 del2 ds 1 last ds 1 timer1 ds 1 timer2 ds 1 timer3 ds 1 mtime ds 1 PSMASK = 90h ;photo bits only PSLEFT = flag.0 PSRITE = flag.1 PSACT = flag.2 MSHI = flag.3 AUTO = flag.4 TIMEOUT = flag.5 PH4 = last.4 PH7 = last.7 TRNX = rb.0 TRNY = rb.1 MOTX = rb.2 MOTY = rb.3 PHDET1 = rb.4 ;photo detector ballance point AUXPWR = rb.5 ;photo detector power-up MODET = rb.6 ;motor stall detect PHDET2 = rb.7 org 0 goto start org 4 reti start bsf RP0 movlw 00000b movwf TRISA movlw 11010000b movwf TRISB movlw 10011111b movwf OPTION bcf RP0 clrf rb movlw 1 movwf mtime cycle call strait call stop bcf AUXPWR sleep decfsz mtime goto cycle movlw 5 movwf mtime bsf AUXPWR movlw 10 call delay call dodet call avoid call escape call dseek goto cycle avoid bsf AUXPWR btfsc PSRITE goto :rite btfsc PSLEFT goto :left goto cycle :rite call right goto :back :left call left :back call reverse movlw 30 call msauto ret ; get out of a boxed-in situation escape bsf AUXPWR movlw 10 movwf timer1 :x2 call strait call forward movlw 50 call msauto btfss TIMEOUT goto :hit :done call stop ret :hit call right call reverse movlw 20 call msauto decfsz timer1 goto :x2 goto :done ; seek dark place to hide dseek bsf AUXPWR movlw 20 ;10 seconds max movwf timer1 :dxx call forward :dx1 call dodet call strait btfsc PSLEFT call right btfsc PSRITE call left movlw 20 call msauto btfss TIMEOUT goto :hit decfsz timer1 goto :dx1 :done call stop ret :hit call strait call reverse movlw 30 call msauto decfsz timer1 goto :dxx goto :done wiggle movlw 7 movwf timer1 :wx call left movlw 10 call ms100 call right movlw 10 call ms100 decfsz timer1 goto :wx ret dodet bcf PSACT movf rb,w ;read the data andlw PSMASK ;mask only photo bits xorwf last ;compare to last ones btfss z ;any changes? bsf PSACT ;yes. movwf last ;save for next time bcf PSLEFT bcf PSRITE btfss PH4 bsf PSRITE ;both low btfsc PH7 bsf PSLEFT ;both hi ret left bcf TRNX bsf TRNY ret right bsf TRNX bcf TRNY ret strait bcf TRNX bcf TRNY ret ; change drive direction w/delay for startup forward bcf MOTX bsf MOTY goto ramp reverse bsf MOTX bcf MOTY goto ramp stop bcf MOTX bcf MOTY goto ramp ramp movlw 10 goto ms100 ; delay 100 ms per count in 'w' ; if AUTO set, return immediately on motor stalled msauto bsf AUTO goto msgo ms100 bcf AUTO msgo bcf TIMEOUT movwf del2 :d2 movlw 100 movwf del1 :d1 movlw 11 movwf del0 :d0 decfsz del0 goto :d0 clrwdt decfsz del1 goto :d1 btfss AUTO ;autostop? goto :go btfsc MODET ;motor stalled? goto :back ;yes :go decfsz del2 goto :d2 bsf TIMEOUT :back bcf AUTO ret delay movwf del1 :d1 movwf del0 :d0 clrwdt decfsz del0 goto :d0 decfsz del1 goto :d1 ret end QEDW c ‡