1

Dependencies:   mcp2515 mbed-dev-f303

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers data_pc.cpp Source File

data_pc.cpp

00001 #include "data_pc.h"
00002 
00003 Serial pc(PA_2, PA_3);              // tx, rx U2 min
00004 
00005 
00006 int pc_control = 0;                                                              // 命令帧标志位
00007 unsigned int flag_A = 0, flag_B = 0;
00008 unsigned int pc_num = 0;
00009 
00010 uint16_t phase_flag_get[1] = {0};
00011 uint16_t phase_flag_use[1] = {0};
00012 unsigned int phase_flag = 0;
00013 
00014 void pc_decode(){
00015     phase_flag = phase_flag_use[0];
00016 }
00017 
00018 void pc_clear(){
00019     phase_flag_use[0] = 0;
00020 }
00021 
00022 void serial_pc_isr(){
00023     while(pc.readable()){
00024         uint16_t c=pc.getc();
00025         if(c == 'A'){
00026             flag_A = 1;
00027             flag_B = 0;
00028             pc_num = 0;
00029             phase_flag_get[0] = 0;
00030             break; 
00031         }
00032         if(c == 'B'){
00033             flag_B = 1;
00034         }
00035         if(flag_A == 1){
00036             if((flag_B != 1) && (pc_num < 1))
00037             {
00038                 phase_flag_get[pc_num] = c;    
00039             }
00040             pc_num++;
00041             
00042             if((flag_B == 1) && (pc_num != 2))
00043             {                        
00044                 flag_A = 0;
00045                 flag_B = 0; 
00046                 pc_num   = 0;     
00047             }
00048             if((flag_B == 1) && (pc_num == 2))
00049             {                        
00050                 flag_A = 0;
00051                 flag_B = 0; 
00052                 pc_num   = 0; 
00053                 
00054                 phase_flag_use[0] = phase_flag_get[0] - '0'; 
00055                 pc_decode();
00056                 
00057                 pc.printf("%d", phase_flag);                                                    // 命令帧接收成功   
00058                 
00059                 pc_clear();
00060                 
00061             }
00062             pc_control = 1;                                                      
00063         } 
00064     }
00065 }