--

-- , ( ) .

( ). - -. - (0) . 0 :

. , . 8- ( = 0xFF) (0x00).

OCR0 . CTC (TCNT0) OCR0, (TCNT0=0). , OCR0 , , , . .

- -. (0xFF), .

- . -. ,

, - 0. , , , , .

- : , ,, , - ( ).

, , AVR- ATtiny13.

CTC

()


- T0

(WGM01, WGM00 =0b10) OCR0 . CTC (TCNT0) OCR0, (TCNT0=0). , OCR0 , , , . .

(WGMn3-0 = 0b0100 0b1100) OCR0A. (TCNT0), OCR0A. . . (TCNTn) , OCR0A , (TCNT0) .


OCF0A, . , .

CTC OC0A , (COM0A1, COMA0 = 0b01). OC0A , . fOC0 =fclk_I/O/2, OCRnA = 0x0000. OCRn :

N (1,8, 32, 64, 128, 256 1024).

. . - - 0.

- (PB0) , .

0 ( WGM00, WGM01,WGM02) TCCROA TCCROB, OCR0A, ( - 1024), ( ), ( TIMSK0).

SEI. .

- keyskan. ( ). ( )

() start, -. keyskan.

. OCF0A TIFR0. , keyskan TIM0_COMPA. ( ) , . , (CS00, CS01, CS02) .

() pause. 1 r19, TIM0_COMPA . , .

() continue. 1 r19 , TIM0_COMPA . .

(CS00, CS01,CS02) .

1)

2,3) T0 ( /1024)

4,5,6)

7,8,9) ,, ( )

10) OC0A.

, 9,6 .

.def temp = r16

.def flags = r19

.def freq = r17

.include"C:\Program Files\Atmel\AVRTools\AvrAssembler2\Appnotes\tn13def.inc"

rjmp RESET ; Reset Handler

NOP;rjmpEXT_INT0 ; IRQ0 Handler

NOP;rjmpPCINT0 ; PCINT0 Handler

NOP;rjmpTIM0_OVF ; Timer0 Overflow Handler

NOP;rjmpEE_RDY ; EEPROM Ready Handler

NOP;rjmpANA_COMP ;Analog Comparator Handler

rjmpTIM0_COMPA ; Timer0 CompareA Handler

NOP;rjmpTIM0_COMPB ;Timer0 CompareB Handler

NOP;rjmpWATCHDOG; Watchdog Interrupt Handler

NOP;rjmpADC ; ADC Conversion Handler

Reset:

ldi temp,1

out DDRB,temp ;PB0 PB1-

ldi freq,1 ;

out OCR0A,freq ;

rjmp keyskan

start:

ldi temp,(1<<COM0A0)+(1<<WGM01)

out TCCR0A,temp ;1<<COM0A0,0<<COM0A1-

; OCR0A

;1<<WGM01 -

ldi temp,(0<<CS00)+(1<<CS02)

out TCCR0B,temp ; 1024

ldi temp,1<<OCIE0A

out TIMSK0,temp ;

; OCR0A

sei ;

keyskan:

sbic pinb,4 ; ., PB4=0

rjmp start ; START

sbic pinb,3 ; ., PB4=0

rjmp pause ; PAUSE

sbic pinb,2 ; ., PB4=0

rjmp stop ; STOP

sbic pinb,1 ; ., PB4=0

rjmp continue ; CONTINUE

rjmp keyskan ; keyskan

TIM0_COMPA: ;

; OCR0A

sbrs flags,1 ;, 1

inc freq ;

out OCR0A,freq ; OCR0A

cpi freq,200 ;

breq stop ;, stop

reti ;

stop:

sbr flags,2 ;2

ldi temp,(0<<CS00)+(0<<CS01)+(0<<CS02)

out TCCR0B,temp ;

rjmp keyskan ; keyskan

pause:

sbr flags,1

rjmp keyskan ; keyskan

continue:

cbr flags,1

rjmp keyskan ; keyskan

PROTEUS





+