CPU = 12F675 MHZ = 4 CONFIG 12692 ' ******************************************* ' PIC program for boiler LED opto-sensor ' ' 8-pin PIC 12F675, internal 4-MHz clock, internal A/D converter ' 10 bit a/d = 1024 units ' full-scale = 5v = 1024, 0 = 0v ' ' if switch = 0 volts then trigger event locks to 6.5 minutes ' ' Bytes Free: 32 ' ******************************************* input GP0 ' switch on pin 7 input GP1 ' a/d input = an1 on pin 6 swi var gpio.bit0 ' define variable for state of pin 7 delay var byte ' adcono equ $1f ' adcono address location option_reg.bit7 = 0 ' enable weak pull-ups (wpu) wpu = %00000001 ' uses internal 10k resistor for switch ansel = %01010010 ' xxxx0010 = ans1 = a/d input on pin 6 '------------------------------- main: adcono = %10000101 ' turn a/d on + use pin 6 pause 300 ' 300 mSecs delay adcono = %10000111 ' start conversion loop: ' if adcon0.bit1 = 1 then loop ' loop until go/done bit 1 = 0 adcono = 0 ' turn off a/d ' a/d result is stored in 2 bytes ' called adresH and adresL serout GP5,n1200-5,[dec ((adresh * 256) + adresl),10,13] ' -5 for osc. calibration. ' PIC outputs a/d result as decimal ' on pin 2 (= GP5) at ~1200 baud. if swi = 1 then main ' get next a/d sample if switch is OFF '------------------------------- ' get next a/d sample if switch is ON and a/d result is still rather small ' and within a noise margin if ((adresh * 256) + adresl) < 50 then main '-------------------------------- ' program gets to here if switch is ON and a/d signal > 0.245 volt is sensed. ' i.e. 50 = noise level i.e. 50 x 0.0049v = 0.245 v ' this next bit adds 6.5 minutes delay delay = 6 loop1: pause 65000 ' pause 65 secs, x 6 = 6.5 mins delay = delay - 1 if delay > 0 then loop1 goto main end ' -------------------------------- ' this delay isn't very good but does work. It's limited by the lack of ' code space using Basic and a small PIC chip. The PIC outputs a data number ' greater than 50 and then stays locked in this delay loop. ' fleXYlog continously processes this data number until a new number is sent ' by the PIC chip 6 minutes later.