keybrd library is an open source library for creating custom-keyboard firmware.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

PortRead_MCP23S17.cpp 719B

1234567891011121314151617181920212223
  1. #include "PortRead_MCP23S17.h"
  2. /*
  3. PortRead_MCP23S17::begin() is not needed because port direction is already configured to input by default.
  4. SPI bus is configured in PortWrite_MCP23S17::begin().
  5. */
  6. /*
  7. returns port value
  8. */
  9. uint8_t PortRead_MCP23S17::read()
  10. {
  11. uint8_t portState; //bit wise
  12. //slower clock
  13. digitalWrite(SS, LOW); //enable Slave Select
  14. SPI.transfer(port.ADDR << 1 | 1); //read command
  15. SPI.transfer(port.num + 0x12); //register address to read data from
  16. portState = SPI.transfer(0); //save the data (0 is dummy data to send)
  17. digitalWrite(SS, HIGH); //disable Slave Select
  18. return portState;
  19. }