5529给串口发送实时时间。
可以通过串口修改万年历时间。
cppvoid main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
initClock();
SetupRTC();
init_uart();
Print_Str("MSP430F5529串口测试\r\n");
delay_ms(100);
//LED
P1DIR |= (BIT0);
P1OUT &= ~(BIT0); //关灯0
_EINT();
while (1)
{
}
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
static unsigned char revbuff = 0;
static unsigned char rev_modify_ifg = 0;
static unsigned char rev_modify_count = 0;
static unsigned char rev_modify_buffer[30]; //A2020-11-11B12:12:12Z2
switch (__even_in_range(UCA1IV, 4))
{
case 0:
break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
// while (!(UCA1IFG & UCTXIFG))
// ; // USCI_A0 TX buffer ready?
// UCA1TXBUF = UCA1RXBUF; // TX -> RXed character
revbuff = UCA1RXBUF;
if (revbuff == 'A')
{
rev_modify_ifg = 1;
rev_modify_count = 0;
}
if (rev_modify_ifg == 1)
{
rev_modify_buffer[rev_modify_count++] = revbuff; //缓存
if (rev_modify_count == 22)
{
rev_modify_ifg = 0; //不再接受
RTCCTL01 = RTCHOLD + RTCMODE + RTCTEV_0; //关闭RTC
RTCYEAR=(rev_modify_buffer[1]-'0')*1000+(rev_modify_buffer[3]-'0')*100+(rev_modify_buffer[3]-'0')*10+(rev_modify_buffer[4]-'0')*1;
RTCMON=(rev_modify_buffer[6]-'0')*10+(rev_modify_buffer[7]-'0')*1;
RTCDAY=(rev_modify_buffer[9]-'0')*10+(rev_modify_buffer[10]-'0')*1;
RTCHOUR=(rev_modify_buffer[12]-'0')*10+(rev_modify_buffer[13]-'0')*1;
RTCMIN=(rev_modify_buffer[15]-'0')*10+(rev_modify_buffer[16]-'0')*1;
RTCSEC=(rev_modify_buffer[18]-'0')*10+(rev_modify_buffer[19]-'0')*1;
RTCDOW=(rev_modify_buffer[21]-'0');
RTCCTL0 |= RTCRDYIE; /* RTCRDY中断使能 */
RTCCTL01 &= ~RTCHOLD; //打开RTC
}
}
break;
case 4:
break; // Vector 4 - TXIFG
default:
break;
}
}
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)
{
switch (__even_in_range(RTCIV, RTC_RT1PSIFG))
{
case RTC_NONE:
break;
case RTC_RTCRDYIFG:
{
/* RTCDOW RTCMON RTCDAY RTCHOUR RTCMIN RTCSEC */
//读取时间
nian = RTCYEAR;
yue = RTCMON;
ri = RTCDAY;
shi = RTCHOUR;
fen = RTCMIN;
miao = RTCSEC;
zhou = RTCDOW;
//闪烁灯
P1OUT ^= BIT0;
//发送串口
memset(buf, 0, sizeof(buf));
sprintf(buf, "%d-%02d-%02d \r\n", nian, yue, ri);
Print_Str(buf);
memset(buf, 0, sizeof(buf));
sprintf(buf, "week %d \r\n", zhou);
Print_Str(buf);
memset(buf, 0, sizeof(buf));
sprintf(buf, "%02d:%02d:%02d \r\n\r\n", shi, fen, miao);
Print_Str(buf);
}
break;
case RTC_RTCTEVIFG:
break;
case RTC_RTCAIFG:
break;
case RTC_RT0PSIFG:
break; /* 分频器 0 */
case RTC_RT1PSIFG:
break; /* 分频器 1 */
default:
break;
}
__no_operation();
}
cpphttps://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!