Re: Polling a Port Pin for a specific amount of time



On Tue, 01 Apr 2008 14:39:09 -0500, "as1" <picghaw@xxxxxxxxx> wrote:

Hello all,

I hope someone can help me as I am tackling my first ever work project
with 8051 and my previous experience is .....absolutely nothing, zero.

I need to poll a pin for 5 seconds,

How precisely? I.e., 5 +/- n seconds where n is micro/milli/tenths/ or
whole seconds. Do Bad Things happen if the interval is exceeded?

and take certain actions when it
changes from high to low,

How much margin do you have; how soon after the edge must the certain
actions commence? How long is the pin guaranteed to stay low? What
happens if the pin has not changed by the end of the interval?

but then go back to polling. Interrupts don't
seem like an ideal solution since it will interfere with the polling
process.

That depends somewhat on the answers to the above. Events that occur
in the "seconds" epoch often imply that they're tied to user events,
where the difference of a few milliseconds is negligible.

All other things being equal, I'd set up a timer to interrupt at a
convenient interval and have that interrupt just increment a tick (so
that it's fairly quick). Keep an eye on the pin value and the ticker
and do the necessary when the pin changes or the ticker times out.

Also, you didn't mention it but it does matter whether the pin change
is from other circuitry or, e.g., a user pushing a button. In the
latter case, you'll also need to worry about debouncing the pin.

--
Rich Webb Norfolk, VA



Thank you all for your comments. I am going to try using a timer as you
all suggested.

.