$regfile = "m128def.dat" $crystal = 16000000 '----------------------- '--- port A config ---- Config Porta = Output '--- port B config ---- Config Portb = Output '--- port C config ---- Config Portc = Input '--- port D config ---- Config Pind.0 = Input Config Pind.1 = Input Config Pind.2 = Input Config Pind.3 = Output Config Pind.4 = Input Config Pind.5 = Input Config Pind.6 = Input '--- port E config ---- Config Porte = Input '---------------------- Config Timer1 = Counter , Capture Edge = Rising , Noise Cancel = 1 , , Prescale = 1 Enable Timer1 Enable Capture1 Enable Ovf1 On Ovf1 Overflow_timer1 On Capture1 Edge_seeker Enable Interrupts '----------------------- Do !nop Loop End ' endless loop '---------------------- edge_seeker: '----pulse making------ !sbi PORTa,1 ' make short pulse to indicate the good working to capture every edge. !nop !nop !nop !cbi PORTa,1 !push r17 !push r18 !push r19 !push r20 !ldi r18,$bf !ldi r20,$40 !in r17,TCCR1B ' from here I change the state of the ICES1 bit. !mov r19,r17 !SBRC r17,6 ' 0 becomes 1 and in case it was 1, I change it in 0. !and r19,r18 !SBRS r17,6 !or r19,r20 !out tccr1b,r19 !pop r20 !pop r19 !pop r18 !pop r17 Return '---------------------- Overflow_timer1: !sbi PORTa,0 !nop !cbi PORTa,0 Return End