Advertisement
RuiViana

Calculo FCS

Jan 13th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. //@00RD00000000*
  2.  
  3. String texto;
  4. boolean flag[10];
  5. char c;
  6. int var;
  7. byte Temp;
  8. void setup()
  9. {
  10. Serial.begin(9600);
  11. pinMode(13,OUTPUT);
  12. }
  13.  
  14. void loop()
  15. {
  16. while(Serial.available())
  17. {
  18. c= Serial.read();
  19.  
  20. if (c == '@')
  21. {
  22. Temp = c;
  23. }
  24. else
  25. {
  26. if (c!='*')
  27. {
  28. Temp = Temp^c;
  29. }
  30. //Serial.println(Temp,HEX);
  31. }
  32.  
  33. if (c=='@' || flag[0]==true) //inicio da String
  34. {
  35. flag[0]=true;
  36. texto += c;
  37. }
  38. if (c=='*') // fim da String
  39. {
  40.  
  41. //calcular FCS
  42. Serial.print(texto); //imprimir na serial mais o FCS
  43. Serial.print (" FCS ");
  44. Serial.println(Temp,HEX);
  45. texto="";
  46. flag[0]=false;
  47. }
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement