Right, have to use interrupt. So will it be like, choose pulse edge, enable interrupt on say rising edge and then turn ON LED? But how to turn it OFF when square wave pulse is low? I just wrote this, trying to visualize how it would work. Please do correct it. Thanks. bsf option_reg, intedg ; select interrupt on rising edge of b0/int pin bsf intcon, int0ie ; enable rb0/int external interrupt intchk btfss intcon, rbif ; check interrupt flag bit goto intchk movf portb, 1 ; end mismatch condition bcf intcon, rbif ; clear interrupt flag bsf portb, 1 ; turn on led btfss intcon, rbif ; check rbif bit bcf portb, 1 ; turn off led retfie On Tue, Oct 20, 2009 at 10:54 AM, Jinx wrote: > > > this is exactly the type of info that is not in any book. thanks for > this. > > You're welcome. What will best help you learn is a project that you > design and program > > For example, if you want to track a square wave and light an LED, a > simple way would be to poll the input. Say you have chosen B0 / INT0 > as the input > > repeat > > btfss portb,0 ;wait here until the input goes high > goto $-1 > > bsf led ;turn the LED on > > btfsc portb,0 ;wait here until the input goes low > goto $-1 > > bcf led ;turn the LED off > > goto repeat ;go back to the start > > As you can see, that ties up the micro for 100% of its time and you > can do no other work with it. If you use an interrupt then that frees > up the micro to do other things. You'd set up the interrupt system to > react to an INT0 event and alternate the edge trigger polarity. This > process is quite straight-forward but can get quite involved depending > on what else is happening in the software, so you need to account > for everything and anything that could happen to ensure smooth running > and good time management > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist