int main(void) { uint32_t cnt = 0;
/* 初始化系统时钟*/ system_clock_config();
/* 初始化中断优先级分组*/ nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
/* 初始化延时函数 */ delay_init();
/* 初始化LCD */ lcd_init(LCD_DISPLAY_VERTICAL);
/* can 1 初始化 */ can_init(CAN1);
/* can 2 初始化 */ can_init(CAN2);
/* 显示信息*/ lcd_string_show(10, 20, 200, 24, 24, (uint8_t*)"CAN Test");
while(1) { /* can 1 数据初始化 */ can_data_init(CAN1);
/* 通过 can 1 发送数据 */ can_transmit_data(CAN1,can1_tx_message);
/* can 2 数据初始化 */ can_data_init(CAN2);
/* 通过 can 2 发送数据 */ can_transmit_data(CAN2, can2_tx_message);
/* can 1 接收到数据 */ if(can1_rx_flag != 0) { /* 清除can 1接收数据标志 */ can1_rx_flag = 0;
/* 显示标题 */ lcd_string_show(10, 60, 200, 24, 24,(uint8_t *)"can 1 received");
/* 显示filterindex */ lcd_string_show(10, 100, 200, 24, 24,(uint8_t *)"filter_index:"); lcd_num_show(170, 100, 200, 24, 24,can1_rx_message.filter_index, 1);
if (can1_rx_message.id_type ==CAN_ID_EXTENDED ) { /* 显示extended id*/ lcd_string_show(10, 130, 200, 24, 24,(uint8_t *)"extended_id:"); lcd_num_show(170, 130, 200, 24, 24,can1_rx_message.extended_id, 1); } else { /* 显示standard id*/ lcd_string_show(10, 130, 200, 24, 24,(uint8_t *)"standard_id:"); lcd_num_show(170, 130, 200, 24, 24,can1_rx_message.standard_id, 1); }
if (can1_rx_message.frame_type ==CAN_TFT_REMOTE ) { /* 无数据 */ lcd_string_show(10, 160, 200, 24, 24,(uint8_t *)"remote frame: no data"); } else { /* 数据比较 */ if(buffer_compare(can2_tx_message.data,can1_rx_message.data, 8) == 0) { /* 数据成功接收 */ lcd_string_show(10, 160, 310, 24, 24,(uint8_t *)"can 1 数据成功接收"); } else { /* 数据接收错误 */ lcd_string_show(10, 160, 310, 24, 24,(uint8_t *)"can 1 数据接收错误"); } } }
/* can 2 接收到数据 */ if(can2_rx_flag != 0) { /* 清除can 2接收数据标志 */ can2_rx_flag = 0;
/* 显示标题 */ lcd_string_show(10, 220, 200, 24, 24,(uint8_t *)"can 2 received");
/* 显示filterindex */ lcd_string_show(10, 260, 200, 24, 24,(uint8_t *)"filter_index:"); lcd_num_show(170, 260, 200, 24, 24,can2_rx_message.filter_index, 1);
if (can2_rx_message.id_type ==CAN_ID_EXTENDED ) { /* 显示extended id*/ lcd_string_show(10, 290, 200, 24, 24,(uint8_t *)"extended_id:"); lcd_num_show(170, 290, 200, 24, 24,can2_rx_message.extended_id, 1); } else { /* 显示standard id*/ lcd_string_show(10, 290, 200, 24, 24,(uint8_t *)"standard_id:"); lcd_num_show(170, 290, 200, 24, 24,can2_rx_message.standard_id, 1); }
if (can2_rx_message.frame_type == CAN_TFT_REMOTE) { /* 无数据 */ lcd_string_show(10, 320, 200, 24, 24,(uint8_t *)"remote frame: no data"); } else { /* 数据比较 */ if(buffer_compare(can1_tx_message.data,can2_rx_message.data, 8) == 0) { /* 数据成功接收 */ lcd_string_show(10, 320, 310, 24, 24,(uint8_t *)"can 2 数据成功接收"); } else { /* 数据接收错误 */ lcd_string_show(10, 320, 310, 24, 24,(uint8_t *)"can 2 数据接收错误"); } } }
cnt++;
/* 显示传输次数 */ lcd_string_show(10, 380, 200, 24, 24,(uint8_t *)"transfer number:"); lcd_num_show(206, 380, 250, 24, 24, cnt,1); delay_ms(1000); } } |