I think Henriks' idea of using a timer/counter is the way to go. This leaves you tons of time to handle other things while the counter works for you in the background.
There is no need to wait with any WHILE/WEND, PAUSE, etc.
And if you prefer Timer0 to increment on high-to-low transitions on RA4, just change OPTION_REG = %10101000 to OPTION_REG = %10111000.Code:CMCON = 0 ' Disable comparators TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter PORTB = 0 ' clear all outputs on PORTB TRISB = 0 ' PORTB outputs ANSEL = 0 ' All digital ' OPTION_REG setup for Timer0 ' Prescaler to WDT with 1:1 prescaler for TMR0 ' TMR0 clock is external input on RA4/T0CKI ' Increment on low-to-high transitions on RA4/T0CKI ' Internal pull-ups disabled OPTION_REG = %10101000 TMR0 = 0 ' Clear TMR0 count Begin: IF TMR0 >= 20 THEN Ledas ' you have time to do lots of other thing here ' while Timr0 counts pulses in the background GOTO Begin Ledas: TMR0 = 0 ' clear Timer0 count here HIGH Led GOTO begin




Bookmarks