2.5.3Initial_high, active_low Interrupt source
If the P2C0 is an initial_high, active_low signal, the interrupt service routine should use INV0 to invert or not to invert the P2C0 for high_pulse generation as follows: (Refer to DEMO4.C)
Initial set:
|
| now_int_state=1; | /* initial state for P2C0 | */ |
|
|
|
|
|
| ||||
|
| outportb(wBase+0x2a,0); | /* select the inverted P2C0 */ |
|
|
|
|
| ||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
void interrupt irq_service() |
|
|
|
|
|
|
|
|
| |||||
{ |
|
|
|
|
| /* now P2C0 is changed to LOW |
|
| */(a) | |||||
if (now_int_state==1) |
|
|
| |||||||||||
{ |
|
|
| /* | */ |
|
| |||||||
|
| COUNT_L++; |
| /* find a LOW_pulse (P2C0) |
|
| */ |
|
| |||||
|
| If((inport(wBase+7)&1)==0)/* the P2C0 is still fixed in LOW | */ |
|
| |||||||||
{ |
|
|
| /* | Æ need to generate a high_pulse | */ |
|
| ||||||
|
| outportb(wBase+0x2a,1);/* | INV0 select the | */(b) | ||||||||||
|
|
|
|
|
| /* | INT_CHAN_0=P2C0=LOW |
|
| */ |
|
| ||
|
| now_int_state=0; |
| /* | INT_CHAN_0 generate a high_pulse | */ |
|
| ||||||
|
|
| /* now P2C0=LOW |
|
|
|
| */ |
|
| ||||
} |
|
|
| /* now P2C0=HIGH |
|
|
|
| */ |
|
| |||
|
| else now_int_state=1; |
|
|
|
|
|
| ||||||
} |
|
|
| /* don’t have to generate high_pulse | */ |
|
| |||||||
|
|
| /* now P2C0 is changed to HIGH |
|
| */(c) | ||||||||
else |
|
|
| |||||||||||
{ |
|
|
| /* |
|
| */ |
|
| |||||
|
| COUNT_H++; |
| /* find a HIGH_pulse (P2C0) |
|
| */ |
|
| |||||
|
| If((inport(wBase+7)&1)==1)/* the P2C0 is still fixed in HIGH | */ |
|
| |||||||||
{ |
|
|
| /* need to generate a high_pulse | */ |
|
| |||||||
|
| outportb(wBase+0x2a,0);/* INV0 select the inverted input */(d) | ||||||||||||
|
|
|
|
|
| /* INT_CHAN_0=!P2C0=LOW |
|
| */ |
|
| |||
|
| now_int_state=1; |
| /* INT_CHAN_0 generate a high_pulse | */ |
|
| |||||||
|
|
| /* now P2C0=HIGH |
|
|
|
| */ |
|
| ||||
} |
|
|
| /* now P2C0=LOW |
|
|
|
| */ |
|
| |||
|
| else now_int_state=0; |
|
|
|
|
|
| ||||||
} |
|
|
| /* don’t have to generate high_pulse | */ |
|
| |||||||
|
|
|
|
|
|
|
|
|
|
|
| |||
if (wIrq>=8) outportb(A2_8259,0x20); |
|
|
|
|
|
|
| |||||||
outportb(A1_8259,0x20); |
|
|
|
|
|
|
|
|
|
| ||||
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| (a) | (b) |
|
| (c) | (d) |
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| P2C0 |
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INV0
INT_CHAN_0