[SOLVED] PIC16F877 RTC Not working

Status
Not open for further replies.

WStevens_sa

Member level 2
Joined
Jan 5, 2011
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
South Africa
Activity points
1,695
Hi all

I wrote the code at the bottom to create a rtc using f877. The inturrupt triggers and sets the seconds minutes and hours. I have outputs RA0 and RA1.
After 60 seconds I want RA0 = 1 and after 2 minutes I want RA1 = 1 however as soon as I simulate using real pic simulator both RA0 and RA1 go on immediately. Can someone please tell me where I have gone wrong.




---------- Post added at 09:57 ---------- Previous post was at 09:18 ----------

Okay I found my first mistake

if (Seconds = 59) {
RA0_bit=1;

Must be.

if (Seconds == 59) {
RA0_bit=1;

Same with the minutes.

I am still not sure if this is working as a true RTC. I hope someone can answer me on this.
 

Hi WStevens, first of all I'm learning MCU programming so I could be wrong. Anyway, this is the ISR code I used with the same microprocessor (f877A) to simulate a clock, last year, with an external clock (Xtal=20MHz), prescaler=32, TMR0 (preload time) =100 (it should be 102 but, trying and retrying, I've seen that 100 was the best). It's not very precise but, for learning and simulating a RCT, it's ok. Well, I see that your code is a copy of mine, the one difference I note is I put TOIF=0 almost at code end. Pratically, I close routine (TOIF= 0) after all counting, not before. Try in this way... I'll be waiting for an answer.

void interrupt isr(void)
{

if (T0IF)
{

TMR0=100;

// CLOCK MANAGEMENT
counter++;
if (counter==1000)
{ counter=0;
seconds++;

if (seconds>59)
{ seconds=0;
minutes++;

if (minutes>59)
{ minutes=0;
hours++;

if (hours>23)
{ hours=0;

}

}

}

}



T0IF=0;
}
}
 
Hi I actually figured it out. Here is my code for creating a Real Time clock using PIC16F877 with a 2x16 character LCD using TMR0 with internal clock of 16MHZ. I used the wiring diagram from 4.12 EXAMPLE 10 **broken link removed** for a Pic16F887 wihch has the same pinouts as the PIC16F877.

I hope this helps somebody.

 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…