|
发表于 2014-5-5 22:35:55
|
显示全部楼层
如果直接用一个24c02和arduino接好,a0,a1,a2都是接地,那么程序里该怎么写?
这个跳不同,为什么?- #include <MsTimer2.h>
- #include <Wire.h>
- int led = 13;
- byte val;
- int i;
- void Flash()
- {
- digitalWrite(led, !digitalRead(led));
- }
- void setup()
- {
- Serial.begin(9600);
- Serial.println("Ready");
- pinMode(led, OUTPUT);
- MsTimer2::set(500, Flash);
- MsTimer2::start();
- }
- void loop()
- {
- if (Serial.available() > 0)
- {
- switch (Serial.read())
- {
- case 'r': // read
- Serial.println("Reading Data...");
- Wire.beginTransmission(0xA0);
- Serial.println("beginTransmission");
- Wire.write(byte(0x00));
- Serial.println("write");
- Wire.endTransmission();
- Serial.println("endTransmission");
- Wire.requestFrom(0xA1, 4);
- Serial.println("requestFrom");
- while(Wire.available() >= 4)
- {
- Serial.println(Wire.read());
- }
- delay(10);
- break;
- case 'w': // write
- Serial.println("Writing Data...");
- Wire.beginTransmission(0xA0);
- Serial.println("beginTransmission");
- Wire.write(byte(0x00));
- Serial.println("write");
- val = 0x01;
- for (i=0; i<4; i++)
- {
- Wire.write(byte(val++));
- }
- Serial.println("w...");
- Wire.endTransmission();
- Serial.println("Write completed!");
- delay(10);
- break;
- default:
- break;
- }
- }
- }
复制代码 |
|