PIC24 RTCC设置一例

2020-02-08 09:04发布

第一次弄16位pic24的RTCC.中断驱动,led周期1秒。插入的汇编部分是规定的RTCWREN修改程序。

#include <p24FV32KA302.h>


//******************主程序************************
int main(void)
{
unsigned char i,j;       
//***************系统初始化部分*********************
TRISBbits.TRISB6=0;                                                //两口均为测试灯
TRISBbits.TRISB5=0;
LATBbits.LATB6=1;
LATBbits.LATB5=1;
//************RTCC settings****************************
IEC3bits.RTCIE=1;                                                //RTCC interrupt enabled
//Open RTCC
asm volatile ("push w7");
asm volatile ("push w8");
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");                 //set the RTCWREN bit
asm volatile ("bset _RCFGCAL, #15");                 //set the RTCEN bit
asm volatile ("pop w8");
asm volatile ("pop w7");
RTCPWC=0x0100;
ALCFGRPT=0xc300;                                                                                                  //半秒中断一次,LED每秒明暗变化一次

//****************主循环***************************
while(1)
{                                                                // The ever versatile Infinite Loop!
for (i=0;i<200;i++)
for (j=0;j<200;j++);
//LATBbits.LATB5^=1;
}                                                                //end of mainloop


}                                                                //end of main()



//*******************interrupt***************************
void __attribute__((__interrupt__, __shadow__)) _RTCCInterrupt(void)
{
IFS3bits.RTCIF=0;                                                //Clear the flag
LATBbits.LATB6^=1;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
10条回答
millwood0
2020-02-09 00:52
pic24s are some of the best chips made by Microchip, in my view. the pic10/12/16 are quite good for simple tasks but no vectored interrupt makes programming them modularly a difficult task. pic18 should have gotten vectored interrupts and it would have then the ability to compete with avrs.

the remappable pins on pic24s are simply great. the consistency of peripherals also makes coding a breeze.

all in all, it is a good chip.

一周热门 更多>