;*** Measure the width of an external pulse with an AVR Mega8
;;   PWM sginal from R/C receiver. One 1-2ms pulse every 20ms.
;;   R/C PWM signal connected to ICP (PortB, Pin0).
;;   Mega8 running at 4Mhz.
;;   Demo code writes lower 8 bits of Timer1/ICR1 to PortD.
;;   Note that if upper 8 bits of ICR1 are not all zero, 
;;   then pulse width exceeds valid range.
;;   -rkumar at hyperreal dot org

.include "m8def.inc"

.org 0x0000             ; Reset vector
rjmp reset
.org 0x0005             ; Timer1 Capture Event Interupt vector
rjmp TIM1_CAPT

ldi r16, low(RAMEND)    ; Set up stack pointer on reset
out SPL, r16
ldi r16, high(RAMEND)
out SPH, r16

ldi r16, (1<