We set the output to be toggled every time the counter value match our OCR0A value. Thus, a square wave is generated:
int main (void)
{
b0_output; //OC0A as led output
TCCR0B = 0x03; //select timer clkio/64
TCCR0A = (0x01)<<6 | 0x02; // Toggle OC0A | CTC MODE
TCNT0 = 0x0; //starting couter value
OCR0A = 0x7F; //around frequency @ 2.2HZ
//make the clk cpu slower
CLKPR = 1<<CLKPCE; //tell cpu to update the CLKPR
CLKPR = 0x8; //clkio = clkcpu/256
while(1) {
;; //interrupt do the rest
}
}
The complete project can be found here: http://labs.bitartist.org/compare_int.tar.gz
No comments:
Post a Comment