周五学习了I2C.周六在家弄了一天周四的作业。终于成功,收获颇多。先说一下周四一直不好使的原因:
Exclude from Simulation不能打挑,否则不参加模拟。所以周四一直没有成功。最后上程序。全部自己编写感觉最后4句非常简练。首次编写位操作程序,很成功。SPI tc
#include<SPI.h>
const int slaveSelectPin = 10;
int A ;
int B ;
void setup() {
pinMode (slaveSelectPin, OUTPUT);
SPI.begin();
Serial.begin(9600);
digitalWrite(slaveSelectPin, HIGH);
SPI.transfer(0x80);
SPI.transfer(0x04);
digitalWrite(slaveSelectPin, LOW);
}
void loop() {
digitalWrite(slaveSelectPin, HIGH);
SPI.transfer(0x02);
A = SPI.transfer(0x00);
B = SPI.transfer(0x00);
digitalWrite(slaveSelectPin, LOW);
/*Serial.print((A&0b10000000)>>7);
Serial.print((A&0b01000000)>>6);
Serial.print((A&0b00100000)>>5);
Serial.print((A&0b00010000)>>4);
Serial.print((A&0b00001000)>>3);
Serial.print((A&0b00000100)>>2);
Serial.print((A&0b00000010)>>1);
Serial.println(A&0b00000001);*/
if(((A&0b01000000)>>6)==0)
Serial.println(A*2+B/32*0.25);
if(((A&0b01000000)>>6)==1)
Serial.println(-(((~A)&0b01111111)*2+2-B/32*0.25));
}