我一直在努力编写一个非常简单的 Arduino 程序,它将地址引脚增加到 EPROM,然后通过其他引脚读取数据。当我无法做像增加一个布尔值数组这样简单的事情时(两个值的 MSB 也几乎总是停留在 1),我的假设是我的代码必须搞砸了,但随后它开始发送两次应该有很多字符(Serial.println(char);
) 发送字符串时没有发生。然后更糟糕的事情开始发生,例如在编译期间没有发现错误时设备完全没有响应。所以我需要知道的是,我的代码是坏了还是我的 Arduino 坏了?我已经尝试过所有波特率,这是我得到的一些输出。请注意,我在代码中插入了延迟以减慢速度,但没有任何改变。我不得不截屏,因为字符不会粘贴到片段中。
这是我的半生不熟的代码,你会注意到它充满了一次发送单个字符的循环(因为这避免了一些疯狂的行为)。
/**
* EEPROM Reader/Dumper for EPROMS or EEPROMS.
*
* @version 1.0.0.0
* @author Bit Fracture
* @date 2015.05.23
*/
//Defining the address lines (four additional pins are manual)
int a_pins[10] = {2,3,4,5,6,7,8,9,10,11};
//Defining the 8-bit data pins
int d_pins[8] = {12,13,14,15,16,17,18,19};
//Store our current address (start at binary 0)
boolean address[10] = {0,0,0,0,0,0,0,0,0,0};
//Store our serial output data (start at binary 0)
boolean data[8] = {0,0,0,0,0,0,0,0};
void setup()
{
//Start communication with the computer
Serial.begin(115200);
delay(100);
//Set address pins to output
for (int i=0; i < sizeof(a_pins); i += 1)
{
pinMode(a_pins[i], OUTPUT);
//Tell Serial this pin's status
Serial.println("PO: " + (a_pins[i]));
delay(100);
}
//Set data pins as input
for (int i=0; i < sizeof(d_pins); i += 1)
{
pinMode(d_pins[i], INPUT);
//Tell Serial this pin's status
Serial.println("PI: " + (d_pins[i]));
delay(100);
}
//Warn start
Serial.println("BEGINNING TRANSMISSION");
}
void loop()
{
//Calculate new binary address
boolean carry = 1; //Start with a carry to initiate increment process
for (int i=0; i < sizeof(address); i += 1)
{
boolean _temp = ((address[i] || carry) && (!address[i] || !carry));
carry = (address[i] && carry);
address[i] = _temp;
}
//Set output pins to new values
for (int i=0; i < sizeof(a_pins); i += 1)
{
digitalWrite(a_pins[i], address[i]);
}
//Allow for the changes to propagate through the EPROM circuitry
delay(250);
//Read the inputs
for (int i=0; i < sizeof(d_pins); i += 1)
{
data[i] = digitalRead(d_pins[i]);
}
//Output the address
for (int i = sizeof(address); i > 0; i--)
{
if (address[i] == 1)
Serial.print("1");
else
Serial.print("0");
}
Serial.print(": ");
//Output the value
for (int j = sizeof(data); j > 0; j--)
{
if (data[j] == 1)
Serial.print("1");
else
Serial.print("0");
}
Serial.println();
//Keep things from going too fast for now
delay(1000);
}
简而言之:我需要了解为什么一开始的串行数据看起来像是在竞速进入程序内存而不是发送它应该发送的字符串,以及为什么我似乎不能做像增加二进制数这样简单的事情并以串行方式输出!
感谢大家