1
\$\begingroup\$

This is my first use of the RTCC interrupt for dspic33F and P24h. I have set the date and the alarm, when the alarm goes on, the LED attached in PIN 15 will blink. The code compiles but there is no result on the LED.

here is the code:

#include<p33Fxxxx.h>


 volatile unsigned int counter=0;

 void __attribute__((interrupt,auto_psv)) _RTCCInterrupt(void)

 {
     counter=1;

 _RTCIF = 0;     // clear flag


 } // RTCC interrupt service routine



 void initRTCC( void)
 {
    // Enables the OSCON write and set
    //_SOSCEN =1;
    asm volatile ("mov #OSCCON,W1");
    asm volatile ("mov.b    #0x46, W2");    // unlock sequence
    asm volatile ("mov.b    #0x57, W3");
    asm volatile ("mov.b    #0x02, W0");    // SOSCEN =1
    asm volatile ("mov.b    W2, [W1]");
    asm volatile ("mov.b    W3, [W1]");
    asm volatile ("mov.b    W0, [W1]");


    //_RTCWREN = 1;       // unlock setting
    asm volatile("disi  #5");
    asm volatile("mov   #0x55, w7");
    asm volatile("mov   w7, _NVMKEY");
    asm volatile("mov   #0xAA, w8");
    asm volatile("mov   w8, _NVMKEY");
        asm volatile("bset  _RCFGCAL, #13");    // RTCWREN =1;
    asm volatile("nop");
    asm volatile("nop");

    _RTCEN = 0; // disable the clock

    // set 07/11/2011 MON 23:59:30
    _RTCPTR = 3;        // start the sequence
    RTCVAL = 0x2011;    // YEAR
    RTCVAL = 0x0711;    // MONTH-1/DAY-1
    RTCVAL = 0x0159;   // WEEKDAY/HOURS
    RTCVAL = 0x5930;    // MINUTES/SECONDS


    // lock and enable
    _RTCEN = 1;         // start the clock
    _RTCWREN = 0;       // lock settings
 } // initRTCC

 void setALARM( void)
 {
    // disable alarm
    _ALRMEN = 0;

    // set the ALARM for a specific day of)
    _ALRMPTR = 2;       // start the sequence
    ALRMVAL = 0x0711;   // MONTH-1/DAY-1
    ALRMVAL = 0x0200;   // WEEKDAY/HOUR
    ALRMVAL = 0x0100;   // MINUTES/SECONDS

    // set the repeat counter
    _ARPT = 0;          // once
    _CHIME = 1;         // indefinitely

    // set the alarm mask
    _AMASK = 0;    
    _ALRMEN = 1;        // enable alarm
    _RTCIF = 0;         // clear flag
    _RTCIE = 1;         // enable interrupt

 } // set ALARM



  main( void)
 {
    TRISB=0;
    initRTCC();
   setALARM();
   _RTCIF = 0;

    while( 1){

        if (counter==1) {

            PORTB = 0xffff;
            counter =0;}

    }
    // repeat the main loop

 } // main
\$\endgroup\$
1
\$\begingroup\$

Interrupts always need to be enabled globally. There's a special instruction for that purpose:

sei

This sets a global interrupt enable flag in the CPU. Similarly there is an instruction for disabling this flag:

cli

There may already be a sei() function available from the headers. But as you are familiar with inline assembly, you can use it that way too.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.