Apple-1-Mini/code/AVR/SerialTest/SerialTest.ino

83 lines
1.4 KiB
Arduino
Raw Normal View History

#define DA A0
#define RDA A1
#define PB0 2
2017-07-15 15:41:20 +00:00
#define PB1 3
#define PB2 4
#define PB3 A5
#define PB4 A4
#define PB5 A3
#define PB6 A2
2017-07-15 15:41:20 +00:00
uint8_t video_data = 0;
uint8_t video_data_pins[] = { PB0, PB1, PB2, PB3, PB4, PB5, PB6 };
uint8_t serial_data;
void setup()
{
pinMode(DA, INPUT);
pinMode(RDA, OUTPUT);
pinMode(PB0, INPUT);
pinMode(PB1, INPUT);
pinMode(PB2, INPUT);
pinMode(PB3, INPUT);
pinMode(PB4, INPUT);
pinMode(PB5, INPUT);
pinMode(PB6, INPUT);
Serial.begin(9600);
2017-07-15 15:41:20 +00:00
Serial.println("Arduino ready...");
}
void loop()
2017-07-15 15:41:20 +00:00
{
process_video_data();
process_serial_data();
}
void process_video_data()
{
digitalWrite(RDA, HIGH); // Tell PIA we are ready to receive data
2017-07-15 15:41:20 +00:00
delayMicroseconds(20);
if (digitalRead(DA)) // Is there any data?
{
2017-07-15 15:41:20 +00:00
video_data = 0;
2017-07-15 15:41:20 +00:00
for (int i = 0; i < 7; i++) // Yes, get byte data
{
if (digitalRead(video_data_pins[i]))
{
2017-07-15 15:41:20 +00:00
video_data |= (1 << i);
}
}
2017-07-15 15:41:20 +00:00
if (video_data == 13)
{
2017-07-15 15:41:20 +00:00
Serial.println();
}
else if (video_data > 31)
{
Serial.print((char)video_data);
}
digitalWrite(RDA, LOW);
2017-07-15 15:41:20 +00:00
delayMicroseconds(20);
}
}
void process_serial_data()
{
if (Serial.available() > 0)
{
serial_data = Serial.read();
if (serial_data == 13)
{
Serial.println();
}
else
{
Serial.print((char)serial_data);
}
}
}