标签归档:RTC

LPC1768 内部RTC程序

typedef struct{

uint8_t RTC_Sec;

uint8_t RTC_Min;

uint8_t RTC_Hour;

uint8_t RTC_Mday;

uint8_t RTC_Wday;

uint16_t RTC_Yday;

uint8_t RTC_Mon;

uint16_t RTC_Year;

}RTCTime;

RTCTime LocalTime;

void RTCStart(void)

{

LPC_RTC->CCR |= 0x01;

}

void RTCInit( void )

{

LPC_SC->PCONP |= CLKPWR_PCONP_PCRTC; //开启RTC电源

if(!(LPC_RTC->CCR & 0x01)) //如果时钟没使能,使能时钟,使能位在芯片复位时状态不会变化,不用每次上电都使能

{

LPC_RTC->ILR = 0;

LPC_RTC->AMR = 0xff;

LPC_RTC->CIIR = 0;

LPC_RTC->CCR = 0;

LocalTime.RTC_Year = 2019;

LocalTime.RTC_Mon = 1;

LocalTime.RTC_Mday = 1;

LocalTime.RTC_Wday = 2;

LocalTime.RTC_Hour = 0;

LocalTime.RTC_Min = 0;

LocalTime.RTC_Sec = 0;

RTCSetTime(&LocalTime);

RTCStart();

}

}

void RTC_Get_Time(RTCTime* Time)

{

Time->RTC_Year= LPC_RTC->YEAR ;

Time->RTC_Mon = LPC_RTC->MONTH;

Time->RTC_Yday = LPC_RTC->DOY;

Time->RTC_Wday = LPC_RTC->DOW;

Time->RTC_Mday = LPC_RTC->DOM;

Time->RTC_Hour = LPC_RTC->HOUR;

Time->RTC_Min = LPC_RTC->MIN;

Time->RTC_Sec = LPC_RTC->SEC;

}

void RTCSetTime(RTCTime* Time)

{

LPC_RTC->SEC = Time->RTC_Sec;

LPC_RTC->MIN = Time->RTC_Min;

LPC_RTC->HOUR = Time->RTC_Hour;

LPC_RTC->DOM = Time->RTC_Mday;

LPC_RTC->DOW = Time->RTC_Wday;

LPC_RTC->DOY = Time->RTC_Yday;

LPC_RTC->MONTH = Time->RTC_Mon;

LPC_RTC->YEAR = Time->RTC_Year;

}