Monday, June 1, 2015

Timer Time: Using Internal ATTiny13A Chip’s Timer, CTC with Automatic Mode

What if we want it to do the task automatically? With neither interrupt routine nor call command?.

We could use CTC mode . The TCNT0 will start counting up, restarted to zero (and generate interrupt) if its value reaches OCR0A value (the compare value we set).

Since, in the matter of talking, the timer has its flag status on pin B0, if we set it as output, we could see the status (high/low, on off) via led connected to it and ground.  

Note that we don’t use ‘interrupt routine’ but the system’s still generate an interrupt.

.include "../"
.def a=r16

.org 0000
sbi ddrb,0              ; pinb as output 
ldi a,0b01000010        ; CTC mode
out TCCR0A,a
ldi r16,0b00000101      ; pre-scaler /1024
    out TCCR0B,a
    ldi a,200                ; compare value
    out OCR0A,a             


rjmp loop