Kingdom Man
New Member
here is some code that Burt has been helping me with, but I have a problem. I want to learn how to set my output high at 1Volt and have my output stay high until it reaches .8Volts. as of now, with this code I can only set my output high or low at one given voltage, so it will trigger high when it hits 1v but the second it goes below 1v it triggers low again.
PHP:
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
CBLOCK 0x020
endc
#define _.8VOLT 0x28
#define _1VOLT 0x33
#define _2VOLT 0x66
#define _2_5VOLT 0x7F
#define _3VOLT 0x99
#define _4VOLT 0xCC
ORG 0x000 ; processor reset vector
goto init ; go to beginning of program
ORG 0x004 ; interrupt vector location
init:
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 Analog
movwf ANSEL
bcf STATUS,RP0 ; address Register Page 0
bcf STATUS,RP1
clrf ADCON0
movlw 0x01
movwf ADCON0 ; configure A2D for Channel 0
MainLoop:
call adcdelay ;delay to charge cap
bsf ADCON0,GO ; start conversion
btfss ADCON0,GO ; this bit will change to zero when the conversion is complete
goto $-1
movf ADRESH,w ; Copy the display to the LEDs
movlw _.8VOLT
subwf ADRESH, w
BNC LessThan.8VOLT ; Branch if less than 1V
movlw _1VOLT
subwf ADRESH, w
BNC LessThan1VOLT ; Branch if Between 1V and 2V
movlw _2VOLT
subwf ADRESH, w
BNC LessThan2VOLT ; Branch if Between 2V and 2.5V
movlw _2_5VOLT
subwf ADRESH, w
BNC LessThan2_5VOLT ; Branch if Between 2.5V and 3V
movlw _3VOLT
subwf ADRESH, w
BNC LessThan3VOLT ; Branch if Between 3V and 4V
movlw _4VOLT
subwf ADRESH, w
BNC LessThan4VOLT ; Branch if Between 3V and 4V
goto MainLoop
LessThan.8VOLT:
bcf PORTC,0
return
LessThan1VOLT:
bsf PORTC,0
return
LessThan2VOLT:
bcf PORTC,0 ; lights led thats in volt range
return
LessThan2_5VOLT:
bsf PORTC,0
return
LessThan3VOLT:
bcf PORTC,0
return
LessThan4VOLT:
bsf PORTC,0
return
adcdelay:
nop ;1 cycle
return ;4 cycles (including call)
end