本帖最后由 neutronlmk 于 2019-8-21 20:17 编辑
常量做参数
- void FT25Hxx_EraseSector(const uint32_t fu32_Address)
- {
- FT25Hxx_WriteEnable(); //FT25Hxx写使能
- FT25Hxx_CS = 0; //使能器件
- SPI_WriteReadData(0x20);
- SPI_WriteReadData((uint8_t)(fu32_Address>>16)); //发送地址
- SPI_WriteReadData((uint8_t)(fu32_Address>>8));
- SPI_WriteReadData((uint8_t)(fu32_Address));
- FT25Hxx_CS = 1; //取消片选
- FT25Hxx_WaitBusy(); //等待写入结束
- }
复制代码变量做参数:
- void FT25Hxx_EraseSector(uint32_t fu32_Address)
- {
- FT25Hxx_WriteEnable(); //FT25Hxx写使能
- FT25Hxx_CS = 0; //使能器件
- SPI_WriteReadData(0x20);
- SPI_WriteReadData((uint8_t)(fu32_Address>>16)); //发送地址
- SPI_WriteReadData((uint8_t)(fu32_Address>>8));
- SPI_WriteReadData((uint8_t)(fu32_Address));
- FT25Hxx_CS = 1; //取消片选
- FT25Hxx_WaitBusy(); //等待写入结束
- }
复制代码编译输出大小不变,使用的ram也不变。
这该如何决择?
增加一个:
- void FT25Hxx_ReadRDID(uint8_t *fu8p_SaveArr)
- {
- uint8_t u8_i;
-
- FT25Hxx_CS = 0; //使能器件
- SPI_WriteReadData(0x9F); //发送读取RDID命令
- SPI_WriteReadData(0x00); //发送24bit地址
- SPI_WriteReadData(0x00);
- SPI_WriteReadData(0x00);
- for(u8_i=0;u8_i<3;u8_i++)
- {
- fu8p_SaveArr[u8_i]=SPI_WriteReadData(0xFF); //循环读数
- }
- FT25Hxx_CS = 1; //取消片选
- }
复制代码
fu8p_SaveArr是否有必要声明为 uint8_t *const fu8p_SaveArr ?
我试过编译OK。
以lz位代码为例,如果函数代码中不小心修改了fu32_Address的值,前者会在编译时立刻报错发现,后者则会在运行时得到错误的结果(擦除错误的扇区、而且也许不会立即被发现)。
感谢感谢
一周热门 更多>