// Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { unsigned char RlState; OCR1A += 1000; // 1mS RlState = (INP_PIN ^ 0x0E0); KeyUState = KeyUState >> 1; KeyDState = KeyDState >> 1; SwAdrState = SwAdrState >> 1; if (RlState & 0x80) KeyUState |= 0x10; if (RlState & 0x40) KeyDState |= 0x10; if (RlState & 0x20) SwAdrState |= 0x10; SEL_PORT |= 0x1F; LED_PORT |= 0xC0; SEG_PORT = 0xFF; switch (TimPhase) { case 0: if (LedUState & 0x02) LED_PORT &= ~LEDU_BIT; if (LedDState & 0x02) LED_PORT &= ~LEDD_BIT; SEG_PORT = ~SegsI[1]; SEL_PORT &= ~SEL2_BIT; break; case 1: if (LedUState & 0x04) LED_PORT &= ~LEDU_BIT; if (LedDState & 0x04) LED_PORT &= ~LEDD_BIT; SEG_PORT = ~SegsI[2]; SEL_PORT &= ~SEL3_BIT; break; case 2: if (LedUState & 0x08) LED_PORT &= ~LEDU_BIT; if (LedDState & 0x08) LED_PORT &= ~LEDD_BIT; SEG_PORT = ~SegsI[3]; SEL_PORT &= ~SEL4_BIT; break; case 3: if (LedUState & 0x10) LED_PORT &= ~LEDU_BIT; if (LedDState & 0x10) LED_PORT &= ~LEDD_BIT; SEG_PORT = ~SegsI[4]; SEL_PORT &= ~SEL5_BIT; break; case 4: if (LedUState & 0x01) LED_PORT &= ~LEDU_BIT; if (LedDState & 0x01) LED_PORT &= ~LEDD_BIT; SEG_PORT = ~SegsI[0]; SEL_PORT &= ~SEL1_BIT; FsMajority[0] = FsMajority[1]; FsMajority[1] = FsMajority[2]; FsMajority[2] = KeyUState | ((unsigned short)KeyDState << 5); FsMajority[3] = ((FsMajority[1] | FsMajority[2]) & FsMajority[0]) | (FsMajority[1] & FsMajority[2]); DestAddr = SwAdrState & 0x0F; SecTmr++; if ((SecTmr & 0x40) == 0) { LedUState = LedState; LedDState = LedState >> 5; SegsI[0] = Segs[0]; SegsI[1] = Segs[1]; SegsI[2] = Segs[2]; SegsI[3] = Segs[3]; SegsI[4] = Segs[4]; } else { // off Blunk State LedUState = LedState & ~LedBlinkState; LedDState = (LedState & ~LedBlinkState) >> 5; SegsI[0] = Segs[0] & ~SegsB[0]; SegsI[1] = Segs[1] & ~SegsB[1]; SegsI[2] = Segs[2] & ~SegsB[2]; SegsI[3] = Segs[3] & ~SegsB[3]; SegsI[4] = Segs[4] & ~SegsB[4]; } TimFlg = 1; if (ModTout) { ModTout--; if (ModTout == 0) { ModBackReq = 1; } } break; } TimPhase++; if (TimPhase > 4) TimPhase = 0; }