SPI Arduino端口模拟 主机程序

//Master End
#define CK 8
#define DO 9
#define CS 10
void setup() {
  pinMode(CK,1);   //SCK
  pinMode(DO,1);   //SDO
  pinMode(CS,1);  //CS
  digitalWrite(CK,0);
  digitalWrite(DO,0);
  digitalWrite(CS,1); //0 Selected 
}
 
void loop() {
  // put your main code here, to run repeatedly:
  char dat = 'b';
  unsigned char i = 0;
  digitalWrite(CK,0);
  digitalWrite(CS,0);
  digitalWrite(CK,1);
  for (i = 0; i < 8; i++){
    digitalWrite(CK,0);
    if (dat & 0x80)
      digitalWrite(DO,1);
    else
      digitalWrite(DO,0);
    dat <<= 1;
    delay(1);
    digitalWrite(CK,1);
    delay(1);
  }
  digitalWrite(CS,1);
  delay(1000);
}