Interfacing with RTCC

From Pinguino
Jump to: navigation, search
Language: English


Timer 1 of the Pinguino PIC18F2550 can be used as a real time clock calendar (RTCC). Here is a simple example to test the real time clock function.

What you will need

  • 1x Pinguino PIC18F2550
  • 1x Breadboard
  • 1x 32,768 KHz crystal
  • 2x 22pF ceramic capacitors
  • Some breadboard jumpers

Hardware Setup

RTCC Example on a Breadboard

Source Code

// Real time clock with a 18F2550 and Pinguino
// Jean-Pierre Mandon 2010

byte hours,mins,secs;

void setup()
{
// configure TIMER 1 to be used as RTCC
TMR1H=0×80;
TMR1L=0;
T1CON=0b00001111;

// init current time
hours=12;
mins=0;
secs=0;

// init interrupt for RTCC module
PIE1bits.TMR1IE=1;
INTCONbits.PEIE=1;
INTCONbits.GIE=1;

// init Serial to display time
Serial.begin(9600);
Serial.print(“\r\n);
Serial.print(Pinguino clock\r\n);
}

// timer 1 is interrupt driven
void UserInterrupt()
{
TMR1H=0×80;
PIR1bits.TMR1IF=0;
secs++;

if (secs==60)
    {
    secs=0;
    mins++;

    if (mins==60)
        {
        mins=0;
        hours++;
  
        if (hours==24) 
            hours=0;
        }
     }
}

// The main loop display time on a serial terminal
void loop()
{
if (hours<10) 
    Serial.print(0);

Serial.print(hours,DEC);
Serial.print(:);

if (mins<10) 
    Serial.print(0);

Serial.print(mins,DEC);
Serial.print(:);

if (secs<10) 
    Serial.print(0);

Serial.print(secs,DEC);
Serial.print(“\r);
}