通过RTC中断1S唤醒
void main(void)
{
WM_Initialize(); // System initialize
// Display "123456"
LCD_Display0_8();
while(1)
{
__bis_SR_register(LPM3_bits + GIE); // 进入 LPM3 w/ interrupt
}
}
void WM_Initialize(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
// WDTCTL = WDTPW + WDTCNTCL + WDTSSEL0 + WDTIS0 + WDTIS1; // Set watchdog 16s
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
GPIO_Config(); // GPIO initialize
CLOCK_Config(); // System clock initialize
LCD_Config(); // LCD module initialize
RTC_Config();
//P1SEL0 |= BIT5; //配置P15为输入脚 20160506
// P1REN |= BIT5;
//P1REN &= ~BIT5; // to be comment 20160506
//TA0CTL = 0; 20160506
}
void CLOCK_Config()
{
P4SEL0 |= BIT1 + BIT2; // Select pin4.1 pin4.2 as crystal function
do
{
CSCTL7 &= ~(XT1OFFG + DCOFFG); // Clear XT1 and DCO fault flag 清除 XT1 DCO 失效标志
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1 & OFIFG); // Test oscillator fault flag 如果失效标志存在
CSCTL4 = SELA__XT1CLK; // IMPORTANT. Select ACLK = XT1 = 32768Hz
}
void LCD_Config()
{
uint8_t ui8Cnt;
uint8_t *pLCD = (uint8_t *)&LCDM0;
for (ui8Cnt = 13; ui8Cnt > 0; ui8Cnt--) // Clear LCD memory
*pLCD++ = 0x00; // CLR LCD
SYSCFG2 |= LCDPCTL; // R13/R23/R33/LCDC1/LCDC2 pins selected 设置 LCD功耗
LCDPCTL0 = 0xFFFF;
LCDPCTL1 = 0x01FF; //设置 LCD管脚 L0~L24 pins selected
LCDVCTL = LCDSELVDD + LCDCPEN; // Mode 2 设置 降低LCD 功耗 片上电荷泵
LCDCSSEL0 = 0x000F; // 设置 公共极 COM0~3
LCDCSSEL1 = 0x0000;
LCDM0 = 0x21; // L0 = COM0, L1 = COM1
LCDM1 = 0x84;
LCDCTL0 |= LCD4MUX + LCDLP + LCDON; // 打开LCD: 4-mux 模式
}
void RTC_Config()
{
RTCCTL = RTCSS__XT1CLK + RTCSR + RTCPS__1 | RTCIE;
RTCMOD = 32768-1; //1s
tRTCData.ui8Year = 14; // RTC initialize
tRTCData.ui8Month = 7;
tRTCData.ui8Day = 30;
tRTCData.ui8Hour = 23;
tRTCData.ui8Minute = 59;
tRTCData.ui8Second = 55;
}
// RTC interrupt service routine
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)
{
switch(__even_in_range(RTCIV,RTCIV_RTCIF))
{
case RTCIV_NONE: break; // No interrupt
case RTCIV_RTCIF: // RTC Overflow
{
uint8_t ui8Days = 31;
uint8_t *pAddress; // For monthly data storage
tRTCData.ui8Second++;
。。。
__low_power_mode_off_on_exit(); //退出中断时唤醒CPU
}
break;
default: break;
}
}
此帖出自
小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>