PDA

View Full Version : is there a simple way make a condition true on a rising edge on an input



EDWARD
- 3rd June 2005, 10:06
is there a way to make a if then statement like this:

IF rising edge is detected on portb.0 THEN

do some code

endif

im trying to increment a varible by 1 every time it receves a low high transistion on input pin portb.0. the timing between of the signals could be from 10 to 500 ms. i cant have any long pauses.

Ingvar
- 3rd June 2005, 11:46
Since you want to use PortB.0 you can check the interruptflag.


OPTION_REG.6 = 1 ' rising edge
INTCON.1 = 0 ' reset the interruptflag

IF INTCON.1 = 1 THEN
INTCON.1 = 0 ' reset the interruptflag
' your code
ENDIF

EDWARD
- 5th June 2005, 19:55
well thats exctly what i needed. thank you very much.

i was trying to run a chunk of code only when portb.0, on my 16f73 configured and set as an input, read a rising edge signal. as ingvar has shown i can use interrupts.



'this part is only run once at the top of my program'

OPTION_REG.6 = 1 ' rising edge
INTCON.1 = 0 ' reset the interruptflag


'this part is contained in a loop'

IF INTCON.1 = 1 THEN
INTCON.1 = 0 ' reset the interruptflag
' your code
ENDIF