Hello, i'm using a T6963C-based display (TLX-711) with a PIC18F4550 and i randomly get some of my text in the wrong position. I'm doing the correct power-on reset, status checking and i've tried using long delays inbetween writing each command but to no avail. I wrote the following code
Code:
#define tlx_WR 0x1
#define tlx_RD 0x2
#define tlx_CD 0x4 //0x8
#define tlx_DATA PORTD
#define tlx_DATAOUT TRISD = 0x00
#define tlx_DATAIN TRISD = 0xFF
#define tlx_FLAGS PORTB
#define tlx_enableFlags TRISB = 0x00
#define tlx_disable PORTA = PORTA | 0x1 // 0x4
#define tlx_enable PORTA = PORTA & 0xFE // 0xFB
unsigned int tempy;
unsigned int tempx;
unsigned char tempz;
#define tlxWait for (tempy=0;tempy<10;tempy++) {};
void tlxWaitUntilFree() {
tlx_DATAIN;
tlx_enableFlags;
do {
tlx_FLAGS = tlx_WR | tlx_CD;
tlx_enable;
tlxWait
tempz = tlx_DATA;
tlx_disable;
tlxWait
} while ((tempz & 0x3) != 0x3);
return;
}
void tlxWriteData(unsigned char inData) {
tlx_DATAOUT;
tlx_enableFlags;
tlx_DATA = inData;
tlx_FLAGS = tlx_RD;
tlx_enable;
tlxWait
tlx_disable;
tlxWait
return;
}
unsigned char tlxReadData() {
tlx_DATAIN;
tlx_enableFlags;
tlx_FLAGS = tlx_WR;
tlx_enable;
tlxWait
tempz = tlx_DATA;
tlx_disable;
tlxWait
return tempz;
}
void tlxWriteCommand(unsigned char inCommand) {
tlx_DATAOUT;
tlx_enableFlags;
tlx_DATA = inCommand;
tlx_FLAGS = tlx_RD | tlx_CD;
tlx_enable;
tlxWait
tlx_disable;
tlxWait
return;
}
void tlxWriteDDC(unsigned char inData1, unsigned char inData2, unsigned char inCommand) {
tlxWaitUntilFree();
tlxWriteData(inData1);
tlxWaitUntilFree();
tlxWriteData(inData2);
tlxWaitUntilFree();
tlxWriteCommand(inCommand);
return;
}
void tlxWriteDC(unsigned char inData1, unsigned char inCommand) {
tlxWaitUntilFree();
tlxWriteData(inData1);
tlxWaitUntilFree();
tlxWriteCommand(inCommand);
return;
}
void tlxWriteC(unsigned char inCommand) {
tlxWaitUntilFree();
tlxWriteCommand(inCommand);
return;
}
#define tlxTextHome(a,b) tlxWriteDDC(a,b,0x40)
#define tlxTextArea(a,b) tlxWriteDDC(a,b,0x41)
#define tlxGraphicsHome(a,b) tlxWriteDDC(a,b,0x42)
#define tlxGraphicsArea(a,b) tlxWriteDDC(a,b,0x43)
#define tlxSetCursor(a,b) tlxWriteDDC(a,b,0x21)
#define tlxSetAddress(a,b) tlxWriteDDC(a,b,0x24)
#define tlxWriteCharInc(a) tlxWriteDC(a,0xC0)
#define tlxOutChar(a) tlxWriteDC(a-0x20,0xC0)
void tlxClearScreen() {
tlxSetAddress(0,0);
for (tempx=0; tempx<320; tempx++) {
tlxWriteCharInc(0x0);
}
}
// Displays a ROM string (uses [size] position(s)) rom const
void tlxWriteString(rom const char *data, char size) {
char i;
for (i=0; i<size; i++) {
tlxWriteCharInc(data[i] - 0x20 );
}
}
void tlxWaitLong() {
OpenTimer2(T2_POST_1_6 & T2_PS_1_16);
WriteTimer2(0x30);
do {
} while (ReadTimer2() >= 0x30);
}
void tlxInit() {
char a;
PORTA = 0xFA;
for (a=0;a<50;a++) {
tlxWaitLong();
}
PORTA = 0xFF;
TRISB = 0; // All pins are output
PORTB = 0;
tlxGraphicsHome(0x40,0x1);
tlxGraphicsArea(0x28,0x0);
tlxTextHome(0,0);
tlxTextArea(0x28,0x0);
tlxWriteC(0x80); // Set Mode (OR)
tlxWriteC(0x97); // Display Mode (Cursor on, blink on, Text on, graphics off)
tlxClearScreen();
}
void tlxWriteDecimal(unsigned int data, char counter) {
char digits[5], i;
for (i=0; i<counter; i++) {
digits[i] = data % 10;
data = (data - digits[i]) / 10;
}
for (i=counter; i>0; i--) {
tlxWriteCharInc( digits[i-1] + 0x10 );
}
}
Where the basic commands are:
tlxWaitUntilFree - status checking
tlxWriteData - write a data byte
tlxReadData - read a data byte
tlxWriteCommand - write a command byte
it's very frustrating, any help very gratefully appreciated!