Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


nitialize Timer/counter2 as asynchronous using the 32.768kHz watch
crystal.

< 10; i++)

cbi


ASS


TCN


TCC 1<<CS20);

gs

sei // enable global interrupt

//
gSE
gMI
gHO
}


ne second interrupt from 32kHz watch crystal
GNAL(SIG_OVERFLOW2)

gSECOND = 0;


gMINUTE = 0;
HOUR++; // increment hour
if (gHOUR > 12)


// i
//
void RTC_init(void)
{
// wait for external crystal to stabilise
for(int i = 0; i
_delay_loop_2(30000);


cli(); // disable global interrupt


(TIMSK2, TOIE2); // disable OCIE2A and TOIE2
R = (1<<AS2); // select asynchronous operation of Timer2
T2 = 0; // clear TCNT2A

R2A |= (1<<CS22) | (

// select precaler: 32.768 kHz / 128 = 1 sec between each overflow


// wait for TCN2UB and TCR2UB to be cleared
while((ASSR & 0x01) | (ASSR & 0x04));


TIFR2 = 0xFF; // clear interrupt-fla
sbi(TIMSK2, TOIE2); // enable Timer2 overflow interrupt


();


initial time and date setting
COND = 0;
NUTE = 0;
UR = 0;

// o
SI
{
gSECOND++; // increment second


if (gSECOND == 60)
{


gMINUTE++; // increment minute
if (gMINUTE > 59)
{
g
Free download pdf