;*******************************************************************
;			File: INIT.ASM
;*******************************************************************


INIT

	FIXPCLATH	INIT

;Set up I/O pins
	BANK1			;Point to TRIS ports.

	MOVLW	B'00000000'	;RA7 NA
				;RA6 NA
				;RA5 NA
				;RA4 NA
				;RA3 NA
				;RA2 NA
				;RA1 NA
				;RA0 Beeper (Output)
	MOVWF	TRISA

	MOVLW	B'00000000'
				;RB7 NA
				;RB6 NA
				;RB5 NA
				;RB4 NA
				;RB3 NA
				;RB2 NA
				;RB1 NA
				;RB0 NA
	MOVWF	TRISB


;*******************************************************************
;Initialize the TIMER control register
	CLRWDT		;must be done for prescaler even if not using WDT
	MOVLW	B'10000000'
			;bit 7 !RBPU=1 Disable Port B weak pull-up resistors
			;bit 6 INTEDG=x 
			;bit 5 T0CS =0 Timer source = Internal Clock
			;bit 4 T0SE =x External source edge select 
			;bit 3 PSA  =0 Set the prescaler for TIMER usage
			;bit 2 PS2  =0 Prescaler value = 2
			;bit 1 PS1  =0
			;bit 0 PS0  =0
	MOVWF	OPTION_REG

;*******************************************************************
;The standard throughout this program is Bank 0
	BANK0

	MOVLW	D'10'	;Number of leg counts (5 for each leg)
	MOVWF	LEGCTR

;*******************************************************************
;Set outputs appropriately:
	CLRF	PORTA
	CLRF	PORTB

;*******************************************************************
;Set variables:
	CLRF	MINUTES
	CLRF	SECONDS
	CLRF	SEMAPHORE

	MOVLW	INTSPERSEC	;Preset pre-seconds counter
	MOVWF	PRECOUNT	
;*******************************************************************
;Enable interrupts
	MOVLW	B'10100000'
			;bit 7  GIE=1 Enables all enabled interrupts
			;bit 6 PEIE=0 Peripheral interrupt (not used)
			;bit 5 TOIE=1 TMR0 Overflow Interrupt enable
			;bit 4 INTE=0 RB0/INT External Interrupt Enable bit (not used)
			;bit 3 RBIE=0 RB port change interrupts disabled
			;bit 2 TOIF=x TMR0 overflow flag bit (observed elswhere)
			;bit 1 INTF=x External interrupt flag bit (not used)
			;bit 0 RBIF=x RB port change interrupt flag bit (not used)
	MOVWF	INTCON

;*******************************************************************
	GOTO	MAIN
