Here is some code for initializing timer0
/*
* Initialize timer0 to use the 32.768 kHz real-time clock crystal
* attached to TOSC1 & 2. Enable output compare interrupt and set
* the output compare register to 32 which will cause an interrupt
* to be generated every 0.9765625 milliseconds - close enough to a
* millisecond.
*/
TIFR |= BV(OCIE0);
TIMSK |= BV(OCIE0); /* enable output compare interrupt */
ASSR |= BV(AS0); /* use asynchronous clock source */
TCNT0 = 0;
OCR0 = MS_OCRMATCH; /* non debug use 32 match in 0.9765625 ms */
TCCR0 = BV(WGM01) | BV(CS00); /* CTC, no prescale */
while (ASSR & 0x07)
;
Then I use a interupt routine
*/
SIGNAL(SIG_OUTPUT_COMPARE0)
{
ms_count++;
}
-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On
Behalf Of ttse7
Sent: Monday, May 30, 2005 4:38 AM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Atmega16 Real time clock
Hi all,
I cannot turn on the real time clock of atmega16, I am sure I put the
32K crystal at TOSC1 and TOSC2, here is a portion of my source code:
....
ASSR |= _BV(AS2);
TCCR2 =0x05;
TCNT2 =0x00;
....
sei();
Can anyone help? Many thanks
Yahoo! Groups LinksMessage
RE: [AVR-Chat] Atmega16 Real time clock
2005-05-31 by wbounce
Attachments
- No local attachments were found for this message.