LPC824専用プログラム

Dependencies:   Ping SDFileSystem mbed-src

Revision:
8:a2eadba03040
Parent:
7:9b1ac6fbf32c
Child:
9:7f98d4415425
diff -r 9b1ac6fbf32c -r a2eadba03040 format.cpp
--- a/format.cpp	Fri Jan 15 15:30:57 2016 +0000
+++ b/format.cpp	Sun Jan 24 09:09:49 2016 +0000
@@ -74,38 +74,102 @@
 #endif /*SD_CARD*/
 
 #ifdef ULTRA_SONIC
+
+//InterruptIn vol(P0_15);
+void fx(void){
+    uint8_t packet, val, order;
+    uint8_t front_dis=0, rear_dis=0;
+    front_dis = 200;
+    rear_dis = 150;
+    val = nucleo.receive();
+    if(val==1){
+        order = nucleo.read();
+        if(order == 0xAB){
+            packet = 0xAA;nucleo.reply(0xAA);
+        }
+        else{
+            packet = 0x55;nucleo.reply(0x55);
+        }
+        pc.printf("SSSSSSSSSSSSSSSSS%d\r\n", order);
+    }
+    else{
+        pc.printf("FFFF%d\r\n", 0);
+    }
+}
+void fx2(void){
+    uint16_t packet, val, order;
+    uint16_t front_dis=0, rear_dis=0;
+    front_dis = 200;
+    rear_dis = 150;
+    val = nucleo.receive();
+    if(val==1){
+        order = nucleo.read();
+        if(order == 0xABCD){
+            packet = 0xAAAA;nucleo.reply(0xAAAA);
+        }
+        else{
+            packet = 0x5555;nucleo.reply(0x5555);
+        }
+        nucleo.reply(0x5555);
+        pc.printf("SSSSSSSSSSSSSSSSS%d\r\n", order);
+    }
+    else{
+        pc.printf("FFFF%d\r\n", 0);
+    }
+}
 void Usw_System(void){
-    uint8_t packet, val, order;
+    int packet, val, order;
     uint16_t front_dis=0, rear_dis=0;
     
+    nucleo.format(8, 3);
+    nucleo.frequency(1000000);
+    nucleo.reply(0x00);
+    /*
+    nucleo.format(16, 3);
+    nucleo.frequency(1000000);
+    nucleo.reply(0x0000);
+    */
+    vol.fall(&fx);
+    //vol.fall(&fx2);
+    
+    led[0]=led[1]=1;
     while(1){
+        /*
         front.Send();
         wait_ms(30);
         front_dis = front.Read_cm();
+        if(front_dis>0xFF) front_dis=0xFF;
         
         rear.Send();
         wait_ms(30);
         rear_dis = rear.Read_cm();
+        if(rear_dis>0xFF) rear_dis=0xFF;
+        */
         
-        while(1){
+        
+        front_dis = 200;
+        rear_dis = 150;
+        
+        //pc.printf("%d\t%d\t\r\n", front_dis, rear_dis);
+        //pc.printf("%d\r\n", vol.read());
+        //fx();
+        //fx2();
+        while(0){
             val = nucleo.receive();
-            if(val){
+            if(val==1){
                 order = nucleo.read();
-                switch(order){
-                    case 0x01:
-                        packet = (front_dis&0x00FF);break;
-                    case 0x02:
-                        packet = (front_dis&0xFF00)>>8;break;
-                    case 0x03:
-                        packet = (rear_dis&0x00FF);break;
-                    case 0x04:
-                        packet = (rear_dis&0xFF00)>>8;break;
-                    default:
-                        packet = 0x00;break;
+                if(order == 0xAB){
+                    packet = 0xAA;nucleo.reply(packet);
                 }
-                nucleo.reply(packet);
+                else{
+                    packet = 0x55;nucleo.reply(packet);
+                }
+                
+                pc.printf("SSSSSSSSSSSSSSSSS%d\r\n", order);
+                break;
             }
             else{
+                pc.printf("FFFF%d\r\n", 0);
                 break;
             }
         }
@@ -143,7 +207,15 @@
     uint8_t ch_num[3]={8, 8, 4};
     uint16_t ir_data[IC_NUM][IR_NUM]={0};
     
-    //nucleo.reply(0x00);
+    int order,packet,val;
+    //nucleo...chipselect will be defined interruptpin.
+    //nucleo...will be high clock and 16bit
+    //nucleo.format(16, 0);
+    //nucleo.frequency(5000000);
+    nucleo.format(8, 0);
+    nucleo.frequency(1000000);
+    nucleo.reply(0x00);
+    
     ir.format(8, 3);
     ir.frequency(1000000);
     int mod=1;
@@ -167,6 +239,31 @@
                ir_data[i][j] = read_input(i, j);
             }
         }
+        while(0){
+            val = nucleo.receive();
+            if(val==1){
+                //order = nucleo.read();
+                order = nucleo.read();
+                //if(order != 0xAA) break;
+                //packet = ir_data[order/10][order%10] & 0x00FF;
+                //nucleo.reply(packet);
+                packet = (ir_data[1][0] & 0x0FF0)>>4;nucleo.reply(packet);
+                /*packet = (ir_data[1][1] & 0xFF00)>>8;nucleo.reply(packet);
+                packet = (ir_data[1][2] & 0xFF00)>>8;nucleo.reply(packet);
+                packet = (ir_data[1][3] & 0xFF00)>>8;nucleo.reply(packet);
+                packet = (ir_data[1][4] & 0xFF00)>>8;nucleo.reply(packet);
+                packet = (ir_data[1][5] & 0xFF00)>>8;nucleo.reply(packet);
+                packet = (ir_data[1][6] & 0xFF00)>>8;nucleo.reply(packet);
+                packet = (ir_data[1][7] & 0xFF00)>>8;nucleo.reply(packet);wait_us(1);*/
+                
+                pc.printf("SSSSSSSSSSSSSSSSS\r\n");
+                break;
+            }
+            else{
+                pc.printf("FFFFF\r\n");
+                break;
+            }
+        }
         pc.printf("%Value is ");
         pc.printf("%d\t", ir_data[1][0]);
         pc.printf("%d\t", ir_data[1][1]);
@@ -191,27 +288,11 @@
     int high_byte = ir.write(command_low) & 0x0F;
     int low_byte = ir.write(0);
     
+    
+    wait_us(1);
     cs[ic] = 1;
-    wait_us(1);
     
     return (high_byte << 8) | low_byte;//0x0000...0xFFFF
-    /*int  static mac=0;
-    int  static mast[10][10] = 
-    {
-        {1,2,3,4,5,6,7,8,9,10},
-        {2,4,6,8,10,12,14,16,18,20},
-        {3,6,9,12,15,18,21,24,27,30},
-        {4,8,12,16,20,24,28,32,36,40},
-        {5,10,15,20,25,30,35,40,45,50},
-        {6,12,18,24,30,36,42,48,54,60},
-        {7,14,21,28,35,42,49,56,63,70},
-        {8,16,24,32,40,48,56,64,72,80},
-        {9,18,27,36,45,54,63,72,81,90},
-        {10,20,30,40,50,60,70,80,90,100},
-    };
-    if(channel==0) mac++;
-    mac = mac%10;
-    return mast[mac][channel];*/
 }
 #endif /*IR_SENSOR*/