【AT-START-L021测评】时钟日历从串口发出
1,打开原来串口通信的项目里面加入rtc时钟
2,生成代码。里面包括下面文件
3,主程序中加入如下代码
int main(void)
{
/* add user code begin 1 */
ertc_time_type time;
uint32_t temp = 0;
/* add user code end 1 */
/* system clock config. */
wk_system_clock_config();
/* config periph clock. */
wk_periph_clock_config();
/* nvic config. */
wk_nvic_config();
/* timebase config. */
wk_timebase_init();
/* init usart1 function. */
wk_usart1_init();
/* init ertc function. */
wk_ertc_init();
/* init gpio function. */
wk_gpio_config();
/* add user code begin 2 */
/* add user code end 2 */
while(1)
{
/* add user code begin 3 */
//if((usart1_rx_counter>=4)&&(usart1_rx_buffer[0]=='s')&&(usart1_rx_buffer[1]=='e')&&(usart1_rx_buffer[2]=='n')&&(usart1_rx_buffer[3]=='d'))
{
int i =0;
gpio_bits_reset(led4_GPIO_PORT, led4_PIN);
gpio_bits_reset(led2_GPIO_PORT, led2_PIN | led3_PIN);
wk_delay_ms(100);//DelayMs(1000);
gpio_bits_set(led4_GPIO_PORT, led4_PIN);
gpio_bits_set(led2_GPIO_PORT, led2_PIN | led3_PIN);
wk_delay_ms(100);//DelayMs(1000);
wk_delay_ms(5);
usart1_rx_counter=0;
usart1_rx_buffer[0]=0;
usart1_rx_buffer[1]=0;
usart1_rx_buffer[2]=0;
usart1_rx_buffer[3]=0;
usart1_tx_counter=0;
ertc_calendar_get(&time);
if(temp != time.sec)
{
temp = time.sec;
/* display date format : year-month-day */
sprintf((char *)usart1_tx_buffer,"%02d-%02d-%02d ",time.year, time.month, time.day);
for(i =0;i<9;i++)
{
usart_data_transmit(USART1, usart1_tx_buffer[i]);
wk_delay_ms(2);
}
/* display time format : hour:min:sec */
sprintf((char *)usart1_tx_buffer,"%02d:%02d:%02d",time.hour, time.min, time.sec);
for(i =0;i<8;i++)
{
usart_data_transmit(USART1, usart1_tx_buffer[i]);
wk_delay_ms(2);
}
}
}
/* add user code end 3 */
}
}
4,测试,发现每秒会有时钟从串口输出。
|