Oscar Alvarado / Mbed 2 deprecated calculoCRC

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
oalvarado_dtk
Date:
Fri Jun 07 22:11:31 2019 +0000
Commit message:
calculo CRC sensor DU-180

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 07 22:11:31 2019 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+
+Serial  out(USBTX, USBRX);
+
+
+
+unsigned char  crc8   (unsigned  char  data,unsigned  char crc){ 
+
+unsigned  char  i = data ^ crc; 
+  crc = 0;
+  if(i & 0x01) crc ^= 0x5e;
+  if(i & 0x02) crc ^= 0xbc;  
+  if(i & 0x04) crc ^= 0x61;
+  if(i & 0x08) crc ^= 0xc2;
+  if(i & 0x10) crc ^= 0x9d;
+  if(i & 0x20) crc ^= 0x23;
+  if(i & 0x40) crc ^= 0x46;
+  if(i & 0x80) crc ^= 0x8c;
+  return crc;
+ }
+
+
+void main (void ){
+    
+    unsigned  char datos[8];
+    unsigned  char crc= 0x00;
+    int  cont = 0;
+    datos[0]=  0x3e;
+    datos[1]=  0x01;
+    datos[2]=  0x06;
+    datos[3]=  0x66;
+    datos[4]=  0x58;
+    datos[5]=  0x00;
+    datos[6]=  0x3f;
+    datos[7]=  0x5e;
+
+    
+  
+    for(cont = 0; cont< 8; cont++ ) {
+        
+        crc=  crc8(datos[cont],crc);
+        
+
+        }
+    
+    out.printf("EL CRC ES :%2X", crc);
+    
+      
+    
+    }
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 07 22:11:31 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file