Hi!
I've got some problems with the initialisation my graphics display (resolution 240x128) with the t6963 controller. i'm using an Infineon XC800 controller. the reset works, but after that nothing shows up at the display except some senseless crap (but only sometimes - in most cases there is nothing to see).
Does anybody have experience with the XC800 Controller and t6963-displays?
Here is the code:
Code:
//************************************************************************
// T6963.C
// LowLevel Routinen für LCD-Displays mit T6963
//************************************************************************
#include <t6963.h>
#include <io.c>
#include <io.h>
#include <MAIN.H>
unsigned char LCD_STAT; // Status-Byte
unsigned char LCD_DATA;
unsigned char LCD_CMD;
unsigned int t;
unsigned int i;
/**** LCD-Display-Routinen **********************************************/
void lcd_init(void)
{
P1_0 = 1;
P1_1 = 1;
P1_2 = 1;
P1_3 = 1;
P1_5 = 0;
for(i = 0; i< 1000;i++);
//IO_vSetPin(P1_5);
P1_5=1;
for(i = 0; i< 1000;i++);
// ca. 125us. Reset
// LCD_RST_H(); // Display Reset fertig
lcd_send_data(G_BASE%256);
lcd_send_data(G_BASE>>8);
lcd_send_cmd(0x42); // set graphics memory to address G_BASE
lcd_send_data(BYTES_PER_ROW%256);
lcd_send_data(BYTES_PER_ROW>>8);
lcd_send_cmd(0x43); // n bytes per graphics line
lcd_send_data(T_BASE%256);
lcd_send_data(T_BASE>>8);
lcd_send_cmd(0x40); // text memory at address T_BASE
lcd_send_data(BYTES_PER_ROW%256);
lcd_send_data(BYTES_PER_ROW>>8);
lcd_send_cmd(0x41); // n bytes per text line
lcd_send_cmd(0x81); // mode set: Graphics OR Text, ROM CGen
lcd_send_cmd(0xa7); // cursor is 8 lines high
lcd_send_data(0x00);
lcd_send_data(0x00);
lcd_send_cmd(0x21); // put cursor at (x,y) location
lcd_send_cmd(0x9C);
lcd_clear_text();
lcd_clear_graph();
// (For cursor to be visible, need to set up position
} // Display's loeschen
void lcd_status(void)
{
P3_DIR = 0x00;
P1_0 = 0;
P1_3 = 1; // Commando High
P1_1 = 0; // Read Low
P1_2 = 0; // Chip Enable Low
LCD_STAT = P3_DATA; // Status lesen
for(t = 0; t<100;t++);
P1_2 = 1; // Chip Enable High
P1_1 = 1; // Read High
LCD_STAT &= (0x03); // Bits ausmaskieren
P3_DIR = 0xff;
/*P3_DATA=LCD_STAT;
for(i = 0; i<1000;i++){
for(t = 0; t<1000;t++);}
P3_DATA = 0;
for(i = 0; i<1000;i++){
for(t = 0; t<1000;t++);}*/
}
void lcd_status_am(void)
{
P3_DIR = 0x00;
P1_0 = 0;
P1_3 = 1; //Commando High
P1_1 = 0; // Read Low
P1_2 = 0; // Chip Enable Low
LCD_STAT = P3_DATA; // Status lesen
for(t = 0; t<100;t++);
P1_2 = 1; // Chip Enable High
P1_1 = 1; // Read High
LCD_STAT &= (0x03); // Bits ausmaskieren
P3_DIR = 0xff;
}
void lcd_send_cmd(char cmd) // Commando an Display senden
{
do
{
lcd_status();
}
while (LCD_STAT != 0x03);
P3_DIR = 0xFF;
//DATA_DIR_OUT(); // Port 2 als Ausgang
P3_DATA = cmd; //LCD_WRITE = cmd;
P1_3 = 1; // Commando High
P1_1 = 1; //Read Low
P1_0 = 0; // Write Low
P1_2 = 0; // Chip Enable Low
for(t = 0; t<100;t++);
P1_2 = 1; // Chip Enable High
P1_0 = 1; // Write High
// P3_DATA=P0_DATA;
/*for(i = 0; i<1000;i++){
for(t = 0; t<1000;t++);}
P3_DATA = 0;
for(i = 0; i<1000;i++){
for(t = 0; t<1000;t++);}*/
}
void lcd_send_data(char dat) // Daten an Display senden
{
do
{
lcd_status();
}
while (LCD_STAT != 0x03);
P3_DIR = 0xFF; // Port 2 als Ausgang
P1_3 = 0; // Commando High
P1_0 = 0; // Write Low
P3_DATA = dat;
P1_2 = 0; // Chip Enable Low
for(t = 0; t<100;t++);
P1_2 = 1; // Chip Enable High
P1_0 = 1; // Write High
//P3_DATA=P0_DATA;
/*for(i = 0; i<1000;i++){
for(t = 0; t<1000;t++);}
P3_0 = 0;
for(i = 0; i<1000;i++){
for(t = 0; t<1000;t++);} */
}
void lcd_send_data_am(char dat) // Daten an Display senden
{
do
{
lcd_status_am();
}
while (LCD_STAT != 0x03);
P3_DIR = 0xFF; // Port 2 als Ausgang
P3_DATA = dat;
for(t = 0; t<100;t++);
P1_3 = 0; // Daten Low
P1_0 = 0; // Write Low
P1_2 = 0; // Chip Enable Low
for(t = 0; t<100;t++);
P1_2 = 1; // Chip Enable High
P1_0 = 1; // Write High
//P3_DATA=dat;
for(t = 0; t<100;t++);
}
/*
void lcd_printp(const char *progmem_s, char adress_h, char adress_l)
{
char c;
lcd_send_data(adress_l);
lcd_send_data(adress_h);
lcd_send_cmd(0x24);
lcd_send_cmd(0xB0);
while ( (c = pgm_read_byte(progmem_s++)))
{
lcd_send_str(c);
}
lcd_send_cmd(0xB2);
}
*/
void lcd_print(int x,int y,char *string) // send string of characters to LCD
{
int i;
int c;
lcd_xy(x,y);
for (i=0;string[i]!=0;i++) {
c = string[i] - 0x20; // convert ASCII to LCD char address
if (c<0) c=0;
lcd_send_data(c);
lcd_send_cmd(0xc0); // write character, increment memory ptr.
} // end for
} // end lcd_string
void lcd_xy(int x, int y) // set memory pointer to (x,y) position (text)
{
int addr;
addr = T_BASE + (y * BYTES_PER_ROW) + x;
lcd_set_address(addr); // set LCD addr. pointer
} // lcd_xy()
/*
void lcd_print(char *txt, char adress_h, char adress_l)
{
char c;
lcd_send_data(adress_l);
lcd_send_data(adress_h);
lcd_send_cmd(0x24);
while((c = *txt)) //Solange Zeichen groeßer 0x00
{
txt++; //Naechstes Zeichen
if (c == 0) break; //Raus wenn Zeichen gleich 0
lcd_send_str(c);
lcd_send_cmd(0xc0);
}
}
*/
void lcd_send_str(unsigned char lcd_dat)
{
lcd_dat -= 0x20; // 20h subtrahieren da Display nicht ASCII
lcd_send_data_am(lcd_dat); // Daten an Display senden
}
void lcd_clear_graph() // clear graphics memory of LCD
{
int i;
lcd_set_address(G_BASE); // addrptr at address G_BASE
for (i=0;i<3840;i++) { // must be 3840 ????????????????? 5120
lcd_send_data(0); lcd_send_cmd(0xc0); // write data, inc ptr.
} // end for(i)
} // end lcd_clear_graph()
//----------------------------------------------------------------
void lcd_clear_text()
{
int i;
lcd_set_address(T_BASE); // addrptr at address T_BASE
for (i=0;i<480;i++) { // must be 480 ??????????? 640
lcd_send_data(0); lcd_send_cmd(0xc0); // write data, inc ptr.
} // end for(i)
} // lcd_clear_text()
//-------------------------------------------------------------------------------
void lcd_set_address(unsigned int addr){
lcd_send_data(addr%256);
lcd_send_data(addr>>8);
lcd_send_cmd(0x24);
}
/*
void lcd_printg(const char *progmem_s, char adress_h, char adress_l)
{
unsigned int length =5120; //< dieses ist die Bildgroesse in Bytes
unsigned char c;
lcd_send_data(adress_l);
lcd_send_data(adress_h);
lcd_send_cmd(0x24);
lcd_send_cmd(0xB0);
while (length !=0) //es wird ein Bild in der Groesse 128*64 Pixel
{ //mit Font 6*8 angezeigt
c = pgm_read_byte(progmem_s++);
lcd_send_strg(c);
length--;
}
lcd_send_cmd(0xB2);
}
*/
void lcd_send_strg(unsigned char lcd_dat)
{
lcd_send_data(lcd_dat); // Daten an Display senden
}
void lcd_setpixel(int column, int row) // set single pixel in 240x64 array
{
int addr; // memory address of byte containing pixel to write
if( (column>=XMAX) || (row>=YMAX) )return;
addr = G_BASE + (row*BYTES_PER_ROW) + (column/8);
lcd_set_address(addr); // set LCD addr. pointer
lcd_send_cmd(0xf8 | ((7-column%8)) ); // set bit-within-byte command
}
void lcd_clrpixel(int column, int row)
{
int addr; // memory address of byte containing pixel to write
if( (column>=XMAX) || (row>=YMAX) )return;
addr = G_BASE + (row*BYTES_PER_ROW) + (column/8);
lcd_set_address(addr); // set LCD addr. pointer
lcd_send_cmd(0xf0 | ((7-column%8)) ); // set bit-within-byte command
}
//--------------------------------------------------------------------------------
void lcd_print_ram(int x,int y,char *string) // send string of characters to LCD
{
int i;
int c;
lcd_xy(x,y);
for (i=0;string[i]!=0;i++) {
c = string[i] - 0x20; // convert ASCII to LCD char address
if (c<0) c=0;
lcd_send_data(c);
lcd_send_cmd(0xc0); // write character, increment memory ptr.
} // end for
} // end lcd_string
//---------------------------------------------------------------------------------
void show(char * s,int start_line,int how_many_line){
int addr,i;
addr = G_BASE +start_line*30;
lcd_set_address(addr); // set LCD addr. pointer
lcd_send_cmd(0xB0);
for(i=0;i<how_many_line*30;i++){
lcd_send_data(s[i]);
}
lcd_send_cmd(0xB2);
}
//---------------------------------------------------------------------------------
void lcd_pixel(int column, int row,char show)
{
int addr; // memory address of byte containing pixel to write
if( (column>=XMAX) || (row>=YMAX) )return;
addr = G_BASE + (row*BYTES_PER_ROW) + (column/8);
lcd_set_address(addr); // set LCD addr. pointer
if(show)
lcd_send_cmd(0xf8 | ((7-column%8)) ); // set bit-within-byte command
else
lcd_send_cmd(0xf0 | ((7-column%8)) ); // set bit-within-byte command
}
//---------------------------------------------------------------------------------
/*****************************************************************************
Name: Int To Ascii Hex
Parameters:
dest_string
Pointer to a buffer will the string will reside
min_digits
Specifies the minimum number of characters the output string will
have. Leading zeros will be written as '0' characters.
Returns:
A pointer to the string's NULL character in the string that was just
created.
Description:
This function is used to convert a passed unsigned int into a ASCII
string represented in Hexidecimal format.
*****************************************************************************/
/*
char * IntToAsciiHex(char * dest_string,int min_digits,unsigned int value)
{
unsigned int i, total_digits = 0;
char buff[4];
for(i=0;i<4;i++)
{
buff[i] = (char)(value & 0x0F);
value = value >> 4;
if( buff[i] <= 9)
buff[i] += '0';
else
buff[i] = (char)(buff[i] - 0xA + 'A');
if(buff[i] != '0')
total_digits = i+1;
}
if( total_digits < min_digits)
total_digits = min_digits;
i = total_digits;
while(i)
{
*dest_string++ = buff[i-1];
i--;
}
*dest_string = 0;
return dest_string;
}
*/
/*****************************************************************************
Name: Int To Ascii Dec
Parameters:
dest_string
Pointer to a buffer will the string will reside
min_digits
Specifies the minimum number of characters the output string will
have. Leading zeros will be written as '0' characters.
Returns:
A pointer to the string's NULL character in the string that was just
created.
Description:
This function is used to convert a passed unsigned int into a ASCII
string represented in base 10 decimal format.
*****************************************************************************/
/*
char * IntToAsciiDec(char * dest_string,int min_digits,unsigned int value)
{
const unsigned long base10[] = {1,10,100,1000,10000,100000};
unsigned int tmp;
unsigned int i, total_digits = 0;
char buff[5];
for(i=0;i<5;i++)
{
tmp = (int)( value % base10[i+1] );
value -= tmp;
buff[i] = (char)( tmp / base10[i] );
buff[i] += '0';
if(buff[i] != '0')
total_digits = i+1;
}
if( total_digits < min_digits)
total_digits = min_digits;
i = total_digits;
while(i)
{
*dest_string++ = buff[i-1];
i--;
}
*dest_string = 0;
return dest_string;
} */
thanks for the help