CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F46J11 and RTC functionality

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
noxus



Joined: 16 Nov 2009
Posts: 6

View user's profile Send private message

PIC18F46J11 and RTC functionality
PostPosted: Tue Nov 24, 2009 9:44 am     Reply with quote

Hello all,
I'm trying to get the RTC (clock & alarm) to work with my PIC18F46J11.
I want the microcontroller to execute some code when an RTC interrupt occurs. Eventually I am going to set the alarm time via a serial interface but for now I've hard coded the begin time and alarm time.
Note: I've attached a second external crystal oscillator for the RTC of the PIC microcontroller. I'm using the following code. (compiler is version 4.099)
Code:
#include <18F46J11.h>

#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOPROTECT
#FUSES RTCOSC_T1   

#use delay(clock=8000000)

#int_RTC
void RTC_isr(void)
{
   output_toggle(PIN_D2);
}

void main()
{
   time_t tWriteTime;
   time_t tAlarmTime;

   tWriteTime.tm_year = 9;
   tWriteTime.tm_mon  = 11;
   tWriteTime.tm_mday = 24;
   tWriteTime.tm_wday = 2;
   tWriteTime.tm_hour = 16;
   tWriteTime.tm_min  = 0;
   tWriteTime.tm_sec  = 0;

   tAlarmTime.tm_year = 9;
   tAlarmTime.tm_mon  = 11;
   tAlarmTime.tm_mday = 24;
   tAlarmTime.tm_wday = 2;
   tAlarmTime.tm_hour = 16;
   tAlarmTime.tm_min  = 0;
   tAlarmTime.tm_sec  = 5;

   setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0x00);
   setup_rtc_alarm(RTC_ALARM_ENABLE,RTC_ALARM_SEC, 0xff);
   rtc_write(&tWriteTime);
   rtc_alarm_write(&tAlarmTime);
   
   enable_interrupts(int_rtc);

   while(1)
   {
   }
}


Via breakpoints and some extra debugging code I noticed that the RTC was indeed incrementing. But I'm not sure that I'm using the correct procedure to set the ALARM functionality. Also, I didn't find anything in the help file regarding the #INT_RTC interrupt routine.

At the moment it looks like the RTC interrupt never occurs when the RTC reaches the alarm time.

Did I set up the microcontroller correctly to generate an interrupt when the alarm time occurs?
I'm not sure since I couldn't find a good example or good documentation regarding this functionality.

Thanks in advance for all the help!
Ttelmah
Guest







PostPosted: Tue Nov 24, 2009 9:54 am     Reply with quote

enable_interrupts(INT_GLOBAL);

There are _two_ bits that must be set before an interrupt is responded to. It's own interrupt enable,and the _global_ interrupt enable....

Best Wishes
noxus



Joined: 16 Nov 2009
Posts: 6

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 10:02 am     Reply with quote

Thanks Ttelmah!
I cannot believe I forgot the enable the global interrupts.
Thanks a million!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group