; ***************************************
; ***** Assembler Code File Details *****
; ***************************************
;    Filename: 		rs-2.asm
;    Date: 		16/09/2004
;    File Version: 	v2.0
;    Written by: 	Mark Craig
;    Project :		Robosapien
;    Function: 		take control of robosapien through original PCB


; ************************************
; ***** (1) Setup PICmicro type. *****
; ************************************

	list      p=16F84A             ; define PICmicro type
        #include <p16F84A.inc>         ; variable definitions
	errorlevel -302		      ; suppress warning 302

; **************************************
; ***** (2) Setup PICmicro config. *****
; **************************************

   	__config   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

; **********************************
; ***** (3) RAM File Registers *****
; **********************************

	cblock 	h'20'
TEMP		; Temporary Scratchpad
COUNTER		; Counter for loops
WC1		; Counter for wait loop
WC2		; Counter for wait loop
WC3		; Counter for wait loop
B0		; General purpose
B1		; General purpose
B2		; General purpose
B3		; General purpose
B4		; General purpose
		; (any other registers go here)
txreg
bitcount

d1		; bitdelay counter
d2		; bitdelay counter
	endc

#DEFINE	SEROUT	PORTA,4		; connected to IR-OUT on PCB
#DEFINE	LED1	PORTA,3		; connected to an LED for debug

; ********************************************
; ***** (4) Assembler code reset vectors *****
; ********************************************

; ***** Reset vector *****
	org	d'00'
	clrf	PORTA		; initialise PORTA
	bsf	SEROUT
	clrf	PORTB		; initialise PORTB
	goto	init		; jump to init

; ***** Interrupt vector *****
	org	d'04'
	return			; return

; *************************************
; ***** (5) Common sub-procedures *****
; *************************************

	#include <wait.inc>     ; wait sub-procedure
	#include <robosap.inc>
				; (any other sub-procedures go here)

; ***************************************
; ***** (6) Start of assembler code *****
; ***************************************

; ***** Initialisation *****
init:	bsf	STATUS,RP0
	movlw	b'00011'
	movwf	TRISA
	movlw	b'00000000'
	movwf	TRISB
	bcf	STATUS,RP0

; ***** Main program *****
main:	

loop:
	bsf	LED1	; debug LED
	movlw	d'5'
	call	wait	; .5 secs

	bcf	LED1	; debug LED
	movlw	h'8A'	; "Left arm out" command
	call	send

	movlw	d'2'
	call	wait	; .2 secs
	goto	loop



; ******************************
; ***** (7) End of Program *****
; ******************************

	sleep
	end












