        org     0000h

	$MOD51GB

PWM_MOT EQU     R0
PWM_STR EQU     R1
STP_GO  EQU     P5.1
FOR_REV EQU     P5.0 


main:
        ;enable A/D operation
        mov     ACON,#010h   

        ;STP_GO is cleared to stop motor
        ;FOR_REV is set to go in reverse

        ;initalize the motor and steering PWM waveforms
        mov     P1,#0FFH        ;must set all bits on port1 to 0
        mov     PWM_MOT,#0C0h   ;set motor for 1/8 speed
        mov     CCAP2h,PWM_MOT
        mov     PWM_STR,#03Bh   ;set steering servo to center
        mov     CCAP1h,PWM_STR
        clr     FOR_REV           ;set relays for FORWARD
        clr     STP_GO          ;block PWM signal to motor
        call    PCA_INIT

        setb    STP_GO
        call    lngDelay

        mov     A,AD1         ; get the left rear IR
        subb    A,#100
        jc      wait

        mov     A,AD2         ; get the front left IR
        mov     A,AD3         ; get the fron right IR


wait:   jmp     wait

	

        ;initializes the programmable counter array for the motor
        ;and the steering servo
PCA_INIT:
        mov     CMOD,#006h      ;set PCA frequency to external
        mov     CCAPM1,#42h     ;put PCA module 1 into PWM mode
        mov     CCAPM2,#42h     ;put PCA module 0 into PWM mode
        setb    CR              ;start the PCA clock
        ret

lngDelay:
        $INCLUDE(lngDelay.inc)

cout:
        $INCLUDE(cout.inc)

PRINT:
        $INCLUDE(PRINT.inc)

SEND_BYTE:
        $INCLUDE(SEND_BYT.inc)



	end
