riccardo-m 0 Newbie Poster

Hi,

I'm trying to make a very simple program that will accept a digital input and respond by setting an output high. When the input goes low again, the output should go low and then after a short delay, a second output will toggle high then low. My code below is what I thought would do it but I think I am not reading the input properly or something. Can anyone spot my mistake?

; 
; 12F675
; Uses 4MHz Xtal
; Reset pin tied internally
; Input on Pin GPIO,0 (Pin 7)
; +5V on Pin 1
; GND on Pin 8
;
		Processor       12F675
		Radix   DEC
		EXPAND
		include         "p12F675.inc"

; -- MAIN PROGRAM INITILIZATION --

	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _MCLRE_OFF & _XT_OSC 

	CBLOCK 0x20
	L1
	L2
	ENDC

		ORG     0x3FF			; processor reset vector
        ORG     0x000			; coding begins here

	BCF STATUS,RP0 				; Bank 0
	CLRF GPIO					; Clear IO Data

	BSF STATUS,RP0 				; Bank 1
	CLRF ANSEL 					; Use Digital I/O
	MOVLW b'00000001'			; Set IO's as Output, except Set GP0 as input
	MOVWF TRISIO				; Set IO's as Output
	
	BCF STATUS,RP0 				; Bank 0

	; Set output pins low
	BCF GPIO,GP1
	BCF GPIO,GP2

START

	BTFSC GPIO,GP0
		CALL PULSE1
	GOTO START

; <-V OUTPUT 1 HIGH V->
PULSE1
	BSF GPIO,GP1				; Set output 1 High (OPEN VALVE)
	BTFSS GPIO,GP0				; Check input status
		CALL PULSE2				; If low, do second (delayed) pulse
	GOTO PULSE1					; Else Loop forever

; <-V OUTPUT 2 PULSE V->
PULSE2
	BCF GPIO,GP1				; Clear output 1	(CLOSE VALVE)
	MOVLW   5					; Choose delay time (ms)
	CALL DELAY					; Wait				(WAIT FOR VALVE TO CLOSE))
	BSF GPIO,GP2				; Set output 2 High	(ENABLE COIL)
	MOVLW   5					; Choose delay time (ms)
	CALL DELAY					; Wait				(BUILD COIL CURRENT)
	BCF GPIO,GP2				; Clear output 2	(FIRE SPARK)
	MOVLW   1					; Choose delay time (ms)
	CALL DELAY					; Wait				(SAFTEY DELAY)
	GOTO START					; Start again


; <-V TIME DELAY ROUTINE V->
; Put number of msec delay needed into L1
DELAY   						;MOVLW   10 				; 10 mS Delay (50Hz)
        MOVWF   L1
Outer   MOVLW   200
        MOVWF   L2
Inner   NOP
        NOP
        DECFSZ  L2,F
        	GOTO    Inner		; Inner loop = 5 usec.
        DECFSZ  L1,F
        	GOTO    Outer
        RETURN

	END							; directive 'end of program'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.