www.cavefischer.at/Sharp Pocket Computer


Drucken am SHARP Thermodrucker CE-126P mit Arduino UNO


Dieses Arduino Programm druckt mit einem Arduino UNO am Sharp Thermodrucker CE-126P.

Variante 1: Daten Transfer Methode PC-12xx

 


// Print to Sharp CE-126P
// Data transfer Methode PC-12xx, Device Select ueber SEL2

const int OUT_SEL2 = 3; // Pin D3, SEL2, pin 10 CE-126P
const int IN_ACK   = 4; // Pin D4, ACK,  pin  9 CE-126P
const int OUT_Dout = 8; // Pin D8, Dout, pin  5 CE-126P
const int OUT_Busy = 9; // Pin D9, Busy, pin  4 CE-126P
const int InfoLED = 13;
boolean ACK;
int DataBit;
long Timeout;
int i;
byte Printline[24] = {byte('H'),  //  1
                      byte('E'),  //  2
                      byte('L'),  //  3
                      byte('L'),  //  4
                      byte('O'),  //  5
                      byte(' '),  //  6
                      byte('W'),  //  7
                      byte('O'),  //  8
                      byte('R'),  //  9
                      byte('L'),  // 10
                      byte('D'),  // 11
                      byte(' '),  // 12
                      byte(' '),  // 13
                      byte(' '),  // 14
                      byte(' '),  // 15
                      byte(' '),  // 16
                      byte(' '),  // 17
                      byte(' '),  // 18
                      byte(' '),  // 19
                      byte(' '),  // 20
                      byte(' '),  // 21
                      byte(' '),  // 22
                      byte(' '),  // 23
                      byte(' ')}; // 24

void setup() {
  pinMode(IN_ACK, INPUT);
  pinMode(OUT_Dout, OUTPUT);
  pinMode(OUT_Busy, OUTPUT);
  pinMode(OUT_SEL2, OUTPUT);
  pinMode(InfoLED, OUTPUT);

  digitalWrite(InfoLED, HIGH);
  digitalWrite(OUT_SEL2, HIGH);
  delayMicroseconds(1000);

  for(int y=0; y<24; y++){
    printByte(Printline[y]);
  }
  printByte(13);

  delayMicroseconds(1000);
  digitalWrite(OUT_SEL2, LOW);
  digitalWrite(InfoLED, LOW);
} // End setup

void loop() {
} // End loop

void printByte(int aDataByte) {
  i = 0;
  do {
    DataBit = aDataByte & (1 << i);
    digitalWrite(OUT_Dout, DataBit);
    digitalWrite(OUT_Busy, HIGH);
    Timeout = millis();
    do {
      ACK = digitalRead(IN_ACK);
      if (millis() - Timeout > 50) break;
    } while (!ACK);
    delayMicroseconds(500);
    digitalWrite(OUT_Busy, LOW);
    Timeout = millis();
    do {
      ACK = digitalRead(IN_ACK);
      if (millis() - Timeout > 50) break;
    } while (ACK);
    delayMicroseconds(500);
    i++;
  } while (i < 8);
} // End printByte


Pinbelegung (Transfer Methode PC-12xx)
Arduino UNO Pin Name Sharp CE-126P
11-pol. Stecker
GND GND Pin 3
D9 (Output) Busy Pin 4
D8 (Output) Dout Pin 5
D4 (Input) ACK Pin 9
D3 (Output) SEL2 Pin 10




Variante 2: Daten Transfer Methode PC-14xx



// Print to Sharp CE-126P
// Data transfer Methode PC-14xx, Device Select ueber Dout (Kennung 32) bei Xout=HIGH
// Achtung: Ascii 79 und Ascii 48 sind anders belegt. 

const int OUT_Xout = 3; // Pin D3, Xout, pin 7 CE-126P
const int IN_ACK   = 4; // Pin D4, ACK,  pin 9 CE-126P mit pull-down Widerstand!
const int OUT_Dout = 8; // Pin D8, Dout, pin 5 CE-126P
const int OUT_Busy = 9; // Pin D9, Busy, pin 4 CE-126P
const int InfoLED = 13;

void setup() {
  pinMode(IN_ACK, INPUT);
  pinMode(OUT_Dout, OUTPUT);
  pinMode(OUT_Busy, OUTPUT);
  pinMode(OUT_Xout, OUTPUT);
  pinMode(InfoLED, OUTPUT);
  
  printZeile("Print to CE-126P");
  printZeile("HALLO SHARP-PC Welt 0123"); // max. 24 Zeichen

} // Ende setup

void loop() {
} // Ende loop

void selectPrinter() {
  delay(100);
  digitalWrite(OUT_Xout, HIGH);
  printByte(32, true);
  digitalWrite(OUT_Xout, LOW);
  delay(2);
} // Ende selectPrinter

void printZeile(char x[]) {
  digitalWrite(InfoLED, HIGH);
  int i = 0;
  selectPrinter();
  do {
    if (x[i] == 48) x[i] = 240; // Null 0 zuordnen -> 240
    if (x[i] == 79) x[i] = 48; // Grosses O zuordnen -> 48
    printByte(x[i], false);
    i++;
  } while ((x[i] != 0) && (i < 24));
  for (int y=0; y<(24-i); i++) { // wenn noetig, Zeile mit Leerzeichen auffuellen 
    printByte(32, false);
  }
  printByte(13, false);
  delay(1500);
  digitalWrite(InfoLED, LOW);
} // Ende printZeile

void printByte(byte aDataByte, boolean deviceSelect) {
  byte i = 0;
  do {
    boolean DataBit = aDataByte & (1 << i);
    digitalWrite(OUT_Dout, DataBit);
    if (deviceSelect) {
      waitforACK(HIGH);
      digitalWrite(OUT_Busy, HIGH);
      waitforACK(LOW);
      digitalWrite(OUT_Busy, LOW);
    }
    else {
      digitalWrite(OUT_Busy, HIGH);
      waitforACK(HIGH);
      digitalWrite(OUT_Busy, LOW);
      waitforACK(LOW);
    }
    delayMicroseconds(100);
    i++;
  } while (i < 8);
  delay(2);
} // Ende printByte

void waitforACK (boolean state) {
  boolean ACK;
  long Timeout = millis();
  do {    
    ACK = digitalRead(IN_ACK);
    if (millis() - Timeout > 500) break;
  } while ((ACK != state));
  delayMicroseconds(100);
} // Ende waitforACK


Pinbelegung (Transfer Methode PC-14xx)
Arduino UNO Pin Name Sharp CE-126P
11-pol. Stecker
GND GND Pin 3
D9 (Output) Busy Pin 4
D8 (Output) Dout Pin 5
D4 (Input, mit 470k pull-down Widerstand) ACK Pin 9
D3 (Output) Xout Pin 7



zum Seitenanfang

© 2018-2022: Walter Fischer