/************************************************************* * @fn I2c_Ack * * @brief This func for ACK * after send 8byte,need set SDA high,wait the slaver pulldown the SDA * * @param none * * @return bool */ bool I2c_Ack( void ) { #if 0 uint8 Ack; P0DIR &= ~BV(0); // Make i2c data wire to be input while(I2C_DAT) { // Waiting for acknowledge low } MicroWait(I2C_DELAY_TIME); I2C_CLK = 1; MicroWait(I2C_DELAY_TIME); I2C_CLK = 0; Ack = FALSE; P0DIR |= BV(0); // Restore i2c data wire direction return Ack; #else unsigned char Ack; P0DIR &= ~BV(0); // while(I2C_DAT) { // HAL_TURN_OFF_LED1(); } // HAL_TURN_ON_LED1(); delay_us(1); I2C_CLK = 1; delay_us(2); I2C_CLK = 0; Ack = 0; P0DIR |= BV(0); return Ack; #endif }
//ms 延时 void Delay_ms(uint16 Time)//n ms延时 { while(Time--) { MicroWait(1000); } }
/************************************************************* * @fn I2c_Stop * * @brief This func for stop * when SCL is '1' and SDA from '0' to '1' * * @param none * * @return none */ void I2c_Stop( void )//when SCL is'1' and SDA from '0'to '1' { #if 0 I2C_CLK = 1; I2C_DAT = 0; MicroWait(I2C_DELAY_TIME); I2C_CLK = 1; MicroWait(I2C_DELAY_TIME); I2C_DAT = 1; #else I2C_CLK = 1; delay_us(2); I2C_DAT = 0; delay_us(2); // I2C_CLK = 1; I2C_DAT = 1; #endif }
/************************************************************* * @fn I2c_Start * * @brief This func for start * when SCL is '1' and SDA from '1' to '0' * * @param none * * @return none */ void I2c_Start( void ) { #if 0 I2C_CLK = 1; // MicroWait(I2C_DELAY_TIME); I2C_DAT = 1; MicroWait(I2C_DELAY_TIME); I2C_DAT = 0; MicroWait(I2C_DELAY_TIME); I2C_CLK = 0; #else delay_us(2); I2C_CLK = 1; // delay_us(2); I2C_DAT = 1; delay_us(2); I2C_DAT = 0; delay_us(2); I2C_CLK = 0; #endif }
void sleep(void) { if (HAL_STATE_LED2()) { HAL_TURN_OFF_LED1(); HAL_TURN_OFF_LED3(); HAL_TURN_ON_LED2(); for(uint8 n=0;n<30;n++) for(uint8 i=0;i<200;i++) MicroWait(50000); HAL_TURN_OFF_LED2(); //sbBinded = 0; } }
/************************************************************************************************** * @fn zapSBL_ResetZNP * * @brief This function resets the ZNP and forces it into its SBL. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ static void zapSBL_ResetZNP(void) { HAL_ZNP_MRDY_CLR(); do { HAL_ZNP_RST(); MicroWait(100); HAL_ZNP_RUN(); HalBoardDelay(ZAP_SBL_DLY_WAIT, FALSE); while (!HAL_ZNP_SRDY_SET() && HalBoardDelayed()) { HAL_BOARD_WAIT_MODE(); } } while (!HAL_ZNP_SRDY_SET()); zapSBL_Buf[0] = SB_FORCE_BOOT; HAL_ZNP_MRDY_SET(); // MRDY must be set before talking to the slave. HalSpiWrite(zapAppPort, zapSBL_Buf, 1); HAL_ZNP_MRDY_CLR(); }
void Delay_10us(void) //10 us延时 { MicroWait(10); }
//延时函数 void Delay_us(void) //1 us延时 { MicroWait(1); }