/*****************************************************************************  加速度センサ関係 ・データ更新完了でデータを吸い上げ手レジスタを更新、CPUに割り込み ・フラグが立っていれば歩数カウント ・加速度センサ割り込みからタスクを登録して下さい。(I2Cの競合回避などがあるので) *****************************************************************************/ #pragma SFR #pragma NOP #pragma HALT #pragma STOP #include "incs.h" // レジスタ名 #define ACC_REG_WHOAMI 0x0F #define ACC_REG_CTRL1 0x20 #define ACC_REG_CTRL5 0x24 #define ACC_REG_X 0x28 // ビット位置 #define ACC_bP_PM0 5 #define ACC_bP_DR0 3 // ビット設定値 #define ACC_BITS_PM_PDN 0 #define ACC_BITS_PM_NORM 1 #define ACC_BITS_PM_LP0R5 2 #define ACC_BITS_PM_LP1 3 #define ACC_BITS_PM_LP2 4 #define ACC_BITS_PM_LP5 5 #define ACC_BITS_PM_LP10 6 #define ACC_BITS_DR_50Hz 0 #define ACC_BITS_DR_100Hz 1 #define ACC_BITS_DR_400Hz 2 #define ACC_BITS_DR_1000Hz 3 #define ACC_BITS_ALL_AXIS_ON 7 //************************************* u8 hosu_mode = 0; /* 0: power down 停止 1: 動作 */ /*****************************************************************************  ・割り込みを確認してデータを吸い上げ、レジスタに書き出します ・本当であればコールバック関数を登録しておけばいいじゃんとなるのですが、 I2Cが使用中だったら?とか考えると私ではそこまでできないのです。 ・自動歩数計とかでも結局 *****************************************************************************/ task_status_immed tsk_cbk_accero(){ // (疑似)isrから登録されます static u8 sequence; u8* dest_adrs; if( system_status.pwr_state == ON ){ // if( 自動歩数計? ) /* sequence += 1; vreg_ctr[VREG_C_ACC_0SEQ + 7 * ( sequence & 0x03 )] = sequence; dest_adrs = &vreg_ctr[VREG_C_ACC_0XH] + 7 * ( sequence & 0x03 ) + 1; iic_mcu_read( IIC_SLA_ACCEL, ( ACC_REG_X | 0x80 ), 6, dest_adrs ); */ iic_mcu_read( IIC_SLA_ACCEL, ( ACC_REG_X | 0x80 ), 6, &vreg_ctr[VREG_C_ACC_XH] ); if(( vreg_ctr[ VREG_C_ACC_CONFIG ] & 0x03 ) == 1 ){ vreg_ctr[ VREG_C_IRQ1 ] |= REG_BIT_ACC_DAT_RDY; IRQ0_ast; } /* switch( system_status.pwr_state ){ case OFF: case ON_TRIG: case ON: case SLEEP_TRIG: case SLEEP: case OFF_TRIG: default: break; } */ } return( ERR_SUCCESS ); } /*=========================================================  加速度センサ透過アクセス リード ========================================================*/ task_status_immed acc_read(){ vreg_ctr[VREG_C_ACC_R_BUF] = iic_mcu_read_a_byte( IIC_SLA_ACCEL, vreg_ctr[VREG_C_ACC_R_ADRS] ); vreg_ctr[ VREG_C_IRQ1 ] |= REG_BIT_ACC_ACK; IRQ0_ast; return( ERR_SUCCESS ); } /*=========================================================  加速度センサ透過アクセス ライト ========================================================*/ task_status_immed acc_write(){ vreg_ctr[VREG_C_ACC_R_BUF] = iic_mcu_write_a_byte( IIC_SLA_ACCEL, vreg_ctr[VREG_C_ACC_W_ADRS], vreg_ctr[VREG_C_ACC_W_BUF] ); vreg_ctr[ VREG_C_IRQ1 ] |= REG_BIT_ACC_ACK; IRQ0_ast; return( ERR_SUCCESS ); } /*****************************************************************************  自動歩数カウントモードにセット todo 他のモードだったら止めたり、復帰させたり 割り込みルーチンなどでカウント判定が必要 *****************************************************************************/ err accero_hosu_start(){ u8 temp; u8 err; u8 str_send_buf[4]; if( system_status.pwr_state == ON ){ temp = iic_mcu_read_a_byte( IIC_SLA_ACCEL, ACC_REG_WHOAMI ); if( iic_mcu_bus_status == ERR_NOSLAVE ){ // vreg_ctr[ VREG_C_ACC_CONFIG_HOSU ] |= 0x01; return( ERR_ERR ); } str_send_buf[0] = ( ACC_BITS_PM_NORM << ACC_bP_PM0 | ACC_BITS_DR_100Hz << ACC_bP_DR0 | ACC_BITS_ALL_AXIS_ON ); // cont1 str_send_buf[1] = 0x00; // 泣ける... str_send_buf[2] = 0x02; str_send_buf[3] = 0x80; err = iic_mcu_write( IIC_SLA_ACCEL, ( ACC_REG_CTRL1 | 0x80 ), 4, str_send_buf ); // str_send_buf[0] = 0x00; // err |= iic_mcu_write( IIC_SLA_ACCEL, ACC_REG_CTRL5, 1, str_send_buf ); return( err ); } } err accero_hosu_stop(){ u8 err; u8 str_send_buf[4]; str_send_buf[0] = ( ACC_BITS_PM_PDN << ACC_bP_PM0 | 0 << ACC_bP_DR0 | ACC_BITS_ALL_AXIS_ON ); str_send_buf[1] = 0x00; // 泣ける... str_send_buf[2] = 0x02; str_send_buf[3] = 0x80; err = iic_mcu_write( IIC_SLA_ACCEL, ( ACC_REG_CTRL1 | 0x80 ) , 4, str_send_buf ); return( err ); }