This particular lab introduces additional kernel functions
that you may use to complete the lab. Remember that the
kernel functions in kernel.c
act as a primitive
operating system for the MicroStamp11. The kernel functions
introduced in this lab control the timing of events.
The additional kernel functions introduced in this lab are
itemized below. We first show the function's prototype,
then we describe its function, and then we provide an
example of its usage.
void pause(int duration);
Description: This function causes program execution
to wait for duration
clock ticks. The actual length
of a clock tick can be controlled. In this version of
kernel.c
, we assume a clock tick takes about 2000
clock cycles where each clock cycle is 500 nanoseconds. So
this pause is 1 m-sec.
Usage: The following statement forces program execution to wait for 10 m-sec.
pause(10);A more complete example is shown in the following program. This program toggles the logical state of an output pin once every second,
void main(void){ init(); while(1){ pause(1000); toggle_pin(3); } }
void button(short pin)
Description: This function causes program execution
to pause until a button attached to pin-address i
sets the pin state high. This function automatically
performs button debouncing by causing program execution to
wait 10 m-sec before returning from the function.
Usage: The following code waits until a button attached to pin I3 is pressed (sets pin I3 high).
button(3);
int count(short pin, short duration)
Description: This function waits until the state of
pin-address i
toggles from 0 to 1. The function
then counts the number of times the button is pushed
(changes state from high to low to high) in duration
clock ticks. Debouncing is automatically performed on the
button pushes and the button count number is returned by
the function call when the time duration
has
expired.
Usage: The following code counts the number of times a button attached to pin I3 is pushed in 1 sec (assuming a 1 m-sec clock tick).
value = count (3, 1000);