This is the the starting version of autograder hardwrae
Fork of AutoGrader_HW_01 by
Diff: main.cpp
- Revision:
- 1:97884b766b51
- Parent:
- 0:440ae480bff2
- Child:
- 2:b3286d232452
--- a/main.cpp Mon Aug 24 01:36:23 2015 +0000 +++ b/main.cpp Mon Aug 31 12:46:13 2015 +0000 @@ -1,9 +1,10 @@ #include "mbed.h" -Ticker Read_Port; +Ticker Read_Port; //Timer Polling + PortIn DataIn(PortC, 0x000000FF); // p21-p26 -DigitalOut Reset(PTC12); -Serial Comm(USBTX, USBRX); +DigitalOut Reset(PTC12); //ptc12 reset +Serial Comm(USBTX, USBRX); #define RX_BUFF_SIZE 64 @@ -13,6 +14,8 @@ int Data_avl; int Port_Data; +int Port_Data_prev=0; +int Time_cntr=0; void Serial_Read_callback() { @@ -43,16 +46,26 @@ void Read_Port_callback() { Port_Data=DataIn.read(); - Data_avl=1; + if((Port_Data ^ Port_Data_prev) != 0) + { + Data_avl=1; + Port_Data_prev=Port_Data; + } + Time_cntr++; } int main() { int ch; int state=0; - int cmd; - int new_frame; - int run_debug; + int cmd=0;; + int paramval[3][3]; + int paramstate=0; + int paramdigcnt=0; + int new_frame=0; + int run_debug=0; + + float scan_time; Comm.baud(115200); Comm.attach(&Serial_Read_callback); @@ -61,20 +74,35 @@ if(Serial_Available()) { ch=Serial_Read(); + Comm.printf("%c",ch,state); switch (state) { case 0: if(ch == '<') + { state++; + paramstate=0;; + } + break; case 1: cmd = ch; state++; break; - case 2: if(ch == '>') + case 2: if(ch == ',') + { + paramstate++; + paramdigcnt=2; + } + else if(ch == '>') { state=0; new_frame =1; + + } + else + { + paramval[paramstate-1][paramdigcnt--]=ch-'0'; } break; @@ -86,11 +114,15 @@ if(new_frame) { + Comm.printf("\n\rStarted polling Command=%c \n\r",cmd); new_frame =0; - + Port_Data_prev=0; + Time_cntr=0; if(cmd == 'P') { - Read_Port.attach(&Read_Port_callback,0.1); + scan_time= (paramval[0][0]-+paramval[0][1]* 10 + paramval[0][2] * 100)*0.01; + Comm.printf("Scan Time %f mS \n\r",scan_time*1000); + Read_Port.attach(&Read_Port_callback,scan_time); Reset=0; wait(0.01); Reset=1; @@ -107,7 +139,9 @@ { if(Data_avl) { - Comm.printf("<%d>",Port_Data); + Comm.printf("<%.4X,%.2X>\n\r",Time_cntr,Port_Data); + Data_avl=0; + Time_cntr=0; } }