• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

CFAG160160B Problems

Corinne

New member
I am programming the CFAG160160 Graphic LCD... I tested it by just displaying simple ABC in the 1st line. All i get is just black strobing in the screen... i have the correct hardware... the pin1 and pin 2 are grounded right? I connected the FGND in the ground as stated in the other thread...

i used zilog encore in programming this... here is the sample of my program... what am i doing wrong?
Code:
#include <stdio.h>
#include <eZ8.h>

/***************************************************************************************************/
/*                                       GPIO Initialization                                       */
/***************************************************************************************************/
void GPIOinit(void)
{
    PGAF = 0x00;        // Port G, alternate function not used
    PGDD = 0x00;        // Data Direction, Output
    
    PFAF = 0x00;        // Port F, alternate function not used
    PFDD = 0x00;        // Data Direction, Output


    /*
    LCD GPIO

        LCD input           RW  RS  DB7:0
        Zilog output        PC3 PC2 PE7:0

        LCD input           enable    reset   chipenable
        Zilog output         PC7       PC6       PC5            
                             '1'       '0'       '0'
    
        from SMSpic         RB3 RB2 RB1 RB0
        to Zilog input      PD7 PD5 PD3 PD1
    */
    PDAF = 0x00;        // Port C, alternate function not used
    PDDD = 0xFF;        // Data Direction, Input    
    
    PCAF = 0x00;        // Port C, alternate function not used
    PCDD = 0x00;        // Data Direction, Output

    PEAF = 0x00;        // Port E, alternate function not used
    PEDD = 0x00;        // Data Direction, Output

}
/*-------------------------------------------------------------------------------------------------*/


main()
{
        GPIOinit();
        
        PCOUT = 0X84; PEOUT = 0x01;
        PCOUT = 0x80; PEOUT = 0X87;

        PCOUT = 0X84; PEOUT = 0x02;
        PCOUT = 0x80; PEOUT = 0x13;
    
        PCOUT = 0X84; PEOUT = 0x03;
        PCOUT = 0x80; PEOUT = 0XA0;

        PCOUT = 0X84; PEOUT = 0x04;
        PCOUT = 0x80; PEOUT = 0x07;

        PCOUT = 0X84; PEOUT = 0x0A;
        PCOUT = 0x80; PEOUT = 0X00;

        PCOUT = 0X84; PEOUT = 0x0B;
        PCOUT = 0x80; PEOUT = 0x00;





        PCOUT = 0X84; PEOUT = 0x0C;
        PCOUT = 0x80; PEOUT = 0x41;

        PCOUT = 0X84; PEOUT = 0x0C;
        PCOUT = 0x80; PEOUT = 0X42;

        PCOUT = 0X84; PEOUT = 0x0C;
        PCOUT = 0x80; PEOUT = 0x43;

}
PCOUT = 0x84 and PCOUT = 0x80 configuration is like this
PC7 - Enable
PC6 - Reset
PC5 - CS
PC4 - X (don't care)
PC3 - R/W
PC2 - RS
PC1 - X
PC0 - X

since i have to access the instruction reg first, R/W is 1 therefore 0x84

then when instructing the mode reg. R/W is 0 => 0x80

please help.. what am i doing wrong? nobody in my school has ever used graphic LCD display. I don't have anyone to ask for help for this.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

CF Tech

Administrator
Thank you for your post. First, let us verify the voltages:

Pin 1 = FGND = 0
Pin 2 = Vss = 0
Pin 3 = Vdd = 5v
Pin 4 = Vo = -12.4v
Pin 5 = R/W = 0 (for this example, can be connected to a processor port that driven low)
Pins 6 to 8 and 10 to 18: Connected to processor pins (see the macros below).

Please note that pin 4 is 12.4v negative, you can use the negative voltage output from pin 20 and a potentiometer to create the -12.4v.

Second, I do not see any delays in your code. Here is the initialization snippet from the sample code that you ater trying to emulate:
Code:
//Sleep(x) delays for x miliseconds. You must create this function.


//These are macros we use to "hide" the PC's parallel poet. You must
//create equivalent macros for your processor:

#define SET_CS (DlPortWritePortUchar(CONT_ADDR,(control|=0x02)))
#define CLR_CS (DlPortWritePortUchar(CONT_ADDR,(control&=~0x02)))
  
#define SET_RS (DlPortWritePortUchar(CONT_ADDR,(control|=0x04)))
#define CLR_RS (DlPortWritePortUchar(CONT_ADDR,(control&=~0x04)))

#define SET_RES  (DlPortWritePortUchar(CONT_ADDR,(control|=0x08)))
#define CLR_RES  (DlPortWritePortUchar(CONT_ADDR,(control&=~0x08)))

#define SET_E (DlPortWritePortUchar(CONT_ADDR,(control|=0x01)))
#define CLR_E (DlPortWritePortUchar(CONT_ADDR,(control&=~0x01)))

#define DATA(x) (DlPortWritePortUchar(DATA_ADDR,(x)));(Sleep(1))

//Function to write a byte to the command register
void COM_W(ubyte data)
  {
  DATA(data);
  SET_RS;
  CLR_CS;
  //R/W is hardwired low
  Sleep(10);
  SET_E;
  Sleep(10);
  CLR_E;
  Sleep(10);
  SET_CS;
  }

//Function to write a byte to the data register
void DATA_W(ubyte data)
  {
  DATA(data);
  CLR_RS;
  CLR_CS;
  //R/W is hardwired low
  Sleep(10);
  SET_E;
  Sleep(10);
  CLR_E;
  Sleep(10);
  SET_CS;
  }

//Function to write a specific byte to a specific the command register
void CP_COMMAND(ubyte comm_reg, ubyte data_reg)
  {
  COM_W(comm_reg);
  DATA_W(data_reg);
  }

//Function to initialize the display
void initialize(void)
  {
  //Idle the control lines & reset the display
  CLR_RES;
  CLR_E;
  CLR_RS;
  SET_CS;
  DATA(0);
  Sleep(10);
  SET_RES;
  Sleep(10);

  //MOV     COMM_REG,#00H           ;Command code--Mode control
  //MOV     DATA_REG,#32H           ;Set 00110010
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x00,0x32);

  //MOV     COMM_REG,#01H           ;Character pitch setting
  //MOV     DATA_REG,#77H           ;Set 10010111
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x01,0x77);

  //MOV     COMM_REG,#02H           ;Character number setting
  //MOV     DATA_REG,#19            ;160/8=20 Char in one line
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x02,19);

  //MOV     COMM_REG,#03H           ;Display duty setting
  //MOV     DATA_REG,#MaxRow_1      ;Set 1/160 duty
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x03,159);

  //MOV     COMM_REG,#08H           ;Display low address setting
  //MOV     DATA_REG,#00H           ;Low address start from 00H
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x08,0x00);

  //MOV     COMM_REG,#09H           ;Display high address setting
  //MOV     DATA_REG,#00H           ;High address start from 00
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x09,0x00);

  //FULLON:
  //MOV     COMM_REG,#0AH           ;Cursor low address setting
  //MOV     DATA_REG,#00H           ;Low address start from 00H
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x0A,0x00);

  //MOV     COMM_REG,#0BH           ;Cursor high address setting
  //MOV     DATA_REG,#00H           ;High address start from 00
  //LCALL   CP_COMMAND              ;Command complete
  CP_COMMAND(0x0B,0x00);

  //The display is initialized, write a pattern to it.
  int
    row,col;
  CLR_CS;
  //Send data command
  DATA(0x0C);
  SET_RS;
  //R/W is hardwired low
  SET_E;
  Sleep(1);
  CLR_E;
  CLR_RS;
  for(row=0;row<=159;row++)
    for(col=0;col<=19;col++)
      {
      DATA(row+col);
      //R/W is hardwired low
      SET_E;
      CLR_E;
      }
  SET_CS;
  }
 

Corinne

New member
thnaks a lot CF Tech... you really have an efficient support system...

just have some clarifications...

in your datasheet... it is written there in the electrical characteristics that supply voltage for LCD, Vo - Vdd is min at 15.4V and Max at 19.4 volts... I'm just confused on what I am really going to use. the -12.4 or the one in the datasheet...

I am already using a potentiometer between the Vdd, Vo and the Vee.
 
The LCD voltage is a combination of the Vdd, +5V, and the Vee voltage through the pot. So with -12.4V at the Vo pin, the total LCD voltage is 17.4V [Vdd - Vo], which is the typical data sheet spec value.
 

Corinne

New member
i still get black strobing lights... what's wrong? I did everything that you guys told me. hardware is perfectly woking... but simple letter A still doesn't come out!
 
Last edited:

CF Tech

Administrator
Does the code I suggested show a pattern? It should be a set of almost curvy alternating bars (counting in binary).

Sometimes modules get damaged in prototyping situations. If you think the module is fried somehow, please write support(at}crystalfontz{dot)com (edit to '@' & '.') and we will see if we can arrange something for you. Please reference this forum post when you write.
 

Corinne

New member
how do i know it's fried? there's a black strobing lights when turn it on. is that OK? My god I only have three days left...

I used this code... I don't have any microcontroller with assembly language. I can't test your program. I patterned it from the one posted in the other thread.
Code:
void delay (loop)
{
	int i, j, k;
	for (k = 0; k <= loop; k++)
	{
		for (i = 0x00; i <= 0xFF; i++)
		{
			for (j = 0x00; j <= 0xff; j++)
			{
			}
		 }
   }
}



void writeinput(int instruction, int data)
{
    int busyflag;
	//int pctemp, petemp;


	//PCOUT = 0x00;
	//PEOUT = 0x00;
    busyflag = 0x80; 			//7th byte ON. Just to enter WHILE

    PCOUT |= 0x20;			 	// CS = 1; Display CS
	PCOUT |= 0x80;				// PORTBbits.RB3 = 1; Enabled = 1; (Activate)
	PCOUT |= 0x04;				// PORTBbits.RB0 = 1; RS = 1
	PCOUT &= 0xF7;				// PORTBbits.RB1 = 0; RW = 0 (writting)

    /* Write Instruction */
    PEOUT = instruction;		// PORTD = instruction; // I wrote the instruction
    PCOUT &= 0xDF;				// CS = 0; //Enable Display
	delay(320);					// Delay10TCYx(1); Wait 320ns. 
    PCOUT |= 0x20;			    // CS=1; Disable Display
    PCOUT &= 0x7F;				// PORTBbits.RB3 = 0; //Enabled = 0 (Deactivate)

    /* Write Data */
	PCOUT &= 0xFB;				// PORTBbits.RB0 = 0; //RS = 0
	PEOUT = data; 				// PORTD = data; //Writes Data
	PCOUT &= 0xDF;				// CS = 0;
	PCOUT |= 0x80;				// PORTBbits.RB3 = 1; //Enabled = 1; (Activate)
	delay(320);					// Delay10TCYx(1);  //Wait 320ns.
	PCOUT &= 0x7F;				// PORTBbits.RB3 = 0; //Enabled=0; (Deactivate)
	PCOUT |= 0x20;				// CS=1; //Disable Display

    /* Readin "Busy" Flag */
   	PCOUT |= 0x04;				// PORTBbits.RB0 = 1; //RS = 1
	PCOUT |= 0x08;				// PORTBbits.RB1 = 1; //R/W = 1 (reading)
    
								
	// TRISD = 0xFF; //Port D as Inputs
    while (busyflag == 0x80)
	{
        PCOUT &= 0xDF;			// CS = 0;
        PCOUT |= 0x80;			// PORTBbits.RB3 = 1; //Enable = 1 (Activate)
        delay(16);				// Delay1TCY();  //Wait 16ns;
		delay(16);				// Delay1TCY();  //Wait 16ns;
    
        busyflag = 0x00;
        busyflag = (busyflag & 0x80); //Just Reading 7th. bit
    
        PCOUT &= 0x7F;			// PORTBbits.RB3 = 0; //Enable = 0 (Deactivate)
        PCOUT |= 0x20; 			// CS=1; //Disable Display
        delay(1600);				// Delay10TCYx(1);  //Wait 160ns
    }
}




main()
{
	GPIOinit();
		
	writeinput(0x00,0x12); //Display OFF (during initialization)
    writeinput(0x01,0x87);
    writeinput(0x02,0x13);
    writeinput(0x03,0xA0);
    writeinput(0x04,0x07);
    writeinput(0x0A,0x00);
    writeinput(0x0B,0x00);

    //Erase all video memory (3.2Kbytes)
    //for(i=0;i<3200;i++)
    //    writeinput(0x0C,0x00); 

    /* Puts into memory position 0,0*/
    writeinput(0x0A,0x00);
    writeinput(0x0B,0x00);
    //writeinput(0x00,0x32); //Turn ON display, graphic mode

	writeinput(0x00,0x38); //Turn ON display, text mode
    writeinput(0x0C,0x41); //Displays "A"



}
 

CF Tech

Administrator
Those are just standard "C" macros I used, not assembly language. If you look carefully inside the macros you will just see that they only contain "C" statements that set or clear and single bit.

Your code just needs to move the control lines in the sequence shown in my code. If the hardware is not damaged, it will work.

What is flashing? Is it the backlight or the pixels?
 

Corinne

New member
how do i know it's the backlight?

when I turn it On, black stright lines apear. sometimes it's moving, sometimes it's just steady...
 
It looks like you have bit PC6 connected as the RESET signal, and it is always low. That would seem to hold the controller chip reset at all times. I think the reset bit needs to go high before you start the init sequence.

You have to finish this in 3 days?? Yikes!

Afterthought: you don't need to dynamically change the CS pin, unless something else is using the same data bus port (PORTE). Just tie it low to save code.

If you are using long delays, you probably don't need to test the busy flag. Your busy test routine never reads the actual bus data, so it should be:
Code:
busyflag = (PEOUT & 0x80); //Just Reading 7th. bit
but it looks like you aren't changing the DDR either, so there is no busy test being done(?).
 
Last edited:

CF Tech

Administrator
I agree with cosmicvoid. Don't try to mess around with reading the busy bit--instead use a longer delay.

It could be that your code is hanging up on the busy check and never going any farther.

You can tell if it's the backlight because the light being emitted from the screen would be flickering. If all that is changing are the black lines on the screen then it's not the backlight.

The reason I wanted to know if it was the backlight, is that I was trying to figure out if perhaps there was some kind of power supply problem.
 

Corinne

New member
i deleted the busyflag already but still nothing appears.

as soon as the power is turned on flickering blackligh appears. do you think is the power problem?
 
You mean that perhaps the backlight draws so much current that it is loading down your supply, and the zilog cpu might be resetting? Why not try disconnecting the backlight... you should still be able to see the pixels without it.
 

Corinne

New member
the only thing shown in my LCD right now are pixeled straight lines... what is wrong now? is my LCD fried?
 
Last edited:
I don't suspect that it is fried. I rather think that either:

1) there is a wiring error in the control signals or data bus, or

2) that your software is still not putting out the correct control signals, or

3) that your initialization data values are putting the display into the wrong mode or wrong parameters.

Do you have access to test equipment, such as an oscilloscope? Do you have a way to debug your program by single-stepping through it?

Have you tried using CF Tech's sample program to use graphic mode? That is known to work.

P.S. Have you checked your PMs?
 
Well, it turns out that your code was not the real problem, but that your wiring was wrong for the control port. This code works OK for text mode. Meanwhile, I have duplicated your hardware setup, thanks to a very generous offer from CF Tech to supply a demo sample of the CFAG160160B. I've been working on some routines for line drawing, and porting my bitmap font work to this row-oriented display. I will post my new font editor and C driver code in the 3rd Party Software forum shortly. Here is a sample of my experiments.

BTW, the C code and font stuff for this display is posted here:
https://forum.crystalfontz.com/showthread.php?s=&threadid=4465
 

Attachments

Last edited:

vado

New member
Corrine. I have the exact problem. Sometimes a strobing line, sometimes 3 vertical liens that travel down the right hand side of the screen.

I have been trying for weeks to remedy this but have not come up with anything yet.

I am using a Phillips P89LPC922 mircrocontroller. (8051 based) running at 12 Mhz

Edit:, wrote this post before checking cosmics code. I will translate that to work with my MCU and report back :D.

Corrine, please post to say if it is the code or hardware .

Thanks
 
Top