canbus rpm test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
guigra
Date:
Wed Sep 29 20:40:07 2010 +0000
Commit message:

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
diff -r 000000000000 -r 2e70b895129c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 29 20:40:07 2010 +0000
@@ -0,0 +1,121 @@
+#include "mbed.h"
+#include "TextLCD.h"
+//leemos el can a 500 kb/s y lo enviamos por el usb
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+Serial pc(USBTX, USBRX); // tx, rx
+CAN can2(p30,p29);
+CANMessage can_MsgRx;
+
+TextLCD lcd(p18,p19,p20,p17,p16,p15,p14); 
+static  char error=0;
+int main() {
+char buffer[20];
+ int engine_data;
+ //float
+ lcd.locate(0,0);
+    lcd.printf("C3 PICASSO v2");
+    
+    lcd.locate(0,1);
+    lcd.printf("RICARDO GUILLEN");
+       
+   
+    
+    wait(3);
+    lcd.cls();
+
+    //inicializamos el can a 500kb/s
+    can2.frequency(500000);
+
+    //bulce principal
+    while (1) {
+    
+        if (can2.read(can_MsgRx)) {
+        
+        
+        
+        
+        
+         switch(can_MsgRx.id){
+            case 0x208:
+            //engine_data =  ((can_MsgRx.data[0]*256) + can_MsgRx.data[1])/4;
+            // sprintf(buffer,"%d rpm ",(int) engine_data);
+            // sprintf(buffer,"%d rpm ",can_MsgRx.id);
+            //unsigned long a=array[0]|(array[1]<<8);
+           /* engine_data=(can_MsgRx.data[0]|(can_MsgRx.data[1]<<8)/10);
+            lcd.locate(0,0);
+            lcd.printf(buffer);
+            lcd.printf("%d rpm %x%x ",(int) engine_data,can_MsgRx.data[0],can_MsgRx.data[1]);
+            */
+            
+            //(s[ 0 ] << 8) +s[ 1 ]
+           /* engine_data=(can_MsgRx.data[0]<<8 + (can_MsgRx.data[1])/10);
+            sprintf(buffer,"0000%x%x",can_MsgRx.data[0],can_MsgRx.data[1]);
+            lcd.locate(0,0);
+            // lcd.printf(buffer);
+            lcd.printf("%d rpm %x%x %s",(int) engine_data,can_MsgRx.data[0],can_MsgRx.data[1],buffer);*/
+            
+            unsigned char b[4];
+            b[0]=0x00;
+            b[1]=0x00;
+            b[2]=can_MsgRx.data[0];
+            b[3]=can_MsgRx.data[1];
+           int valor= (b[0] << 24) + ((b[1] & 0xFF) << 16)+ ((b[2] & 0xFF) << 8)+ (b[3] & 0xFF);
+           lcd.locate(0,0);
+            // lcd.printf(buffer);
+            lcd.printf("%d rpm ", (valor/10));
+           
+            
+             break;
+            //default:
+            //lcd.locate(0,1);
+            //lcd.printf("default:%x",can_MsgRx.id);
+            }
+                
+           // pc.printf("id: 0x%x data:", can_MsgRx.id);
+           pc.printf("%x,",can_MsgRx.id);
+            for (char i=0; i<can_MsgRx.len; i++) {
+            if(i==can_MsgRx.len-1){
+                    pc.printf("%x", can_MsgRx.data[i]);
+            }else{
+                        pc.printf("%x,", can_MsgRx.data[i]);
+                      
+            }
+            }
+            pc.printf("\n\r");
+            // mensaje ok, 
+           // led3 = !led3;
+            led3=1;
+            led4=0;
+            
+           
+            
+           
+            
+            
+            
+            
+            
+            
+           
+            
+            
+        
+        }else{
+            if(error==254){
+              // pc.printf("Errores: %x last: %x \n\r",error, can2.rderror()); 
+               error=0;            
+           }
+                   
+             error++;
+            // led4 = !led4;
+             led4=1;
+             led3=0;
+        
+        }
+    }
+   
+}
diff -r 000000000000 -r 2e70b895129c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 29 20:40:07 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da