
;*******************************
;Touch Switch.asm
;1-10-2010 
;*******************************


	list	p=12F629
	radix	dec
	include	"p12f629.inc"
	
		errorlevel	-302	; Dont complain about BANK 1 Registers during assembly

	__CONFIG	_MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT  ;Internal osc.

;_MCLRE_OFF  - master clear must be off for gp3 to work as input pin 

;****************************************************************
; variables - names and files
;****************************************************************


temp1		equ 20h	;
temp2		equ 21h	;
temp3		equ 22h	;
temp4		equ	23h	; 
_flash      equ	24h	; 


;****************************************************************
;Equates
;****************************************************************
status		equ	0x03
rp1			equ	0x06
rp0			equ	0x05
GPIO 		equ 0x05
			

status		equ	03h
option_reg	equ 81h


		; bits on GPIO
				
pin7		equ	0	;GP0  
pin6	 	equ	1	;GP1  out to LED
pin5		equ	2	;GP2  out to LED
pin4		equ	3	;GP3  
pin3		equ	4	;GP4 
pin2		equ	5	;GP5  input 
 

		;bits
				
rp0			equ	5			;bit 5 of the status register

;****************************************************************
;Beginning of program
;****************************************************************
		org		0x00
		nop
		nop
		nop
		nop
		nop			
SetUp	bsf		status, rp0 	;Bank 1			
       	movlw	b'11101000'		;Set TRIS  GP1,2,out  GP5 in
		movwf	TRISIO	   	    ;		
		bcf		status, rp0		;bank 0
		movlw   07h         	;turn off Comparator ports
        movwf   CMCON       	;must be placed in bank 0 
        call	flash 
		clrf 	GPIO       		;Clear GPIO of junk			
		goto 	Main	
			

;****************************************************************
;* Delays 			*
;****************************************************************


_10us	goto	$+1
		goto	$+1
		goto	$+1
		goto	$+1		
		retlw 	00




_250uS	movlw	.80
		movwf	temp1
		decfsz 	temp1,f
		goto 	$-1		
		retlw 	00


_1mS	nop
		decfsz 	temp1,f
		goto 	$-2		
		retlw 	00	
		
		
		
		
_10mS	movlw	.10
		movwf	temp2
_10		nop
		decfsz 	temp1,f
		goto 	_10
		decfsz 	temp2,f
		goto 	_10	
		retlw 	00	
						
		
		
		
_20mS	movlw	.20
		movwf	temp2
_20		nop
		decfsz 	temp1,f
		goto 	_20
		decfsz 	temp2,f
		goto 	_20	
		retlw 	00	
		
		
				
_250mS	movlw	.250
		movwf	temp2
_250	nop
		decfsz 	temp1,f
		goto 	_250
		decfsz 	temp2,f
		goto 	_250	
		retlw 	00			


;****************************************************************
;* Sub Routines 			*
;****************************************************************
					
		;flash LED at start-up
		
flash	movlw	0ffh
		movwf	_flash
		bsf		gpio,1
		nop
		decfsz	_flash,1
		goto	$-2
		bcf		gpio,1
		retlw	00		
		
													
;****************************************************************
;* Main 							*
;****************************************************************
	
		
		
Main	bcf		gpio,4			;make line LOW to discharge 100p
		call	_10uS	
		bsf		gpio,4			;make line HIGH to charge 100p
		;goto	$+1
		;goto	$+1		
		bsf		status, rp0 	;Bank 1			
       	movlw	b'11111000'		;Set TRIS  GP4 in
		movwf	TRISIO	   	    ;		
		bcf		status, rp0		;bank 0		
		;call	_10mS
		call	_20mS
		btfss	gpio,4
		goto	$+3
		bcf		gpio,2
		goto	Main
		bsf		status, rp0 	;Bank 1			
       	movlw	b'11001000'		;Set TRIS  GP4 out
		movwf	TRISIO	   	    ;		
		bcf		status, rp0		;bank 0
		bsf		gpio,4			;turn on LEDs and transistor
		call	_250mS
		goto	Main
		
			
		
		
		END	
		
		
		
		