; PicBot ; Test version 1.4 device PIC16C56, RC_OSC, WDT_ON, PROTECT_OFF reset startup org 000h pops = 15 ; pops per cycle popdur = 50 ; x ontime+offtime ontime = 1 ; duty cycle = ontime/(ontime+offtime) offtime = 1 pausedur = 100 ; x10 wakeup = 25 ; spontanious wakeup delay ; port assignments... ; Ra0 - 24LC65 clock ; Ra1 - 24LC65 data ; Ra2 - 1381 output ; Ra3 - debug led ; Rb0 - Left Photocell ; Rb1 - Left Feeler ; Rb2 - Right Motor Forward (grounds blue when 1) ; Rb3 - Right Motor Reverse (grounds red when 1) ; Rb4 - Left Motor Forward (grounds red when 1) ; Rb5 - Left Motor Reverse (grounds blue when 1) ; Rb6 - Right Feeler ; Rb7 - Right Photocell ; actions... ; xx5432xx ; -------- rl = 00010000b ; light on right, pop left motor forward ll = 00000100b ; light on left, pop right motor forward el = 00010100b ; equal light, pop both motors forward rf = 00100100b ; touch on right, pop left motor back, right forward lf = 00011000b ; touch on left, pop right motor back, left forward ;bf = 00010100b ; touch on both, pop both motors backwards ;both feelers = random move temp = 0Bh loops = 0Ch charge = 0Dh varA = 0Eh varB = 0Fh lightL = 10h lightR = 11h popcnt = 12h dbgreg = 1Eh dbgtemp = 1Fh reject1 = 00111100b reject2 = 00000000b reject3 = 00110000b reject4 = 00001100b ; wait sub wait movlw 75 movwf temp wait2 nop nop nop decfsz temp goto wait2 decfsz loops goto wait clr wdt ret ;debug subs shortflash setb ra.3 mov loops, #30 call wait clrb ra.3 mov loops, #220 call wait ret longflash setb ra.3 mov loops, #200 call wait clrb ra.3 mov loops, #50 call wait ret ; flash number in dbgreg (bits 0 - 7 at 1/4 sec intervals) debug mov dbgtemp, #8 dbgloop jb dbgreg.0, dbg1 setb ra.3 mov loops, #30 call wait clrb ra.3 mov loops, #250 call wait jmp dbgnext dbg1 setb ra.3 mov loops, #200 call wait clrb ra.3 mov loops, #80 call wait dbgnext djnz dbgtemp, dbgloop mov loops, #255 call wait ret ;*********** main code here startup mov OPTION, #00001111b ; int rtc, max wdt (!OPTION for SPASM) mov !ra, #00000111b ; 2=1381in 1=eedata 0=eeclk (set to hi-z) mov !rb, #11000011b ; 0,7=photo ins 1,6=feeler ins 2-5 motor outs clr ra ; clear led out (ra.3) clr rb ; clear motor outs jnb ra.2, nap ; go to sleep if not enough power jnb rb.1, jump ; if feeler touching make it move jnb rb.6, jump ; inc charge ; otherwise charge x sleep cjb charge, #wakeup, nap ; timeouts then jump jump mov popcnt, #pops ; set pop countdown poploop ; read photocells mov lightL, #127 ; max light level mov !rb, #11000010b ; make L photobit an out clr rb ; short out cap mov loops, #15 ; for few ms call wait mov !rb, #11000011b ; make ins again ploopL jb rb.0, readR ; go on when input goes high djnz lightL, ploopL ; loop if still above 0 readR mov lightR, #127 mov !rb, #01000011b clr rb mov loops, #15 call wait mov !rb, #11000011b ploopR jb rb.7, readend djnz lightR, ploopR readend ; debugging - display light levels ; mov dbgreg, lightL ; call debug ; mov dbgreg, lightR ; call debug ; get random move in varA getrand mov varA, rtcc and varA, #15 rl varA rl varA xor varA, rtcc and varA, #00111100b cje varA, #reject1, getrand cje varA, #reject2, getrand cje varA, #reject3, getrand cje varA, #reject4, getrand ; examine move for situation mov temp, rb and temp, #01000010b cje temp, #00000000b, bothfeelers jnb temp.1, leftfeeler jnb temp.6, rightfeeler ; no feelers, find light and lightL, #11111000b and lightR, #11111000b cjb lightL, lightR, rightlight cjb lightR, lightL, leftlight ; equal light mov varA, #el jmp move rightlight mov varA, #rl jmp move leftlight mov varA, #ll jmp move rightfeeler mov varA, #rf jmp move leftfeeler mov varA, #lf jmp move bothfeelers ; mov varA, #bf ; both feelers, go with random in varA move mov varB, #popdur ; how much drloop mov rb, varA mov loops, #ontime call wait mov rb, #00000000b mov loops, #offtime call wait djnz varB, drloop ; loop until done drstop mov varA, #pausedur drstop1 mov loops, #10 call wait djnz varA, drstop1 djnz popcnt, poploop ; next pop clr charge ; charge some more nap sleep ; sleep...