官方的例子,跑不起来,秒始终不会增加!:L
#include "p18cxxx.h" //PIC18F26J50
#include <rtcc.h>
#pragma config WDTEN = OFF //WDT disabled (enabled by SWDTEN bit)
#pragma config PLLDIV = 2 //Divide by 3 (12 MHz oscillator input)
#pragma config STVREN = ON //stack overflow/underflow reset enabled
#pragma config XINST = OFF //Extended instruction set disabled
#pragma config CPUDIV = OSC1 //No CPU system clock divide
#pragma config CP0 = OFF //Program memory is not code-protected
// #pragma config OSC = HSPLL //HS oscillator, PLL enabled, HSPLL used by USB
#pragma config OSC = INTOSCPLL
#pragma config T1DIG = OFF //Sec Osc clock source may be selected
#pragma config LPT1OSC = OFF //high power Timer1 mode
#pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF //Two-Speed Start-up disabled
#pragma config WDTPS = 32768 //1:32768
#pragma config RTCOSC = INTOSCREF //RTCC uses INTRC as clock
#pragma config DSBOREN = OFF //Zero-Power BOR disabled in Deep Sleep
#pragma config DSWDTOSC = INTOSCREF //DSWDT uses INTOSC/INTRC as clock
#pragma config DSWDTEN = OFF //Disabled
#pragma config DSWDTPS = 2048 //1:8,192 (8.5 seconds)
#pragma config IOL1WAY = OFF //IOLOCK bit can be set and cleared
#pragma config MSSP7B_EN = MSK7 //7 Bit address masking
#pragma config WPFP = PAGE_0 //Write Protect Program Flash Page 0
#pragma config WPEND = PAGE_0 //Start protection at page 0
#pragma config WPCFG = OFF //Write/Erase last page protect Disabled
#pragma config WPDIS = OFF //WPFP[5:0], WPEND, and WPCFG bits ignored
rtccTimeDate rtccTimeDate ,rtccAlrmTimeDate, rtcc_read_TimeDate ;
void drv_RTCC_Init(void)
{
RtccInitClock(); //turn on clock source
RtccWrOn(); //write enable the rtcc registers
mRtccSetClockOe(1); //enable RTCC output on RTCC output pin
PIE3bits.RTCCIE=1;
//Set Date and time using global structures defined in libraries
rtccTimeDate.f.hour = 1; //Set Hour
rtccTimeDate.f.min = 0; //Set minute
rtccTimeDate.f.sec = 0; //Set second
rtccTimeDate.f.mday = 04; //Set day
rtccTimeDate.f.mon = 04; //Se month
rtccTimeDate.f.year = 09; //set year
rtccTimeDate.f.wday = 6; //Set which day of the week for the corrsponding date
//Set the alarm time and date using gloabl structures defined in libraries
rtccAlrmTimeDate.f.hour = rtccTimeDate.f.hour; //Set Hour
rtccAlrmTimeDate.f.min = rtccTimeDate.f.min ; //Set minute
rtccAlrmTimeDate.f.sec = rtccTimeDate.f.sec + 4; //alarm after ten seconds
rtccAlrmTimeDate.f.mday = rtccTimeDate.f.mday; //Set day
rtccAlrmTimeDate.f.wday = rtccTimeDate.f.wday; //Set which day of the week for the corrsponding date
rtccAlrmTimeDate.f.mon = rtccTimeDate.f.mon; //Se month
rtccAlrmTimeDate.f.year = rtccTimeDate.f.year; //set year
RtccWriteTimeDate(&rtccTimeDate,1); //write into registers
// RtccSetAlarmRpt(RTCC_RPT_TEN_SEC,1); //Set the alarm repeat to every minute
// RtccSetAlarmRptCount(5,1); //set alarm repeat count
// RtccWriteAlrmTimeDate(&rtccAlrmTimeDate); //write the time for alarm into alarm registers
mRtccOn(); //enable the rtcc
// mRtccAlrmEnable(); //enable the rtcc alarm to wake the device up from deep sleep
mRtccAlrmDisable();
}
void main(void)
{
drv_RTCC_Init();
mRtcc_Clear_Intr_Status_Bit; //clears the RTCC interrupt status bit
while(1)
{
while(PIR3bits.RTCCIF==0) //wait untill alarm is set
{
RtccReadTimeDate(&rtcc_read_TimeDate); //rtcc_read_TimeDate will have latest time
Nop(); //这里设断点观察rtcc_read_TimeDate,发现秒始终不会增加
Nop();
}
Nop();
Nop();
}
}
|