CFAF240320P problems

sch0bert

New member
Hello,

I'm working with the CFAF240320P LCD, fist I used the demostration code that you give but it doesnt work. After reading the controler datasheet I did a new code but I have some problems.

This is my initialization like it says in the datasheet (block diagram for turning it on). I'm working with a 16 bits interface by the way.

void initialization()
{

SET_RD;
SET_WR;
SET_CS;
SET_CD;
PTBD=0x00; // all data lines low
PTED=0x00; // all data lines low

CLR_RESET;
delay(10000);
delay(10000);
SET_RESET;
delay(500);

write_command(0x0003); // Power control (1)
write_data(0xA8A4);
delay(500);

write_command(0x000c); // Power control (2)
write_data(0x0004);
delay(500);

write_command(0x000D); // Power control (3)
write_data(0x000f);
delay(500);

write_command(0x000E); // Power control (4)
write_data(0x0000);
delay(500);

write_command(0x001E); // Power control (5)
write_data(0x0000);
delay(500);


write_command(0x0007); // Display control
write_data(0x0021); // GON = 1 DTE = 0
delay(500); // D[1:0] = 01 The internal display is performed although the display is off


write_command(0x0000); // Oscillation Start
write_data(0x0001); // The oscillator will be turned on when OSCEN = 1, off when OSCEN = 0
delay(500);

write_command(0x0007); // Display control
write_data(0x0023); // GON = 1 DTE = 0
delay(500); // D[1:0] = 11

write_command(0x0010); // Sleep Mode
write_data(0x0000);
delay(10000); // Wait 30 ms

write_command(0x0007); // Display control
write_data(0x0033); // GON = 1 DTE = 1
delay(500); // D[1:0] = 11

write_command(0x0011); // Entry mode
write_data(0x6F38);
delay(500);

write_command(0x0002); // LCD Drive AC control
write_data(0x06FF);
delay(500);

write_command(0x0001); // Driver output control
write_data(0x433F);
delay(500);
}

It do paint the screen but it does it slow, now Im painting windows colors in differents areas of the screen but the color arent the ones I suppose to be.

This is how I write the data and the commands, if I put the delays it becomes slower and in the end it do the same.

void write_command(unsigned int command)
{

PTBD= (unsigned char)(command & 0x00FF);
PTED= (unsigned char)(command>>8);

CLR_CD;
CLR_WR;
CLR_CS;
SET_RD;

// delay(10);

//SET_WR;
// delay(1000);
__RESET_WATCHDOG(); /* feeds the dog */
// delay(1000);

SET_CS;
SET_WR;
// delay(1000);
}

/*************************************************/
void write_data(unsigned int data)
{

PTBD=(unsigned char)(data & 0x00FF);
PTED=(unsigned char)(data>>8);


SET_CD;
CLR_WR;
CLR_CS;
SET_RD;


// delay(10);

//CLR_WR;
// delay(1000);
__RESET_WATCHDOG(); /* feeds the dog */
// delay(1000);

SET_CS;
SET_WR;
//delay(1000);
}

I'm painting the LCD with this colors,

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF

BUT, every time i paint black its looks white, blue is looks like blue sky, green looks like white also and the red looks like yellow.

Is there any other changes or things I have to do before painting, or am I do it something wrong?
Does anybody have a code that do work?

Help,
Pascal.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Code:
	write_command(0x0001);        // Driver output control
	write_data(0x433F);
... the color arent the ones I suppose to be.... BUT, every time i paint black its looks white, blue is looks like blue sky, green looks like white also and the red looks like yellow.
Try different combinations of the "RL", "REV", and "BGR" bits in register 0x0001.
 

sch0bert

New member
Pixel Paint

I found the error, it was a bad conection pin. Now Im looking foward to paint a sigle pixel anywhere I want, how can I paint one without painting the full screen?

I'm tried changing the x and y (R4E and R4F) but it always move all the screen to that posicion and it takes it as the first position

void PaintPixel(unsigned int X, unsigned int Y, unsigned int color){


write_command(0x004E); // X address set
write_data(0);
write_command(0x004F); // Y Address set
write_data(0);

write_command(0x0044); // horizontal RAM address position
write_data(((X<<8)|(X&0x00FF)));
write_command(0x0045); // vertical RAM address position
write_data(Y);
write_command(0x0046); // vertical RAM address position
write_data(Y);

write_command(0x0022); //RAM data write

write_data(color);
}
 
Do not change registers 0x0044, 0x0045, and 0x0046; they should stay at the initial values, I think, as that determines the screen window addresses.

Just change registers 0x004E and 0x004F to set the X and Y cursor location.
Code:
void PaintPixel(unsigned int X, unsigned int Y, unsigned int color){
    write_command(0x004E);   // X address set
    write_data(X);
    write_command(0x004F);   // Y Address set
    write_data(Y);
    write_command(0x0022);   //RAM data write
    write_data(color);
}
 

sch0bert

New member
Do not change registers 0x0044, 0x0045, and 0x0046; they should stay at the initial values, I think, as that determines the screen window addresses.

Just change registers 0x004E and 0x004F to set the X and Y cursor location.
Code:
void PaintPixel(unsigned int X, unsigned int Y, unsigned int color){
    write_command(0x004E);   // X address set
    write_data(X);
    write_command(0x004F);   // Y Address set
    write_data(Y);
    write_command(0x0022);   //RAM data write
    write_data(color);
}

I put this on main

for(;dinamicX>100;dinamicX++,dinamicY++){

PaintPixel(dinamicX,dinamicY,RED);
}

where dinamicX and Y started in 0. The result was that it start painting a vertical line and every time that dinamicY was added 1, it moved the full line down. I was hoping for a transversal line going down, that's why I said before that the full screen moves moving to the 4E and 4F registers
 
... for(;dinamicX>100;dinamicX++,dinamicY++) ...
If X and Y start at 0, this code will never execute.

Have you tried using the initialization code from the CFA sample file? You should do that. I see that you do not have any settings for registers 44 ~ 4B.
Code:
    write_command(0x0044);    //Horizontal RAM end and start address
    write_data(0xEF00);       // 239, 0
    write_command(0x0045);    //Vertical RAM start address
    write_data(0x0000);
    write_command(0x0046);    //Vertical RAM end address
    write_data(0x013F);       //  319
    write_command(0x0048);   // first window start
    write_data(0x0000);
    write_command(0x0049);   // first window end
    write_data(0x013F);
    write_command(0x004A);   // first window start
    write_data(0x0000);
    write_command(0x004B);   // first window end
    write_data(0x013F);
After that, you should only need to set 4E and 4F for pixel address.
 

sch0bert

New member
oohhh! sorry, is < hehe i didnt copied that from the code that im using. After adding this

write_data(0xEF00); // 239, 0
write_command(0x0045); //Vertical RAM start address
write_data(0x0000);
write_command(0x0046); //Vertical RAM end address
write_data(0x013F); // 319
write_command(0x0048); // first window start
write_data(0x0000);
write_command(0x0049); // first window end
write_data(0x013F);
write_command(0x004A); // first window start
write_data(0x0000);
write_command(0x004B); // first window end
write_data(0x013F);

in main, i could paint the pixels i wanned. Thank you!!
 
Last edited:
Top