; ********************************* ; *** Robosapien IR-OUT control *** ; ********************************* ; *** Created by Mark Craig *** ; *********************************************************************************************** ; * * ; * Filename: robosap.inc * ; * Date: 21/09/2004 * ; * File Version: v1.0 * ; * Written by: Mark Craig (*) * ; * Homepage: http://homepages.strath.ac.uk/~lau01246 * ; * Project : Robosapien * ; * Function: take control of robosapien through original PCB * ; * by sending IR commands directly to the PCB (as * ; * opposed to the IR-receiver) * ; * * ; * (*): The delays are created using the following address: * ; * Generated by http://www.golovchenko.org/cgi-bin/delay (January 1, 2002 version) * ; * See also various delay routines at http://www.piclist.com/techref/microchip/delays.htm * ; * * ; * (C): You are free to copy, use, distribute etc. but give credit where due. * ; * * ; * #DEFINE SEROUT PORTA,4 ; connected to IR-OUT on PCB * ; * and include variables: d1, d2, bitcount and txreg * ; * * ; *********************************************************************************************** ; *** DelayX repeats a 415cycle (approx 0.5/1200) routine W times *** DelayX movwf d2 DelayX_0 ;409 cycles movlw 0x88 movwf d1 DelayX_1 decfsz d1, f goto DelayX_1 ;2 cycles goto $+1 ;4 cycles (including call) decfsz d2, f goto DelayX_0 return ; *** - *** ; *** delay look-ups *** ; If delays need to be lengthened slightly here would be the best place. delay830 movlw d'2' ; 1/1200 goto DelayX delay2500 movlw d'6' ; 3/1200 goto DelayX delay6664 movlw d'16' ; 8/1200 goto DelayX delay7916 movlw d'19' ; 9.5 /1200 goto DelayX ; Generated by http://www.golovchenko.org/cgi-bin/delay (January 1, 2002 version) ; See also various delay routines at http://www.piclist.com/techref/microchip/delays.htm ; *** Send routine, sends command in W through SEROUT pin to robosapien's PCB *** send: movwf txreg movlw d'08' ; 8 bits of data movwf bitcount ; a counter for bits bcf SEROUT ; Low (start bit) ; for 8/1200s call delay6664 ; send_loop: rlf txreg, f ; roll leftmost bit into carry bsf SEROUT ; high btfsc STATUS, C ; if carry = 0 skip, call delay2500 ; go do additional 3/1200 then return call delay830 ; 1/1200 bcf SEROUT ; low call delay830 ; 1/1200 decfsz bitcount, f ; one less data bit, skip when 0 goto send_loop ; more bits left, delay this one goto $+1 bsf SEROUT ; Stop high. return ; *** Read IR *** readir: ; This is to receive ir commands from the remote ; it will loop until it receives a command then return ; with command in W btfsc IRIN goto readir ; start bit detected clrf rxreg ; clear file rxreg movlw d'08' ; 8 bits of data movwf bitcount ; a counter for bits call delay7916 ; 9 1/2 /1200 sec delay read_loop: bcf STATUS,C ; carry = 0 btfsc IRIN ; if IRIN = 0 skip bsf STATUS,C ; carry = 1 btfsc STATUS,C ; skip if 0 (shorter delay) call delay2500 ; 3/1200 sec delay call delay830 ; 1/1200 sec delay giving 4/1200 if 1 or 1/1200 if 0 call delay830 ; 1/1200 sec delay rlf rxreg, f ; rotate carry into rxreg decfsz bitcount, f ; decrease counter, if not zero loop goto read_loop movfw rxreg ; else move received data to W return ; and return ; *** END OF INCLUDE FILE ***