Last active
August 29, 2015 14:01
-
-
Save EstebanFuentealba/b674b469d72c88ba4536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Link Cable Arduino Desc | |
// 6 GND GND | |
// 5 2 SC | |
// 2 3 SI | |
// 3 4 SO | |
#define delayMs 20 | |
unsigned char DATA_BLOCK[415] = {0x87,0x80,0x82,0x8A,0x84,0x91,0x50,0x00,0x00,0x00,0x00,0x1,0x4A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x4A,0x1,0x2c,0x4a,0x00,0x14,0x08,0x1F,0x7E,0x38,0x09,0x19,0x4,0xd2,0x3,0xd,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0xc0,0xc0,0xc0,0x4a,0x1,0x2c,0x0,0x96,0x0,0x97,0x0,0x98,0x0,0x99,0x4A,0x1,0x2c,0x4a,0x00,0x14,0x08,0x1F,0x7E,0x38,0x09,0x19,0x4,0xd2,0x3,0xd,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0xc0,0xc0,0xc0,0x4a,0x1,0x2c,0x0,0x96,0x0,0x97,0x0,0x98,0x0,0x99,0x4A,0x1,0x2c,0x4a,0x00,0x14,0x08,0x1F,0x7E,0x38,0x09,0x19,0x4,0xd2,0x3,0xd,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0xc0,0xc0,0xc0,0x4a,0x1,0x2c,0x0,0x96,0x0,0x97,0x0,0x98,0x0,0x99,0x4A,0x1,0x2c,0x4a,0x00,0x14,0x08,0x1F,0x7E,0x38,0x09,0x19,0x4,0xd2,0x3,0xd,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0xc0,0xc0,0xc0,0x4a,0x1,0x2c,0x0,0x96,0x0,0x97,0x0,0x98,0x0,0x99,0x4A,0x1,0x2c,0x4a,0x00,0x14,0x08,0x1F,0x7E,0x38,0x09,0x19,0x4,0xd2,0x3,0xd,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0xc0,0xc0,0xc0,0x4a,0x1,0x2c,0x0,0x96,0x0,0x97,0x0,0x98,0x0,0x99,0x4A,0x1,0x2c,0x4a,0x00,0x14,0x08,0x1F,0x7E,0x38,0x09,0x19,0x4,0xd2,0x3,0xd,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0xc0,0xc0,0xc0,0x4a,0x1,0x2c,0x0,0x96,0x0,0x97,0x0,0x98,0x0,0x99,0x81,0x8E,0x81,0x81,0x8E,0x50,0x00,0x00,0x00,0x00,0x00,0x81,0x8E,0x81,0x81,0x8E,0x50,0x00,0x00,0x00,0x00,0x00,0x81,0x8E,0x81,0x81,0x8E,0x50,0x00,0x00,0x00,0x00,0x00,0x81,0x8E,0x81,0x81,0x8E,0x50,0x00,0x00,0x00,0x00,0x00,0x81,0x8E,0x81,0x81,0x8E,0x50,0x00,0x00,0x00,0x00,0x00,0x81,0x8E,0x81,0x81,0x8E,0x50,0x00,0x00,0x00,0x00,0x00,0x80,0xAB,0xA2,0xA7,0xA4,0xAC,0xB8,0x50,0x50,0x50,0x50,0x80,0xAB,0xA2,0xA7,0xA4,0xAC,0xB8,0x50,0x50,0x50,0x50,0x80,0xAB,0xA2,0xA7,0xA4,0xAC,0xB8,0x50,0x50,0x50,0x50,0x80,0xAB,0xA2,0xA7,0xA4,0xAC,0xB8,0x50,0x50,0x50,0x50,0x80,0xAB,0xA2,0xA7,0xA4,0xAC,0xB8,0x50,0x50,0x50,0x50,0x80,0xAB,0xA2,0xA7,0xA4,0xAC,0xB8,0x50,0x50,0x50,0x50}; | |
int volatile CLOCK_PIN = 2; | |
int volatile SO_PIN = 4; | |
int volatile SI_PIN = 3; | |
int volatile data = 0; | |
int volatile counter = 0; | |
int volatile val = 0; | |
unsigned volatile long lastReceive = 0; | |
volatile byte outputBuffer = 0x01; | |
void setup() { | |
pinMode(SI_PIN, INPUT); | |
digitalWrite( SI_PIN, HIGH); | |
pinMode(SO_PIN, OUTPUT); | |
pinMode(CLOCK_PIN, OUTPUT); | |
Serial.begin(9600); | |
attachInterrupt( 0, clock, RISING ); | |
} | |
void clock() | |
{ | |
unsigned long t = 0; | |
byte in; | |
if ( lastReceive > 0 ) | |
{ | |
if ( micros() - lastReceive > 120 ) // too long, must be a new sequence (takes about 120 microsecs for a bit) | |
{ | |
counter = 0; | |
val = 0; | |
in = 0x00; | |
} | |
} | |
data = digitalRead(SI_PIN); | |
if ( data == HIGH ){ | |
val |= ( 1 << (7-counter) ); | |
in |= ( 1 << (7-counter) ); | |
} | |
if ( counter == 7 ) | |
{ | |
Serial.print("<< "); | |
Serial.println( val, DEC ); | |
Serial.println( val, HEX ); | |
val = 0; | |
in = 0x00; | |
counter = -1; | |
} | |
counter++; | |
lastReceive = micros(); | |
} | |
// 8 clock intervals (8bits per packet) | |
void GBSerialOut(uint8_t command) { | |
//uint8_t gbReplyy=0; | |
for (uint8_t clock=0; clock<8; ++clock) { | |
digitalWrite(CLOCK_PIN, 0); // Send clock signal | |
if((command << clock) & 0x80){ | |
digitalWrite(SO_PIN, 1); // Write out to printer | |
} | |
else{ | |
digitalWrite(SO_PIN, 0); | |
} | |
delayMicroseconds(delayMs); // Wait 20-60us | |
digitalWrite(CLOCK_PIN, 1); // End clock | |
} | |
delayMicroseconds(delayMs); // Wait 20-60us | |
} | |
uint8_t cmd; | |
boolean discover = true; | |
void loop() { | |
cmd = Serial.read(); | |
if (cmd == 's') { | |
GBSerialOut(0x01); | |
delay(8000); | |
GBSerialOut(0x60); | |
delay(1000); | |
GBSerialOut(0x7F); | |
delay(1000); | |
GBSerialOut(0xD4); | |
delay(1000); | |
GBSerialOut(0xD0); | |
// INIT SENT DATA | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment