LPC824専用プログラム
Dependencies: Ping SDFileSystem mbed-src
Diff: format.cpp
- Revision:
- 10:641da47d4a14
- Parent:
- 9:7f98d4415425
- Child:
- 11:a5023f22f25a
diff -r 7f98d4415425 -r 641da47d4a14 format.cpp --- a/format.cpp Sun Jan 24 15:16:26 2016 +0000 +++ b/format.cpp Sun Jan 24 17:23:15 2016 +0000 @@ -154,16 +154,13 @@ #endif /*COLOR_SENSOR*/ #ifdef IR_SENSOR + uint8_t ir_notice=0;//4bit -uint8_t ir_key=0;//4bit +static uint8_t const ir_key=0xA;//4bit uint8_t ir_position[2]={0};//4bit*2 -uint8_t i;//ic -uint8_t j;//ch -uint8_t ch_num[3]={8, 8, 4}; -uint16_t ir_data[IC_NUM][IR_NUM]={0}; -uint16_t order,packet,val; void emergency(void){ + uint16_t order,packet,val; //ir_key=0xA; //ir_notice=0xC; //ir_position[1]=0xE; @@ -185,6 +182,16 @@ } } void Ir_System(void){ + + uint8_t i;//ic + uint8_t j;//ch + uint8_t num_long, num_short; + uint16_t ir_val, ir_val_long[8], ir_val_short[12]; + uint8_t ir_posi, ir_posi_long[8], ir_posi_short[12]; + static uint8_t const ch_num[3]={8, 8, 4}; + + uint16_t ir_data[IC_NUM][IR_NUM]={0}; + nucleo.format(16, 3); nucleo.frequency(1000000); nucleo.reply(0x0000); @@ -192,15 +199,43 @@ ir.format(8, 3); ir.frequency(1000000); - call.fall(&emergency); + supply.period(0.010);//T=10[ms] + supply.write(0.9);//L...10%,H...90% + + //call.fall(&emergency); for(i=0; i<IC_NUM; i++) cs[i]=1; while(1) { + + num_short=0; + num_long=0; for(i=0; i<IC_NUM; i++){//IC for(j=0; j<ch_num[i]; j++){//Ch - ir_data[i][j] = read_input(i, j); + ir_data[i][j] = read_input(i, j); + /* + ir_val = read_input(i, j); + ir_posi = read_position(i, j); + + if(i==0){ + ir_val_long[num_long] = ir_val; + ir_posi_long[num_long] = ir_posi; + num_long++; + } + else{ + ir_val_short[num_short] = ir_val; + ir_posi_short[num_short] = ir_posi; + num_short++; + }*/ } } + + //BubbleSort(ir_val_short, ir_posi_short, 12); + //BubbleSort(ir_val_long, ir_posi_long, 8); + + ir_position[0] = ir_posi_short[0]; + ir_position[1] = ir_posi_long[0]; + ir_notice=0; + pc.printf("%Value is "); pc.printf("%d\t", ir_data[1][0]); pc.printf("%d\t", ir_data[1][1]); @@ -214,45 +249,56 @@ //emergency(); } } -int read_input(int ic, int channel) +uint16_t read_input(uint8_t ic, uint8_t channel) { - - int command_high = START_BIT | MODE_SINGLE | ((channel & 0x04) >> 2); - int command_low = (channel & 0x03) << 6; + uint16_t command_high = START_BIT | MODE_SINGLE | ((channel & 0x04) >> 2); + uint16_t command_low = (channel & 0x03) << 6; cs[ic] = 0; ir.write(command_high); - int high_byte = ir.write(command_low) & 0x0F; - int low_byte = ir.write(0); - + uint16_t high_byte = ir.write(command_low) & 0x0F; + uint16_t low_byte = ir.write(0); wait_us(1); cs[ic] = 1; return (high_byte << 8) | low_byte;//0x0000...0xFFFF } -void BubbleSort(uint16_t *data, uint8_t n) +uint8_t read_position(uint8_t ic, uint8_t channel){ + //DigitalOut cs[IC_NUM] = {cs1, cs2, cs3}; + static uint8_t const ir_location[3][8]= + {//0,1,2...7(ch) + {1, 2, 3, 4, 5, 6, 7, 8},//cs1,Long*8 + {1, 2, 3, 4, 5, 6, 7, 8},//cs2,Short*8 + {9, 10, 11, 12},//cs3,Short*4 + }; + return ir_location[ic][channel]; +} +void BubbleSort(uint16_t *data, uint8_t *data2, uint8_t n)//昇順にする { bool flag; - uint8_t i;//inclement - uint16_t temp;//temporary + uint8_t i, j;//inclement + uint16_t temp;//temporary for value + uint8_t temp2;//temporary for position + j=0; do{ + j++; flag=0; - for (i=0; i<n-1; i++) { - if (data[i]>data[i+1]) { - /* 左右の並びがおかしければ入れ替える */ + for (i=0; i<n-j; i++) { + if (data[i]<data[i+1]) { + // 左右の並びがおかしければ入れ替える flag=1; temp=data[i]; data[i]=data[i+1]; data[i+1]=temp; + + temp2=data2[i]; + data2[i]=data2[i+1]; + data2[i+1]=temp2; } } - } while (flag==1); /* 入れ替えがある間,繰り返す.*/ + } while (flag==1); //入れ替えがある間,繰り返す. } #endif /*IR_SENSOR*/ - - - -