LPC824専用プログラム

Dependencies:   Ping SDFileSystem mbed-src

Revision:
7:9b1ac6fbf32c
Parent:
6:79dc74e4926a
Child:
8:a2eadba03040
--- a/format.cpp	Tue Jan 12 14:59:09 2016 +0000
+++ b/format.cpp	Fri Jan 15 15:30:57 2016 +0000
@@ -137,110 +137,81 @@
 #endif /*COLOR_SENSOR*/
 
 #ifdef IR_SENSOR
-void Ir_System2(void){
-    
-    static uint8_t const START_BIT      = 0x04;
-    static uint8_t const MODE_SINGLE    = 0x02;    // Single-ended mode
-    //static uint8_t const MODE_DIFF      = 0x00;    // Differential mode
-    
+void Ir_System(void){
     int i;//ic
     int j;//ch
     uint8_t ch_num[3]={8, 8, 4};
-    int command_high;
-    int command_low;
-    int high_byte;
-    int low_byte;
+    uint16_t ir_data[IC_NUM][IR_NUM]={0};
     
-    uint16_t ir_data[3][8]={0};
-    //clock_t stime,etime;
-    
-    supply = 1;
+    //nucleo.reply(0x00);
+    ir.format(8, 3);
     ir.frequency(1000000);
+    int mod=1;
     
     for(i=0; i<IC_NUM; i++) cs[i]=1;
     while(1) {
-        //stime = clock();
+        /*cs[1]=1;
+        
+        mod = ir.write(mod);
+        //ir.write(0)&0xFF;
+        
+        cs[1]=0;
+        wait_us(1);
+        
+        pc.printf("%Value is ");
+        pc.printf("%d\t", mod);
+        pc.printf("\r\n");
+        */
         for(i=0; i<IC_NUM; i++){//IC
             for(j=0; j<ch_num[i]; j++){//Ch
-                command_high = START_BIT | MODE_SINGLE | ((j & 0x04) >> 2);
-                command_low = (j & 0x03) << 6;
-                
-                cs[i] = 0;
-                
-                ir.write(command_high);
-                high_byte = ir.write(command_low) & 0x0F;
-                low_byte = ir.write(0);
-                
-                cs[i] = 1;
-                wait_us(1);
-                
-                ir_data[i][j] = (high_byte << 8) | low_byte;
+               ir_data[i][j] = read_input(i, j);
             }
         }
-        //etime = clock();
-        //pc.printf("%.4f\n", (float)(etime-stime)/CLOCKS_PER_SEC);
         pc.printf("%Value is ");
+        pc.printf("%d\t", ir_data[1][0]);
+        pc.printf("%d\t", ir_data[1][1]);
         pc.printf("%d\t", ir_data[1][2]);
+        pc.printf("%d\t", ir_data[1][3]);
         pc.printf("%d\t", ir_data[1][4]);
-        pc.printf("%d\t", ir_data[0][0]);
-        pc.printf("%d\t", ir_data[0][4]);
+        pc.printf("%d\t", ir_data[1][5]);
+        pc.printf("%d\t", ir_data[1][6]);
+        pc.printf("%d\t", ir_data[1][7]);
         pc.printf("\r\n");
     }
 }
-void Ir_System(void){
+int read_input(int ic, int channel)
+{
     
-    static uint8_t const START_BIT      = 0x04;
-    static uint8_t const MODE_SINGLE    = 0x02;    // Single-ended mode
-    //static uint8_t const MODE_DIFF      = 0x00;    // Differential mode
-    
-    static uint8_t const IR_NUM[IC_NUM] = {8, 8, 4};
+    int command_high = START_BIT | MODE_SINGLE | ((channel & 0x04) >> 2);
+    int command_low = (channel & 0x03) << 6;
     
-    uint8_t ic, ch;
-    unsigned int command_high, command_low;
-    unsigned int high_byte, low_byte;
+    cs[ic] = 0;
     
-    //uint8_t i;
-    //uint8_t packet, val, order;
+    ir.write(command_high);
+    int high_byte = ir.write(command_low) & 0x0F;
+    int low_byte = ir.write(0);
     
-    uint16_t ir_data[IC_NUM][CH_NUM];
-    
-    supply = 1;
-    ir.frequency(1000000);
+    cs[ic] = 1;
+    wait_us(1);
     
-    for(ic=0; ic<IC_NUM; ic++) cs[ic]=1;
-    while(1) {
-        for(ic=0; ic<IC_NUM; ic++){//IC
-            for(ch=0; ch<IR_NUM[ic]; ch++){//Ch
-                command_high = START_BIT | MODE_SINGLE | ((ch & 0x04) >> 2);
-                command_low = (ch & 0x03) << 6;
-
-                cs[ic] = 0;
-
-                ir.write(command_high);
-                high_byte = ir.write(command_low) & 0x0F;
-                low_byte = ir.write(0);
-
-                cs[ic] = 1;
-                wait_us(1);
-                ir_data[ic][ch] = ((high_byte << 4) | (low_byte >> 4))&0xFF;
-
-            }
-        }
-        pc.printf("%d\t%d\t%d\t%d\t\r\n", ir_data[1][0], ir_data[1][1], ir_data[1][2], ir_data[1][3]);
-        /*while(1){
-            val = nucleo.receive();
-            if(val){
-                order = nucleo.read();
-                packet = ir_data[order/10][order%10] & 0x00FF;
-                nucleo.reply(packet);
-                wait_us(1);
-            }
-            else{
-                break;
-            }
-        }*/
-        
-    }
+    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*/