40.6.2. Čítač / měřič kmitočtu

Zdroje a odkazy:

;
        .org    0
	rjmp    reset

reset:
        ; Initialize SP to ramend
        ldi     temp,low(ramend)
        out     spl,temp
        ; Initialize baudrate for uart
        ldi     temp,baudconstant
        out     ubrr,temp
        ⋮

; command interpretation loop for frequency meter
loop:
⋮
reset:
        …
        ldi     temp,0b10000110         ; Enable input to 16 bit counter (Timer/Counter 1).
        out     tccr1b,temp
        …

        ; Enable the watchdog
        wdr                             ; must be
        ldi     temp,0b00001111         ; WDT enable
        out     wdtcr,temp              ;+

        sei                             ; Enable interrupts
        rjmp    Main                    ; Start execution of main loop.
; Measure frequency for 1, 10 and 100 seconds.
measurefreq:
        ldi     temp,0                  ; Clear 16 bit counter
        out     tcnt1h,temp
        out     tcnt1l,temp
        clr     ZL                      ; Clear ZL which is the overflow counter.

	sbi     PORTD,4                 ; Pulse prescaler reset
        cbi     PORTD,4

        ldi     temp,0b10000000         ; Enable overflow interrupts from 16 bit timer.
        out     TIMSK,temp

        cbi     DDRD,3                  ; Make gate pin high impedance
        cbi     PORTD,3                 ; Gate signal into prescaler - turn off pullup

AnotherSecond:
        rcall   Delay1Second            ; Delay 1 second.
        dec     iterations              ; Measure more than 1 second if necessary
        brne    AnotherSecond

        sbi     DDRD,3                  ; Make gate signal low Z.
        sbi     PORTD,3                 ; Disable signal into prescaler.

        clr     temp                    ; Disable overflow interrupts.
        out     TIMSK,temp              ;+ Note: using tccr1b to disable counter causes 1+.
        ret
Licence Creative Commons
Elektronika a počítače, jejímž autorem je Radek Hnilica, podléhá licenci Creative Commons Uveďte autora-Nevyužívejte dílo komerčně-Zachovejte licenci 3.0 Česká republika .