void ks0108WriteData(uint8_t data) {
uint8_t displayData, yOffset, cmdPort;
#ifdef DEBUGGING // Künstliche Verlangsamung der Datenausgabe
volatile uint16_t i; // Kann zur Anpassung verwendet werden, falls Ausgabe
for(i=0; i<50; i++); // keine Harmonie mit Display herstellen kann
#endif
if(ks0108Coord.x >= 128)
return;
if(ks0108Coord.x < 64) {
LCD_CMD_PORT &= ~(0x01 << CSEL2); // deselect chip 2
LCD_CMD_PORT |= 0x01 << CSEL1; // select chip 1
} else if(ks0108Coord.x >= 64) {
LCD_CMD_PORT &= ~(0x01 << CSEL1); // deselect chip 1
LCD_CMD_PORT |= 0x01 << CSEL2; // select chip 2
}
if(ks0108Coord.x == 64) // chip2 X-address = 0
ks0108WriteCommand(LCD_SET_ADD, CHIP2);
LCD_CMD_PORT |= 0x01 << D_I; // D/I = 1
LCD_CMD_PORT &= ~(0x01 << R_W); // R/W = 0
LCD_DATA_DIR = 0xFF; // data port is output
yOffset = ks0108Coord.y%8;
if(yOffset != 0) {
// first page
cmdPort = LCD_CMD_PORT; // save command port
displayData = ks0108ReadData();
LCD_CMD_PORT = cmdPort; // restore command port
LCD_DATA_DIR = 0xFF; // data port is output
displayData |= data << yOffset;
if(ks0108Inverted)
displayData = ~displayData;
LCD_DATA_OUT = displayData; // write data
ks0108Enable(); // enable
// second page
ks0108GotoXY(ks0108Coord.x, ks0108Coord.y+8);
displayData = ks0108ReadData();
LCD_CMD_PORT = cmdPort; // restore command port
LCD_DATA_DIR = 0xFF; // data port is output
displayData |= data >> (8-yOffset);
if(ks0108Inverted)
displayData = ~displayData;
LCD_DATA_OUT = displayData; // write data
ks0108Enable(); // enable
ks0108GotoXY(ks0108Coord.x+1, ks0108Coord.y-8);
} else {
if(ks0108Inverted)
data = ~data;
LCD_DATA_OUT = data; // write data
ks0108Enable(); // enable
ks0108Coord.x++;
}
LCD_DATA_OUT = 0x00;
}