Hi
I am a newbie on Microprocessors and have been learning to program the devices. The code below only works if I take the converted output from ADRESH and place it on PORTC. When I add the highlighted section it fails. I have tried everything I could think out but without success. Could someone please point me in the right direction.
Thanks
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Display ; define a variable to hold the diplay
Delay
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
movlw 0xFF
movwf TRISA ; Make PortA all input
clrf TRISC ; Make PortC all output
movlw 0x10 ; A2D Clock Fosc/8
movwf ADCON1
bcf STATUS,RP0 ; back to Register Page 0
bcf STATUS,RP0 ; address Register Page 2
bsf STATUS,RP1
movlw 0xFF ; we want all Port A pins Analoga
movwf ANSEL
bcf STATUS,RP0 ; address Register Page 0
bcf STATUS,RP1
movlw 0x01
movwf ADCON0 ; configure A2D for Channel 0 (RA0), Left justified, and turn on the A2D module
MainLoop:
call Delay200mS
bsf ADCON0,GO ; start A2D conversion
btfss ADCON0,GO ; this bit will change to zero when the conversion is complete
goto $-1
movf ADRESH,w ; read the A2D
movwf Display
movf Display,w ; save the value
;movf PORTC ; send to PORTC
TEST_0:
sublw 0xDE ; Subtract W from Reference
btfsc STATUS,C ; Is battery Voltage higher than Reference?
goto Switch0
bsf PORTC,0 ; If battery Voltage is higher than Reference - Set PORTC,0 to high
goto TEST_1
Switch0:
bcf PORTC,0 ; If battery Voltage is lower than Reference - Set PORTC,0 to low
TEST_1:
sublw 0xE2 ; Subtract W from Reference
btfsc STATUS,C ; Is battery Voltage higher than Reference?
goto Switch1
bsf PORTC,1 ; If battery Voltage is higher than Reference - Set PORTC,1 to high
goto MainLoop
Switch1:
bcf PORTC,1 ; If battery Voltage is lower than Reference - Set PORTC,1 to low
goto MainLoop
Delay200mS:
decfsz Delay,f ; delay
goto $-1
decfsz Delay+1,f ; delay 768uS
goto $-3
return
end
I am a newbie on Microprocessors and have been learning to program the devices. The code below only works if I take the converted output from ADRESH and place it on PORTC. When I add the highlighted section it fails. I have tried everything I could think out but without success. Could someone please point me in the right direction.
Thanks
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Display ; define a variable to hold the diplay
Delay
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
movlw 0xFF
movwf TRISA ; Make PortA all input
clrf TRISC ; Make PortC all output
movlw 0x10 ; A2D Clock Fosc/8
movwf ADCON1
bcf STATUS,RP0 ; back to Register Page 0
bcf STATUS,RP0 ; address Register Page 2
bsf STATUS,RP1
movlw 0xFF ; we want all Port A pins Analoga
movwf ANSEL
bcf STATUS,RP0 ; address Register Page 0
bcf STATUS,RP1
movlw 0x01
movwf ADCON0 ; configure A2D for Channel 0 (RA0), Left justified, and turn on the A2D module
MainLoop:
call Delay200mS
bsf ADCON0,GO ; start A2D conversion
btfss ADCON0,GO ; this bit will change to zero when the conversion is complete
goto $-1
movf ADRESH,w ; read the A2D
movwf Display
movf Display,w ; save the value
;movf PORTC ; send to PORTC
TEST_0:
sublw 0xDE ; Subtract W from Reference
btfsc STATUS,C ; Is battery Voltage higher than Reference?
goto Switch0
bsf PORTC,0 ; If battery Voltage is higher than Reference - Set PORTC,0 to high
goto TEST_1
Switch0:
bcf PORTC,0 ; If battery Voltage is lower than Reference - Set PORTC,0 to low
TEST_1:
sublw 0xE2 ; Subtract W from Reference
btfsc STATUS,C ; Is battery Voltage higher than Reference?
goto Switch1
bsf PORTC,1 ; If battery Voltage is higher than Reference - Set PORTC,1 to high
goto MainLoop
Switch1:
bcf PORTC,1 ; If battery Voltage is lower than Reference - Set PORTC,1 to low
goto MainLoop
Delay200mS:
decfsz Delay,f ; delay
goto $-1
decfsz Delay+1,f ; delay 768uS
goto $-3
return
end