;*****
;Alex E-S
;27/4/2008
;Version 2 (original did not work at all)
;Revision 4 (rework)
;for PIC 16F54
;Clock 2.4576MHz
;Function: control file for lightseeking robot.
list P = 16F54
include "c:\PIC\P16F5X.inc"
__config _XT_OSC&_WDT_OFF&_CP_OFF
;==========
;Declarations:
porta equ 05h
portb equ 06h
org 0x0;1FFh
goto Start
org 0x04
;==========
; Subroutines:
Init
clrf porta ;Resets porta
clrf portb ;Resets portb
movlw b'1100' ;Sets porta
tris porta ;as i/o
movlw b'00000000' ;sets portb
tris portb ;as outputs
retlw 0 ;resets working reg to 0
;==========when dark sensors go low, when light sensors go high
;Program Start
Start
call Init
Main
bcf porta,0 ;turns both
bcf porta,1
bcf portb,0 ;motors off
bcf portb,1
btfsc porta,2 ;tests light on right LDR
goto rightlight ;if light,goto rightlight
btfsc porta,3 ;tests light on left LDR
goto leftlight ;if light,goto left light
goto Main
rightlight
btfsc porta,3 ;tests if light on left LDR too
goto bothlight ;if there is,goto bothlight
bsf portb,0 ;if not turns on left motor to turn towards light
goto Main
leftlight
btfsc porta,2 ;tests if light on right LDR too
goto bothlight ;if there is,goto bothlight
bsf porta,0 ;if not turns on right motor to turn towards light
goto Main
;nolight ;behaviour if no light (rotate set amount?(90 degrees?)
;goto Main
; bsf porta,rightmotor initially no action,call from Main when developed.
bothlight ;behaviour if both light
bsf porta,0 ;turns on
bsf portb,0 ;both motors (for set time?)
goto Main
END