;
;  PIC12C509
;    Scanner Controller  Ver 0.1
;		Programmed by DD
;
;    Rev 0.1  3/August/2005   DD
;         Initial Version.
;
;
;	Data Format
;	+---------------+
;	| | |X|X|X|O|I|I|   GPIO  I:Input   O:Output   X:Don't Use
;       +---------------+   
;       Input Data
;                           GPO => Unlock Signal Input 
;                           GP1 => Lock Signal Input
;
; 	Output Data
;		            GP2 => Scanner Control (Low is active)
;
;       Function
;           
;       Flow Chart
;           (START):
;                    GP2=1   
;           (LP):
;                    If GP0=1 go to LOCK
;                    If GP1=1 go to UNLOCK
;                    go to LP
;           (LOCK):
;                    GP2=0
;                    go to LP
;           (UNLOCK):
;                    GP2=1
;                    go to LP

	list    p=pic12C509A
	include "p12c509a.inc"
;
	__FUSES _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
;	Configuration Code = 0xFFEA
;	When burning PIC, the following configuration is necessary
;		MCLR is OFF
;		Code Protection(CP) is OFF
;		Watch Dog Timer(WDT) is OFF
;		Clock is Internal RC Oscillator

	cblock  0x08    ;Store variables above control registers
	endc


	org 0x00		;Start of Code Space
;=========================================
;  Start Program (& Wake up from Sleep)
;=========================================
START	movlw	b'00111011'	;GP2:Output  GP5,4,3,1,0:Input
	tris	6		;Set GPIO Input/Output
	movlw   b'00000000'	;Wakeup Enable
	option
	movlw	b'00000100'	;GP2=1
	movwf	GPIO
LP	btfsc	GPIO,1		;If GP1=1
	goto	LOCK		;   go to LOCK
	btfsc   GPIO,0		;If GP0=1,
	goto	UNLOCK		;   go to UNLOCK
	goto    LP		;  go to LP

LOCK	bcf	GPIO,2		;   GP2=0
	goto    LP		;  go to LP

UNLOCK	bsf	GPIO,2		;   GP2=1
	goto    LP		;  go to LP

	end


