#include <16F84A.h> // Pic Model 16F84A #fuses XT,NOWDT,NOPROTECT,PUT #use delay(clock=4000000) // Crystal Oscillator Frequency #define phase1 0x04 #define phase2 0x10 #define phase3 0x08 #define phase4 0x20 #define portB 0x06 int cont=0; #INT_EXT void INT_EXT_isr () { if(!input(PIN_B1)) { cont ++; if(cont == 4) { cont=0; } } else { if(cont==0) { cont = 4; } cont--; } switch(cont) { case 0 : #asm movlw phase1 movwf portB #endasm break; case 1 : #asm movlw phase2 movwf portB #endasm break; case 2 : #asm movlw phase3 movwf portB #endasm break; case 3 : #asm movlw phase4 movwf portB #endasm break; } delay_us(100); } //about 250ms 114 = 1sec #define HIGH_START 28 byte seconds, high_count; #INT_RTCC clock_isr() { if(--high_count==0) { #asm movlw 0x00 movwf portB #endasm high_count=HIGH_START; } } void main(void) { set_tris_b(0x03); enable_interrupts(GLOBAL); enable_interrupts(INT_EXT); set_rtcc(0); setup_counters(RTCC_INTERNAL, RTCC_DIV_128); enable_interrupts(INT_RTCC); high_count=HIGH_START; ext_int_edge(L_TO_H); //set all phases to 0 by default #asm movlw 0x00 movwf portB #endasm while(1); }