Hello friends,
I have taken up a project using 16F676 which will switch on a gadget to battery position when there is no AC Main supply. On resumption of AC Main supply the microcontroller will take some delay for stabilization of main supply then switch over to AC Main position. Also before switching over to ‘main’ position the microcontroller will check if the main supply is within permissible limit. When checking the stages one by one I face a problem in delay loop. Please see the code. When no delay is used the program works well. But on insertion of delay loop the BTFSC instruction has no effect and the relay operated from RA2 remains on even the RC5 bit is made ground. Please help.
config. bits. MCLR-OFF, PWRTE-OFF, CP-OFF, WDT-OFF, INTOSC
cblock 0x20
count1
count2
count3
endc
BSF STATUS, RP0
MOVLW 0X38
MOVWF TRISA
MOVLW 0X2C
MOVWF TRISC
MOVLW 0XC0
MOVWF ANSEL
MOVLW 0X87
MOVWF OPTION_REG
BCF STATUS, RP0
MOVLW 0X7
MOVWF CMCON
MOVLW 0X19
MOVWF ADCON0
MOVLW b'00100000'
MOVWF INTCON
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BTFSS PORTC, 5 ; See if AC Main is present
GOTO AC_ON
INV_ON: MOVLW 0X4 ; If not, turn on Change Over Relay
MOVWF PORTA ; to inverter position.
CONT1: BTFSC PORTC,5
GOTO CONT1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AC_ON:
MOVLW D’10’ ; D
MOVWF COUNT3 ;
CT_2: MOVLW D’255’ ; E
MOVWF COUNT2 ;
CT_1: MOVLW D’255’ ; L
MOVWF COUNT1 ;
WAIT_1: BCF INTCON,2 ; A
DLY_1: BTFSC PORTC, 5 ;
GOTO INV_ON ; Y
BTFSS INTCON,2 ;
GOTO DLY_1 ;
DECFSZ COUNT1,1 ;
GOTO WAIT_1 ;
DECFSZ COUNT2,1 ;
GOTO CT_1 ;
DECFSZ COUNT3,1 ;
GOTO CT_2 ;
MOVLW b'00000000'
MOVWF PORTC ; Turn off change over relay to switch
over to Main position.
CONT2: BTFSC PORTC, 5 ; Check if AC Main is present or not.
GOTO INV_ON ; If present continue here otherwise
GOTO CONT2 turn on relay .
END
I have taken up a project using 16F676 which will switch on a gadget to battery position when there is no AC Main supply. On resumption of AC Main supply the microcontroller will take some delay for stabilization of main supply then switch over to AC Main position. Also before switching over to ‘main’ position the microcontroller will check if the main supply is within permissible limit. When checking the stages one by one I face a problem in delay loop. Please see the code. When no delay is used the program works well. But on insertion of delay loop the BTFSC instruction has no effect and the relay operated from RA2 remains on even the RC5 bit is made ground. Please help.
Code:
cblock 0x20
count1
count2
count3
endc
BSF STATUS, RP0
MOVLW 0X38
MOVWF TRISA
MOVLW 0X2C
MOVWF TRISC
MOVLW 0XC0
MOVWF ANSEL
MOVLW 0X87
MOVWF OPTION_REG
BCF STATUS, RP0
MOVLW 0X7
MOVWF CMCON
MOVLW 0X19
MOVWF ADCON0
MOVLW b'00100000'
MOVWF INTCON
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BTFSS PORTC, 5 ; See if AC Main is present
GOTO AC_ON
INV_ON: MOVLW 0X4 ; If not, turn on Change Over Relay
MOVWF PORTA ; to inverter position.
CONT1: BTFSC PORTC,5
GOTO CONT1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AC_ON:
MOVLW D’10’ ; D
MOVWF COUNT3 ;
CT_2: MOVLW D’255’ ; E
MOVWF COUNT2 ;
CT_1: MOVLW D’255’ ; L
MOVWF COUNT1 ;
WAIT_1: BCF INTCON,2 ; A
DLY_1: BTFSC PORTC, 5 ;
GOTO INV_ON ; Y
BTFSS INTCON,2 ;
GOTO DLY_1 ;
DECFSZ COUNT1,1 ;
GOTO WAIT_1 ;
DECFSZ COUNT2,1 ;
GOTO CT_1 ;
DECFSZ COUNT3,1 ;
GOTO CT_2 ;
MOVLW b'00000000'
MOVWF PORTC ; Turn off change over relay to switch
over to Main position.
CONT2: BTFSC PORTC, 5 ; Check if AC Main is present or not.
GOTO INV_ON ; If present continue here otherwise
GOTO CONT2 turn on relay .
END