Hello
I'm using PIC18F67K22 with internal OSC 4MHz and CCS compiler ver
4.130. I have the RTCC clock selection used with (SOSC0 & SOSC1)
via crystal 32.768kHz.
I have a simple test program where I set the alarm for 10secs
and then wait to see if my LED will flash after 10secs. The process
then repeats itself as per my program.
However, I can not achieve this since my LED is not flashing
at will with the RTCC alarm. On its own, the LED does flash and i can
even set the flashing rate to any rate that i desire.
Please can someone help and suggest where i'm wrong in my code
below and how to achieve RTCC alarm.
Thanks
Haseeb
I'm using PIC18F67K22 with internal OSC 4MHz and CCS compiler ver
4.130. I have the RTCC clock selection used with (SOSC0 & SOSC1)
via crystal 32.768kHz.
I have a simple test program where I set the alarm for 10secs
and then wait to see if my LED will flash after 10secs. The process
then repeats itself as per my program.
However, I can not achieve this since my LED is not flashing
at will with the RTCC alarm. On its own, the LED does flash and i can
even set the flashing rate to any rate that i desire.
Please can someone help and suggest where i'm wrong in my code
below and how to achieve RTCC alarm.
Thanks
Haseeb
Code:
#include <18F67K22.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, MCLR
// Set Speed to 4Mhz
#use delay(clock=4000000)
#include <stdio.h>
int alarm_flag = 0;
#int_RTC
void RTC_isr(void)
{
alarm_flag = 1; //raise flag once 10secs lapse
}
void main(void)
{
delay_ms(500); //startup delay
enable_interrupts(INT_RTC); //enable RTC interrupts
setup_rtc(RTC_ENABLE); //enable RTC
while(true) //loop forever
{
setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_10_SECONDS, 0x08); //initiallize 10 sec alarm
while(alarm_flag == 0); //stay here until 10sec alarm
alarm_flag = 0; //reset flag
//flash to indicate 10sec alarm
output_high(pin_B4);
delay_ms(200);
output_low(pin_B4);
delay_ms(200);
output_high(pin_B4);
delay_ms(200);
output_low(pin_B4);
delay_ms(200);
}
}