hotrodhed120
Member
I've wrote this code and everything works fine until I try to bypass the output on cfan. I want to turn it on with the pushbutton even if the ad result in cooling_fan0 should turn it off, but when I add the "btfsc cfbf goto on0" to the off0 routine the output just flickers once when I push the button and stays off. Otherwise, the rest of the program works fine. Can anyone help with some advise or show me what I'm doing wrong? Sorry for the mess!
Code:
#DEFINE CFBF FLAG_TEMP,4
#define cfan ctemp,7
start
bsf status,5
movlw d'255' ;porta inputs
movwf trisa ;
movlw b'11111111' ;
movwf trisb ;
movlw d'0' ;portc outputs
movwf trisc
movlw b'11010111' ;
movwf option_reg
movlw b'00001100' ;setup ad inputs and V ref
movwf adcon1 ;ad control, bank 1
bcf status,5
CLRF INTCON
clrf porta
clrf portb
clrf portc
CLRF CTEMP
CLRF FLAG_TEMP
clrw
MAIN
call COOLING_FAN0
CALL BUTTON_CHECK
goto main
;================================================
COOLING_FAN0 ;
call ADREAD0 ;
bcf status,c
SUBLW d'127' ;
btfss status,c ;
GOTO off0
GOTO on0
CF0 return
;===============================================
off0 BTFSC CFBF
GOTO ON0
bcf cfan
movfw ctemp
movwf portc
goto CF0
;===============================================
on0 bsf cfan
movfw ctemp
movwf portc
goto CF0
;==================================================
COOLING_FAN_BYPASS
CALL DEBOUNCE
BTFSS CFPB
RETURN
CFBLOOP BTFSC CFPB
GOTO CFBLOOP
MOVFW CTEMP
XORLW B'10000000'
MOVWF CTEMP
MOVWF PORTC
MOVFW FLAG_TEMP
XORLW B'0001000'
MOVWF FLAG_TEMP
RETURN
;=====================================================
BUTTON_CHECK
BTFSC A1PB
CALL ACCES1_TOGGLE
BTFSC CFPB
CALL COOLING_FAN_BYPASS
RETURN
;====================================================