# PIC18 and RTCC combination

I'm quite new in the microcontroller world, since I work on it only for my internship. But I have a problem in my main project. I was implementing an automaton based on a PIC18F46J50, and we printed the final product on a board using a new pic. I choosed a PIC18F45K22.

We realised yesterday that this PIC does not handle th RTCC module, and it is one of the main features of this project. Since the board is already printed, it's a big problem to find a PIC with the same number of PIN, but it's my year project, so it's quite important for me to find a solution so here is my question.

Is there any other PIC that have 44 PIN (or 40) and a RTCC module ? Or is there any way to implement a RTCC module without it on the PIC ?

• You can use Microchip Advanced Part Selector to search for another PIC with the same number of pins and an RTCC – m.Alin Aug 1 '15 at 12:37
• And yes, you can implement an RTCC in software, provided that your system doesn't lose power. – m.Alin Aug 1 '15 at 12:38
• ok, it's to late to by an other PIC, but we made some software modification and it can do the trick. btw an other solution would have been to use RTCC module trough I2C or SPI bus – Nico Balas Aug 4 '15 at 14:15

I found a software solution, I programmed the calendar in interuption.

this is the solution for PIC18F45K22 on TIMER 1 in low interupt.

if(PIR1bits.TMR1IF && PIE1bits.TMR1IE)
{
PIR1bits.TMR1IF =0; /* Clear Interrupt Flag 1 */
TMR1H = TMR1H_INIT;
TMR1L = TMR1L_INIT;
}


void hal_clk_ITtask()
{
tmdt.f.sec ++;
if(tmdt.f.sec == 60)
{
tmdt.f.min ++;
tmdt.f.sec = 0;
}
if(tmdt.f.min == 60)
{
tmdt.f.hour ++;
tmdt.f.min = 0;
}
if(tmdt.f.hour == 24)
{
tmdt.f.day ++;
tmdt.f.hour = 0;
}
if(tmdt.f.day == 7)
{
tmdt.f.day = 0;
}
}


but I can't be sure of the precision. I didn't test it for more than an hour.