Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mcp2515 mbed-dev-f303
Diff: DATA_PC/data_pc.cpp
- Revision:
- 0:d80c66cb1b3a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DATA_PC/data_pc.cpp Tue Nov 10 09:09:58 2020 +0000
@@ -0,0 +1,65 @@
+#include "data_pc.h"
+
+Serial pc(PA_2, PA_3); // tx, rx U2 min
+
+
+int pc_control = 0; // 命令帧标志位
+unsigned int flag_A = 0, flag_B = 0;
+unsigned int pc_num = 0;
+
+uint16_t phase_flag_get[1] = {0};
+uint16_t phase_flag_use[1] = {0};
+unsigned int phase_flag = 0;
+
+void pc_decode(){
+ phase_flag = phase_flag_use[0];
+}
+
+void pc_clear(){
+ phase_flag_use[0] = 0;
+}
+
+void serial_pc_isr(){
+ while(pc.readable()){
+ uint16_t c=pc.getc();
+ if(c == 'A'){
+ flag_A = 1;
+ flag_B = 0;
+ pc_num = 0;
+ phase_flag_get[0] = 0;
+ break;
+ }
+ if(c == 'B'){
+ flag_B = 1;
+ }
+ if(flag_A == 1){
+ if((flag_B != 1) && (pc_num < 1))
+ {
+ phase_flag_get[pc_num] = c;
+ }
+ pc_num++;
+
+ if((flag_B == 1) && (pc_num != 2))
+ {
+ flag_A = 0;
+ flag_B = 0;
+ pc_num = 0;
+ }
+ if((flag_B == 1) && (pc_num == 2))
+ {
+ flag_A = 0;
+ flag_B = 0;
+ pc_num = 0;
+
+ phase_flag_use[0] = phase_flag_get[0] - '0';
+ pc_decode();
+
+ pc.printf("%d", phase_flag); // 命令帧接收成功
+
+ pc_clear();
+
+ }
+ pc_control = 1;
+ }
+ }
+}
\ No newline at end of file