| ??? 05/05/03 20:29 Read: times |
#44856 - RE: multi-tasking in software Responding to: ???'s previous message |
Below is a quick code block which is not compiled, tested, even not thought on it detailed...
void timer_interrupt() interrupt 0 {
in = P2;
delta = old_in ^ in;
old_in = in;
for (int i=0; i<4; i++) {
delta = delta >> 1;
// state change?
if (CY) {
state_flag[i] = 1;
in = in >> 1;
val[i] = CY;
counter[i] = 0;
cntr_flag[i] = 0;
} else
in = in >> 1;
// incr counter?
if (!flag[i])
if (counter[i]++ == thresh[val[i]])
cntr_flag[i] = 1;
}
}
void main() {
while (1) {
for (int i=0; i<4; i++) {
if (state_flag[i] || cntr_flag[i]) {
// diable interrupt
state_flag[i] = cntr_flag[i] = counter[i] = 0;
// enable interrupt
process_event(i); // do whatever you want
}
}
}
}
is it completely garbage? |



