您的位置:首页 > 财经 > 金融 > 【TB作品】MSP430F5529单片机,基于串口的万年历

【TB作品】MSP430F5529单片机,基于串口的万年历

2024/11/16 19:57:52 来源:https://blog.csdn.net/x1131230123/article/details/139381694  浏览:    关键词:【TB作品】MSP430F5529单片机,基于串口的万年历

功能

5529给串口发送实时时间。
可以通过串口修改万年历时间。

部分代码


void main(void)
{WDTCTL = WDTPW + WDTHOLD; // Stop WDTinitClock();SetupRTC();init_uart();Print_Str("MSP430F5529串口测试\r\n");delay_ms(100);//LEDP1DIR |= (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:12Z2switch (__even_in_range(UCA1IV, 4)){case 0:break;                             // Vector 0 - no interruptcase 2:                                   // Vector 2 - RXIFG
//        while (!(UCA1IFG & UCTXIFG))
//            ;             // USCI_A0 TX buffer ready?
//        UCA1TXBUF = UCA1RXBUF;                  // TX -> RXed characterrevbuff = 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; //关闭RTCRTCYEAR=(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 - TXIFGdefault: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();
}

全部代码

https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com