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
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.
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.
unsigned int counter = 0 ;
unsigned char seconds = 0, minutes = 0, hours = 0 ;
void interrupt(void) {
if(T0IF_bit == 1) // Check for interrupt flag
{
T0IF_bit=0;
counter++ ;
if(counter > 15625){ // 1 sec 16 Mhz crystal = 16000000 / 4 / 256
counter = 0 ;
seconds++ ;
if(seconds == 60){
seconds = 0 ;
minutes++ ;
if(minutes == 60){
minutes = 0 ;
hours++ ;
if(hours == 24){
hours = 0 ;
}
}
}
}
}
}
void main()
{
TMR0 = 0; //Clear timer 0
T0CS_bit = 0; //use internal clock
T0SE_bit = 0; // on rising edge
PSA_bit = 1; // use prescaler
PS1_bit = 1; // prescaler divides in 256
PS2_bit = 1;
PORTA = 0; /*set RA0-RA5 low */
TRISA = 0; /*set PORTA to output*/
PORTD = 0; /*set RA0-RA5 low */
TRISD = 0; /*set PORTA to output*/
ADCON1 = 7; //Disable ADC
//CMCON = 7; - FOR 16F877A
while(1)
{
if (Seconds = 59) {
RA0_bit=1;
}
if (Minutes = 2) {
RA1_bit=1;
}
}
}
---------- 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.