Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
@jpanhalt to my knowledge everything i needed was on that page.
One-shot: While remaining in a low power mode i.e. running on a 32 KHz watch crysta
Connect the sensor to an interrupt line on the microcontroller or CPU.
That page refers to placing an LED on PortB.4. The schematic shows an LED on GP5 (pin2) of the 12F675. The 12F series have GPIO. Thus, reference to "PortB" made me think there was a different version somewhere else for the 12F series.
I can only read, at best, a little Assembly, so maybe the correct pin assignment was somewhere else in the code. Sorry to raise that concern unnecessarily.
John
@ device pic12F675, LP_OSC, wdt_on, mclr_on, protect_off
'Place the sensor is on GPIO.2
sensorPin VAR GPIO.2 : TrisIO.2=1
'Place a LED on port B.4
testLED VAR GPIO.1 : trisio.1 = 0 : testLED = 0
'this variable holds (buffers) the previous state of the sensor
tilt VAR BYTE
sensorPrev VAR BYTE
sensorPrev = tilt ' this is not used i would say they uesd it in a
'interrupt handier
'a counter- increases when the sensor moves
sensorCount VAR WORD
sensorCount = 0
'a couter - increases on every loop iteration
gapcount VAR WORD
gapcount = 0
'this variable determines how often we check for sensor changes.
gap VAR WORD
gap = 500
CMCON = $7
ANSEL = $0
'take a breather
PAUSE 1000
'beginning of main loop routine
main:
gapcount = gapcount + 1
'we use this if statement to activate the sensor routine -
'- once every {gap} cycles. In this code - once every 500 loops.
IF gapcount > gap THEN
'reset the counter
gapcount = 0
'if the sensor pin has changed since last checked
IF sensorPin <> sensorPrev THEN
'increment by 5 unless the counter is already very high
IF sensorCount < 50 THEN
sensorCount = sensorCount+5
ENDIF
'else if the sensor did not change states
ELSE
'slowly decrease the sensor unless its already at 0
IF sensorCount> 0 THEN
sensorCount = sensorCount-1
ENDIF
ENDIF
'if the sensor moved repeatedly - we have real motion!
IF sensorCount> 25 THEN
testLED = 1
ELSE
testLED = 0
ENDIF
'set the sensor buffer to current sensorPit, toward next check
sensorPrev = sensorPin
ENDIF
'loop again...
GOSUB main